plinkit 1.0.0-dev.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -91
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +10 -32
- package/dist/index.es.js +1444 -1609
- package/dist/plinkit.umd.js +4 -4
- package/package.json +5 -5
package/dist/plinkit.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Z,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(Z=typeof globalThis<"u"?globalThis:Z||self,j(Z.Plinkit={}))})(this,function(Z){Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"});var j=(d,E)=>()=>(E||(d((E={exports:{}}).exports,E),d=null),E.exports),Ce=35,Me=24,Te=.08,Be=6,Ee=.85,ce=.7,Ae=.16,Ie=.92,Le=256,Re=1e3,ke=class{ctx=null;masterGain=null;buffers=new Map;lastHitByBall=new Map;activePegVoices=0;muted;volume;destroyed=!1;unlockedOnce=!1;pendingUiTap=!1;gestureCleanup=null;visibilityCleanup=null;config;constructor(d){this.config=d,this.muted=d.muted,this.volume=he(d.masterVolume),this.installGestureUnlock(),this.installVisibilityHandler()}setMuted(d){this.muted=d,this.masterGain&&(this.masterGain.gain.value=d?0:this.volume),d||this.tryUnlock()}isMuted(){return this.muted}setVolume(d){this.volume=he(d),this.masterGain&&!this.muted&&(this.masterGain.gain.value=this.volume)}resume(){this.tryUnlock()}playPegHit(d,E){if(this.destroyed||this.muted||!this.unlockedOnce)return;const T=this.ctx;if(!T)return;const A=T.currentTime*1e3,f=this.lastHitByBall.get(d);if(f!==void 0&&A-f<Ce||(this.lastHitByBall.set(d,A),this.maybeCleanupLastHits(A),this.activePegVoices>=Me))return;const e=Math.max(Te,Math.min(1,E/Be));this.playSample("peg",e,!0)}playBucketHit(){this.playSample("bucket",Ee,!1)}playUiTap(){if(!(this.destroyed||this.muted)){if(this.ensureContext(),this.unlockedOnce){this.playSample("uiTap",ce,!1);return}this.pendingUiTap=!0,this.tryUnlock()}}playSample(d,E,T){if(this.destroyed||this.muted||!this.unlockedOnce)return;const A=this.ctx,f=this.masterGain;if(!A||!f)return;const e=this.buffers.get(d);if(!e)return;const o=A.createBufferSource();o.buffer=e,o.playbackRate.value=Ie+Math.random()*Ae;const a=A.createGain();a.gain.value=E,o.connect(a),a.connect(f),T&&(this.activePegVoices+=1),o.onended=()=>{T&&(this.activePegVoices=Math.max(0,this.activePegVoices-1)),o.disconnect(),a.disconnect()},o.start()}destroy(){this.destroyed||(this.destroyed=!0,this.gestureCleanup?.(),this.gestureCleanup=null,this.visibilityCleanup?.(),this.visibilityCleanup=null,this.buffers.clear(),this.lastHitByBall.clear(),this.ctx&&(this.ctx.close().catch(ae),this.ctx=null,this.masterGain=null))}ensureContext(){if(this.destroyed||this.ctx||typeof window>"u")return;const d=window.AudioContext??window.webkitAudioContext;d&&(this.ctx=new d,this.masterGain=this.ctx.createGain(),this.masterGain.gain.value=this.muted?0:this.volume,this.masterGain.connect(this.ctx.destination),this.loadBuffers())}tryUnlock(){if(this.destroyed)return;this.ensureContext();const d=this.ctx;if(d){if(d.state==="running"){this.markUnlocked();return}d.resume().then(()=>this.markUnlocked()).catch(ae)}}markUnlocked(){this.destroyed||this.unlockedOnce||(this.unlockedOnce=!0,this.playSilentPing(),this.gestureCleanup?.(),this.gestureCleanup=null,this.pendingUiTap&&(this.pendingUiTap=!1,this.playSample("uiTap",ce,!1)))}playSilentPing(){const d=this.ctx;if(d)try{const E=d.createBuffer(1,1,Math.max(22050,d.sampleRate)),T=d.createBufferSource();T.buffer=E;const A=d.createGain();A.gain.value=1e-5,T.connect(A),A.connect(d.destination);try{T.start(0)}catch{}try{T.stop(0)}catch{}}catch{}}installGestureUnlock(){if(typeof window>"u")return;const d={passive:!0,capture:!0},E=!0,T=()=>this.tryUnlock();window.addEventListener("pointerdown",T,d),window.addEventListener("pointerup",T,d),window.addEventListener("touchstart",T,d),window.addEventListener("touchend",T,d),window.addEventListener("keydown",T,E),this.gestureCleanup=()=>{window.removeEventListener("pointerdown",T,d),window.removeEventListener("pointerup",T,d),window.removeEventListener("touchstart",T,d),window.removeEventListener("touchend",T,d),window.removeEventListener("keydown",T,E)}}installVisibilityHandler(){if(typeof document>"u")return;const d=()=>{this.destroyed||document.hidden||this.unlockedOnce&&this.ctx?.resume().catch(ae)};document.addEventListener("visibilitychange",d),this.visibilityCleanup=()=>document.removeEventListener("visibilitychange",d)}async loadBuffers(){const d=[];this.config.pegHitUrl&&d.push(this.loadBuffer("peg",this.config.pegHitUrl)),this.config.bucketHitUrl&&d.push(this.loadBuffer("bucket",this.config.bucketHitUrl)),this.config.uiTapUrl&&d.push(this.loadBuffer("uiTap",this.config.uiTapUrl)),await Promise.allSettled(d)}async loadBuffer(d,E){const T=this.ctx;if(T)try{const A=await fetch(E);if(!A.ok)return;const f=await A.arrayBuffer(),e=await T.decodeAudioData(f);this.destroyed||this.buffers.set(d,e)}catch{}}maybeCleanupLastHits(d){if(!(this.lastHitByBall.size<=Le))for(const[E,T]of this.lastHitByBall)d-T>Re&&this.lastHitByBall.delete(E)}};function he(d){return!Number.isFinite(d)||d<0?0:d>1?1:d}function ae(){}var be=class{rafId=null;step;constructor(d){this.step=d}start(){if(this.rafId!==null)return;const d=E=>{this.step(E),this.rafId=window.requestAnimationFrame(d)};this.rafId=window.requestAnimationFrame(d)}stop(){this.rafId!==null&&(window.cancelAnimationFrame(this.rafId),this.rafId=null)}};function ge(d,E){const T=d.bottomPegCount-d.topPegCount+1,A=d.radius+d.sidePaddingPx,f=(E-A*2)/Math.max(d.bottomPegCount-1,1);return{rows:T,sidePadding:A,baseSpacing:f,targetVerticalStep:f*d.verticalStepRatio}}function De(d){const{width:E,height:T,topPegCount:A}=d;if(d.bottomPegCount<A)throw new Error("bottomPegCount must be greater than or equal to topPegCount");const f=ge(d,E),e=E*.5,o=d.topPaddingPx,a=Math.max(o+60,T-d.bottomPaddingPx),r=f.rows>1?(a-o)/(f.rows-1):0,c=Math.min(f.targetVerticalStep,r),n=a-c*Math.max(f.rows-1,0),h=[];for(let l=0;l<f.rows;l++){const t=A+l,i=n+l*c,s=(t-1)*f.baseSpacing,u=e-s*.5;h.push({row:l,count:t,y:i,startX:u,rowWidth:s,leftX:u,rightX:u+s})}return{rows:f.rows,center:e,minTopY:o,bottomY:a,sidePadding:f.sidePadding,baseSpacing:f.baseSpacing,verticalStep:c,startY:n,rowAnchors:h}}function Ue(d,E){const T=[];for(const A of d.rowAnchors)for(let f=0;f<A.count;f++)T.push({x:A.startX+f*d.baseSpacing,y:A.y,radius:E});return T}function Fe(d,E,T){if(d.rows<2)return[];const A=[],f=(T.spread-1)*d.baseSpacing,e=t=>t<d.center?t-f:t>d.center?t+f:t,o=d.rowAnchors[0],a=o.leftX,r=o.rightX,c=d.startY-d.minTopY,n=E*2.5,h=Math.min(d.verticalStep,Math.max(n,c/3)),l=c>=n?Math.min(3,Math.floor(c/h)):0;for(let t=1;t<=l;t++){const i=d.startY-t*h+T.yOffset,s=a-t*d.baseSpacing*.5,u=r+t*d.baseSpacing*.5;A.push({x:e(s),y:i,radius:E},{x:e(u),y:i,radius:E})}for(let t=0;t<l;t++){const i=d.startY-t*h,s=d.startY-(t+1)*h,u=a-t*d.baseSpacing*.5,m=a-(t+1)*d.baseSpacing*.5,x=r+t*d.baseSpacing*.5,P=r+(t+1)*d.baseSpacing*.5;A.push({x:e((u+m)/2),y:(i+s)/2+T.yOffset,radius:E},{x:e((x+P)/2),y:(i+s)/2+T.yOffset,radius:E})}for(let t=0;t<d.rows-1;t++){const i=d.rowAnchors[t],s=d.rowAnchors[t+1],u=(i.y+s.y)/2+T.yOffset;A.push({x:e((i.leftX+s.leftX)/2),y:u,radius:E},{x:e((i.rightX+s.rightX)/2),y:u,radius:E})}return A}var At=600,Oe=-1,He=8;function Ve(d){const{mainPegs:E,ballRadius:T,heightPolicy:A}=d;if(We(A),ze(E),!Number.isFinite(T)||T<=0)throw new Error("ballRadius must be greater than 0");const f=ge(E,600);if(f.baseSpacing<=0)throw new Error("mainPegs produce non-positive base spacing; reduce sidePaddingPx or peg counts");const{rows:e,baseSpacing:o,targetVerticalStep:a}=f,r=a*Math.max(e-1,0),c=A.topPaddingPx,n=a*2,h=T*2+He,l=E.radius+T+Oe,t=Math.max(A.bottomPaddingPx,l+h);return{worldHeight:c+n+r+t,resolvedMainPegs:{...E,topPaddingPx:c,bottomPaddingPx:t},rows:e,baseSpacing:o,verticalStep:a,requiredBottomPaddingPx:t}}function Ne(d){const{parentWidthPx:E,viewport:T,worldHeight:A}=d;if(Ge(T),!Number.isFinite(E)||E<=0)throw new Error("Parent width must be greater than 0");if(!Number.isFinite(A)||A<=0)throw new Error("World height must be greater than 0");const f=E;return{displayWidth:f,displayHeight:f*(A/600),worldScale:f/600}}function We(d){if(!Number.isFinite(d.topPaddingPx)||d.topPaddingPx<0)throw new Error("viewport.heightPolicy.topPaddingPx must be >= 0");if(!Number.isFinite(d.bottomPaddingPx)||d.bottomPaddingPx<0)throw new Error("viewport.heightPolicy.bottomPaddingPx must be >= 0")}function Ge(d){if(!Number.isFinite(d.dprCap)||d.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function ze(d){if(!Number.isFinite(d.radius)||d.radius<=0)throw new Error("layout.mainPegs.radius must be greater than 0");if(!Number.isFinite(d.topPegCount)||d.topPegCount<1)throw new Error("layout.mainPegs.topPegCount must be >= 1");if(!Number.isFinite(d.bottomPegCount)||d.bottomPegCount<d.topPegCount)throw new Error("layout.mainPegs.bottomPegCount must be >= topPegCount");if(!Number.isFinite(d.verticalStepRatio)||d.verticalStepRatio<=0)throw new Error("layout.mainPegs.verticalStepRatio must be > 0");if(!Number.isFinite(d.sidePaddingPx)||d.sidePaddingPx<0)throw new Error("layout.mainPegs.sidePaddingPx must be >= 0")}var Xe=j(((d,E)=>{(function(A,f){typeof d=="object"&&typeof E=="object"?E.exports=f():typeof define=="function"&&define.amd?define("Matter",[],f):typeof d=="object"?d.Matter=f():A.Matter=f()})(d,function(){return(function(T){var A={};function f(e){if(A[e])return A[e].exports;var o=A[e]={i:e,l:!1,exports:{}};return T[e].call(o.exports,o,o.exports,f),o.l=!0,o.exports}return f.m=T,f.c=A,f.d=function(e,o,a){f.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:a})},f.r=function(e){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,o){if(o&1&&(e=f(e)),o&8||o&4&&typeof e=="object"&&e&&e.__esModule)return e;var a=Object.create(null);if(f.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),o&2&&typeof e!="string")for(var r in e)f.d(a,r,function(c){return e[c]}.bind(null,r));return a},f.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(o,"a",o),o},f.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},f.p="",f(f.s=20)})([(function(T,A){var f={};T.exports=f,(function(){f._baseDelta=1e3/60,f._nextId=0,f._seed=0,f._nowStartTime=+new Date,f._warnedOnce={},f._decomp=null,f.extend=function(o,a){var r,c;typeof a=="boolean"?(r=2,c=a):(r=1,c=!0);for(var n=r;n<arguments.length;n++){var h=arguments[n];if(h)for(var l in h)c&&h[l]&&h[l].constructor===Object&&(!o[l]||o[l].constructor===Object)?(o[l]=o[l]||{},f.extend(o[l],c,h[l])):o[l]=h[l]}return o},f.clone=function(o,a){return f.extend({},a,o)},f.keys=function(o){if(Object.keys)return Object.keys(o);var a=[];for(var r in o)a.push(r);return a},f.values=function(o){var a=[];if(Object.keys){for(var r=Object.keys(o),c=0;c<r.length;c++)a.push(o[r[c]]);return a}for(var n in o)a.push(o[n]);return a},f.get=function(o,a,r,c){a=a.split(".").slice(r,c);for(var n=0;n<a.length;n+=1)o=o[a[n]];return o},f.set=function(o,a,r,c,n){var h=a.split(".").slice(c,n);return f.get(o,a,0,-1)[h[h.length-1]]=r,r},f.shuffle=function(o){for(var a=o.length-1;a>0;a--){var r=Math.floor(f.random()*(a+1)),c=o[a];o[a]=o[r],o[r]=c}return o},f.choose=function(o){return o[Math.floor(f.random()*o.length)]},f.isElement=function(o){return typeof HTMLElement<"u"?o instanceof HTMLElement:!!(o&&o.nodeType&&o.nodeName)},f.isArray=function(o){return Object.prototype.toString.call(o)==="[object Array]"},f.isFunction=function(o){return typeof o=="function"},f.isPlainObject=function(o){return typeof o=="object"&&o.constructor===Object},f.isString=function(o){return toString.call(o)==="[object String]"},f.clamp=function(o,a,r){return o<a?a:o>r?r:o},f.sign=function(o){return o<0?-1:1},f.now=function(){if(typeof window<"u"&&window.performance){if(window.performance.now)return window.performance.now();if(window.performance.webkitNow)return window.performance.webkitNow()}return Date.now?Date.now():new Date-f._nowStartTime},f.random=function(o,a){return o=typeof o<"u"?o:0,a=typeof a<"u"?a:1,o+e()*(a-o)};var e=function(){return f._seed=(f._seed*9301+49297)%233280,f._seed/233280};f.colorToNumber=function(o){return o=o.replace("#",""),o.length==3&&(o=o.charAt(0)+o.charAt(0)+o.charAt(1)+o.charAt(1)+o.charAt(2)+o.charAt(2)),parseInt(o,16)},f.logLevel=1,f.log=function(){console&&f.logLevel>0&&f.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},f.info=function(){console&&f.logLevel>0&&f.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},f.warn=function(){console&&f.logLevel>0&&f.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},f.warnOnce=function(){var o=Array.prototype.slice.call(arguments).join(" ");f._warnedOnce[o]||(f.warn(o),f._warnedOnce[o]=!0)},f.deprecated=function(o,a,r){o[a]=f.chain(function(){f.warnOnce("🔅 deprecated 🔅",r)},o[a])},f.nextId=function(){return f._nextId++},f.indexOf=function(o,a){if(o.indexOf)return o.indexOf(a);for(var r=0;r<o.length;r++)if(o[r]===a)return r;return-1},f.map=function(o,a){if(o.map)return o.map(a);for(var r=[],c=0;c<o.length;c+=1)r.push(a(o[c]));return r},f.topologicalSort=function(o){var a=[],r=[],c=[];for(var n in o)!r[n]&&!c[n]&&f._topologicalSort(n,r,c,o,a);return a},f._topologicalSort=function(o,a,r,c,n){var h=c[o]||[];r[o]=!0;for(var l=0;l<h.length;l+=1){var t=h[l];r[t]||a[t]||f._topologicalSort(t,a,r,c,n)}r[o]=!1,a[o]=!0,n.push(o)},f.chain=function(){for(var o=[],a=0;a<arguments.length;a+=1){var r=arguments[a];r._chained?o.push.apply(o,r._chained):o.push(r)}var c=function(){for(var n,h=new Array(arguments.length),l=0,t=arguments.length;l<t;l++)h[l]=arguments[l];for(l=0;l<o.length;l+=1){var i=o[l].apply(n,h);typeof i<"u"&&(n=i)}return n};return c._chained=o,c},f.chainPathBefore=function(o,a,r){return f.set(o,a,f.chain(r,f.get(o,a)))},f.chainPathAfter=function(o,a,r){return f.set(o,a,f.chain(f.get(o,a),r))},f.setDecomp=function(o){f._decomp=o},f.getDecomp=function(){var o=f._decomp;try{!o&&typeof window<"u"&&(o=window.decomp),!o&&typeof global<"u"&&(o=global.decomp)}catch{o=null}return o}})()}),(function(T,A){var f={};T.exports=f,(function(){f.create=function(e){var o={min:{x:0,y:0},max:{x:0,y:0}};return e&&f.update(o,e),o},f.update=function(e,o,a){e.min.x=1/0,e.max.x=-1/0,e.min.y=1/0,e.max.y=-1/0;for(var r=0;r<o.length;r++){var c=o[r];c.x>e.max.x&&(e.max.x=c.x),c.x<e.min.x&&(e.min.x=c.x),c.y>e.max.y&&(e.max.y=c.y),c.y<e.min.y&&(e.min.y=c.y)}a&&(a.x>0?e.max.x+=a.x:e.min.x+=a.x,a.y>0?e.max.y+=a.y:e.min.y+=a.y)},f.contains=function(e,o){return o.x>=e.min.x&&o.x<=e.max.x&&o.y>=e.min.y&&o.y<=e.max.y},f.overlaps=function(e,o){return e.min.x<=o.max.x&&e.max.x>=o.min.x&&e.max.y>=o.min.y&&e.min.y<=o.max.y},f.translate=function(e,o){e.min.x+=o.x,e.max.x+=o.x,e.min.y+=o.y,e.max.y+=o.y},f.shift=function(e,o){var a=e.max.x-e.min.x,r=e.max.y-e.min.y;e.min.x=o.x,e.max.x=o.x+a,e.min.y=o.y,e.max.y=o.y+r}})()}),(function(T,A){var f={};T.exports=f,(function(){f.create=function(e,o){return{x:e||0,y:o||0}},f.clone=function(e){return{x:e.x,y:e.y}},f.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},f.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},f.rotate=function(e,o,a){var r=Math.cos(o),c=Math.sin(o);a||(a={});var n=e.x*r-e.y*c;return a.y=e.x*c+e.y*r,a.x=n,a},f.rotateAbout=function(e,o,a,r){var c=Math.cos(o),n=Math.sin(o);r||(r={});var h=a.x+((e.x-a.x)*c-(e.y-a.y)*n);return r.y=a.y+((e.x-a.x)*n+(e.y-a.y)*c),r.x=h,r},f.normalise=function(e){var o=f.magnitude(e);return o===0?{x:0,y:0}:{x:e.x/o,y:e.y/o}},f.dot=function(e,o){return e.x*o.x+e.y*o.y},f.cross=function(e,o){return e.x*o.y-e.y*o.x},f.cross3=function(e,o,a){return(o.x-e.x)*(a.y-e.y)-(o.y-e.y)*(a.x-e.x)},f.add=function(e,o,a){return a||(a={}),a.x=e.x+o.x,a.y=e.y+o.y,a},f.sub=function(e,o,a){return a||(a={}),a.x=e.x-o.x,a.y=e.y-o.y,a},f.mult=function(e,o){return{x:e.x*o,y:e.y*o}},f.div=function(e,o){return{x:e.x/o,y:e.y/o}},f.perp=function(e,o){return o=o===!0?-1:1,{x:o*-e.y,y:o*e.x}},f.neg=function(e){return{x:-e.x,y:-e.y}},f.angle=function(e,o){return Math.atan2(o.y-e.y,o.x-e.x)},f._temp=[f.create(),f.create(),f.create(),f.create(),f.create(),f.create()]})()}),(function(T,A,f){var e={};T.exports=e;var o=f(2),a=f(0);(function(){e.create=function(r,c){for(var n=[],h=0;h<r.length;h++){var l=r[h],t={x:l.x,y:l.y,index:h,body:c,isInternal:!1};n.push(t)}return n},e.fromPath=function(r,c){var n=/L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi,h=[];return r.replace(n,function(l,t,i){h.push({x:parseFloat(t),y:parseFloat(i)})}),e.create(h,c)},e.centre=function(r){for(var c=e.area(r,!0),n={x:0,y:0},h,l,t,i=0;i<r.length;i++)t=(i+1)%r.length,h=o.cross(r[i],r[t]),l=o.mult(o.add(r[i],r[t]),h),n=o.add(n,l);return o.div(n,6*c)},e.mean=function(r){for(var c={x:0,y:0},n=0;n<r.length;n++)c.x+=r[n].x,c.y+=r[n].y;return o.div(c,r.length)},e.area=function(r,c){for(var n=0,h=r.length-1,l=0;l<r.length;l++)n+=(r[h].x-r[l].x)*(r[h].y+r[l].y),h=l;return c?n/2:Math.abs(n)/2},e.inertia=function(r,c){for(var n=0,h=0,l=r,t,i,s=0;s<l.length;s++)i=(s+1)%l.length,t=Math.abs(o.cross(l[i],l[s])),n+=t*(o.dot(l[i],l[i])+o.dot(l[i],l[s])+o.dot(l[s],l[s])),h+=t;return c/6*(n/h)},e.translate=function(r,c,n){n=typeof n<"u"?n:1;var h=r.length,l=c.x*n,t=c.y*n,i;for(i=0;i<h;i++)r[i].x+=l,r[i].y+=t;return r},e.rotate=function(r,c,n){if(c!==0){var h=Math.cos(c),l=Math.sin(c),t=n.x,i=n.y,s=r.length,u,m,x,P;for(P=0;P<s;P++)u=r[P],m=u.x-t,x=u.y-i,u.x=t+(m*h-x*l),u.y=i+(m*l+x*h);return r}},e.contains=function(r,c){for(var n=c.x,h=c.y,l=r.length,t=r[l-1],i,s=0;s<l;s++){if(i=r[s],(n-t.x)*(i.y-t.y)+(h-t.y)*(t.x-i.x)>0)return!1;t=i}return!0},e.scale=function(r,c,n,h){if(c===1&&n===1)return r;h=h||e.centre(r);for(var l,t,i=0;i<r.length;i++)l=r[i],t=o.sub(l,h),r[i].x=h.x+t.x*c,r[i].y=h.y+t.y*n;return r},e.chamfer=function(r,c,n,h,l){typeof c=="number"?c=[c]:c=c||[8],n=typeof n<"u"?n:-1,h=h||2,l=l||14;for(var t=[],i=0;i<r.length;i++){var s=r[i-1>=0?i-1:r.length-1],u=r[i],m=r[(i+1)%r.length],x=c[i<c.length?i:c.length-1];if(x===0){t.push(u);continue}var P=o.normalise({x:u.y-s.y,y:s.x-u.x}),B=o.normalise({x:m.y-u.y,y:u.x-m.x}),g=Math.sqrt(2*Math.pow(x,2)),p=o.mult(a.clone(P),x),y=o.normalise(o.mult(o.add(P,B),.5)),v=o.sub(u,o.mult(y,g)),w=n;n===-1&&(w=Math.pow(x,.32)*1.75),w=a.clamp(w,h,l),w%2===1&&(w+=1);for(var S=Math.acos(o.dot(P,B))/w,C=0;C<w;C++)t.push(o.add(o.rotate(p,S*C),v))}return t},e.clockwiseSort=function(r){var c=e.mean(r);return r.sort(function(n,h){return o.angle(c,n)-o.angle(c,h)}),r},e.isConvex=function(r){var c=0,n=r.length,h,l,t,i;if(n<3)return null;for(h=0;h<n;h++)if(l=(h+1)%n,t=(h+2)%n,i=(r[l].x-r[h].x)*(r[t].y-r[l].y),i-=(r[l].y-r[h].y)*(r[t].x-r[l].x),i<0?c|=1:i>0&&(c|=2),c===3)return!1;return c!==0?!0:null},e.hull=function(r){var c=[],n=[],h,l;for(r=r.slice(0),r.sort(function(t,i){var s=t.x-i.x;return s!==0?s:t.y-i.y}),l=0;l<r.length;l+=1){for(h=r[l];n.length>=2&&o.cross3(n[n.length-2],n[n.length-1],h)<=0;)n.pop();n.push(h)}for(l=r.length-1;l>=0;l-=1){for(h=r[l];c.length>=2&&o.cross3(c[c.length-2],c[c.length-1],h)<=0;)c.pop();c.push(h)}return c.pop(),n.pop(),c.concat(n)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(2),r=f(7),c=f(0),n=f(1),h=f(11);(function(){e._timeCorrection=!0,e._inertiaScale=4,e._nextCollidingGroupId=1,e._nextNonCollidingGroupId=-1,e._nextCategory=1,e._baseDelta=1e3/60,e.create=function(t){var i={id:c.nextId(),type:"body",label:"Body",parts:[],plugin:{},angle:0,vertices:o.fromPath("L 0 0 L 40 0 L 40 40 L 0 40"),position:{x:0,y:0},force:{x:0,y:0},torque:0,positionImpulse:{x:0,y:0},constraintImpulse:{x:0,y:0,angle:0},totalContacts:0,speed:0,angularSpeed:0,velocity:{x:0,y:0},angularVelocity:0,isSensor:!1,isStatic:!1,isSleeping:!1,motion:0,sleepThreshold:60,density:.001,restitution:0,friction:.1,frictionStatic:.5,frictionAir:.01,collisionFilter:{category:1,mask:4294967295,group:0},slop:.05,timeScale:1,render:{visible:!0,opacity:1,strokeStyle:null,fillStyle:null,lineWidth:null,sprite:{xScale:1,yScale:1,xOffset:0,yOffset:0}},events:null,bounds:null,chamfer:null,circleRadius:0,positionPrev:null,anglePrev:0,parent:null,axes:null,area:0,mass:0,inertia:0,deltaTime:16.666666666666668,_original:null},s=c.extend(i,t);return l(s,t),s},e.nextGroup=function(t){return t?e._nextNonCollidingGroupId--:e._nextCollidingGroupId++},e.nextCategory=function(){return e._nextCategory=e._nextCategory<<1,e._nextCategory};var l=function(t,i){i=i||{},e.set(t,{bounds:t.bounds||n.create(t.vertices),positionPrev:t.positionPrev||a.clone(t.position),anglePrev:t.anglePrev||t.angle,vertices:t.vertices,parts:t.parts||[t],isStatic:t.isStatic,isSleeping:t.isSleeping,parent:t.parent||t}),o.rotate(t.vertices,t.angle,t.position),h.rotate(t.axes,t.angle),n.update(t.bounds,t.vertices,t.velocity),e.set(t,{axes:i.axes||t.axes,area:i.area||t.area,mass:i.mass||t.mass,inertia:i.inertia||t.inertia});var s=t.isStatic?"#14151f":c.choose(["#f19648","#f5d259","#f55a3c","#063e7b","#ececd1"]),u=t.isStatic?"#555":"#ccc",m=t.isStatic&&t.render.fillStyle===null?1:0;t.render.fillStyle=t.render.fillStyle||s,t.render.strokeStyle=t.render.strokeStyle||u,t.render.lineWidth=t.render.lineWidth||m,t.render.sprite.xOffset+=-(t.bounds.min.x-t.position.x)/(t.bounds.max.x-t.bounds.min.x),t.render.sprite.yOffset+=-(t.bounds.min.y-t.position.y)/(t.bounds.max.y-t.bounds.min.y)};e.set=function(t,i,s){var u;typeof i=="string"&&(u=i,i={},i[u]=s);for(u in i)if(Object.prototype.hasOwnProperty.call(i,u))switch(s=i[u],u){case"isStatic":e.setStatic(t,s);break;case"isSleeping":r.set(t,s);break;case"mass":e.setMass(t,s);break;case"density":e.setDensity(t,s);break;case"inertia":e.setInertia(t,s);break;case"vertices":e.setVertices(t,s);break;case"position":e.setPosition(t,s);break;case"angle":e.setAngle(t,s);break;case"velocity":e.setVelocity(t,s);break;case"angularVelocity":e.setAngularVelocity(t,s);break;case"speed":e.setSpeed(t,s);break;case"angularSpeed":e.setAngularSpeed(t,s);break;case"parts":e.setParts(t,s);break;case"centre":e.setCentre(t,s);break;default:t[u]=s}},e.setStatic=function(t,i){for(var s=0;s<t.parts.length;s++){var u=t.parts[s];i?(u.isStatic||(u._original={restitution:u.restitution,friction:u.friction,mass:u.mass,inertia:u.inertia,density:u.density,inverseMass:u.inverseMass,inverseInertia:u.inverseInertia}),u.restitution=0,u.friction=1,u.mass=u.inertia=u.density=1/0,u.inverseMass=u.inverseInertia=0,u.positionPrev.x=u.position.x,u.positionPrev.y=u.position.y,u.anglePrev=u.angle,u.angularVelocity=0,u.speed=0,u.angularSpeed=0,u.motion=0):u._original&&(u.restitution=u._original.restitution,u.friction=u._original.friction,u.mass=u._original.mass,u.inertia=u._original.inertia,u.density=u._original.density,u.inverseMass=u._original.inverseMass,u.inverseInertia=u._original.inverseInertia,u._original=null),u.isStatic=i}},e.setMass=function(t,i){t.inertia=t.inertia/(t.mass/6)*(i/6),t.inverseInertia=1/t.inertia,t.mass=i,t.inverseMass=1/t.mass,t.density=t.mass/t.area},e.setDensity=function(t,i){e.setMass(t,i*t.area),t.density=i},e.setInertia=function(t,i){t.inertia=i,t.inverseInertia=1/t.inertia},e.setVertices=function(t,i){i[0].body===t?t.vertices=i:t.vertices=o.create(i,t),t.axes=h.fromVertices(t.vertices),t.area=o.area(t.vertices),e.setMass(t,t.density*t.area);var s=o.centre(t.vertices);o.translate(t.vertices,s,-1),e.setInertia(t,e._inertiaScale*o.inertia(t.vertices,t.mass)),o.translate(t.vertices,t.position),n.update(t.bounds,t.vertices,t.velocity)},e.setParts=function(t,i,s){var u;for(i=i.slice(0),t.parts.length=0,t.parts.push(t),t.parent=t,u=0;u<i.length;u++){var m=i[u];m!==t&&(m.parent=t,t.parts.push(m))}if(t.parts.length!==1){if(s=typeof s<"u"?s:!0,s){var x=[];for(u=0;u<i.length;u++)x=x.concat(i[u].vertices);o.clockwiseSort(x);var P=o.hull(x),B=o.centre(P);e.setVertices(t,P),o.translate(t.vertices,B)}var g=e._totalProperties(t);t.area=g.area,t.parent=t,t.position.x=g.centre.x,t.position.y=g.centre.y,t.positionPrev.x=g.centre.x,t.positionPrev.y=g.centre.y,e.setMass(t,g.mass),e.setInertia(t,g.inertia),e.setPosition(t,g.centre)}},e.setCentre=function(t,i,s){s?(t.positionPrev.x+=i.x,t.positionPrev.y+=i.y,t.position.x+=i.x,t.position.y+=i.y):(t.positionPrev.x=i.x-(t.position.x-t.positionPrev.x),t.positionPrev.y=i.y-(t.position.y-t.positionPrev.y),t.position.x=i.x,t.position.y=i.y)},e.setPosition=function(t,i,s){var u=a.sub(i,t.position);s?(t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.velocity.x=u.x,t.velocity.y=u.y,t.speed=a.magnitude(u)):(t.positionPrev.x+=u.x,t.positionPrev.y+=u.y);for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.position.x+=u.x,x.position.y+=u.y,o.translate(x.vertices,u),n.update(x.bounds,x.vertices,t.velocity)}},e.setAngle=function(t,i,s){var u=i-t.angle;s?(t.anglePrev=t.angle,t.angularVelocity=u,t.angularSpeed=Math.abs(u)):t.anglePrev+=u;for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.angle+=u,o.rotate(x.vertices,u,t.position),h.rotate(x.axes,u),n.update(x.bounds,x.vertices,t.velocity),m>0&&a.rotateAbout(x.position,u,t.position,x.position)}},e.setVelocity=function(t,i){var s=t.deltaTime/e._baseDelta;t.positionPrev.x=t.position.x-i.x*s,t.positionPrev.y=t.position.y-i.y*s,t.velocity.x=(t.position.x-t.positionPrev.x)/s,t.velocity.y=(t.position.y-t.positionPrev.y)/s,t.speed=a.magnitude(t.velocity)},e.getVelocity=function(t){var i=e._baseDelta/t.deltaTime;return{x:(t.position.x-t.positionPrev.x)*i,y:(t.position.y-t.positionPrev.y)*i}},e.getSpeed=function(t){return a.magnitude(e.getVelocity(t))},e.setSpeed=function(t,i){e.setVelocity(t,a.mult(a.normalise(e.getVelocity(t)),i))},e.setAngularVelocity=function(t,i){var s=t.deltaTime/e._baseDelta;t.anglePrev=t.angle-i*s,t.angularVelocity=(t.angle-t.anglePrev)/s,t.angularSpeed=Math.abs(t.angularVelocity)},e.getAngularVelocity=function(t){return(t.angle-t.anglePrev)*e._baseDelta/t.deltaTime},e.getAngularSpeed=function(t){return Math.abs(e.getAngularVelocity(t))},e.setAngularSpeed=function(t,i){e.setAngularVelocity(t,c.sign(e.getAngularVelocity(t))*i)},e.translate=function(t,i,s){e.setPosition(t,a.add(t.position,i),s)},e.rotate=function(t,i,s,u){if(!s)e.setAngle(t,t.angle+i,u);else{var m=Math.cos(i),x=Math.sin(i),P=t.position.x-s.x,B=t.position.y-s.y;e.setPosition(t,{x:s.x+(P*m-B*x),y:s.y+(P*x+B*m)},u),e.setAngle(t,t.angle+i,u)}},e.scale=function(t,i,s,u){var m=0,x=0;u=u||t.position;for(var P=0;P<t.parts.length;P++){var B=t.parts[P];o.scale(B.vertices,i,s,u),B.axes=h.fromVertices(B.vertices),B.area=o.area(B.vertices),e.setMass(B,t.density*B.area),o.translate(B.vertices,{x:-B.position.x,y:-B.position.y}),e.setInertia(B,e._inertiaScale*o.inertia(B.vertices,B.mass)),o.translate(B.vertices,{x:B.position.x,y:B.position.y}),P>0&&(m+=B.area,x+=B.inertia),B.position.x=u.x+(B.position.x-u.x)*i,B.position.y=u.y+(B.position.y-u.y)*s,n.update(B.bounds,B.vertices,t.velocity)}t.parts.length>1&&(t.area=m,t.isStatic||(e.setMass(t,t.density*m),e.setInertia(t,x))),t.circleRadius&&(i===s?t.circleRadius*=i:t.circleRadius=null)},e.update=function(t,i){i=(typeof i<"u"?i:1e3/60)*t.timeScale;var s=i*i,u=e._timeCorrection?i/(t.deltaTime||i):1,m=1-t.frictionAir*(i/c._baseDelta),x=(t.position.x-t.positionPrev.x)*u,P=(t.position.y-t.positionPrev.y)*u;t.velocity.x=x*m+t.force.x/t.mass*s,t.velocity.y=P*m+t.force.y/t.mass*s,t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.position.x+=t.velocity.x,t.position.y+=t.velocity.y,t.deltaTime=i,t.angularVelocity=(t.angle-t.anglePrev)*m*u+t.torque/t.inertia*s,t.anglePrev=t.angle,t.angle+=t.angularVelocity;for(var B=0;B<t.parts.length;B++){var g=t.parts[B];o.translate(g.vertices,t.velocity),B>0&&(g.position.x+=t.velocity.x,g.position.y+=t.velocity.y),t.angularVelocity!==0&&(o.rotate(g.vertices,t.angularVelocity,t.position),h.rotate(g.axes,t.angularVelocity),B>0&&a.rotateAbout(g.position,t.angularVelocity,t.position,g.position)),n.update(g.bounds,g.vertices,t.velocity)}},e.updateVelocities=function(t){var i=e._baseDelta/t.deltaTime,s=t.velocity;s.x=(t.position.x-t.positionPrev.x)*i,s.y=(t.position.y-t.positionPrev.y)*i,t.speed=Math.sqrt(s.x*s.x+s.y*s.y),t.angularVelocity=(t.angle-t.anglePrev)*i,t.angularSpeed=Math.abs(t.angularVelocity)},e.applyForce=function(t,i,s){var u={x:i.x-t.position.x,y:i.y-t.position.y};t.force.x+=s.x,t.force.y+=s.y,t.torque+=u.x*s.y-u.y*s.x},e._totalProperties=function(t){for(var i={mass:0,area:0,inertia:0,centre:{x:0,y:0}},s=t.parts.length===1?0:1;s<t.parts.length;s++){var u=t.parts[s],m=u.mass!==1/0?u.mass:1;i.mass+=m,i.area+=u.area,i.inertia+=u.inertia,i.centre=a.add(i.centre,a.mult(u.position,m))}return i.centre=a.div(i.centre,i.mass),i}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(0);(function(){e.on=function(a,r,c){for(var n=r.split(" "),h,l=0;l<n.length;l++)h=n[l],a.events=a.events||{},a.events[h]=a.events[h]||[],a.events[h].push(c);return c},e.off=function(a,r,c){if(!r){a.events={};return}typeof r=="function"&&(c=r,r=o.keys(a.events).join(" "));for(var n=r.split(" "),h=0;h<n.length;h++){var l=a.events[n[h]],t=[];if(c&&l)for(var i=0;i<l.length;i++)l[i]!==c&&t.push(l[i]);a.events[n[h]]=t}},e.trigger=function(a,r,c){var n,h,l,t,i=a.events;if(i&&o.keys(i).length>0){c||(c={}),n=r.split(" ");for(var s=0;s<n.length;s++)if(h=n[s],l=i[h],l){t=o.clone(c,!1),t.name=h,t.source=a;for(var u=0;u<l.length;u++)l[u].apply(a,[t])}}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(5),a=f(0),r=f(1),c=f(4);(function(){e.create=function(n){return a.extend({id:a.nextId(),type:"composite",parent:null,isModified:!1,bodies:[],constraints:[],composites:[],label:"Composite",plugin:{},cache:{allBodies:null,allConstraints:null,allComposites:null}},n)},e.setModified=function(n,h,l,t){if(n.isModified=h,h&&n.cache&&(n.cache.allBodies=null,n.cache.allConstraints=null,n.cache.allComposites=null),l&&n.parent&&e.setModified(n.parent,h,l,t),t)for(var i=0;i<n.composites.length;i++){var s=n.composites[i];e.setModified(s,h,l,t)}},e.add=function(n,h){var l=[].concat(h);o.trigger(n,"beforeAdd",{object:h});for(var t=0;t<l.length;t++){var i=l[t];switch(i.type){case"body":if(i.parent!==i){a.warn("Composite.add: skipped adding a compound body part (you must add its parent instead)");break}e.addBody(n,i);break;case"constraint":e.addConstraint(n,i);break;case"composite":e.addComposite(n,i);break;case"mouseConstraint":e.addConstraint(n,i.constraint);break}}return o.trigger(n,"afterAdd",{object:h}),n},e.remove=function(n,h,l){var t=[].concat(h);o.trigger(n,"beforeRemove",{object:h});for(var i=0;i<t.length;i++){var s=t[i];switch(s.type){case"body":e.removeBody(n,s,l);break;case"constraint":e.removeConstraint(n,s,l);break;case"composite":e.removeComposite(n,s,l);break;case"mouseConstraint":e.removeConstraint(n,s.constraint);break}}return o.trigger(n,"afterRemove",{object:h}),n},e.addComposite=function(n,h){return n.composites.push(h),h.parent=n,e.setModified(n,!0,!0,!1),n},e.removeComposite=function(n,h,l){var t=a.indexOf(n.composites,h);if(t!==-1){var i=e.allBodies(h);e.removeCompositeAt(n,t);for(var s=0;s<i.length;s++)i[s].sleepCounter=0}if(l)for(var s=0;s<n.composites.length;s++)e.removeComposite(n.composites[s],h,!0);return n},e.removeCompositeAt=function(n,h){return n.composites.splice(h,1),e.setModified(n,!0,!0,!1),n},e.addBody=function(n,h){return n.bodies.push(h),e.setModified(n,!0,!0,!1),n},e.removeBody=function(n,h,l){var t=a.indexOf(n.bodies,h);if(t!==-1&&(e.removeBodyAt(n,t),h.sleepCounter=0),l)for(var i=0;i<n.composites.length;i++)e.removeBody(n.composites[i],h,!0);return n},e.removeBodyAt=function(n,h){return n.bodies.splice(h,1),e.setModified(n,!0,!0,!1),n},e.addConstraint=function(n,h){return n.constraints.push(h),e.setModified(n,!0,!0,!1),n},e.removeConstraint=function(n,h,l){var t=a.indexOf(n.constraints,h);if(t!==-1&&e.removeConstraintAt(n,t),l)for(var i=0;i<n.composites.length;i++)e.removeConstraint(n.composites[i],h,!0);return n},e.removeConstraintAt=function(n,h){return n.constraints.splice(h,1),e.setModified(n,!0,!0,!1),n},e.clear=function(n,h,l){if(l)for(var t=0;t<n.composites.length;t++)e.clear(n.composites[t],h,!0);return h?n.bodies=n.bodies.filter(function(i){return i.isStatic}):n.bodies.length=0,n.constraints.length=0,n.composites.length=0,e.setModified(n,!0,!0,!1),n},e.allBodies=function(n){if(n.cache&&n.cache.allBodies)return n.cache.allBodies;for(var h=[].concat(n.bodies),l=0;l<n.composites.length;l++)h=h.concat(e.allBodies(n.composites[l]));return n.cache&&(n.cache.allBodies=h),h},e.allConstraints=function(n){if(n.cache&&n.cache.allConstraints)return n.cache.allConstraints;for(var h=[].concat(n.constraints),l=0;l<n.composites.length;l++)h=h.concat(e.allConstraints(n.composites[l]));return n.cache&&(n.cache.allConstraints=h),h},e.allComposites=function(n){if(n.cache&&n.cache.allComposites)return n.cache.allComposites;for(var h=[].concat(n.composites),l=0;l<n.composites.length;l++)h=h.concat(e.allComposites(n.composites[l]));return n.cache&&(n.cache.allComposites=h),h},e.get=function(n,h,l){var t,i;switch(l){case"body":t=e.allBodies(n);break;case"constraint":t=e.allConstraints(n);break;case"composite":t=e.allComposites(n).concat(n);break}return t?(i=t.filter(function(s){return s.id.toString()===h.toString()}),i.length===0?null:i[0]):null},e.move=function(n,h,l){return e.remove(n,h),e.add(l,h),n},e.rebase=function(n){for(var h=e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)),l=0;l<h.length;l++)h[l].id=a.nextId();return n},e.translate=function(n,h,l){for(var t=l?e.allBodies(n):n.bodies,i=0;i<t.length;i++)c.translate(t[i],h);return n},e.rotate=function(n,h,l,t){for(var i=Math.cos(h),s=Math.sin(h),u=t?e.allBodies(n):n.bodies,m=0;m<u.length;m++){var x=u[m],P=x.position.x-l.x,B=x.position.y-l.y;c.setPosition(x,{x:l.x+(P*i-B*s),y:l.y+(P*s+B*i)}),c.rotate(x,h)}return n},e.scale=function(n,h,l,t,i){for(var s=i?e.allBodies(n):n.bodies,u=0;u<s.length;u++){var m=s[u],x=m.position.x-t.x,P=m.position.y-t.y;c.setPosition(m,{x:t.x+x*h,y:t.y+P*l}),c.scale(m,h,l)}return n},e.bounds=function(n){for(var h=e.allBodies(n),l=[],t=0;t<h.length;t+=1){var i=h[t];l.push(i.bounds.min,i.bounds.max)}return r.create(l)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(4),a=f(5),r=f(0);(function(){e._motionWakeThreshold=.18,e._motionSleepThreshold=.08,e._minBias=.9,e.update=function(c,n){for(var h=n/r._baseDelta,l=e._motionSleepThreshold,t=0;t<c.length;t++){var i=c[t],s=o.getSpeed(i),u=o.getAngularSpeed(i),m=s*s+u*u;if(i.force.x!==0||i.force.y!==0){e.set(i,!1);continue}var x=Math.min(i.motion,m),P=Math.max(i.motion,m);i.motion=e._minBias*x+(1-e._minBias)*P,i.sleepThreshold>0&&i.motion<l?(i.sleepCounter+=1,i.sleepCounter>=i.sleepThreshold/h&&e.set(i,!0)):i.sleepCounter>0&&(i.sleepCounter-=1)}},e.afterCollisions=function(c){for(var n=e._motionSleepThreshold,h=0;h<c.length;h++){var l=c[h];if(l.isActive){var t=l.collision,i=t.bodyA.parent,s=t.bodyB.parent;if(!(i.isSleeping&&s.isSleeping||i.isStatic||s.isStatic)&&(i.isSleeping||s.isSleeping)){var u=i.isSleeping&&!i.isStatic?i:s,m=u===i?s:i;!u.isStatic&&m.motion>n&&e.set(u,!1)}}}},e.set=function(c,n){var h=c.isSleeping;n?(c.isSleeping=!0,c.sleepCounter=c.sleepThreshold,c.positionImpulse.x=0,c.positionImpulse.y=0,c.positionPrev.x=c.position.x,c.positionPrev.y=c.position.y,c.anglePrev=c.angle,c.speed=0,c.angularSpeed=0,c.motion=0,h||a.trigger(c,"sleepStart")):(c.isSleeping=!1,c.sleepCounter=0,h&&a.trigger(c,"sleepEnd"))}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(9);(function(){var r=[],c={overlap:0,axis:null},n={overlap:0,axis:null};e.create=function(h,l){return{pair:null,collided:!1,bodyA:h,bodyB:l,parentA:h.parent,parentB:l.parent,depth:0,normal:{x:0,y:0},tangent:{x:0,y:0},penetration:{x:0,y:0},supports:[null,null],supportCount:0}},e.collides=function(h,l,t){if(e._overlapAxes(c,h.vertices,l.vertices,h.axes),c.overlap<=0||(e._overlapAxes(n,l.vertices,h.vertices,l.axes),n.overlap<=0))return null;var i=t&&t.table[a.id(h,l)],s;i?s=i.collision:(s=e.create(h,l),s.collided=!0,s.bodyA=h.id<l.id?h:l,s.bodyB=h.id<l.id?l:h,s.parentA=s.bodyA.parent,s.parentB=s.bodyB.parent),h=s.bodyA,l=s.bodyB;var u;c.overlap<n.overlap?u=c:u=n;var m=s.normal,x=s.tangent,P=s.penetration,B=s.supports,g=u.overlap,p=u.axis,y=p.x,v=p.y,w=l.position.x-h.position.x,S=l.position.y-h.position.y;y*w+v*S>=0&&(y=-y,v=-v),m.x=y,m.y=v,x.x=-v,x.y=y,P.x=y*g,P.y=v*g,s.depth=g;var C=e._findSupports(h,l,m,1),M=0;if(o.contains(h.vertices,C[0])&&(B[M++]=C[0]),o.contains(h.vertices,C[1])&&(B[M++]=C[1]),M<2){var I=e._findSupports(l,h,m,-1);o.contains(l.vertices,I[0])&&(B[M++]=I[0]),M<2&&o.contains(l.vertices,I[1])&&(B[M++]=I[1])}return M===0&&(B[M++]=C[0]),s.supportCount=M,s},e._overlapAxes=function(h,l,t,i){var s=l.length,u=t.length,m=l[0].x,x=l[0].y,P=t[0].x,B=t[0].y,g=i.length,p=Number.MAX_VALUE,y=0,v,w,S,C,M,I;for(M=0;M<g;M++){var R=i[M],L=R.x,b=R.y,k=m*L+x*b,D=P*L+B*b,O=k,H=D;for(I=1;I<s;I+=1)C=l[I].x*L+l[I].y*b,C>O?O=C:C<k&&(k=C);for(I=1;I<u;I+=1)C=t[I].x*L+t[I].y*b,C>H?H=C:C<D&&(D=C);if(w=O-D,S=H-k,v=w<S?w:S,v<p&&(p=v,y=M,v<=0))break}h.axis=i[y],h.overlap=p},e._findSupports=function(h,l,t,i){var s=l.vertices,u=s.length,m=h.position.x,x=h.position.y,P=t.x*i,B=t.y*i,g=s[0],p=g,y=P*(m-p.x)+B*(x-p.y),v,w,S;for(S=1;S<u;S+=1)p=s[S],w=P*(m-p.x)+B*(x-p.y),w<y&&(y=w,g=p);return v=s[(u+g.index-1)%u],y=P*(m-v.x)+B*(x-v.y),p=s[(g.index+1)%u],P*(m-p.x)+B*(x-p.y)<y?(r[0]=g,r[1]=p,r):(r[0]=g,r[1]=v,r)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(16);(function(){e.create=function(a,r){var c=a.bodyA,n=a.bodyB,h={id:e.id(c,n),bodyA:c,bodyB:n,collision:a,contacts:[o.create(),o.create()],contactCount:0,separation:0,isActive:!0,isSensor:c.isSensor||n.isSensor,timeCreated:r,timeUpdated:r,inverseMass:0,friction:0,frictionStatic:0,restitution:0,slop:0};return e.update(h,a,r),h},e.update=function(a,r,c){var n=r.supports,h=r.supportCount,l=a.contacts,t=r.parentA,i=r.parentB;a.isActive=!0,a.timeUpdated=c,a.collision=r,a.separation=r.depth,a.inverseMass=t.inverseMass+i.inverseMass,a.friction=t.friction<i.friction?t.friction:i.friction,a.frictionStatic=t.frictionStatic>i.frictionStatic?t.frictionStatic:i.frictionStatic,a.restitution=t.restitution>i.restitution?t.restitution:i.restitution,a.slop=t.slop>i.slop?t.slop:i.slop,a.contactCount=h,r.pair=a;var s=n[0],u=l[0],m=n[1],x=l[1];(x.vertex===s||u.vertex===m)&&(l[1]=u,l[0]=u=x,x=l[1]),u.vertex=s,x.vertex=m},e.setActive=function(a,r,c){r?(a.isActive=!0,a.timeUpdated=c):(a.isActive=!1,a.contactCount=0)},e.id=function(a,r){return a.id<r.id?a.id.toString(36)+":"+r.id.toString(36):r.id.toString(36)+":"+a.id.toString(36)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(2),r=f(7),c=f(1),n=f(11),h=f(0);(function(){e._warming=.4,e._torqueDampen=1,e._minLength=1e-6,e.create=function(l){var t=l;t.bodyA&&!t.pointA&&(t.pointA={x:0,y:0}),t.bodyB&&!t.pointB&&(t.pointB={x:0,y:0});var i=t.bodyA?a.add(t.bodyA.position,t.pointA):t.pointA,s=t.bodyB?a.add(t.bodyB.position,t.pointB):t.pointB,u=a.magnitude(a.sub(i,s));t.length=typeof t.length<"u"?t.length:u,t.id=t.id||h.nextId(),t.label=t.label||"Constraint",t.type="constraint",t.stiffness=t.stiffness||(t.length>0?1:.7),t.damping=t.damping||0,t.angularStiffness=t.angularStiffness||0,t.angleA=t.bodyA?t.bodyA.angle:t.angleA,t.angleB=t.bodyB?t.bodyB.angle:t.angleB,t.plugin={};var m={visible:!0,lineWidth:2,strokeStyle:"#ffffff",type:"line",anchors:!0};return t.length===0&&t.stiffness>.1?(m.type="pin",m.anchors=!1):t.stiffness<.9&&(m.type="spring"),t.render=h.extend(m,t.render),t},e.preSolveAll=function(l){for(var t=0;t<l.length;t+=1){var i=l[t],s=i.constraintImpulse;i.isStatic||s.x===0&&s.y===0&&s.angle===0||(i.position.x+=s.x,i.position.y+=s.y,i.angle+=s.angle)}},e.solveAll=function(l,t){for(var i=h.clamp(t/h._baseDelta,0,1),s=0;s<l.length;s+=1){var u=l[s],m=!u.bodyA||u.bodyA&&u.bodyA.isStatic,x=!u.bodyB||u.bodyB&&u.bodyB.isStatic;(m||x)&&e.solve(l[s],i)}for(s=0;s<l.length;s+=1)u=l[s],m=!u.bodyA||u.bodyA&&u.bodyA.isStatic,x=!u.bodyB||u.bodyB&&u.bodyB.isStatic,!m&&!x&&e.solve(l[s],i)},e.solve=function(l,t){var i=l.bodyA,s=l.bodyB,u=l.pointA,m=l.pointB;if(!(!i&&!s)){i&&!i.isStatic&&(a.rotate(u,i.angle-l.angleA,u),l.angleA=i.angle),s&&!s.isStatic&&(a.rotate(m,s.angle-l.angleB,m),l.angleB=s.angle);var x=u,P=m;if(i&&(x=a.add(i.position,u)),s&&(P=a.add(s.position,m)),!(!x||!P)){var B=a.sub(x,P),g=a.magnitude(B);g<e._minLength&&(g=e._minLength);var p=(g-l.length)/g,y=l.stiffness>=1||l.length===0?l.stiffness*t:l.stiffness*t*t,v=l.damping*t,w=a.mult(B,p*y),S=(i?i.inverseMass:0)+(s?s.inverseMass:0),C=S+((i?i.inverseInertia:0)+(s?s.inverseInertia:0)),M,I,R,L,b;if(v>0){var k=a.create();R=a.div(B,g),b=a.sub(s&&a.sub(s.position,s.positionPrev)||k,i&&a.sub(i.position,i.positionPrev)||k),L=a.dot(R,b)}i&&!i.isStatic&&(I=i.inverseMass/S,i.constraintImpulse.x-=w.x*I,i.constraintImpulse.y-=w.y*I,i.position.x-=w.x*I,i.position.y-=w.y*I,v>0&&(i.positionPrev.x-=v*R.x*L*I,i.positionPrev.y-=v*R.y*L*I),M=a.cross(u,w)/C*e._torqueDampen*i.inverseInertia*(1-l.angularStiffness),i.constraintImpulse.angle-=M,i.angle-=M),s&&!s.isStatic&&(I=s.inverseMass/S,s.constraintImpulse.x+=w.x*I,s.constraintImpulse.y+=w.y*I,s.position.x+=w.x*I,s.position.y+=w.y*I,v>0&&(s.positionPrev.x+=v*R.x*L*I,s.positionPrev.y+=v*R.y*L*I),M=a.cross(m,w)/C*e._torqueDampen*s.inverseInertia*(1-l.angularStiffness),s.constraintImpulse.angle+=M,s.angle+=M)}}},e.postSolveAll=function(l){for(var t=0;t<l.length;t++){var i=l[t],s=i.constraintImpulse;if(!(i.isStatic||s.x===0&&s.y===0&&s.angle===0)){r.set(i,!1);for(var u=0;u<i.parts.length;u++){var m=i.parts[u];o.translate(m.vertices,s),u>0&&(m.position.x+=s.x,m.position.y+=s.y),s.angle!==0&&(o.rotate(m.vertices,s.angle,i.position),n.rotate(m.axes,s.angle),u>0&&a.rotateAbout(m.position,s.angle,i.position,m.position)),c.update(m.bounds,m.vertices,i.velocity)}s.angle*=e._warming,s.x*=e._warming,s.y*=e._warming}}},e.pointAWorld=function(l){return{x:(l.bodyA?l.bodyA.position.x:0)+(l.pointA?l.pointA.x:0),y:(l.bodyA?l.bodyA.position.y:0)+(l.pointA?l.pointA.y:0)}},e.pointBWorld=function(l){return{x:(l.bodyB?l.bodyB.position.x:0)+(l.pointB?l.pointB.x:0),y:(l.bodyB?l.bodyB.position.y:0)+(l.pointB?l.pointB.y:0)}},e.currentLength=function(l){var t=(l.bodyA?l.bodyA.position.x:0)+(l.pointA?l.pointA.x:0),i=(l.bodyA?l.bodyA.position.y:0)+(l.pointA?l.pointA.y:0),s=(l.bodyB?l.bodyB.position.x:0)+(l.pointB?l.pointB.x:0),u=(l.bodyB?l.bodyB.position.y:0)+(l.pointB?l.pointB.y:0),m=t-s,x=i-u;return Math.sqrt(m*m+x*x)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(2),a=f(0);(function(){e.fromVertices=function(r){for(var c={},n=0;n<r.length;n++){var h=(n+1)%r.length,l=o.normalise({x:r[h].y-r[n].y,y:r[n].x-r[h].x}),t=l.y===0?1/0:l.x/l.y;t=t.toFixed(3).toString(),c[t]=l}return a.values(c)},e.rotate=function(r,c){if(c!==0)for(var n=Math.cos(c),h=Math.sin(c),l=0;l<r.length;l++){var t=r[l],i=t.x*n-t.y*h;t.y=t.x*h+t.y*n,t.x=i}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(0),r=f(4),c=f(1),n=f(2);(function(){e.rectangle=function(h,l,t,i,s){s=s||{};var u={label:"Rectangle Body",position:{x:h,y:l},vertices:o.fromPath("L 0 0 L "+t+" 0 L "+t+" "+i+" L 0 "+i)};if(s.chamfer){var m=s.chamfer;u.vertices=o.chamfer(u.vertices,m.radius,m.quality,m.qualityMin,m.qualityMax),delete s.chamfer}return r.create(a.extend({},u,s))},e.trapezoid=function(h,l,t,i,s,u){u=u||{},s>=1&&a.warn("Bodies.trapezoid: slope parameter must be < 1."),s*=.5;var m=(1-s*2)*t,x=t*s,P=x+m,B=P+x,g;s<.5?g="L 0 0 L "+x+" "+-i+" L "+P+" "+-i+" L "+B+" 0":g="L 0 0 L "+P+" "+-i+" L "+B+" 0";var p={label:"Trapezoid Body",position:{x:h,y:l},vertices:o.fromPath(g)};if(u.chamfer){var y=u.chamfer;p.vertices=o.chamfer(p.vertices,y.radius,y.quality,y.qualityMin,y.qualityMax),delete u.chamfer}return r.create(a.extend({},p,u))},e.circle=function(h,l,t,i,s){i=i||{};var u={label:"Circle Body",circleRadius:t};s=s||25;var m=Math.ceil(Math.max(10,Math.min(s,t)));return m%2===1&&(m+=1),e.polygon(h,l,m,t,a.extend({},u,i))},e.polygon=function(h,l,t,i,s){if(s=s||{},t<3)return e.circle(h,l,i,s);for(var u=2*Math.PI/t,m="",x=u*.5,P=0;P<t;P+=1){var B=x+P*u,g=Math.cos(B)*i,p=Math.sin(B)*i;m+="L "+g.toFixed(3)+" "+p.toFixed(3)+" "}var y={label:"Polygon Body",position:{x:h,y:l},vertices:o.fromPath(m)};if(s.chamfer){var v=s.chamfer;y.vertices=o.chamfer(y.vertices,v.radius,v.quality,v.qualityMin,v.qualityMax),delete s.chamfer}return r.create(a.extend({},y,s))},e.fromVertices=function(h,l,t,i,s,u,m,x){var P=a.getDecomp(),B=!!(P&&P.quickDecomp),g,p,y,v,w,S,C,M,I,R;for(i=i||{},p=[],s=typeof s<"u"?s:!1,u=typeof u<"u"?u:.01,m=typeof m<"u"?m:10,x=typeof x<"u"?x:.01,a.isArray(t[0])||(t=[t]),I=0;I<t.length;I+=1)if(w=t[I],y=o.isConvex(w),v=!y,v&&!B&&a.warnOnce("Bodies.fromVertices: Install the 'poly-decomp' library and use Common.setDecomp or provide 'decomp' as a global to decompose concave vertices."),y||!B)y?w=o.clockwiseSort(w):w=o.hull(w),p.push({position:{x:h,y:l},vertices:w});else{var L=w.map(function(U){return[U.x,U.y]});P.makeCCW(L),u!==!1&&P.removeCollinearPoints(L,u),x!==!1&&P.removeDuplicatePoints&&P.removeDuplicatePoints(L,x);var b=P.quickDecomp(L);for(S=0;S<b.length;S++){var k=b[S].map(function(U){return{x:U[0],y:U[1]}});m>0&&o.area(k)<m||p.push({position:o.centre(k),vertices:k})}}for(S=0;S<p.length;S++)p[S]=r.create(a.extend(p[S],i));if(s){var D=5;for(S=0;S<p.length;S++){var O=p[S];for(C=S+1;C<p.length;C++){var H=p[C];if(c.overlaps(O.bounds,H.bounds)){var G=O.vertices,V=H.vertices;for(M=0;M<O.vertices.length;M++)for(R=0;R<H.vertices.length;R++){var Q=n.magnitudeSquared(n.sub(G[(M+1)%G.length],V[R])),X=n.magnitudeSquared(n.sub(G[M],V[(R+1)%V.length]));Q<D&&X<D&&(G[M].isInternal=!0,V[R].isInternal=!0)}}}}}return p.length>1?(g=r.create(a.extend({parts:p.slice(0)},i)),r.setPosition(g,{x:h,y:l}),g):p[0]}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(0),a=f(8);(function(){e.create=function(r){return o.extend({bodies:[],collisions:[],pairs:null},r)},e.setBodies=function(r,c){r.bodies=c.slice(0)},e.clear=function(r){r.bodies=[],r.collisions=[]},e.collisions=function(r){var c=r.pairs,n=r.bodies,h=n.length,l=e.canCollide,t=a.collides,i=r.collisions,s=0,u,m;for(n.sort(e._compareBoundsX),u=0;u<h;u++){var x=n[u],P=x.bounds,B=x.bounds.max.x,g=x.bounds.max.y,p=x.bounds.min.y,y=x.isStatic||x.isSleeping,v=x.parts.length,w=v===1;for(m=u+1;m<h;m++){var S=n[m],C=S.bounds;if(C.min.x>B)break;if(!(g<C.min.y||p>C.max.y)&&!(y&&(S.isStatic||S.isSleeping))&&l(x.collisionFilter,S.collisionFilter)){var M=S.parts.length;if(w&&M===1){var I=t(x,S,c);I&&(i[s++]=I)}else for(var R=v>1?1:0,L=M>1?1:0,b=R;b<v;b++)for(var k=x.parts[b],P=k.bounds,D=L;D<M;D++){var O=S.parts[D],C=O.bounds;if(!(P.min.x>C.max.x||P.max.x<C.min.x||P.max.y<C.min.y||P.min.y>C.max.y)){var I=t(k,O,c);I&&(i[s++]=I)}}}}}return i.length!==s&&(i.length=s),i},e.canCollide=function(r,c){return r.group===c.group&&r.group!==0?r.group>0:(r.mask&c.category)!==0&&(c.mask&r.category)!==0},e._compareBoundsX=function(r,c){return r.bounds.min.x-c.bounds.min.x}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(0);(function(){e.create=function(a){var r={};return a||o.log("Mouse.create: element was undefined, defaulting to document.body","warn"),r.element=a||document.body,r.absolute={x:0,y:0},r.position={x:0,y:0},r.mousedownPosition={x:0,y:0},r.mouseupPosition={x:0,y:0},r.offset={x:0,y:0},r.scale={x:1,y:1},r.wheelDelta=0,r.button=-1,r.pixelRatio=parseInt(r.element.getAttribute("data-pixel-ratio"),10)||1,r.sourceEvents={mousemove:null,mousedown:null,mouseup:null,mousewheel:null},r.mousemove=function(c){var n=e._getRelativeMousePosition(c,r.element,r.pixelRatio);c.changedTouches&&(r.button=0,c.preventDefault()),r.absolute.x=n.x,r.absolute.y=n.y,r.position.x=r.absolute.x*r.scale.x+r.offset.x,r.position.y=r.absolute.y*r.scale.y+r.offset.y,r.sourceEvents.mousemove=c},r.mousedown=function(c){var n=e._getRelativeMousePosition(c,r.element,r.pixelRatio);c.changedTouches?(r.button=0,c.preventDefault()):r.button=c.button,r.absolute.x=n.x,r.absolute.y=n.y,r.position.x=r.absolute.x*r.scale.x+r.offset.x,r.position.y=r.absolute.y*r.scale.y+r.offset.y,r.mousedownPosition.x=r.position.x,r.mousedownPosition.y=r.position.y,r.sourceEvents.mousedown=c},r.mouseup=function(c){var n=e._getRelativeMousePosition(c,r.element,r.pixelRatio);c.changedTouches&&c.preventDefault(),r.button=-1,r.absolute.x=n.x,r.absolute.y=n.y,r.position.x=r.absolute.x*r.scale.x+r.offset.x,r.position.y=r.absolute.y*r.scale.y+r.offset.y,r.mouseupPosition.x=r.position.x,r.mouseupPosition.y=r.position.y,r.sourceEvents.mouseup=c},r.mousewheel=function(c){r.wheelDelta=Math.max(-1,Math.min(1,c.wheelDelta||-c.detail)),c.preventDefault(),r.sourceEvents.mousewheel=c},e.setElement(r,r.element),r},e.setElement=function(a,r){a.element=r,r.addEventListener("mousemove",a.mousemove,{passive:!0}),r.addEventListener("mousedown",a.mousedown,{passive:!0}),r.addEventListener("mouseup",a.mouseup,{passive:!0}),r.addEventListener("wheel",a.mousewheel,{passive:!1}),r.addEventListener("touchmove",a.mousemove,{passive:!1}),r.addEventListener("touchstart",a.mousedown,{passive:!1}),r.addEventListener("touchend",a.mouseup,{passive:!1})},e.clearSourceEvents=function(a){a.sourceEvents.mousemove=null,a.sourceEvents.mousedown=null,a.sourceEvents.mouseup=null,a.sourceEvents.mousewheel=null,a.wheelDelta=0},e.setOffset=function(a,r){a.offset.x=r.x,a.offset.y=r.y,a.position.x=a.absolute.x*a.scale.x+a.offset.x,a.position.y=a.absolute.y*a.scale.y+a.offset.y},e.setScale=function(a,r){a.scale.x=r.x,a.scale.y=r.y,a.position.x=a.absolute.x*a.scale.x+a.offset.x,a.position.y=a.absolute.y*a.scale.y+a.offset.y},e._getRelativeMousePosition=function(a,r,c){var n=r.getBoundingClientRect(),h=document.documentElement||document.body.parentNode||document.body,l=window.pageXOffset!==void 0?window.pageXOffset:h.scrollLeft,t=window.pageYOffset!==void 0?window.pageYOffset:h.scrollTop,i=a.changedTouches,s,u;return i?(s=i[0].pageX-n.left-l,u=i[0].pageY-n.top-t):(s=a.pageX-n.left-l,u=a.pageY-n.top-t),{x:s/(r.clientWidth/(r.width||r.clientWidth)*c),y:u/(r.clientHeight/(r.height||r.clientHeight)*c)}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(0);(function(){e._registry={},e.register=function(a){if(e.isPlugin(a)||o.warn("Plugin.register:",e.toString(a),"does not implement all required fields."),a.name in e._registry){var r=e._registry[a.name],c=e.versionParse(a.version).number,n=e.versionParse(r.version).number;c>n?(o.warn("Plugin.register:",e.toString(r),"was upgraded to",e.toString(a)),e._registry[a.name]=a):c<n?o.warn("Plugin.register:",e.toString(r),"can not be downgraded to",e.toString(a)):a!==r&&o.warn("Plugin.register:",e.toString(a),"is already registered to different plugin object")}else e._registry[a.name]=a;return a},e.resolve=function(a){return e._registry[e.dependencyParse(a).name]},e.toString=function(a){return typeof a=="string"?a:(a.name||"anonymous")+"@"+(a.version||a.range||"0.0.0")},e.isPlugin=function(a){return a&&a.name&&a.version&&a.install},e.isUsed=function(a,r){return a.used.indexOf(r)>-1},e.isFor=function(a,r){var c=a.for&&e.dependencyParse(a.for);return!a.for||r.name===c.name&&e.versionSatisfies(r.version,c.range)},e.use=function(a,r){if(a.uses=(a.uses||[]).concat(r||[]),a.uses.length===0){o.warn("Plugin.use:",e.toString(a),"does not specify any dependencies to install.");return}for(var c=e.dependencies(a),n=o.topologicalSort(c),h=[],l=0;l<n.length;l+=1)if(n[l]!==a.name){var t=e.resolve(n[l]);if(!t){h.push("❌ "+n[l]);continue}e.isUsed(a,t.name)||(e.isFor(t,a)||(o.warn("Plugin.use:",e.toString(t),"is for",t.for,"but installed on",e.toString(a)+"."),t._warned=!0),t.install?t.install(a):(o.warn("Plugin.use:",e.toString(t),"does not specify an install function."),t._warned=!0),t._warned?(h.push("🔶 "+e.toString(t)),delete t._warned):h.push("✅ "+e.toString(t)),a.used.push(t.name))}h.length>0&&o.info(h.join(" "))},e.dependencies=function(a,r){var c=e.dependencyParse(a),n=c.name;if(r=r||{},!(n in r)){a=e.resolve(a)||a,r[n]=o.map(a.uses||[],function(l){e.isPlugin(l)&&e.register(l);var t=e.dependencyParse(l),i=e.resolve(l);return i&&!e.versionSatisfies(i.version,t.range)?(o.warn("Plugin.dependencies:",e.toString(i),"does not satisfy",e.toString(t),"used by",e.toString(c)+"."),i._warned=!0,a._warned=!0):i||(o.warn("Plugin.dependencies:",e.toString(l),"used by",e.toString(c),"could not be resolved."),a._warned=!0),t.name});for(var h=0;h<r[n].length;h+=1)e.dependencies(r[n][h],r);return r}},e.dependencyParse=function(a){return o.isString(a)?(/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-+]+)?))?$/.test(a)||o.warn("Plugin.dependencyParse:",a,"is not a valid dependency string."),{name:a.split("@")[0],range:a.split("@")[1]||"*"}):{name:a.name,range:a.range||a.version}},e.versionParse=function(a){var r=/^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-+]+)?$/;r.test(a)||o.warn("Plugin.versionParse:",a,"is not a valid version or range.");var c=r.exec(a),n=Number(c[4]),h=Number(c[5]),l=Number(c[6]);return{isRange:!!(c[1]||c[2]),version:c[3],range:a,operator:c[1]||c[2]||"",major:n,minor:h,patch:l,parts:[n,h,l],prerelease:c[7],number:n*1e8+h*1e4+l}},e.versionSatisfies=function(a,r){r=r||"*";var c=e.versionParse(r),n=e.versionParse(a);if(c.isRange){if(c.operator==="*"||a==="*")return!0;if(c.operator===">")return n.number>c.number;if(c.operator===">=")return n.number>=c.number;if(c.operator==="~")return n.major===c.major&&n.minor===c.minor&&n.patch>=c.patch;if(c.operator==="^")return c.major>0?n.major===c.major&&n.number>=c.number:c.minor>0?n.minor===c.minor&&n.patch>=c.patch:n.patch===c.patch}return a===r||a==="*"}})()}),(function(T,A){var f={};T.exports=f,(function(){f.create=function(e){return{vertex:e,normalImpulse:0,tangentImpulse:0}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(7),a=f(18),r=f(13),c=f(19),n=f(5),h=f(6),l=f(10),t=f(0),i=f(4);(function(){e._deltaMax=1e3/60,e.create=function(s){s=s||{};var u=t.extend({positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],plugin:{},gravity:{x:0,y:1,scale:.001},timing:{timestamp:0,timeScale:1,lastDelta:0,lastElapsed:0,lastUpdatesPerFrame:0}},s);return u.world=s.world||h.create({label:"World"}),u.pairs=s.pairs||c.create(),u.detector=s.detector||r.create(),u.detector.pairs=u.pairs,u.grid={buckets:[]},u.world.gravity=u.gravity,u.broadphase=u.grid,u.metrics={},u},e.update=function(s,u){var m=t.now(),x=s.world,P=s.detector,B=s.pairs,g=s.timing,p=g.timestamp,y;u>e._deltaMax&&t.warnOnce("Matter.Engine.update: delta argument is recommended to be less than or equal to",e._deltaMax.toFixed(3),"ms."),u=typeof u<"u"?u:t._baseDelta,u*=g.timeScale,g.timestamp+=u,g.lastDelta=u;var v={timestamp:g.timestamp,delta:u};n.trigger(s,"beforeUpdate",v);var w=h.allBodies(x),S=h.allConstraints(x);for(x.isModified&&(r.setBodies(P,w),h.setModified(x,!1,!1,!0)),s.enableSleeping&&o.update(w,u),e._bodiesApplyGravity(w,s.gravity),u>0&&e._bodiesUpdate(w,u),n.trigger(s,"beforeSolve",v),l.preSolveAll(w),y=0;y<s.constraintIterations;y++)l.solveAll(S,u);l.postSolveAll(w);var C=r.collisions(P);c.update(B,C,p),s.enableSleeping&&o.afterCollisions(B.list),B.collisionStart.length>0&&n.trigger(s,"collisionStart",{pairs:B.collisionStart,timestamp:g.timestamp,delta:u});var M=t.clamp(20/s.positionIterations,0,1);for(a.preSolvePosition(B.list),y=0;y<s.positionIterations;y++)a.solvePosition(B.list,u,M);for(a.postSolvePosition(w),l.preSolveAll(w),y=0;y<s.constraintIterations;y++)l.solveAll(S,u);for(l.postSolveAll(w),a.preSolveVelocity(B.list),y=0;y<s.velocityIterations;y++)a.solveVelocity(B.list,u);return e._bodiesUpdateVelocities(w),B.collisionActive.length>0&&n.trigger(s,"collisionActive",{pairs:B.collisionActive,timestamp:g.timestamp,delta:u}),B.collisionEnd.length>0&&n.trigger(s,"collisionEnd",{pairs:B.collisionEnd,timestamp:g.timestamp,delta:u}),e._bodiesClearForces(w),n.trigger(s,"afterUpdate",v),s.timing.lastElapsed=t.now()-m,s},e.merge=function(s,u){if(t.extend(s,u),u.world){s.world=u.world,e.clear(s);for(var m=h.allBodies(s.world),x=0;x<m.length;x++){var P=m[x];o.set(P,!1),P.id=t.nextId()}}},e.clear=function(s){c.clear(s.pairs),r.clear(s.detector)},e._bodiesClearForces=function(s){for(var u=s.length,m=0;m<u;m++){var x=s[m];x.force.x=0,x.force.y=0,x.torque=0}},e._bodiesApplyGravity=function(s,u){var m=typeof u.scale<"u"?u.scale:.001,x=s.length;if(!(u.x===0&&u.y===0||m===0))for(var P=0;P<x;P++){var B=s[P];B.isStatic||B.isSleeping||(B.force.y+=B.mass*u.y*m,B.force.x+=B.mass*u.x*m)}},e._bodiesUpdate=function(s,u){for(var m=s.length,x=0;x<m;x++){var P=s[x];P.isStatic||P.isSleeping||i.update(P,u)}},e._bodiesUpdateVelocities=function(s){for(var u=s.length,m=0;m<u;m++)i.updateVelocities(s[m])}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(0),r=f(1);(function(){e._restingThresh=2,e._restingThreshTangent=Math.sqrt(6),e._positionDampen=.9,e._positionWarming=.8,e._frictionNormalMultiplier=5,e._frictionMaxStatic=Number.MAX_VALUE,e.preSolvePosition=function(c){var n,h,l,t=c.length;for(n=0;n<t;n++)h=c[n],h.isActive&&(l=h.contactCount,h.collision.parentA.totalContacts+=l,h.collision.parentB.totalContacts+=l)},e.solvePosition=function(c,n,h){var l,t,i,s,u,m,x,P,B=e._positionDampen*(h||1),g=a.clamp(n/a._baseDelta,0,1),p=c.length;for(l=0;l<p;l++)t=c[l],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,u=i.parentB,m=i.normal,t.separation=i.depth+m.x*(u.positionImpulse.x-s.positionImpulse.x)+m.y*(u.positionImpulse.y-s.positionImpulse.y));for(l=0;l<p;l++)t=c[l],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,u=i.parentB,m=i.normal,P=t.separation-t.slop*g,(s.isStatic||u.isStatic)&&(P*=2),s.isStatic||s.isSleeping||(x=B/s.totalContacts,s.positionImpulse.x+=m.x*P*x,s.positionImpulse.y+=m.y*P*x),u.isStatic||u.isSleeping||(x=B/u.totalContacts,u.positionImpulse.x-=m.x*P*x,u.positionImpulse.y-=m.y*P*x))},e.postSolvePosition=function(c){for(var n=e._positionWarming,h=c.length,l=o.translate,t=r.update,i=0;i<h;i++){var s=c[i],u=s.positionImpulse,m=u.x,x=u.y,P=s.velocity;if(s.totalContacts=0,m!==0||x!==0){for(var B=0;B<s.parts.length;B++){var g=s.parts[B];l(g.vertices,u),t(g.bounds,g.vertices,P),g.position.x+=m,g.position.y+=x}s.positionPrev.x+=m,s.positionPrev.y+=x,m*P.x+x*P.y<0?(u.x=0,u.y=0):(u.x*=n,u.y*=n)}}},e.preSolveVelocity=function(c){var n=c.length,h,l;for(h=0;h<n;h++){var t=c[h];if(!(!t.isActive||t.isSensor)){var i=t.contacts,s=t.contactCount,u=t.collision,m=u.parentA,x=u.parentB,P=u.normal,B=u.tangent;for(l=0;l<s;l++){var g=i[l],p=g.vertex,y=g.normalImpulse,v=g.tangentImpulse;if(y!==0||v!==0){var w=P.x*y+B.x*v,S=P.y*y+B.y*v;m.isStatic||m.isSleeping||(m.positionPrev.x+=w*m.inverseMass,m.positionPrev.y+=S*m.inverseMass,m.anglePrev+=m.inverseInertia*((p.x-m.position.x)*S-(p.y-m.position.y)*w)),x.isStatic||x.isSleeping||(x.positionPrev.x-=w*x.inverseMass,x.positionPrev.y-=S*x.inverseMass,x.anglePrev-=x.inverseInertia*((p.x-x.position.x)*S-(p.y-x.position.y)*w))}}}}},e.solveVelocity=function(c,n){var h=n/a._baseDelta,l=h*h*h,t=-e._restingThresh*h,i=e._restingThreshTangent,s=e._frictionNormalMultiplier*h,u=e._frictionMaxStatic,m=c.length,x,P,B,g;for(B=0;B<m;B++){var p=c[B];if(!(!p.isActive||p.isSensor)){var y=p.collision,v=y.parentA,w=y.parentB,S=y.normal.x,C=y.normal.y,M=y.tangent.x,I=y.tangent.y,R=p.inverseMass,L=p.friction*p.frictionStatic*s,b=p.contacts,k=p.contactCount,D=1/k,O=v.position.x-v.positionPrev.x,H=v.position.y-v.positionPrev.y,G=v.angle-v.anglePrev,V=w.position.x-w.positionPrev.x,Q=w.position.y-w.positionPrev.y,X=w.angle-w.anglePrev;for(g=0;g<k;g++){var U=b[g],W=U.vertex,N=W.x-v.position.x,q=W.y-v.position.y,K=W.x-w.position.x,Y=W.y-w.position.y,z=O-q*G,Ct=H+N*G,Mt=V-Y*X,Tt=Q+K*X,pe=z-Mt,me=Ct-Tt,ue=S*pe+C*me,$=M*pe+I*me,xe=p.separation+ue,fe=Math.min(xe,1);fe=xe<0?0:fe;var ye=fe*L;$<-ye||$>ye?(P=$>0?$:-$,x=p.friction*($>0?1:-1)*l,x<-P?x=-P:x>P&&(x=P)):(x=$,P=u);var Se=N*C-q*S,we=K*C-Y*S,Pe=D/(R+v.inverseInertia*Se*Se+w.inverseInertia*we*we),ne=(1+p.restitution)*ue*Pe;if(x*=Pe,ue<t)U.normalImpulse=0;else{var Bt=U.normalImpulse;U.normalImpulse+=ne,U.normalImpulse>0&&(U.normalImpulse=0),ne=U.normalImpulse-Bt}if($<-i||$>i)U.tangentImpulse=0;else{var Et=U.tangentImpulse;U.tangentImpulse+=x,U.tangentImpulse<-P&&(U.tangentImpulse=-P),U.tangentImpulse>P&&(U.tangentImpulse=P),x=U.tangentImpulse-Et}var se=S*ne+M*x,re=C*ne+I*x;v.isStatic||v.isSleeping||(v.positionPrev.x+=se*v.inverseMass,v.positionPrev.y+=re*v.inverseMass,v.anglePrev+=(N*re-q*se)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=se*w.inverseMass,w.positionPrev.y-=re*w.inverseMass,w.anglePrev-=(K*re-Y*se)*w.inverseInertia)}}}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(9),a=f(0);(function(){e.create=function(r){return a.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},r)},e.update=function(r,c,n){var h=o.update,l=o.create,t=o.setActive,i=r.table,s=r.list,u=s.length,m=u,x=r.collisionStart,P=r.collisionEnd,B=r.collisionActive,g=c.length,p=0,y=0,v=0,w,S,C;for(C=0;C<g;C++)w=c[C],S=w.pair,S?(S.isActive&&(B[v++]=S),h(S,w,n)):(S=l(w,n),i[S.id]=S,x[p++]=S,s[m++]=S);for(m=0,u=s.length,C=0;C<u;C++)S=s[C],S.timeUpdated>=n?s[m++]=S:(t(S,!1,n),S.collision.bodyA.sleepCounter>0&&S.collision.bodyB.sleepCounter>0?s[m++]=S:(P[y++]=S,delete i[S.id]));s.length!==m&&(s.length=m),x.length!==p&&(x.length=p),P.length!==y&&(P.length=y),B.length!==v&&(B.length=v)},e.clear=function(r){return r.table={},r.list.length=0,r.collisionStart.length=0,r.collisionActive.length=0,r.collisionEnd.length=0,r}})()}),(function(T,A,f){var e=T.exports=f(21);e.Axes=f(11),e.Bodies=f(12),e.Body=f(4),e.Bounds=f(1),e.Collision=f(8),e.Common=f(0),e.Composite=f(6),e.Composites=f(22),e.Constraint=f(10),e.Contact=f(16),e.Detector=f(13),e.Engine=f(17),e.Events=f(5),e.Grid=f(23),e.Mouse=f(14),e.MouseConstraint=f(24),e.Pair=f(9),e.Pairs=f(19),e.Plugin=f(15),e.Query=f(25),e.Render=f(26),e.Resolver=f(18),e.Runner=f(27),e.SAT=f(28),e.Sleeping=f(7),e.Svg=f(29),e.Vector=f(2),e.Vertices=f(3),e.World=f(30),e.Engine.run=e.Runner.run,e.Common.deprecated(e.Engine,"run","Engine.run ➤ use Matter.Runner.run(engine) instead")}),(function(T,A,f){var e={};T.exports=e;var o=f(15),a=f(0);(function(){e.name="matter-js",e.version="0.20.0",e.uses=[],e.used=[],e.use=function(){o.use(e,Array.prototype.slice.call(arguments))},e.before=function(r,c){return r=r.replace(/^Matter./,""),a.chainPathBefore(e,r,c)},e.after=function(r,c){return r=r.replace(/^Matter./,""),a.chainPathAfter(e,r,c)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(6),a=f(10),r=f(0),c=f(4),n=f(12),h=r.deprecated;(function(){e.stack=function(l,t,i,s,u,m,x){for(var P=o.create({label:"Stack"}),B=l,g=t,p,y=0,v=0;v<s;v++){for(var w=0,S=0;S<i;S++){var C=x(B,g,S,v,p,y);if(C){var M=C.bounds.max.y-C.bounds.min.y,I=C.bounds.max.x-C.bounds.min.x;M>w&&(w=M),c.translate(C,{x:I*.5,y:M*.5}),B=C.bounds.max.x+u,o.addBody(P,C),p=C,y+=1}else B+=u}g+=w+m,B=l}return P},e.chain=function(l,t,i,s,u,m){for(var x=l.bodies,P=1;P<x.length;P++){var B=x[P-1],g=x[P],p=B.bounds.max.y-B.bounds.min.y,y=B.bounds.max.x-B.bounds.min.x,v=g.bounds.max.y-g.bounds.min.y,w=g.bounds.max.x-g.bounds.min.x,S={bodyA:B,pointA:{x:y*t,y:p*i},bodyB:g,pointB:{x:w*s,y:v*u}},C=r.extend(S,m);o.addConstraint(l,a.create(C))}return l.label+=" Chain",l},e.mesh=function(l,t,i,s,u){var m=l.bodies,x,P,B,g,p;for(x=0;x<i;x++){for(P=1;P<t;P++)B=m[P-1+x*t],g=m[P+x*t],o.addConstraint(l,a.create(r.extend({bodyA:B,bodyB:g},u)));if(x>0)for(P=0;P<t;P++)B=m[P+(x-1)*t],g=m[P+x*t],o.addConstraint(l,a.create(r.extend({bodyA:B,bodyB:g},u))),s&&P>0&&(p=m[P-1+(x-1)*t],o.addConstraint(l,a.create(r.extend({bodyA:p,bodyB:g},u)))),s&&P<t-1&&(p=m[P+1+(x-1)*t],o.addConstraint(l,a.create(r.extend({bodyA:p,bodyB:g},u))))}return l.label+=" Mesh",l},e.pyramid=function(l,t,i,s,u,m,x){return e.stack(l,t,i,s,u,m,function(P,B,g,p,y,v){var w=Math.min(s,Math.ceil(i/2)),S=y?y.bounds.max.x-y.bounds.min.x:0;if(!(p>w)){p=w-p;var C=p,M=i-1-p;if(!(g<C||g>M))return v===1&&c.translate(y,{x:(g+(i%2===1?1:-1))*S,y:0}),x(l+(y?g*S:0)+g*u,B,g,p,y,v)}})},e.newtonsCradle=function(l,t,i,s,u){for(var m=o.create({label:"Newtons Cradle"}),x=0;x<i;x++){var P=1.9,B=n.circle(l+x*(s*P),t+u,s,{inertia:1/0,restitution:1,friction:0,frictionAir:1e-4,slop:1}),g=a.create({pointA:{x:l+x*(s*P),y:t},bodyB:B});o.addBody(m,B),o.addConstraint(m,g)}return m},h(e,"newtonsCradle","Composites.newtonsCradle ➤ moved to newtonsCradle example"),e.car=function(l,t,i,s,u){var m=c.nextGroup(!0),x=20,P=-i*.5+x,B=i*.5-x,g=0,p=o.create({label:"Car"}),y=n.rectangle(l,t,i,s,{collisionFilter:{group:m},chamfer:{radius:s*.5},density:2e-4}),v=n.circle(l+P,t+g,u,{collisionFilter:{group:m},friction:.8}),w=n.circle(l+B,t+g,u,{collisionFilter:{group:m},friction:.8}),S=a.create({bodyB:y,pointB:{x:P,y:g},bodyA:v,stiffness:1,length:0}),C=a.create({bodyB:y,pointB:{x:B,y:g},bodyA:w,stiffness:1,length:0});return o.addBody(p,y),o.addBody(p,v),o.addBody(p,w),o.addConstraint(p,S),o.addConstraint(p,C),p},h(e,"car","Composites.car ➤ moved to car example"),e.softBody=function(l,t,i,s,u,m,x,P,B,g){B=r.extend({inertia:1/0},B),g=r.extend({stiffness:.2,render:{type:"line",anchors:!1}},g);var p=e.stack(l,t,i,s,u,m,function(y,v){return n.circle(y,v,P,B)});return e.mesh(p,i,s,x,g),p.label="Soft Body",p},h(e,"softBody","Composites.softBody ➤ moved to softBody and cloth examples")})()}),(function(T,A,f){var e={};T.exports=e;var o=f(9),a=f(0),r=a.deprecated;(function(){e.create=function(c){return a.extend({buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48},c)},e.update=function(c,n,h,l){var t,i,s,u=h.world,m=c.buckets,x,P,B=!1;for(t=0;t<n.length;t++){var g=n[t];if(!(g.isSleeping&&!l)&&!(u.bounds&&(g.bounds.max.x<u.bounds.min.x||g.bounds.min.x>u.bounds.max.x||g.bounds.max.y<u.bounds.min.y||g.bounds.min.y>u.bounds.max.y))){var p=e._getRegion(c,g);if(!g.region||p.id!==g.region.id||l){(!g.region||l)&&(g.region=p);var y=e._regionUnion(p,g.region);for(i=y.startCol;i<=y.endCol;i++)for(s=y.startRow;s<=y.endRow;s++){P=e._getBucketId(i,s),x=m[P];var v=i>=p.startCol&&i<=p.endCol&&s>=p.startRow&&s<=p.endRow,w=i>=g.region.startCol&&i<=g.region.endCol&&s>=g.region.startRow&&s<=g.region.endRow;!v&&w&&w&&x&&e._bucketRemoveBody(c,x,g),(g.region===p||v&&!w||l)&&(x||(x=e._createBucket(m,P)),e._bucketAddBody(c,x,g))}g.region=p,B=!0}}}B&&(c.pairsList=e._createActivePairsList(c))},r(e,"update","Grid.update ➤ replaced by Matter.Detector"),e.clear=function(c){c.buckets={},c.pairs={},c.pairsList=[]},r(e,"clear","Grid.clear ➤ replaced by Matter.Detector"),e._regionUnion=function(c,n){var h=Math.min(c.startCol,n.startCol),l=Math.max(c.endCol,n.endCol),t=Math.min(c.startRow,n.startRow),i=Math.max(c.endRow,n.endRow);return e._createRegion(h,l,t,i)},e._getRegion=function(c,n){var h=n.bounds,l=Math.floor(h.min.x/c.bucketWidth),t=Math.floor(h.max.x/c.bucketWidth),i=Math.floor(h.min.y/c.bucketHeight),s=Math.floor(h.max.y/c.bucketHeight);return e._createRegion(l,t,i,s)},e._createRegion=function(c,n,h,l){return{id:c+","+n+","+h+","+l,startCol:c,endCol:n,startRow:h,endRow:l}},e._getBucketId=function(c,n){return"C"+c+"R"+n},e._createBucket=function(c,n){return c[n]=[]},e._bucketAddBody=function(c,n,h){var l=c.pairs,t=o.id,i=n.length,s;for(s=0;s<i;s++){var u=n[s];if(!(h.id===u.id||h.isStatic&&u.isStatic)){var m=t(h,u),x=l[m];x?x[2]+=1:l[m]=[h,u,1]}}n.push(h)},e._bucketRemoveBody=function(c,n,h){var l=c.pairs,t=o.id,i;n.splice(a.indexOf(n,h),1);var s=n.length;for(i=0;i<s;i++){var u=l[t(h,n[i])];u&&(u[2]-=1)}},e._createActivePairsList=function(c){var n,h=c.pairs,l=a.keys(h),t=l.length,i=[],s;for(s=0;s<t;s++)n=h[l[s]],n[2]>0?i.push(n):delete h[l[s]];return i}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(3),a=f(7),r=f(14),c=f(5),n=f(13),h=f(10),l=f(6),t=f(0),i=f(1);(function(){e.create=function(s,u){var m=(s?s.mouse:null)||(u?u.mouse:null);m||(s&&s.render&&s.render.canvas?m=r.create(s.render.canvas):u&&u.element?m=r.create(u.element):(m=r.create(),t.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var x=h.create({label:"Mouse Constraint",pointA:m.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),P={type:"mouseConstraint",mouse:m,element:null,body:null,constraint:x,collisionFilter:{category:1,mask:4294967295,group:0}},B=t.extend(P,u);return c.on(s,"beforeUpdate",function(){var g=l.allBodies(s.world);e.update(B,g),e._triggerEvents(B)}),B},e.update=function(s,u){var m=s.mouse,x=s.constraint,P=s.body;if(m.button===0){if(x.bodyB)a.set(x.bodyB,!1),x.pointA=m.position;else for(var B=0;B<u.length;B++)if(P=u[B],i.contains(P.bounds,m.position)&&n.canCollide(P.collisionFilter,s.collisionFilter))for(var g=P.parts.length>1?1:0;g<P.parts.length;g++){var p=P.parts[g];if(o.contains(p.vertices,m.position)){x.pointA=m.position,x.bodyB=s.body=P,x.pointB={x:m.position.x-P.position.x,y:m.position.y-P.position.y},x.angleB=P.angle,a.set(P,!1),c.trigger(s,"startdrag",{mouse:m,body:P});break}}}else x.bodyB=s.body=null,x.pointB=null,P&&c.trigger(s,"enddrag",{mouse:m,body:P})},e._triggerEvents=function(s){var u=s.mouse,m=u.sourceEvents;m.mousemove&&c.trigger(s,"mousemove",{mouse:u}),m.mousedown&&c.trigger(s,"mousedown",{mouse:u}),m.mouseup&&c.trigger(s,"mouseup",{mouse:u}),r.clearSourceEvents(u)}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(2),a=f(8),r=f(1),c=f(12),n=f(3);(function(){e.collides=function(h,l){for(var t=[],i=l.length,s=h.bounds,u=a.collides,m=r.overlaps,x=0;x<i;x++){var P=l[x],B=P.parts.length,g=B===1?0:1;if(m(P.bounds,s))for(var p=g;p<B;p++){var y=P.parts[p];if(m(y.bounds,s)){var v=u(y,h);if(v){t.push(v);break}}}}return t},e.ray=function(h,l,t,i){i=i||1e-100;for(var s=o.angle(l,t),u=o.magnitude(o.sub(l,t)),m=(t.x+l.x)*.5,x=(t.y+l.y)*.5,P=c.rectangle(m,x,u,i,{angle:s}),B=e.collides(P,h),g=0;g<B.length;g+=1){var p=B[g];p.body=p.bodyB=p.bodyA}return B},e.region=function(h,l,t){for(var i=[],s=0;s<h.length;s++){var u=h[s],m=r.overlaps(u.bounds,l);(m&&!t||!m&&t)&&i.push(u)}return i},e.point=function(h,l){for(var t=[],i=0;i<h.length;i++){var s=h[i];if(r.contains(s.bounds,l))for(var u=s.parts.length===1?0:1;u<s.parts.length;u++){var m=s.parts[u];if(r.contains(m.bounds,l)&&n.contains(m.vertices,l)){t.push(s);break}}}return t}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(4),a=f(0),r=f(6),c=f(1),n=f(5),h=f(2),l=f(14);(function(){var t,i;typeof window<"u"&&(t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(g){window.setTimeout(function(){g(a.now())},1e3/60)},i=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),e._goodFps=30,e._goodDelta=1e3/60,e.create=function(g){var p={engine:null,element:null,canvas:null,mouse:null,frameRequestId:null,timing:{historySize:60,delta:0,deltaHistory:[],lastTime:0,lastTimestamp:0,lastElapsed:0,timestampElapsed:0,timestampElapsedHistory:[],engineDeltaHistory:[],engineElapsedHistory:[],engineUpdatesHistory:[],elapsedHistory:[]},options:{width:800,height:600,pixelRatio:1,background:"#14151f",wireframeBackground:"#14151f",wireframeStrokeStyle:"#bbb",hasBounds:!!g.bounds,enabled:!0,wireframes:!0,showSleeping:!0,showDebug:!1,showStats:!1,showPerformance:!1,showBounds:!1,showVelocity:!1,showCollisions:!1,showSeparations:!1,showAxes:!1,showPositions:!1,showAngleIndicator:!1,showIds:!1,showVertexNumbers:!1,showConvexHulls:!1,showInternalEdges:!1,showMousePosition:!1}},y=a.extend(p,g);return y.canvas&&(y.canvas.width=y.options.width||y.canvas.width,y.canvas.height=y.options.height||y.canvas.height),y.mouse=g.mouse,y.engine=g.engine,y.canvas=y.canvas||m(y.options.width,y.options.height),y.context=y.canvas.getContext("2d"),y.textures={},y.bounds=y.bounds||{min:{x:0,y:0},max:{x:y.canvas.width,y:y.canvas.height}},y.controller=e,y.options.showBroadphase=!1,y.options.pixelRatio!==1&&e.setPixelRatio(y,y.options.pixelRatio),a.isElement(y.element)&&y.element.appendChild(y.canvas),y},e.run=function(g){(function p(y){g.frameRequestId=t(p),s(g,y),e.world(g,y),g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0),(g.options.showStats||g.options.showDebug)&&e.stats(g,g.context,y),(g.options.showPerformance||g.options.showDebug)&&e.performance(g,g.context,y),g.context.setTransform(1,0,0,1,0,0)})()},e.stop=function(g){i(g.frameRequestId)},e.setPixelRatio=function(g,p){var y=g.options,v=g.canvas;p==="auto"&&(p=x(v)),y.pixelRatio=p,v.setAttribute("data-pixel-ratio",p),v.width=y.width*p,v.height=y.height*p,v.style.width=y.width+"px",v.style.height=y.height+"px"},e.setSize=function(g,p,y){g.options.width=p,g.options.height=y,g.bounds.max.x=g.bounds.min.x+p,g.bounds.max.y=g.bounds.min.y+y,g.options.pixelRatio!==1?e.setPixelRatio(g,g.options.pixelRatio):(g.canvas.width=p,g.canvas.height=y)},e.lookAt=function(g,p,y,v){v=typeof v<"u"?v:!0,p=a.isArray(p)?p:[p],y=y||{x:0,y:0};for(var w={min:{x:1/0,y:1/0},max:{x:-1/0,y:-1/0}},S=0;S<p.length;S+=1){var C=p[S],M=C.bounds?C.bounds.min:C.min||C.position||C,I=C.bounds?C.bounds.max:C.max||C.position||C;M&&I&&(M.x<w.min.x&&(w.min.x=M.x),I.x>w.max.x&&(w.max.x=I.x),M.y<w.min.y&&(w.min.y=M.y),I.y>w.max.y&&(w.max.y=I.y))}var R=w.max.x-w.min.x+2*y.x,L=w.max.y-w.min.y+2*y.y,b=g.canvas.height,k=g.canvas.width/b,D=R/L,O=1,H=1;D>k?H=D/k:O=k/D,g.options.hasBounds=!0,g.bounds.min.x=w.min.x,g.bounds.max.x=w.min.x+R*O,g.bounds.min.y=w.min.y,g.bounds.max.y=w.min.y+L*H,v&&(g.bounds.min.x+=R*.5-R*O*.5,g.bounds.max.x+=R*.5-R*O*.5,g.bounds.min.y+=L*.5-L*H*.5,g.bounds.max.y+=L*.5-L*H*.5),g.bounds.min.x-=y.x,g.bounds.max.x-=y.x,g.bounds.min.y-=y.y,g.bounds.max.y-=y.y,g.mouse&&(l.setScale(g.mouse,{x:(g.bounds.max.x-g.bounds.min.x)/g.canvas.width,y:(g.bounds.max.y-g.bounds.min.y)/g.canvas.height}),l.setOffset(g.mouse,g.bounds.min))},e.startViewTransform=function(g){var p=g.bounds.max.x-g.bounds.min.x,y=g.bounds.max.y-g.bounds.min.y,v=p/g.options.width,w=y/g.options.height;g.context.setTransform(g.options.pixelRatio/v,0,0,g.options.pixelRatio/w,0,0),g.context.translate(-g.bounds.min.x,-g.bounds.min.y)},e.endViewTransform=function(g){g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0)},e.world=function(g,p){var y=a.now(),v=g.engine,w=v.world,S=g.canvas,C=g.context,M=g.options,I=g.timing,R=r.allBodies(w),L=r.allConstraints(w),b=M.wireframes?M.wireframeBackground:M.background,k=[],D=[],O,H={timestamp:v.timing.timestamp};if(n.trigger(g,"beforeRender",H),g.currentBackground!==b&&B(g,b),C.globalCompositeOperation="source-in",C.fillStyle="transparent",C.fillRect(0,0,S.width,S.height),C.globalCompositeOperation="source-over",M.hasBounds){for(O=0;O<R.length;O++){var G=R[O];c.overlaps(G.bounds,g.bounds)&&k.push(G)}for(O=0;O<L.length;O++){var V=L[O],Q=V.bodyA,X=V.bodyB,U=V.pointA,W=V.pointB;Q&&(U=h.add(Q.position,V.pointA)),X&&(W=h.add(X.position,V.pointB)),!(!U||!W)&&(c.contains(g.bounds,U)||c.contains(g.bounds,W))&&D.push(V)}e.startViewTransform(g),g.mouse&&(l.setScale(g.mouse,{x:(g.bounds.max.x-g.bounds.min.x)/g.options.width,y:(g.bounds.max.y-g.bounds.min.y)/g.options.height}),l.setOffset(g.mouse,g.bounds.min))}else D=L,k=R,g.options.pixelRatio!==1&&g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0);!M.wireframes||v.enableSleeping&&M.showSleeping?e.bodies(g,k,C):(M.showConvexHulls&&e.bodyConvexHulls(g,k,C),e.bodyWireframes(g,k,C)),M.showBounds&&e.bodyBounds(g,k,C),(M.showAxes||M.showAngleIndicator)&&e.bodyAxes(g,k,C),M.showPositions&&e.bodyPositions(g,k,C),M.showVelocity&&e.bodyVelocity(g,k,C),M.showIds&&e.bodyIds(g,k,C),M.showSeparations&&e.separations(g,v.pairs.list,C),M.showCollisions&&e.collisions(g,v.pairs.list,C),M.showVertexNumbers&&e.vertexNumbers(g,k,C),M.showMousePosition&&e.mousePosition(g,g.mouse,C),e.constraints(D,C),M.hasBounds&&e.endViewTransform(g),n.trigger(g,"afterRender",H),I.lastElapsed=a.now()-y},e.stats=function(g,p,y){for(var v=g.engine,w=v.world,S=r.allBodies(w),C=0,M=55,I=44,R=0,L=0,b=0;b<S.length;b+=1)C+=S[b].parts.length;var k={Part:C,Body:S.length,Cons:r.allConstraints(w).length,Comp:r.allComposites(w).length,Pair:v.pairs.list.length};p.fillStyle="#0e0f19",p.fillRect(R,L,M*5.5,I),p.font="12px Arial",p.textBaseline="top",p.textAlign="right";for(var D in k){var O=k[D];p.fillStyle="#aaa",p.fillText(D,R+M,L+8),p.fillStyle="#eee",p.fillText(O,R+M,L+26),R+=M}},e.performance=function(g,p){var y=g.engine,v=g.timing,w=v.deltaHistory,S=v.elapsedHistory,C=v.timestampElapsedHistory,M=v.engineDeltaHistory,I=v.engineUpdatesHistory,R=v.engineElapsedHistory,L=y.timing.lastUpdatesPerFrame,b=y.timing.lastDelta,k=u(w),D=u(S),O=u(M),H=u(I),G=u(R),V=u(C)/k||0,Q=Math.round(k/b),X=1e3/k||0,U=4,W=12,N=60,q=34,K=10,Y=69;p.fillStyle="#0e0f19",p.fillRect(0,50,W*5+N*6+22,q),e.status(p,K,Y,N,U,w.length,Math.round(X)+" fps",X/e._goodFps,function(z){return w[z]/k-1}),e.status(p,K+W+N,Y,N,U,M.length,b.toFixed(2)+" dt",e._goodDelta/b,function(z){return M[z]/O-1}),e.status(p,K+(W+N)*2,Y,N,U,I.length,L+" upf",Math.pow(a.clamp(H/Q||1,0,1),4),function(z){return I[z]/H-1}),e.status(p,K+(W+N)*3,Y,N,U,R.length,G.toFixed(2)+" ut",1-L*G/e._goodFps,function(z){return R[z]/G-1}),e.status(p,K+(W+N)*4,Y,N,U,S.length,D.toFixed(2)+" rt",1-D/e._goodFps,function(z){return S[z]/D-1}),e.status(p,K+(W+N)*5,Y,N,U,C.length,V.toFixed(2)+" x",V*V*V,function(z){return(C[z]/w[z]/V||0)-1})},e.status=function(g,p,y,v,w,S,C,M,I){g.strokeStyle="#888",g.fillStyle="#444",g.lineWidth=1,g.fillRect(p,y+7,v,1),g.beginPath(),g.moveTo(p,y+7-w*a.clamp(.4*I(0),-2,2));for(var R=0;R<v;R+=1)g.lineTo(p+R,y+7-(R<S?w*a.clamp(.4*I(R),-2,2):0));g.stroke(),g.fillStyle="hsl("+a.clamp(25+95*M,0,120)+",100%,60%)",g.fillRect(p,y-7,4,4),g.font="12px Arial",g.textBaseline="middle",g.textAlign="right",g.fillStyle="#eee",g.fillText(C,p+v,y-5)},e.constraints=function(g,p){for(var y=p,v=0;v<g.length;v++){var w=g[v];if(!(!w.render.visible||!w.pointA||!w.pointB)){var S=w.bodyA,C=w.bodyB,M,I;if(S?M=h.add(S.position,w.pointA):M=w.pointA,w.render.type==="pin")y.beginPath(),y.arc(M.x,M.y,3,0,2*Math.PI),y.closePath();else{if(C?I=h.add(C.position,w.pointB):I=w.pointB,y.beginPath(),y.moveTo(M.x,M.y),w.render.type==="spring")for(var R=h.sub(I,M),L=h.perp(h.normalise(R)),b=Math.ceil(a.clamp(w.length/5,12,20)),k,D=1;D<b;D+=1)k=D%2===0?1:-1,y.lineTo(M.x+R.x*(D/b)+L.x*k*4,M.y+R.y*(D/b)+L.y*k*4);y.lineTo(I.x,I.y)}w.render.lineWidth&&(y.lineWidth=w.render.lineWidth,y.strokeStyle=w.render.strokeStyle,y.stroke()),w.render.anchors&&(y.fillStyle=w.render.strokeStyle,y.beginPath(),y.arc(M.x,M.y,3,0,2*Math.PI),y.arc(I.x,I.y,3,0,2*Math.PI),y.closePath(),y.fill())}}},e.bodies=function(g,p,y){var v=y;g.engine;var w=g.options,S=w.showInternalEdges||!w.wireframes,C,M,I,R;for(I=0;I<p.length;I++)if(C=p[I],!!C.render.visible){for(R=C.parts.length>1?1:0;R<C.parts.length;R++)if(M=C.parts[R],!!M.render.visible){if(w.showSleeping&&C.isSleeping?v.globalAlpha=.5*M.render.opacity:M.render.opacity!==1&&(v.globalAlpha=M.render.opacity),M.render.sprite&&M.render.sprite.texture&&!w.wireframes){var L=M.render.sprite,b=P(g,L.texture);v.translate(M.position.x,M.position.y),v.rotate(M.angle),v.drawImage(b,b.width*-L.xOffset*L.xScale,b.height*-L.yOffset*L.yScale,b.width*L.xScale,b.height*L.yScale),v.rotate(-M.angle),v.translate(-M.position.x,-M.position.y)}else{if(M.circleRadius)v.beginPath(),v.arc(M.position.x,M.position.y,M.circleRadius,0,2*Math.PI);else{v.beginPath(),v.moveTo(M.vertices[0].x,M.vertices[0].y);for(var k=1;k<M.vertices.length;k++)!M.vertices[k-1].isInternal||S?v.lineTo(M.vertices[k].x,M.vertices[k].y):v.moveTo(M.vertices[k].x,M.vertices[k].y),M.vertices[k].isInternal&&!S&&v.moveTo(M.vertices[(k+1)%M.vertices.length].x,M.vertices[(k+1)%M.vertices.length].y);v.lineTo(M.vertices[0].x,M.vertices[0].y),v.closePath()}w.wireframes?(v.lineWidth=1,v.strokeStyle=g.options.wireframeStrokeStyle,v.stroke()):(v.fillStyle=M.render.fillStyle,M.render.lineWidth&&(v.lineWidth=M.render.lineWidth,v.strokeStyle=M.render.strokeStyle,v.stroke()),v.fill())}v.globalAlpha=1}}},e.bodyWireframes=function(g,p,y){var v=y,w=g.options.showInternalEdges,S,C,M,I,R;for(v.beginPath(),M=0;M<p.length;M++)if(S=p[M],!!S.render.visible)for(R=S.parts.length>1?1:0;R<S.parts.length;R++){for(C=S.parts[R],v.moveTo(C.vertices[0].x,C.vertices[0].y),I=1;I<C.vertices.length;I++)!C.vertices[I-1].isInternal||w?v.lineTo(C.vertices[I].x,C.vertices[I].y):v.moveTo(C.vertices[I].x,C.vertices[I].y),C.vertices[I].isInternal&&!w&&v.moveTo(C.vertices[(I+1)%C.vertices.length].x,C.vertices[(I+1)%C.vertices.length].y);v.lineTo(C.vertices[0].x,C.vertices[0].y)}v.lineWidth=1,v.strokeStyle=g.options.wireframeStrokeStyle,v.stroke()},e.bodyConvexHulls=function(g,p,y){var v=y,w,S,C;for(v.beginPath(),S=0;S<p.length;S++)if(w=p[S],!(!w.render.visible||w.parts.length===1)){for(v.moveTo(w.vertices[0].x,w.vertices[0].y),C=1;C<w.vertices.length;C++)v.lineTo(w.vertices[C].x,w.vertices[C].y);v.lineTo(w.vertices[0].x,w.vertices[0].y)}v.lineWidth=1,v.strokeStyle="rgba(255,255,255,0.2)",v.stroke()},e.vertexNumbers=function(g,p,y){var v=y,w,S,C;for(w=0;w<p.length;w++){var M=p[w].parts;for(C=M.length>1?1:0;C<M.length;C++){var I=M[C];for(S=0;S<I.vertices.length;S++)v.fillStyle="rgba(255,255,255,0.2)",v.fillText(w+"_"+S,I.position.x+(I.vertices[S].x-I.position.x)*.8,I.position.y+(I.vertices[S].y-I.position.y)*.8)}}},e.mousePosition=function(g,p,y){var v=y;v.fillStyle="rgba(255,255,255,0.8)",v.fillText(p.position.x+" "+p.position.y,p.position.x+5,p.position.y-5)},e.bodyBounds=function(g,p,y){var v=y;g.engine;var w=g.options;v.beginPath();for(var S=0;S<p.length;S++)if(p[S].render.visible)for(var C=p[S].parts,M=C.length>1?1:0;M<C.length;M++){var I=C[M];v.rect(I.bounds.min.x,I.bounds.min.y,I.bounds.max.x-I.bounds.min.x,I.bounds.max.y-I.bounds.min.y)}w.wireframes?v.strokeStyle="rgba(255,255,255,0.08)":v.strokeStyle="rgba(0,0,0,0.1)",v.lineWidth=1,v.stroke()},e.bodyAxes=function(g,p,y){var v=y;g.engine;var w=g.options,S,C,M,I;for(v.beginPath(),C=0;C<p.length;C++){var R=p[C],L=R.parts;if(R.render.visible)if(w.showAxes)for(M=L.length>1?1:0;M<L.length;M++)for(S=L[M],I=0;I<S.axes.length;I++){var b=S.axes[I];v.moveTo(S.position.x,S.position.y),v.lineTo(S.position.x+b.x*20,S.position.y+b.y*20)}else for(M=L.length>1?1:0;M<L.length;M++)for(S=L[M],I=0;I<S.axes.length;I++)v.moveTo(S.position.x,S.position.y),v.lineTo((S.vertices[0].x+S.vertices[S.vertices.length-1].x)/2,(S.vertices[0].y+S.vertices[S.vertices.length-1].y)/2)}w.wireframes?(v.strokeStyle="indianred",v.lineWidth=1):(v.strokeStyle="rgba(255, 255, 255, 0.4)",v.globalCompositeOperation="overlay",v.lineWidth=2),v.stroke(),v.globalCompositeOperation="source-over"},e.bodyPositions=function(g,p,y){var v=y;g.engine;var w=g.options,S,C,M,I;for(v.beginPath(),M=0;M<p.length;M++)if(S=p[M],!!S.render.visible)for(I=0;I<S.parts.length;I++)C=S.parts[I],v.arc(C.position.x,C.position.y,3,0,2*Math.PI,!1),v.closePath();for(w.wireframes?v.fillStyle="indianred":v.fillStyle="rgba(0,0,0,0.5)",v.fill(),v.beginPath(),M=0;M<p.length;M++)S=p[M],S.render.visible&&(v.arc(S.positionPrev.x,S.positionPrev.y,2,0,2*Math.PI,!1),v.closePath());v.fillStyle="rgba(255,165,0,0.8)",v.fill()},e.bodyVelocity=function(g,p,y){var v=y;v.beginPath();for(var w=0;w<p.length;w++){var S=p[w];if(S.render.visible){var C=o.getVelocity(S);v.moveTo(S.position.x,S.position.y),v.lineTo(S.position.x+C.x,S.position.y+C.y)}}v.lineWidth=3,v.strokeStyle="cornflowerblue",v.stroke()},e.bodyIds=function(g,p,y){var v=y,w,S;for(w=0;w<p.length;w++)if(p[w].render.visible){var C=p[w].parts;for(S=C.length>1?1:0;S<C.length;S++){var M=C[S];v.font="12px Arial",v.fillStyle="rgba(255,255,255,0.5)",v.fillText(M.id,M.position.x+10,M.position.y-10)}}},e.collisions=function(g,p,y){var v=y,w=g.options,S,C,M,I;for(v.beginPath(),M=0;M<p.length;M++)if(S=p[M],!!S.isActive)for(C=S.collision,I=0;I<S.contactCount;I++){var R=S.contacts[I].vertex;v.rect(R.x-1.5,R.y-1.5,3.5,3.5)}for(w.wireframes?v.fillStyle="rgba(255,255,255,0.7)":v.fillStyle="orange",v.fill(),v.beginPath(),M=0;M<p.length;M++)if(S=p[M],!!S.isActive&&(C=S.collision,S.contactCount>0)){var L=S.contacts[0].vertex.x,b=S.contacts[0].vertex.y;S.contactCount===2&&(L=(S.contacts[0].vertex.x+S.contacts[1].vertex.x)/2,b=(S.contacts[0].vertex.y+S.contacts[1].vertex.y)/2),C.bodyB===C.supports[0].body||C.bodyA.isStatic===!0?v.moveTo(L-C.normal.x*8,b-C.normal.y*8):v.moveTo(L+C.normal.x*8,b+C.normal.y*8),v.lineTo(L,b)}w.wireframes?v.strokeStyle="rgba(255,165,0,0.7)":v.strokeStyle="orange",v.lineWidth=1,v.stroke()},e.separations=function(g,p,y){var v=y,w=g.options,S,C,M,I,R;for(v.beginPath(),R=0;R<p.length;R++)if(S=p[R],!!S.isActive){C=S.collision,M=C.bodyA,I=C.bodyB;var L=1;!I.isStatic&&!M.isStatic&&(L=.5),I.isStatic&&(L=0),v.moveTo(I.position.x,I.position.y),v.lineTo(I.position.x-C.penetration.x*L,I.position.y-C.penetration.y*L),L=1,!I.isStatic&&!M.isStatic&&(L=.5),M.isStatic&&(L=0),v.moveTo(M.position.x,M.position.y),v.lineTo(M.position.x+C.penetration.x*L,M.position.y+C.penetration.y*L)}w.wireframes?v.strokeStyle="rgba(255,165,0,0.5)":v.strokeStyle="orange",v.stroke()},e.inspector=function(g,p){g.engine;var y=g.selected,v=g.render,w=v.options,S;if(w.hasBounds){var C=v.bounds.max.x-v.bounds.min.x,M=v.bounds.max.y-v.bounds.min.y,I=C/v.options.width,R=M/v.options.height;p.scale(1/I,1/R),p.translate(-v.bounds.min.x,-v.bounds.min.y)}for(var L=0;L<y.length;L++){var b=y[L].data;switch(p.translate(.5,.5),p.lineWidth=1,p.strokeStyle="rgba(255,165,0,0.9)",p.setLineDash([1,2]),b.type){case"body":S=b.bounds,p.beginPath(),p.rect(Math.floor(S.min.x-3),Math.floor(S.min.y-3),Math.floor(S.max.x-S.min.x+6),Math.floor(S.max.y-S.min.y+6)),p.closePath(),p.stroke();break;case"constraint":var k=b.pointA;b.bodyA&&(k=b.pointB),p.beginPath(),p.arc(k.x,k.y,10,0,2*Math.PI),p.closePath(),p.stroke();break}p.setLineDash([]),p.translate(-.5,-.5)}g.selectStart!==null&&(p.translate(.5,.5),p.lineWidth=1,p.strokeStyle="rgba(255,165,0,0.6)",p.fillStyle="rgba(255,165,0,0.1)",S=g.selectBounds,p.beginPath(),p.rect(Math.floor(S.min.x),Math.floor(S.min.y),Math.floor(S.max.x-S.min.x),Math.floor(S.max.y-S.min.y)),p.closePath(),p.stroke(),p.fill(),p.translate(-.5,-.5)),w.hasBounds&&p.setTransform(1,0,0,1,0,0)};var s=function(g,p){var y=g.engine,v=g.timing,w=v.historySize,S=y.timing.timestamp;v.delta=p-v.lastTime||e._goodDelta,v.lastTime=p,v.timestampElapsed=S-v.lastTimestamp||0,v.lastTimestamp=S,v.deltaHistory.unshift(v.delta),v.deltaHistory.length=Math.min(v.deltaHistory.length,w),v.engineDeltaHistory.unshift(y.timing.lastDelta),v.engineDeltaHistory.length=Math.min(v.engineDeltaHistory.length,w),v.timestampElapsedHistory.unshift(v.timestampElapsed),v.timestampElapsedHistory.length=Math.min(v.timestampElapsedHistory.length,w),v.engineUpdatesHistory.unshift(y.timing.lastUpdatesPerFrame),v.engineUpdatesHistory.length=Math.min(v.engineUpdatesHistory.length,w),v.engineElapsedHistory.unshift(y.timing.lastElapsed),v.engineElapsedHistory.length=Math.min(v.engineElapsedHistory.length,w),v.elapsedHistory.unshift(v.lastElapsed),v.elapsedHistory.length=Math.min(v.elapsedHistory.length,w)},u=function(g){for(var p=0,y=0;y<g.length;y+=1)p+=g[y];return p/g.length||0},m=function(g,p){var y=document.createElement("canvas");return y.width=g,y.height=p,y.oncontextmenu=function(){return!1},y.onselectstart=function(){return!1},y},x=function(g){var p=g.getContext("2d");return(window.devicePixelRatio||1)/(p.webkitBackingStorePixelRatio||p.mozBackingStorePixelRatio||p.msBackingStorePixelRatio||p.oBackingStorePixelRatio||p.backingStorePixelRatio||1)},P=function(g,p){var y=g.textures[p];return y||(y=g.textures[p]=new Image,y.src=p,y)},B=function(g,p){var y=p;/(jpg|gif|png)$/.test(p)&&(y="url("+p+")"),g.canvas.style.background=y,g.canvas.style.backgroundSize="contain",g.currentBackground=p}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(5),a=f(17),r=f(0);(function(){e._maxFrameDelta=1e3/15,e._frameDeltaFallback=1e3/60,e._timeBufferMargin=1.5,e._elapsedNextEstimate=1,e._smoothingLowerBound=.1,e._smoothingUpperBound=.9,e.create=function(n){var h=r.extend({delta:16.666666666666668,frameDelta:null,frameDeltaSmoothing:!0,frameDeltaSnapping:!0,frameDeltaHistory:[],frameDeltaHistorySize:100,frameRequestId:null,timeBuffer:0,timeLastTick:null,maxUpdates:null,maxFrameTime:33.333333333333336,lastUpdatesDeferred:0,enabled:!0},n);return h.fps=0,h},e.run=function(n,h){return n.timeBuffer=e._frameDeltaFallback,(function l(t){n.frameRequestId=e._onNextFrame(n,l),t&&n.enabled&&e.tick(n,h,t)})(),n},e.tick=function(n,h,l){var t=r.now(),i=n.delta,s=0,u=l-n.timeLastTick;if((!u||!n.timeLastTick||u>Math.max(e._maxFrameDelta,n.maxFrameTime))&&(u=n.frameDelta||e._frameDeltaFallback),n.frameDeltaSmoothing){n.frameDeltaHistory.push(u),n.frameDeltaHistory=n.frameDeltaHistory.slice(-n.frameDeltaHistorySize);var m=n.frameDeltaHistory.slice(0).sort();u=c(n.frameDeltaHistory.slice(m.length*e._smoothingLowerBound,m.length*e._smoothingUpperBound))||u}n.frameDeltaSnapping&&(u=1e3/Math.round(1e3/u)),n.frameDelta=u,n.timeLastTick=l,n.timeBuffer+=n.frameDelta,n.timeBuffer=r.clamp(n.timeBuffer,0,n.frameDelta+i*e._timeBufferMargin),n.lastUpdatesDeferred=0;var x=n.maxUpdates||Math.ceil(n.maxFrameTime/i),P={timestamp:h.timing.timestamp};o.trigger(n,"beforeTick",P),o.trigger(n,"tick",P);for(var B=r.now();i>0&&n.timeBuffer>=i*e._timeBufferMargin;){o.trigger(n,"beforeUpdate",P),a.update(h,i),o.trigger(n,"afterUpdate",P),n.timeBuffer-=i,s+=1;var g=r.now()-t,p=r.now()-B,y=g+e._elapsedNextEstimate*p/s;if(s>=x||y>n.maxFrameTime){n.lastUpdatesDeferred=Math.round(Math.max(0,n.timeBuffer/i-e._timeBufferMargin));break}}h.timing.lastUpdatesPerFrame=s,o.trigger(n,"afterTick",P),n.frameDeltaHistory.length>=100&&(n.lastUpdatesDeferred&&Math.round(n.frameDelta/i)>x?r.warnOnce("Matter.Runner: runner reached runner.maxUpdates, see docs."):n.lastUpdatesDeferred&&r.warnOnce("Matter.Runner: runner reached runner.maxFrameTime, see docs."),typeof n.isFixed<"u"&&r.warnOnce("Matter.Runner: runner.isFixed is now redundant, see docs."),(n.deltaMin||n.deltaMax)&&r.warnOnce("Matter.Runner: runner.deltaMin and runner.deltaMax were removed, see docs."),n.fps!==0&&r.warnOnce("Matter.Runner: runner.fps was replaced by runner.delta, see docs."))},e.stop=function(n){e._cancelNextFrame(n)},e._onNextFrame=function(n,h){if(typeof window<"u"&&window.requestAnimationFrame)n.frameRequestId=window.requestAnimationFrame(h);else throw new Error("Matter.Runner: missing required global window.requestAnimationFrame.");return n.frameRequestId},e._cancelNextFrame=function(n){if(typeof window<"u"&&window.cancelAnimationFrame)window.cancelAnimationFrame(n.frameRequestId);else throw new Error("Matter.Runner: missing required global window.cancelAnimationFrame.")};var c=function(n){for(var h=0,l=n.length,t=0;t<l;t+=1)h+=n[t];return h/l||0}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(8),a=f(0).deprecated;(function(){e.collides=function(r,c){return o.collides(r,c)},a(e,"collides","SAT.collides ➤ replaced by Collision.collides")})()}),(function(T,A,f){var e={};T.exports=e,f(1);var o=f(0);(function(){e.pathToVertices=function(a,r){typeof window<"u"&&!("SVGPathSeg"in window)&&o.warn("Svg.pathToVertices: SVGPathSeg not defined, a polyfill is required.");var c,n,h,l,t,i,s,u,m,x,P=[],B,g,p=0,y=0,v=0;r=r||15;var w=function(C,M,I){var R=I%2===1&&I>1;if(!m||C!=m.x||M!=m.y){m&&R?(B=m.x,g=m.y):(B=0,g=0);var L={x:B+C,y:g+M};(R||!m)&&(m=L),P.push(L),y=B+C,v=g+M}},S=function(C){var M=C.pathSegTypeAsLetter.toUpperCase();if(M!=="Z"){switch(M){case"M":case"L":case"T":case"C":case"S":case"Q":y=C.x,v=C.y;break;case"H":y=C.x;break;case"V":v=C.y;break}w(y,v,C.pathSegType)}};for(e._svgPathToAbsolute(a),h=a.getTotalLength(),i=[],c=0;c<a.pathSegList.numberOfItems;c+=1)i.push(a.pathSegList.getItem(c));for(s=i.concat();p<h;){if(x=a.getPathSegAtLength(p),t=i[x],t!=u){for(;s.length&&s[0]!=t;)S(s.shift());u=t}switch(t.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":l=a.getPointAtLength(p),w(l.x,l.y,0);break}p+=r}for(c=0,n=s.length;c<n;++c)S(s[c]);return P},e._svgPathToAbsolute=function(a){for(var r,c,n,h,l,t,i=a.pathSegList,s=0,u=0,m=i.numberOfItems,x=0;x<m;++x){var P=i.getItem(x),B=P.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(B))"x"in P&&(s=P.x),"y"in P&&(u=P.y);else switch("x1"in P&&(n=s+P.x1),"x2"in P&&(l=s+P.x2),"y1"in P&&(h=u+P.y1),"y2"in P&&(t=u+P.y2),"x"in P&&(s+=P.x),"y"in P&&(u+=P.y),B){case"m":i.replaceItem(a.createSVGPathSegMovetoAbs(s,u),x);break;case"l":i.replaceItem(a.createSVGPathSegLinetoAbs(s,u),x);break;case"h":i.replaceItem(a.createSVGPathSegLinetoHorizontalAbs(s),x);break;case"v":i.replaceItem(a.createSVGPathSegLinetoVerticalAbs(u),x);break;case"c":i.replaceItem(a.createSVGPathSegCurvetoCubicAbs(s,u,n,h,l,t),x);break;case"s":i.replaceItem(a.createSVGPathSegCurvetoCubicSmoothAbs(s,u,l,t),x);break;case"q":i.replaceItem(a.createSVGPathSegCurvetoQuadraticAbs(s,u,n,h),x);break;case"t":i.replaceItem(a.createSVGPathSegCurvetoQuadraticSmoothAbs(s,u),x);break;case"a":i.replaceItem(a.createSVGPathSegArcAbs(s,u,P.r1,P.r2,P.angle,P.largeArcFlag,P.sweepFlag),x);break;case"z":case"Z":s=r,u=c;break}(B=="M"||B=="m")&&(r=s,c=u)}}})()}),(function(T,A,f){var e={};T.exports=e;var o=f(6);f(0),(function(){e.create=o.create,e.add=o.add,e.remove=o.remove,e.clear=o.clear,e.addComposite=o.addComposite,e.addBody=o.addBody,e.addConstraint=o.addConstraint})()})])})})),F=Xe();function Ke(d,E,T){return d<E?E:d>T?T:d}function J(d){const E=d.plugin.ballId;return typeof E=="number"?E:d.id}function Ye(d,E,T,A){return Ke(Math.floor((d-E)/T),0,A-1)}var $e=.18,Qe=.12,Ze=420,Je=.12,je=180,qe=2,_e=5,et=600,tt=2,it=25e3,nt=.15;function de(d,E){return{x:d,y:E,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:E,anchorAgeMs:0,aliveMs:0}}var st=class{tracker=new Map;track(d,E,T){this.tracker.set(d,de(E,T))}untrack(d){this.tracker.delete(d)}clear(){this.tracker.clear()}process(d,E,T){const A=[],f=new Set,e=[];for(const o of E){const a=J(o);f.add(a);const r=this.tracker.get(a)??de(o.position.x,o.position.y),c=r.aliveMs+d;if(c>=it||r.kickCount>=_e){A.push(o),this.tracker.delete(a);continue}const n=o.position.x-r.x,h=o.position.y-r.y,l=Math.sqrt(n*n+h*h),t=o.velocity,i=Math.sqrt(t.x*t.x+t.y*t.y),s=o.position.y>T.worldHeight*Je;let u=r.anchorY,m=r.anchorAgeMs+d;o.position.y>u+tt&&(u=o.position.y,m=0);const x=s&&(i<$e&&l<Qe||m>et)?r.stuckMs+d:Math.max(0,r.stuckMs-d*2),P=Math.max(0,r.kickCooldownMs-d);this.tracker.set(a,{x:o.position.x,y:o.position.y,stuckMs:x,kickCooldownMs:P,kickCount:r.kickCount,anchorY:u,anchorAgeMs:m,aliveMs:c}),x>=Ze&&P<=0&&e.push({ball:o,id:a,stuckMs:x})}this.applyKicks(e,T);for(const o of this.tracker.keys())f.has(o)||this.tracker.delete(o);return A}applyKicks(d,E){if(d.length===0)return;d.sort((A,f)=>Math.abs(f.ball.position.y-A.ball.position.y)>.1?f.ball.position.y-A.ball.position.y:f.stuckMs-A.stuckMs);const T=Math.min(qe,d.length);for(let A=0;A<T;A++){const{ball:f,id:e}=d[A],o=this.tracker.get(e);if(!o)continue;const a=f.velocity,r=Math.abs(f.position.x-E.center)/E.halfWidth<nt?Math.random()<.5?1:-1:f.position.x<E.center?1:-1,c=r*(.35+Math.random()*.35)+(Math.random()-.5)*.25,n=1.1+Math.random()*.5;F.Body.setVelocity(f,{x:a.x+c,y:Math.max(a.y+n,n)}),F.Body.translate(f,{x:r*(.2+Math.random()*.4),y:.25+Math.random()*.35}),this.tracker.set(e,{...o,x:f.position.x,y:f.position.y,stuckMs:0,kickCooldownMs:je,kickCount:o.kickCount+1})}}};function rt(d){const E=Math.max(0,Math.min(1,d)),T=E**1.3;return{windStrength:T*4e-7,collisionNudge:T*.13,spawnSigmaRatio:E>0?.04-T*.035:0}}var at=.4;function ot(d,E,T){if(!(T<=0))for(const A of d){if(Math.sqrt(A.velocity.x*A.velocity.x+A.velocity.y*A.velocity.y)<at)continue;const f=A.position.x-E;F.Body.applyForce(A,A.position,{x:-T*f,y:0})}}var _="plinkit-ball";function lt(){const d=Math.random(),E=Math.random();return Math.sqrt(-2*Math.log(d||1e-15))*Math.cos(2*Math.PI*E)}function ut(d,E){const T=Math.max(d.radius+8,d.height*.06);let A;return E&&E>0?A=lt()*d.width*E:A=(Math.random()-.5)*d.width*.08,F.Bodies.circle(d.width*.5+A,T,d.radius,{label:_,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var ee="plinkit-peg",te="plinkit-guide",oe="plinkit-wall",ft=.22,ct=4,ht=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new st;dist;removeCollisionNudge=null;removeCollisionStart=null;constructor(d){this.engine=F.Engine.create({gravity:{x:0,y:d.gravityY,scale:.001}}),this.config=d,this.dist=rt(d.houseEdge??0),this.rebuildStaticBodies(d.width,d.height);const E=this.dist.collisionNudge;if(E>0){const T=A=>{const f=this.center,e=this.config.width*.5;for(const o of A.pairs){const a=o.bodyA.label==="plinkit-ball"?o.bodyA:o.bodyB.label==="plinkit-ball"?o.bodyB:null;if(!a||a.plugin.settled||!(o.bodyA.label===ee||o.bodyB.label===ee||o.bodyA.label===te||o.bodyB.label===te))continue;const r=(a.position.x-f)/e;F.Body.setVelocity(a,{x:a.velocity.x-E*r,y:a.velocity.y})}};F.Events.on(this.engine,"collisionEnd",T),this.removeCollisionNudge=()=>F.Events.off(this.engine,"collisionEnd",T)}if(d.onCollision){const T=d.onCollision,A=f=>{for(const e of f.pairs){const o=e.bodyA.label==="plinkit-ball"?e.bodyA:e.bodyB.label==="plinkit-ball"?e.bodyB:null;if(!o||o.plugin.settled)continue;const a=e.bodyA===o?e.bodyB.label:e.bodyA.label;let r=null;if(a===ee?r="peg":a===te&&(r="guide"),!r)continue;const c=Math.hypot(o.velocity.x,o.velocity.y);T({ballId:J(o),target:r,speed:c})}};F.Events.on(this.engine,"collisionStart",A),this.removeCollisionStart=()=>F.Events.off(this.engine,"collisionStart",A)}}resize(d,E){this.config={...this.config,width:d,height:E},this.rebuildStaticBodies(d,E)}setBallCost(d){this.config={...this.config,ballCost:d}}spawnBall(){const d=ut({width:this.config.width,height:this.config.height,radius:this.config.ballRadius},this.dist.spawnSigmaRatio);d.plugin.ballId=this.nextBallId,d.plugin.wager=this.config.ballCost,this.nextBallId+=1,this.antiStuck.track(J(d),d.position.x,d.position.y),F.World.add(this.engine.world,d)}canSpawnBall(){const d=this.config.height*ft;let E=0;const T=F.Composite.allBodies(this.engine.world).filter(A=>A.label===_);for(const A of T)if(!A.plugin.settled&&A.position.y<=d&&(E+=1,E>=ct))return!1;return!0}step(d){F.Engine.update(this.engine,d);const E=F.Composite.allBodies(this.engine.world).filter(e=>e.label===_),T=E.filter(e=>!e.plugin.settled);ot(T,this.center,this.dist.windStrength);const A=this.antiStuck.process(d,T,{center:this.center,halfWidth:this.config.width*.5,worldHeight:this.config.height}).map(e=>this.settleBall(e)),f=this.cleanupBalls(E);return A.length>0?[...A,...f]:f}snapshot(){const d=this.config.layout.mainPegs.radius;return{pegs:this.pegs.map(E=>({x:E.position.x,y:E.position.y,radius:E.circleRadius??d})),guidePegs:this.guidePegs.map(E=>({x:E.position.x,y:E.position.y,radius:E.circleRadius??d})),balls:F.Composite.allBodies(this.engine.world).filter(E=>E.label===_).map(E=>({id:J(E),x:E.position.x,y:E.position.y,radius:E.circleRadius??this.config.ballRadius})),walls:this.getWallRects(),buckets:this.buckets}}destroy(){this.removeCollisionNudge?.(),this.removeCollisionStart?.(),F.World.clear(this.engine.world,!1),F.Engine.clear(this.engine)}cleanupBalls(d){const E=[],T=this.config.height+this.config.ballRadius,A=this.getBucketTop();for(const f of d){if(f.position.y>T){this.antiStuck.untrack(J(f)),F.World.remove(this.engine.world,f);continue}if(!f.plugin.settled&&f.position.y>=A){E.push(this.settleBall(f));continue}const e=f.circleRadius??this.config.ballRadius,o=this.config.height-e-1;!f.plugin.settled&&f.position.y>=o&&E.push(this.settleBall(f))}return E}rebuildStaticBodies(d,E){this.antiStuck.clear(),this.pegs.length>0&&(F.World.remove(this.engine.world,this.pegs),this.pegs=[]),this.guidePegs.length>0&&(F.World.remove(this.engine.world,this.guidePegs),this.guidePegs=[]),this.walls&&(F.World.remove(this.engine.world,[this.walls.leftWall,this.walls.rightWall,this.walls.floor]),this.walls=null),this.center=d*.5;const T=Math.max(18,d*.02),A=d/this.config.multipliers.length,f=this.config.layout.mainPegs,e=De({...f,width:d,height:E});this.layoutGeometry=e;const o=f.radius,a=this.config.layout.edgeGuides.radius;this.pegs=Ue(e,o).map(t=>F.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:ee,restitution:.3})),this.pegBaseY=this.pegs.reduce((t,i)=>Math.max(t,i.position.y),0);const r=this.getBucketTop(),c=F.Bodies.rectangle(-T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),n=F.Bodies.rectangle(d+T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),h=F.Bodies.rectangle(d*.5,E+T*.5,d,T,{isStatic:!0,isSensor:!0,label:oe});this.walls={leftWall:c,rightWall:n,floor:h},F.World.add(this.engine.world,[c,n,h]),this.guidePegs=Fe(e,a,{spread:this.config.layout.edgeGuides.spread,yOffset:this.config.layout.edgeGuides.yOffset}).map(t=>F.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:te,restitution:.3})),F.World.add(this.engine.world,this.pegs),F.World.add(this.engine.world,this.guidePegs);const l=E-r;this.buckets=this.config.multipliers.map((t,i)=>({index:i,multiplier:t,x:A*i,y:r,width:A,height:l}))}getWallRects(){return this.walls?[this.walls.leftWall,this.walls.rightWall,this.walls.floor].map(d=>({x:d.position.x,y:d.position.y,width:d.bounds.max.x-d.bounds.min.x,height:d.bounds.max.y-d.bounds.min.y})):[]}getBucketTop(){const d=this.config.layout.mainPegs.radius+this.config.ballRadius-1;return this.pegBaseY>0?Math.min(this.config.height-6,this.pegBaseY+d):this.config.height*.85}settleBall(d){d.plugin.settled=!0,F.Body.set(d,"isSensor",!0);const E=this.layoutGeometry,T=this.config.layout.mainPegs,A=E?.sidePadding??T.radius+T.sidePaddingPx,f=E?.baseSpacing??(this.config.width-A*2)/Math.max(T.bottomPegCount-1,1),e=Ye(d.position.x,A,f,this.config.multipliers.length),o=this.config.multipliers[e]??0,a=typeof d.plugin.wager=="number"?d.plugin.wager:this.config.ballCost;return{ballId:J(d),bucketIndex:e,multiplier:o,wager:a,payout:a*o}}},gt=`
|
|
1
|
+
(function(Z,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(Z=typeof globalThis<"u"?globalThis:Z||self,j(Z.Plinkit={}))})(this,function(Z){Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"});var j=(p,B)=>()=>(B||(p((B={exports:{}}).exports,B),p=null),B.exports),Se=class{rafId=null;step;constructor(p){this.step=p}start(){if(this.rafId!==null)return;const p=B=>{this.step(B),this.rafId=window.requestAnimationFrame(p)};this.rafId=window.requestAnimationFrame(p)}stop(){this.rafId!==null&&(window.cancelAnimationFrame(this.rafId),this.rafId=null)}};function ce(p,B){const A=p.bottomPegCount-p.topPegCount+1,E=p.radius+p.sidePaddingPx,c=(B-E*2)/Math.max(p.bottomPegCount-1,1);return{rows:A,sidePadding:E,baseSpacing:c,targetVerticalStep:c*p.verticalStepRatio}}function we(p){const{width:B,height:A,topPegCount:E}=p;if(p.bottomPegCount<E)throw new Error("bottomPegCount must be greater than or equal to topPegCount");const c=ce(p,B),e=B*.5,o=p.topPaddingPx,r=Math.max(o+60,A-p.bottomPaddingPx),a=c.rows>1?(r-o)/(c.rows-1):0,u=Math.min(c.targetVerticalStep,a),n=r-u*Math.max(c.rows-1,0),h=[];for(let l=0;l<c.rows;l++){const t=E+l,i=n+l*u,s=(t-1)*c.baseSpacing,f=e-s*.5;h.push({row:l,count:t,y:i,startX:f,rowWidth:s,leftX:f,rightX:f+s})}return{rows:c.rows,center:e,minTopY:o,bottomY:r,sidePadding:c.sidePadding,baseSpacing:c.baseSpacing,verticalStep:u,startY:n,rowAnchors:h}}function Pe(p,B){const A=[];for(const E of p.rowAnchors)for(let c=0;c<E.count;c++)A.push({x:E.startX+c*p.baseSpacing,y:E.y,radius:B});return A}function Ce(p,B,A){if(p.rows<2)return[];const E=[],c=(A.spread-1)*p.baseSpacing,e=t=>t<p.center?t-c:t>p.center?t+c:t,o=p.rowAnchors[0],r=o.leftX,a=o.rightX,u=p.startY-p.minTopY,n=B*2.5,h=Math.min(p.verticalStep,Math.max(n,u/3)),l=u>=n?Math.min(3,Math.floor(u/h)):0;for(let t=1;t<=l;t++){const i=p.startY-t*h+A.yOffset,s=r-t*p.baseSpacing*.5,f=a+t*p.baseSpacing*.5;E.push({x:e(s),y:i,radius:B},{x:e(f),y:i,radius:B})}for(let t=0;t<l;t++){const i=p.startY-t*h,s=p.startY-(t+1)*h,f=r-t*p.baseSpacing*.5,m=r-(t+1)*p.baseSpacing*.5,x=a+t*p.baseSpacing*.5,P=a+(t+1)*p.baseSpacing*.5;E.push({x:e((f+m)/2),y:(i+s)/2+A.yOffset,radius:B},{x:e((x+P)/2),y:(i+s)/2+A.yOffset,radius:B})}for(let t=0;t<p.rows-1;t++){const i=p.rowAnchors[t],s=p.rowAnchors[t+1],f=(i.y+s.y)/2+A.yOffset;E.push({x:e((i.leftX+s.leftX)/2),y:f,radius:B},{x:e((i.rightX+s.rightX)/2),y:f,radius:B})}return E}var pt=600,Me=-1,Te=8;function Ae(p){const{mainPegs:B,ballRadius:A,heightPolicy:E}=p;if(Ee(E),Le(B),!Number.isFinite(A)||A<=0)throw new Error("ballRadius must be greater than 0");const c=ce(B,600);if(c.baseSpacing<=0)throw new Error("mainPegs produce non-positive base spacing; reduce sidePaddingPx or peg counts");const{rows:e,baseSpacing:o,targetVerticalStep:r}=c,a=r*Math.max(e-1,0),u=E.topPaddingPx,n=r*2,h=A*2+Te,l=B.radius+A+Me,t=Math.max(E.bottomPaddingPx,l+h);return{worldHeight:u+n+a+t,resolvedMainPegs:{...B,topPaddingPx:u,bottomPaddingPx:t},rows:e,baseSpacing:o,verticalStep:r,requiredBottomPaddingPx:t}}function Be(p){const{parentWidthPx:B,viewport:A,worldHeight:E}=p;if(Ie(A),!Number.isFinite(B)||B<=0)throw new Error("Parent width must be greater than 0");if(!Number.isFinite(E)||E<=0)throw new Error("World height must be greater than 0");const c=B;return{displayWidth:c,displayHeight:c*(E/600),worldScale:c/600}}function Ee(p){if(!Number.isFinite(p.topPaddingPx)||p.topPaddingPx<0)throw new Error("viewport.heightPolicy.topPaddingPx must be >= 0");if(!Number.isFinite(p.bottomPaddingPx)||p.bottomPaddingPx<0)throw new Error("viewport.heightPolicy.bottomPaddingPx must be >= 0")}function Ie(p){if(!Number.isFinite(p.dprCap)||p.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function Le(p){if(!Number.isFinite(p.radius)||p.radius<=0)throw new Error("layout.mainPegs.radius must be greater than 0");if(!Number.isFinite(p.topPegCount)||p.topPegCount<1)throw new Error("layout.mainPegs.topPegCount must be >= 1");if(!Number.isFinite(p.bottomPegCount)||p.bottomPegCount<p.topPegCount)throw new Error("layout.mainPegs.bottomPegCount must be >= topPegCount");if(!Number.isFinite(p.verticalStepRatio)||p.verticalStepRatio<=0)throw new Error("layout.mainPegs.verticalStepRatio must be > 0");if(!Number.isFinite(p.sidePaddingPx)||p.sidePaddingPx<0)throw new Error("layout.mainPegs.sidePaddingPx must be >= 0")}var Re=j(((p,B)=>{(function(E,c){typeof p=="object"&&typeof B=="object"?B.exports=c():typeof define=="function"&&define.amd?define("Matter",[],c):typeof p=="object"?p.Matter=c():E.Matter=c()})(p,function(){return(function(A){var E={};function c(e){if(E[e])return E[e].exports;var o=E[e]={i:e,l:!1,exports:{}};return A[e].call(o.exports,o,o.exports,c),o.l=!0,o.exports}return c.m=A,c.c=E,c.d=function(e,o,r){c.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:r})},c.r=function(e){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.t=function(e,o){if(o&1&&(e=c(e)),o&8||o&4&&typeof e=="object"&&e&&e.__esModule)return e;var r=Object.create(null);if(c.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),o&2&&typeof e!="string")for(var a in e)c.d(r,a,function(u){return e[u]}.bind(null,a));return r},c.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(o,"a",o),o},c.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},c.p="",c(c.s=20)})([(function(A,E){var c={};A.exports=c,(function(){c._baseDelta=1e3/60,c._nextId=0,c._seed=0,c._nowStartTime=+new Date,c._warnedOnce={},c._decomp=null,c.extend=function(o,r){var a,u;typeof r=="boolean"?(a=2,u=r):(a=1,u=!0);for(var n=a;n<arguments.length;n++){var h=arguments[n];if(h)for(var l in h)u&&h[l]&&h[l].constructor===Object&&(!o[l]||o[l].constructor===Object)?(o[l]=o[l]||{},c.extend(o[l],u,h[l])):o[l]=h[l]}return o},c.clone=function(o,r){return c.extend({},r,o)},c.keys=function(o){if(Object.keys)return Object.keys(o);var r=[];for(var a in o)r.push(a);return r},c.values=function(o){var r=[];if(Object.keys){for(var a=Object.keys(o),u=0;u<a.length;u++)r.push(o[a[u]]);return r}for(var n in o)r.push(o[n]);return r},c.get=function(o,r,a,u){r=r.split(".").slice(a,u);for(var n=0;n<r.length;n+=1)o=o[r[n]];return o},c.set=function(o,r,a,u,n){var h=r.split(".").slice(u,n);return c.get(o,r,0,-1)[h[h.length-1]]=a,a},c.shuffle=function(o){for(var r=o.length-1;r>0;r--){var a=Math.floor(c.random()*(r+1)),u=o[r];o[r]=o[a],o[a]=u}return o},c.choose=function(o){return o[Math.floor(c.random()*o.length)]},c.isElement=function(o){return typeof HTMLElement<"u"?o instanceof HTMLElement:!!(o&&o.nodeType&&o.nodeName)},c.isArray=function(o){return Object.prototype.toString.call(o)==="[object Array]"},c.isFunction=function(o){return typeof o=="function"},c.isPlainObject=function(o){return typeof o=="object"&&o.constructor===Object},c.isString=function(o){return toString.call(o)==="[object String]"},c.clamp=function(o,r,a){return o<r?r:o>a?a:o},c.sign=function(o){return o<0?-1:1},c.now=function(){if(typeof window<"u"&&window.performance){if(window.performance.now)return window.performance.now();if(window.performance.webkitNow)return window.performance.webkitNow()}return Date.now?Date.now():new Date-c._nowStartTime},c.random=function(o,r){return o=typeof o<"u"?o:0,r=typeof r<"u"?r:1,o+e()*(r-o)};var e=function(){return c._seed=(c._seed*9301+49297)%233280,c._seed/233280};c.colorToNumber=function(o){return o=o.replace("#",""),o.length==3&&(o=o.charAt(0)+o.charAt(0)+o.charAt(1)+o.charAt(1)+o.charAt(2)+o.charAt(2)),parseInt(o,16)},c.logLevel=1,c.log=function(){console&&c.logLevel>0&&c.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.info=function(){console&&c.logLevel>0&&c.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.warn=function(){console&&c.logLevel>0&&c.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.warnOnce=function(){var o=Array.prototype.slice.call(arguments).join(" ");c._warnedOnce[o]||(c.warn(o),c._warnedOnce[o]=!0)},c.deprecated=function(o,r,a){o[r]=c.chain(function(){c.warnOnce("🔅 deprecated 🔅",a)},o[r])},c.nextId=function(){return c._nextId++},c.indexOf=function(o,r){if(o.indexOf)return o.indexOf(r);for(var a=0;a<o.length;a++)if(o[a]===r)return a;return-1},c.map=function(o,r){if(o.map)return o.map(r);for(var a=[],u=0;u<o.length;u+=1)a.push(r(o[u]));return a},c.topologicalSort=function(o){var r=[],a=[],u=[];for(var n in o)!a[n]&&!u[n]&&c._topologicalSort(n,a,u,o,r);return r},c._topologicalSort=function(o,r,a,u,n){var h=u[o]||[];a[o]=!0;for(var l=0;l<h.length;l+=1){var t=h[l];a[t]||r[t]||c._topologicalSort(t,r,a,u,n)}a[o]=!1,r[o]=!0,n.push(o)},c.chain=function(){for(var o=[],r=0;r<arguments.length;r+=1){var a=arguments[r];a._chained?o.push.apply(o,a._chained):o.push(a)}var u=function(){for(var n,h=new Array(arguments.length),l=0,t=arguments.length;l<t;l++)h[l]=arguments[l];for(l=0;l<o.length;l+=1){var i=o[l].apply(n,h);typeof i<"u"&&(n=i)}return n};return u._chained=o,u},c.chainPathBefore=function(o,r,a){return c.set(o,r,c.chain(a,c.get(o,r)))},c.chainPathAfter=function(o,r,a){return c.set(o,r,c.chain(c.get(o,r),a))},c.setDecomp=function(o){c._decomp=o},c.getDecomp=function(){var o=c._decomp;try{!o&&typeof window<"u"&&(o=window.decomp),!o&&typeof global<"u"&&(o=global.decomp)}catch{o=null}return o}})()}),(function(A,E){var c={};A.exports=c,(function(){c.create=function(e){var o={min:{x:0,y:0},max:{x:0,y:0}};return e&&c.update(o,e),o},c.update=function(e,o,r){e.min.x=1/0,e.max.x=-1/0,e.min.y=1/0,e.max.y=-1/0;for(var a=0;a<o.length;a++){var u=o[a];u.x>e.max.x&&(e.max.x=u.x),u.x<e.min.x&&(e.min.x=u.x),u.y>e.max.y&&(e.max.y=u.y),u.y<e.min.y&&(e.min.y=u.y)}r&&(r.x>0?e.max.x+=r.x:e.min.x+=r.x,r.y>0?e.max.y+=r.y:e.min.y+=r.y)},c.contains=function(e,o){return o.x>=e.min.x&&o.x<=e.max.x&&o.y>=e.min.y&&o.y<=e.max.y},c.overlaps=function(e,o){return e.min.x<=o.max.x&&e.max.x>=o.min.x&&e.max.y>=o.min.y&&e.min.y<=o.max.y},c.translate=function(e,o){e.min.x+=o.x,e.max.x+=o.x,e.min.y+=o.y,e.max.y+=o.y},c.shift=function(e,o){var r=e.max.x-e.min.x,a=e.max.y-e.min.y;e.min.x=o.x,e.max.x=o.x+r,e.min.y=o.y,e.max.y=o.y+a}})()}),(function(A,E){var c={};A.exports=c,(function(){c.create=function(e,o){return{x:e||0,y:o||0}},c.clone=function(e){return{x:e.x,y:e.y}},c.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},c.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},c.rotate=function(e,o,r){var a=Math.cos(o),u=Math.sin(o);r||(r={});var n=e.x*a-e.y*u;return r.y=e.x*u+e.y*a,r.x=n,r},c.rotateAbout=function(e,o,r,a){var u=Math.cos(o),n=Math.sin(o);a||(a={});var h=r.x+((e.x-r.x)*u-(e.y-r.y)*n);return a.y=r.y+((e.x-r.x)*n+(e.y-r.y)*u),a.x=h,a},c.normalise=function(e){var o=c.magnitude(e);return o===0?{x:0,y:0}:{x:e.x/o,y:e.y/o}},c.dot=function(e,o){return e.x*o.x+e.y*o.y},c.cross=function(e,o){return e.x*o.y-e.y*o.x},c.cross3=function(e,o,r){return(o.x-e.x)*(r.y-e.y)-(o.y-e.y)*(r.x-e.x)},c.add=function(e,o,r){return r||(r={}),r.x=e.x+o.x,r.y=e.y+o.y,r},c.sub=function(e,o,r){return r||(r={}),r.x=e.x-o.x,r.y=e.y-o.y,r},c.mult=function(e,o){return{x:e.x*o,y:e.y*o}},c.div=function(e,o){return{x:e.x/o,y:e.y/o}},c.perp=function(e,o){return o=o===!0?-1:1,{x:o*-e.y,y:o*e.x}},c.neg=function(e){return{x:-e.x,y:-e.y}},c.angle=function(e,o){return Math.atan2(o.y-e.y,o.x-e.x)},c._temp=[c.create(),c.create(),c.create(),c.create(),c.create(),c.create()]})()}),(function(A,E,c){var e={};A.exports=e;var o=c(2),r=c(0);(function(){e.create=function(a,u){for(var n=[],h=0;h<a.length;h++){var l=a[h],t={x:l.x,y:l.y,index:h,body:u,isInternal:!1};n.push(t)}return n},e.fromPath=function(a,u){var n=/L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi,h=[];return a.replace(n,function(l,t,i){h.push({x:parseFloat(t),y:parseFloat(i)})}),e.create(h,u)},e.centre=function(a){for(var u=e.area(a,!0),n={x:0,y:0},h,l,t,i=0;i<a.length;i++)t=(i+1)%a.length,h=o.cross(a[i],a[t]),l=o.mult(o.add(a[i],a[t]),h),n=o.add(n,l);return o.div(n,6*u)},e.mean=function(a){for(var u={x:0,y:0},n=0;n<a.length;n++)u.x+=a[n].x,u.y+=a[n].y;return o.div(u,a.length)},e.area=function(a,u){for(var n=0,h=a.length-1,l=0;l<a.length;l++)n+=(a[h].x-a[l].x)*(a[h].y+a[l].y),h=l;return u?n/2:Math.abs(n)/2},e.inertia=function(a,u){for(var n=0,h=0,l=a,t,i,s=0;s<l.length;s++)i=(s+1)%l.length,t=Math.abs(o.cross(l[i],l[s])),n+=t*(o.dot(l[i],l[i])+o.dot(l[i],l[s])+o.dot(l[s],l[s])),h+=t;return u/6*(n/h)},e.translate=function(a,u,n){n=typeof n<"u"?n:1;var h=a.length,l=u.x*n,t=u.y*n,i;for(i=0;i<h;i++)a[i].x+=l,a[i].y+=t;return a},e.rotate=function(a,u,n){if(u!==0){var h=Math.cos(u),l=Math.sin(u),t=n.x,i=n.y,s=a.length,f,m,x,P;for(P=0;P<s;P++)f=a[P],m=f.x-t,x=f.y-i,f.x=t+(m*h-x*l),f.y=i+(m*l+x*h);return a}},e.contains=function(a,u){for(var n=u.x,h=u.y,l=a.length,t=a[l-1],i,s=0;s<l;s++){if(i=a[s],(n-t.x)*(i.y-t.y)+(h-t.y)*(t.x-i.x)>0)return!1;t=i}return!0},e.scale=function(a,u,n,h){if(u===1&&n===1)return a;h=h||e.centre(a);for(var l,t,i=0;i<a.length;i++)l=a[i],t=o.sub(l,h),a[i].x=h.x+t.x*u,a[i].y=h.y+t.y*n;return a},e.chamfer=function(a,u,n,h,l){typeof u=="number"?u=[u]:u=u||[8],n=typeof n<"u"?n:-1,h=h||2,l=l||14;for(var t=[],i=0;i<a.length;i++){var s=a[i-1>=0?i-1:a.length-1],f=a[i],m=a[(i+1)%a.length],x=u[i<u.length?i:u.length-1];if(x===0){t.push(f);continue}var P=o.normalise({x:f.y-s.y,y:s.x-f.x}),T=o.normalise({x:m.y-f.y,y:f.x-m.x}),g=Math.sqrt(2*Math.pow(x,2)),d=o.mult(r.clone(P),x),y=o.normalise(o.mult(o.add(P,T),.5)),v=o.sub(f,o.mult(y,g)),w=n;n===-1&&(w=Math.pow(x,.32)*1.75),w=r.clamp(w,h,l),w%2===1&&(w+=1);for(var S=Math.acos(o.dot(P,T))/w,C=0;C<w;C++)t.push(o.add(o.rotate(d,S*C),v))}return t},e.clockwiseSort=function(a){var u=e.mean(a);return a.sort(function(n,h){return o.angle(u,n)-o.angle(u,h)}),a},e.isConvex=function(a){var u=0,n=a.length,h,l,t,i;if(n<3)return null;for(h=0;h<n;h++)if(l=(h+1)%n,t=(h+2)%n,i=(a[l].x-a[h].x)*(a[t].y-a[l].y),i-=(a[l].y-a[h].y)*(a[t].x-a[l].x),i<0?u|=1:i>0&&(u|=2),u===3)return!1;return u!==0?!0:null},e.hull=function(a){var u=[],n=[],h,l;for(a=a.slice(0),a.sort(function(t,i){var s=t.x-i.x;return s!==0?s:t.y-i.y}),l=0;l<a.length;l+=1){for(h=a[l];n.length>=2&&o.cross3(n[n.length-2],n[n.length-1],h)<=0;)n.pop();n.push(h)}for(l=a.length-1;l>=0;l-=1){for(h=a[l];u.length>=2&&o.cross3(u[u.length-2],u[u.length-1],h)<=0;)u.pop();u.push(h)}return u.pop(),n.pop(),u.concat(n)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(2),a=c(7),u=c(0),n=c(1),h=c(11);(function(){e._timeCorrection=!0,e._inertiaScale=4,e._nextCollidingGroupId=1,e._nextNonCollidingGroupId=-1,e._nextCategory=1,e._baseDelta=1e3/60,e.create=function(t){var i={id:u.nextId(),type:"body",label:"Body",parts:[],plugin:{},angle:0,vertices:o.fromPath("L 0 0 L 40 0 L 40 40 L 0 40"),position:{x:0,y:0},force:{x:0,y:0},torque:0,positionImpulse:{x:0,y:0},constraintImpulse:{x:0,y:0,angle:0},totalContacts:0,speed:0,angularSpeed:0,velocity:{x:0,y:0},angularVelocity:0,isSensor:!1,isStatic:!1,isSleeping:!1,motion:0,sleepThreshold:60,density:.001,restitution:0,friction:.1,frictionStatic:.5,frictionAir:.01,collisionFilter:{category:1,mask:4294967295,group:0},slop:.05,timeScale:1,render:{visible:!0,opacity:1,strokeStyle:null,fillStyle:null,lineWidth:null,sprite:{xScale:1,yScale:1,xOffset:0,yOffset:0}},events:null,bounds:null,chamfer:null,circleRadius:0,positionPrev:null,anglePrev:0,parent:null,axes:null,area:0,mass:0,inertia:0,deltaTime:16.666666666666668,_original:null},s=u.extend(i,t);return l(s,t),s},e.nextGroup=function(t){return t?e._nextNonCollidingGroupId--:e._nextCollidingGroupId++},e.nextCategory=function(){return e._nextCategory=e._nextCategory<<1,e._nextCategory};var l=function(t,i){i=i||{},e.set(t,{bounds:t.bounds||n.create(t.vertices),positionPrev:t.positionPrev||r.clone(t.position),anglePrev:t.anglePrev||t.angle,vertices:t.vertices,parts:t.parts||[t],isStatic:t.isStatic,isSleeping:t.isSleeping,parent:t.parent||t}),o.rotate(t.vertices,t.angle,t.position),h.rotate(t.axes,t.angle),n.update(t.bounds,t.vertices,t.velocity),e.set(t,{axes:i.axes||t.axes,area:i.area||t.area,mass:i.mass||t.mass,inertia:i.inertia||t.inertia});var s=t.isStatic?"#14151f":u.choose(["#f19648","#f5d259","#f55a3c","#063e7b","#ececd1"]),f=t.isStatic?"#555":"#ccc",m=t.isStatic&&t.render.fillStyle===null?1:0;t.render.fillStyle=t.render.fillStyle||s,t.render.strokeStyle=t.render.strokeStyle||f,t.render.lineWidth=t.render.lineWidth||m,t.render.sprite.xOffset+=-(t.bounds.min.x-t.position.x)/(t.bounds.max.x-t.bounds.min.x),t.render.sprite.yOffset+=-(t.bounds.min.y-t.position.y)/(t.bounds.max.y-t.bounds.min.y)};e.set=function(t,i,s){var f;typeof i=="string"&&(f=i,i={},i[f]=s);for(f in i)if(Object.prototype.hasOwnProperty.call(i,f))switch(s=i[f],f){case"isStatic":e.setStatic(t,s);break;case"isSleeping":a.set(t,s);break;case"mass":e.setMass(t,s);break;case"density":e.setDensity(t,s);break;case"inertia":e.setInertia(t,s);break;case"vertices":e.setVertices(t,s);break;case"position":e.setPosition(t,s);break;case"angle":e.setAngle(t,s);break;case"velocity":e.setVelocity(t,s);break;case"angularVelocity":e.setAngularVelocity(t,s);break;case"speed":e.setSpeed(t,s);break;case"angularSpeed":e.setAngularSpeed(t,s);break;case"parts":e.setParts(t,s);break;case"centre":e.setCentre(t,s);break;default:t[f]=s}},e.setStatic=function(t,i){for(var s=0;s<t.parts.length;s++){var f=t.parts[s];i?(f.isStatic||(f._original={restitution:f.restitution,friction:f.friction,mass:f.mass,inertia:f.inertia,density:f.density,inverseMass:f.inverseMass,inverseInertia:f.inverseInertia}),f.restitution=0,f.friction=1,f.mass=f.inertia=f.density=1/0,f.inverseMass=f.inverseInertia=0,f.positionPrev.x=f.position.x,f.positionPrev.y=f.position.y,f.anglePrev=f.angle,f.angularVelocity=0,f.speed=0,f.angularSpeed=0,f.motion=0):f._original&&(f.restitution=f._original.restitution,f.friction=f._original.friction,f.mass=f._original.mass,f.inertia=f._original.inertia,f.density=f._original.density,f.inverseMass=f._original.inverseMass,f.inverseInertia=f._original.inverseInertia,f._original=null),f.isStatic=i}},e.setMass=function(t,i){t.inertia=t.inertia/(t.mass/6)*(i/6),t.inverseInertia=1/t.inertia,t.mass=i,t.inverseMass=1/t.mass,t.density=t.mass/t.area},e.setDensity=function(t,i){e.setMass(t,i*t.area),t.density=i},e.setInertia=function(t,i){t.inertia=i,t.inverseInertia=1/t.inertia},e.setVertices=function(t,i){i[0].body===t?t.vertices=i:t.vertices=o.create(i,t),t.axes=h.fromVertices(t.vertices),t.area=o.area(t.vertices),e.setMass(t,t.density*t.area);var s=o.centre(t.vertices);o.translate(t.vertices,s,-1),e.setInertia(t,e._inertiaScale*o.inertia(t.vertices,t.mass)),o.translate(t.vertices,t.position),n.update(t.bounds,t.vertices,t.velocity)},e.setParts=function(t,i,s){var f;for(i=i.slice(0),t.parts.length=0,t.parts.push(t),t.parent=t,f=0;f<i.length;f++){var m=i[f];m!==t&&(m.parent=t,t.parts.push(m))}if(t.parts.length!==1){if(s=typeof s<"u"?s:!0,s){var x=[];for(f=0;f<i.length;f++)x=x.concat(i[f].vertices);o.clockwiseSort(x);var P=o.hull(x),T=o.centre(P);e.setVertices(t,P),o.translate(t.vertices,T)}var g=e._totalProperties(t);t.area=g.area,t.parent=t,t.position.x=g.centre.x,t.position.y=g.centre.y,t.positionPrev.x=g.centre.x,t.positionPrev.y=g.centre.y,e.setMass(t,g.mass),e.setInertia(t,g.inertia),e.setPosition(t,g.centre)}},e.setCentre=function(t,i,s){s?(t.positionPrev.x+=i.x,t.positionPrev.y+=i.y,t.position.x+=i.x,t.position.y+=i.y):(t.positionPrev.x=i.x-(t.position.x-t.positionPrev.x),t.positionPrev.y=i.y-(t.position.y-t.positionPrev.y),t.position.x=i.x,t.position.y=i.y)},e.setPosition=function(t,i,s){var f=r.sub(i,t.position);s?(t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.velocity.x=f.x,t.velocity.y=f.y,t.speed=r.magnitude(f)):(t.positionPrev.x+=f.x,t.positionPrev.y+=f.y);for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.position.x+=f.x,x.position.y+=f.y,o.translate(x.vertices,f),n.update(x.bounds,x.vertices,t.velocity)}},e.setAngle=function(t,i,s){var f=i-t.angle;s?(t.anglePrev=t.angle,t.angularVelocity=f,t.angularSpeed=Math.abs(f)):t.anglePrev+=f;for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.angle+=f,o.rotate(x.vertices,f,t.position),h.rotate(x.axes,f),n.update(x.bounds,x.vertices,t.velocity),m>0&&r.rotateAbout(x.position,f,t.position,x.position)}},e.setVelocity=function(t,i){var s=t.deltaTime/e._baseDelta;t.positionPrev.x=t.position.x-i.x*s,t.positionPrev.y=t.position.y-i.y*s,t.velocity.x=(t.position.x-t.positionPrev.x)/s,t.velocity.y=(t.position.y-t.positionPrev.y)/s,t.speed=r.magnitude(t.velocity)},e.getVelocity=function(t){var i=e._baseDelta/t.deltaTime;return{x:(t.position.x-t.positionPrev.x)*i,y:(t.position.y-t.positionPrev.y)*i}},e.getSpeed=function(t){return r.magnitude(e.getVelocity(t))},e.setSpeed=function(t,i){e.setVelocity(t,r.mult(r.normalise(e.getVelocity(t)),i))},e.setAngularVelocity=function(t,i){var s=t.deltaTime/e._baseDelta;t.anglePrev=t.angle-i*s,t.angularVelocity=(t.angle-t.anglePrev)/s,t.angularSpeed=Math.abs(t.angularVelocity)},e.getAngularVelocity=function(t){return(t.angle-t.anglePrev)*e._baseDelta/t.deltaTime},e.getAngularSpeed=function(t){return Math.abs(e.getAngularVelocity(t))},e.setAngularSpeed=function(t,i){e.setAngularVelocity(t,u.sign(e.getAngularVelocity(t))*i)},e.translate=function(t,i,s){e.setPosition(t,r.add(t.position,i),s)},e.rotate=function(t,i,s,f){if(!s)e.setAngle(t,t.angle+i,f);else{var m=Math.cos(i),x=Math.sin(i),P=t.position.x-s.x,T=t.position.y-s.y;e.setPosition(t,{x:s.x+(P*m-T*x),y:s.y+(P*x+T*m)},f),e.setAngle(t,t.angle+i,f)}},e.scale=function(t,i,s,f){var m=0,x=0;f=f||t.position;for(var P=0;P<t.parts.length;P++){var T=t.parts[P];o.scale(T.vertices,i,s,f),T.axes=h.fromVertices(T.vertices),T.area=o.area(T.vertices),e.setMass(T,t.density*T.area),o.translate(T.vertices,{x:-T.position.x,y:-T.position.y}),e.setInertia(T,e._inertiaScale*o.inertia(T.vertices,T.mass)),o.translate(T.vertices,{x:T.position.x,y:T.position.y}),P>0&&(m+=T.area,x+=T.inertia),T.position.x=f.x+(T.position.x-f.x)*i,T.position.y=f.y+(T.position.y-f.y)*s,n.update(T.bounds,T.vertices,t.velocity)}t.parts.length>1&&(t.area=m,t.isStatic||(e.setMass(t,t.density*m),e.setInertia(t,x))),t.circleRadius&&(i===s?t.circleRadius*=i:t.circleRadius=null)},e.update=function(t,i){i=(typeof i<"u"?i:1e3/60)*t.timeScale;var s=i*i,f=e._timeCorrection?i/(t.deltaTime||i):1,m=1-t.frictionAir*(i/u._baseDelta),x=(t.position.x-t.positionPrev.x)*f,P=(t.position.y-t.positionPrev.y)*f;t.velocity.x=x*m+t.force.x/t.mass*s,t.velocity.y=P*m+t.force.y/t.mass*s,t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.position.x+=t.velocity.x,t.position.y+=t.velocity.y,t.deltaTime=i,t.angularVelocity=(t.angle-t.anglePrev)*m*f+t.torque/t.inertia*s,t.anglePrev=t.angle,t.angle+=t.angularVelocity;for(var T=0;T<t.parts.length;T++){var g=t.parts[T];o.translate(g.vertices,t.velocity),T>0&&(g.position.x+=t.velocity.x,g.position.y+=t.velocity.y),t.angularVelocity!==0&&(o.rotate(g.vertices,t.angularVelocity,t.position),h.rotate(g.axes,t.angularVelocity),T>0&&r.rotateAbout(g.position,t.angularVelocity,t.position,g.position)),n.update(g.bounds,g.vertices,t.velocity)}},e.updateVelocities=function(t){var i=e._baseDelta/t.deltaTime,s=t.velocity;s.x=(t.position.x-t.positionPrev.x)*i,s.y=(t.position.y-t.positionPrev.y)*i,t.speed=Math.sqrt(s.x*s.x+s.y*s.y),t.angularVelocity=(t.angle-t.anglePrev)*i,t.angularSpeed=Math.abs(t.angularVelocity)},e.applyForce=function(t,i,s){var f={x:i.x-t.position.x,y:i.y-t.position.y};t.force.x+=s.x,t.force.y+=s.y,t.torque+=f.x*s.y-f.y*s.x},e._totalProperties=function(t){for(var i={mass:0,area:0,inertia:0,centre:{x:0,y:0}},s=t.parts.length===1?0:1;s<t.parts.length;s++){var f=t.parts[s],m=f.mass!==1/0?f.mass:1;i.mass+=m,i.area+=f.area,i.inertia+=f.inertia,i.centre=r.add(i.centre,r.mult(f.position,m))}return i.centre=r.div(i.centre,i.mass),i}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(0);(function(){e.on=function(r,a,u){for(var n=a.split(" "),h,l=0;l<n.length;l++)h=n[l],r.events=r.events||{},r.events[h]=r.events[h]||[],r.events[h].push(u);return u},e.off=function(r,a,u){if(!a){r.events={};return}typeof a=="function"&&(u=a,a=o.keys(r.events).join(" "));for(var n=a.split(" "),h=0;h<n.length;h++){var l=r.events[n[h]],t=[];if(u&&l)for(var i=0;i<l.length;i++)l[i]!==u&&t.push(l[i]);r.events[n[h]]=t}},e.trigger=function(r,a,u){var n,h,l,t,i=r.events;if(i&&o.keys(i).length>0){u||(u={}),n=a.split(" ");for(var s=0;s<n.length;s++)if(h=n[s],l=i[h],l){t=o.clone(u,!1),t.name=h,t.source=r;for(var f=0;f<l.length;f++)l[f].apply(r,[t])}}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(5),r=c(0),a=c(1),u=c(4);(function(){e.create=function(n){return r.extend({id:r.nextId(),type:"composite",parent:null,isModified:!1,bodies:[],constraints:[],composites:[],label:"Composite",plugin:{},cache:{allBodies:null,allConstraints:null,allComposites:null}},n)},e.setModified=function(n,h,l,t){if(n.isModified=h,h&&n.cache&&(n.cache.allBodies=null,n.cache.allConstraints=null,n.cache.allComposites=null),l&&n.parent&&e.setModified(n.parent,h,l,t),t)for(var i=0;i<n.composites.length;i++){var s=n.composites[i];e.setModified(s,h,l,t)}},e.add=function(n,h){var l=[].concat(h);o.trigger(n,"beforeAdd",{object:h});for(var t=0;t<l.length;t++){var i=l[t];switch(i.type){case"body":if(i.parent!==i){r.warn("Composite.add: skipped adding a compound body part (you must add its parent instead)");break}e.addBody(n,i);break;case"constraint":e.addConstraint(n,i);break;case"composite":e.addComposite(n,i);break;case"mouseConstraint":e.addConstraint(n,i.constraint);break}}return o.trigger(n,"afterAdd",{object:h}),n},e.remove=function(n,h,l){var t=[].concat(h);o.trigger(n,"beforeRemove",{object:h});for(var i=0;i<t.length;i++){var s=t[i];switch(s.type){case"body":e.removeBody(n,s,l);break;case"constraint":e.removeConstraint(n,s,l);break;case"composite":e.removeComposite(n,s,l);break;case"mouseConstraint":e.removeConstraint(n,s.constraint);break}}return o.trigger(n,"afterRemove",{object:h}),n},e.addComposite=function(n,h){return n.composites.push(h),h.parent=n,e.setModified(n,!0,!0,!1),n},e.removeComposite=function(n,h,l){var t=r.indexOf(n.composites,h);if(t!==-1){var i=e.allBodies(h);e.removeCompositeAt(n,t);for(var s=0;s<i.length;s++)i[s].sleepCounter=0}if(l)for(var s=0;s<n.composites.length;s++)e.removeComposite(n.composites[s],h,!0);return n},e.removeCompositeAt=function(n,h){return n.composites.splice(h,1),e.setModified(n,!0,!0,!1),n},e.addBody=function(n,h){return n.bodies.push(h),e.setModified(n,!0,!0,!1),n},e.removeBody=function(n,h,l){var t=r.indexOf(n.bodies,h);if(t!==-1&&(e.removeBodyAt(n,t),h.sleepCounter=0),l)for(var i=0;i<n.composites.length;i++)e.removeBody(n.composites[i],h,!0);return n},e.removeBodyAt=function(n,h){return n.bodies.splice(h,1),e.setModified(n,!0,!0,!1),n},e.addConstraint=function(n,h){return n.constraints.push(h),e.setModified(n,!0,!0,!1),n},e.removeConstraint=function(n,h,l){var t=r.indexOf(n.constraints,h);if(t!==-1&&e.removeConstraintAt(n,t),l)for(var i=0;i<n.composites.length;i++)e.removeConstraint(n.composites[i],h,!0);return n},e.removeConstraintAt=function(n,h){return n.constraints.splice(h,1),e.setModified(n,!0,!0,!1),n},e.clear=function(n,h,l){if(l)for(var t=0;t<n.composites.length;t++)e.clear(n.composites[t],h,!0);return h?n.bodies=n.bodies.filter(function(i){return i.isStatic}):n.bodies.length=0,n.constraints.length=0,n.composites.length=0,e.setModified(n,!0,!0,!1),n},e.allBodies=function(n){if(n.cache&&n.cache.allBodies)return n.cache.allBodies;for(var h=[].concat(n.bodies),l=0;l<n.composites.length;l++)h=h.concat(e.allBodies(n.composites[l]));return n.cache&&(n.cache.allBodies=h),h},e.allConstraints=function(n){if(n.cache&&n.cache.allConstraints)return n.cache.allConstraints;for(var h=[].concat(n.constraints),l=0;l<n.composites.length;l++)h=h.concat(e.allConstraints(n.composites[l]));return n.cache&&(n.cache.allConstraints=h),h},e.allComposites=function(n){if(n.cache&&n.cache.allComposites)return n.cache.allComposites;for(var h=[].concat(n.composites),l=0;l<n.composites.length;l++)h=h.concat(e.allComposites(n.composites[l]));return n.cache&&(n.cache.allComposites=h),h},e.get=function(n,h,l){var t,i;switch(l){case"body":t=e.allBodies(n);break;case"constraint":t=e.allConstraints(n);break;case"composite":t=e.allComposites(n).concat(n);break}return t?(i=t.filter(function(s){return s.id.toString()===h.toString()}),i.length===0?null:i[0]):null},e.move=function(n,h,l){return e.remove(n,h),e.add(l,h),n},e.rebase=function(n){for(var h=e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)),l=0;l<h.length;l++)h[l].id=r.nextId();return n},e.translate=function(n,h,l){for(var t=l?e.allBodies(n):n.bodies,i=0;i<t.length;i++)u.translate(t[i],h);return n},e.rotate=function(n,h,l,t){for(var i=Math.cos(h),s=Math.sin(h),f=t?e.allBodies(n):n.bodies,m=0;m<f.length;m++){var x=f[m],P=x.position.x-l.x,T=x.position.y-l.y;u.setPosition(x,{x:l.x+(P*i-T*s),y:l.y+(P*s+T*i)}),u.rotate(x,h)}return n},e.scale=function(n,h,l,t,i){for(var s=i?e.allBodies(n):n.bodies,f=0;f<s.length;f++){var m=s[f],x=m.position.x-t.x,P=m.position.y-t.y;u.setPosition(m,{x:t.x+x*h,y:t.y+P*l}),u.scale(m,h,l)}return n},e.bounds=function(n){for(var h=e.allBodies(n),l=[],t=0;t<h.length;t+=1){var i=h[t];l.push(i.bounds.min,i.bounds.max)}return a.create(l)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(4),r=c(5),a=c(0);(function(){e._motionWakeThreshold=.18,e._motionSleepThreshold=.08,e._minBias=.9,e.update=function(u,n){for(var h=n/a._baseDelta,l=e._motionSleepThreshold,t=0;t<u.length;t++){var i=u[t],s=o.getSpeed(i),f=o.getAngularSpeed(i),m=s*s+f*f;if(i.force.x!==0||i.force.y!==0){e.set(i,!1);continue}var x=Math.min(i.motion,m),P=Math.max(i.motion,m);i.motion=e._minBias*x+(1-e._minBias)*P,i.sleepThreshold>0&&i.motion<l?(i.sleepCounter+=1,i.sleepCounter>=i.sleepThreshold/h&&e.set(i,!0)):i.sleepCounter>0&&(i.sleepCounter-=1)}},e.afterCollisions=function(u){for(var n=e._motionSleepThreshold,h=0;h<u.length;h++){var l=u[h];if(l.isActive){var t=l.collision,i=t.bodyA.parent,s=t.bodyB.parent;if(!(i.isSleeping&&s.isSleeping||i.isStatic||s.isStatic)&&(i.isSleeping||s.isSleeping)){var f=i.isSleeping&&!i.isStatic?i:s,m=f===i?s:i;!f.isStatic&&m.motion>n&&e.set(f,!1)}}}},e.set=function(u,n){var h=u.isSleeping;n?(u.isSleeping=!0,u.sleepCounter=u.sleepThreshold,u.positionImpulse.x=0,u.positionImpulse.y=0,u.positionPrev.x=u.position.x,u.positionPrev.y=u.position.y,u.anglePrev=u.angle,u.speed=0,u.angularSpeed=0,u.motion=0,h||r.trigger(u,"sleepStart")):(u.isSleeping=!1,u.sleepCounter=0,h&&r.trigger(u,"sleepEnd"))}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(9);(function(){var a=[],u={overlap:0,axis:null},n={overlap:0,axis:null};e.create=function(h,l){return{pair:null,collided:!1,bodyA:h,bodyB:l,parentA:h.parent,parentB:l.parent,depth:0,normal:{x:0,y:0},tangent:{x:0,y:0},penetration:{x:0,y:0},supports:[null,null],supportCount:0}},e.collides=function(h,l,t){if(e._overlapAxes(u,h.vertices,l.vertices,h.axes),u.overlap<=0||(e._overlapAxes(n,l.vertices,h.vertices,l.axes),n.overlap<=0))return null;var i=t&&t.table[r.id(h,l)],s;i?s=i.collision:(s=e.create(h,l),s.collided=!0,s.bodyA=h.id<l.id?h:l,s.bodyB=h.id<l.id?l:h,s.parentA=s.bodyA.parent,s.parentB=s.bodyB.parent),h=s.bodyA,l=s.bodyB;var f;u.overlap<n.overlap?f=u:f=n;var m=s.normal,x=s.tangent,P=s.penetration,T=s.supports,g=f.overlap,d=f.axis,y=d.x,v=d.y,w=l.position.x-h.position.x,S=l.position.y-h.position.y;y*w+v*S>=0&&(y=-y,v=-v),m.x=y,m.y=v,x.x=-v,x.y=y,P.x=y*g,P.y=v*g,s.depth=g;var C=e._findSupports(h,l,m,1),M=0;if(o.contains(h.vertices,C[0])&&(T[M++]=C[0]),o.contains(h.vertices,C[1])&&(T[M++]=C[1]),M<2){var I=e._findSupports(l,h,m,-1);o.contains(l.vertices,I[0])&&(T[M++]=I[0]),M<2&&o.contains(l.vertices,I[1])&&(T[M++]=I[1])}return M===0&&(T[M++]=C[0]),s.supportCount=M,s},e._overlapAxes=function(h,l,t,i){var s=l.length,f=t.length,m=l[0].x,x=l[0].y,P=t[0].x,T=t[0].y,g=i.length,d=Number.MAX_VALUE,y=0,v,w,S,C,M,I;for(M=0;M<g;M++){var R=i[M],L=R.x,D=R.y,k=m*L+x*D,b=P*L+T*D,U=k,W=b;for(I=1;I<s;I+=1)C=l[I].x*L+l[I].y*D,C>U?U=C:C<k&&(k=C);for(I=1;I<f;I+=1)C=t[I].x*L+t[I].y*D,C>W?W=C:C<b&&(b=C);if(w=U-b,S=W-k,v=w<S?w:S,v<d&&(d=v,y=M,v<=0))break}h.axis=i[y],h.overlap=d},e._findSupports=function(h,l,t,i){var s=l.vertices,f=s.length,m=h.position.x,x=h.position.y,P=t.x*i,T=t.y*i,g=s[0],d=g,y=P*(m-d.x)+T*(x-d.y),v,w,S;for(S=1;S<f;S+=1)d=s[S],w=P*(m-d.x)+T*(x-d.y),w<y&&(y=w,g=d);return v=s[(f+g.index-1)%f],y=P*(m-v.x)+T*(x-v.y),d=s[(g.index+1)%f],P*(m-d.x)+T*(x-d.y)<y?(a[0]=g,a[1]=d,a):(a[0]=g,a[1]=v,a)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(16);(function(){e.create=function(r,a){var u=r.bodyA,n=r.bodyB,h={id:e.id(u,n),bodyA:u,bodyB:n,collision:r,contacts:[o.create(),o.create()],contactCount:0,separation:0,isActive:!0,isSensor:u.isSensor||n.isSensor,timeCreated:a,timeUpdated:a,inverseMass:0,friction:0,frictionStatic:0,restitution:0,slop:0};return e.update(h,r,a),h},e.update=function(r,a,u){var n=a.supports,h=a.supportCount,l=r.contacts,t=a.parentA,i=a.parentB;r.isActive=!0,r.timeUpdated=u,r.collision=a,r.separation=a.depth,r.inverseMass=t.inverseMass+i.inverseMass,r.friction=t.friction<i.friction?t.friction:i.friction,r.frictionStatic=t.frictionStatic>i.frictionStatic?t.frictionStatic:i.frictionStatic,r.restitution=t.restitution>i.restitution?t.restitution:i.restitution,r.slop=t.slop>i.slop?t.slop:i.slop,r.contactCount=h,a.pair=r;var s=n[0],f=l[0],m=n[1],x=l[1];(x.vertex===s||f.vertex===m)&&(l[1]=f,l[0]=f=x,x=l[1]),f.vertex=s,x.vertex=m},e.setActive=function(r,a,u){a?(r.isActive=!0,r.timeUpdated=u):(r.isActive=!1,r.contactCount=0)},e.id=function(r,a){return r.id<a.id?r.id.toString(36)+":"+a.id.toString(36):a.id.toString(36)+":"+r.id.toString(36)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(2),a=c(7),u=c(1),n=c(11),h=c(0);(function(){e._warming=.4,e._torqueDampen=1,e._minLength=1e-6,e.create=function(l){var t=l;t.bodyA&&!t.pointA&&(t.pointA={x:0,y:0}),t.bodyB&&!t.pointB&&(t.pointB={x:0,y:0});var i=t.bodyA?r.add(t.bodyA.position,t.pointA):t.pointA,s=t.bodyB?r.add(t.bodyB.position,t.pointB):t.pointB,f=r.magnitude(r.sub(i,s));t.length=typeof t.length<"u"?t.length:f,t.id=t.id||h.nextId(),t.label=t.label||"Constraint",t.type="constraint",t.stiffness=t.stiffness||(t.length>0?1:.7),t.damping=t.damping||0,t.angularStiffness=t.angularStiffness||0,t.angleA=t.bodyA?t.bodyA.angle:t.angleA,t.angleB=t.bodyB?t.bodyB.angle:t.angleB,t.plugin={};var m={visible:!0,lineWidth:2,strokeStyle:"#ffffff",type:"line",anchors:!0};return t.length===0&&t.stiffness>.1?(m.type="pin",m.anchors=!1):t.stiffness<.9&&(m.type="spring"),t.render=h.extend(m,t.render),t},e.preSolveAll=function(l){for(var t=0;t<l.length;t+=1){var i=l[t],s=i.constraintImpulse;i.isStatic||s.x===0&&s.y===0&&s.angle===0||(i.position.x+=s.x,i.position.y+=s.y,i.angle+=s.angle)}},e.solveAll=function(l,t){for(var i=h.clamp(t/h._baseDelta,0,1),s=0;s<l.length;s+=1){var f=l[s],m=!f.bodyA||f.bodyA&&f.bodyA.isStatic,x=!f.bodyB||f.bodyB&&f.bodyB.isStatic;(m||x)&&e.solve(l[s],i)}for(s=0;s<l.length;s+=1)f=l[s],m=!f.bodyA||f.bodyA&&f.bodyA.isStatic,x=!f.bodyB||f.bodyB&&f.bodyB.isStatic,!m&&!x&&e.solve(l[s],i)},e.solve=function(l,t){var i=l.bodyA,s=l.bodyB,f=l.pointA,m=l.pointB;if(!(!i&&!s)){i&&!i.isStatic&&(r.rotate(f,i.angle-l.angleA,f),l.angleA=i.angle),s&&!s.isStatic&&(r.rotate(m,s.angle-l.angleB,m),l.angleB=s.angle);var x=f,P=m;if(i&&(x=r.add(i.position,f)),s&&(P=r.add(s.position,m)),!(!x||!P)){var T=r.sub(x,P),g=r.magnitude(T);g<e._minLength&&(g=e._minLength);var d=(g-l.length)/g,y=l.stiffness>=1||l.length===0?l.stiffness*t:l.stiffness*t*t,v=l.damping*t,w=r.mult(T,d*y),S=(i?i.inverseMass:0)+(s?s.inverseMass:0),C=S+((i?i.inverseInertia:0)+(s?s.inverseInertia:0)),M,I,R,L,D;if(v>0){var k=r.create();R=r.div(T,g),D=r.sub(s&&r.sub(s.position,s.positionPrev)||k,i&&r.sub(i.position,i.positionPrev)||k),L=r.dot(R,D)}i&&!i.isStatic&&(I=i.inverseMass/S,i.constraintImpulse.x-=w.x*I,i.constraintImpulse.y-=w.y*I,i.position.x-=w.x*I,i.position.y-=w.y*I,v>0&&(i.positionPrev.x-=v*R.x*L*I,i.positionPrev.y-=v*R.y*L*I),M=r.cross(f,w)/C*e._torqueDampen*i.inverseInertia*(1-l.angularStiffness),i.constraintImpulse.angle-=M,i.angle-=M),s&&!s.isStatic&&(I=s.inverseMass/S,s.constraintImpulse.x+=w.x*I,s.constraintImpulse.y+=w.y*I,s.position.x+=w.x*I,s.position.y+=w.y*I,v>0&&(s.positionPrev.x+=v*R.x*L*I,s.positionPrev.y+=v*R.y*L*I),M=r.cross(m,w)/C*e._torqueDampen*s.inverseInertia*(1-l.angularStiffness),s.constraintImpulse.angle+=M,s.angle+=M)}}},e.postSolveAll=function(l){for(var t=0;t<l.length;t++){var i=l[t],s=i.constraintImpulse;if(!(i.isStatic||s.x===0&&s.y===0&&s.angle===0)){a.set(i,!1);for(var f=0;f<i.parts.length;f++){var m=i.parts[f];o.translate(m.vertices,s),f>0&&(m.position.x+=s.x,m.position.y+=s.y),s.angle!==0&&(o.rotate(m.vertices,s.angle,i.position),n.rotate(m.axes,s.angle),f>0&&r.rotateAbout(m.position,s.angle,i.position,m.position)),u.update(m.bounds,m.vertices,i.velocity)}s.angle*=e._warming,s.x*=e._warming,s.y*=e._warming}}},e.pointAWorld=function(l){return{x:(l.bodyA?l.bodyA.position.x:0)+(l.pointA?l.pointA.x:0),y:(l.bodyA?l.bodyA.position.y:0)+(l.pointA?l.pointA.y:0)}},e.pointBWorld=function(l){return{x:(l.bodyB?l.bodyB.position.x:0)+(l.pointB?l.pointB.x:0),y:(l.bodyB?l.bodyB.position.y:0)+(l.pointB?l.pointB.y:0)}},e.currentLength=function(l){var t=(l.bodyA?l.bodyA.position.x:0)+(l.pointA?l.pointA.x:0),i=(l.bodyA?l.bodyA.position.y:0)+(l.pointA?l.pointA.y:0),s=(l.bodyB?l.bodyB.position.x:0)+(l.pointB?l.pointB.x:0),f=(l.bodyB?l.bodyB.position.y:0)+(l.pointB?l.pointB.y:0),m=t-s,x=i-f;return Math.sqrt(m*m+x*x)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(2),r=c(0);(function(){e.fromVertices=function(a){for(var u={},n=0;n<a.length;n++){var h=(n+1)%a.length,l=o.normalise({x:a[h].y-a[n].y,y:a[n].x-a[h].x}),t=l.y===0?1/0:l.x/l.y;t=t.toFixed(3).toString(),u[t]=l}return r.values(u)},e.rotate=function(a,u){if(u!==0)for(var n=Math.cos(u),h=Math.sin(u),l=0;l<a.length;l++){var t=a[l],i=t.x*n-t.y*h;t.y=t.x*h+t.y*n,t.x=i}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(0),a=c(4),u=c(1),n=c(2);(function(){e.rectangle=function(h,l,t,i,s){s=s||{};var f={label:"Rectangle Body",position:{x:h,y:l},vertices:o.fromPath("L 0 0 L "+t+" 0 L "+t+" "+i+" L 0 "+i)};if(s.chamfer){var m=s.chamfer;f.vertices=o.chamfer(f.vertices,m.radius,m.quality,m.qualityMin,m.qualityMax),delete s.chamfer}return a.create(r.extend({},f,s))},e.trapezoid=function(h,l,t,i,s,f){f=f||{},s>=1&&r.warn("Bodies.trapezoid: slope parameter must be < 1."),s*=.5;var m=(1-s*2)*t,x=t*s,P=x+m,T=P+x,g;s<.5?g="L 0 0 L "+x+" "+-i+" L "+P+" "+-i+" L "+T+" 0":g="L 0 0 L "+P+" "+-i+" L "+T+" 0";var d={label:"Trapezoid Body",position:{x:h,y:l},vertices:o.fromPath(g)};if(f.chamfer){var y=f.chamfer;d.vertices=o.chamfer(d.vertices,y.radius,y.quality,y.qualityMin,y.qualityMax),delete f.chamfer}return a.create(r.extend({},d,f))},e.circle=function(h,l,t,i,s){i=i||{};var f={label:"Circle Body",circleRadius:t};s=s||25;var m=Math.ceil(Math.max(10,Math.min(s,t)));return m%2===1&&(m+=1),e.polygon(h,l,m,t,r.extend({},f,i))},e.polygon=function(h,l,t,i,s){if(s=s||{},t<3)return e.circle(h,l,i,s);for(var f=2*Math.PI/t,m="",x=f*.5,P=0;P<t;P+=1){var T=x+P*f,g=Math.cos(T)*i,d=Math.sin(T)*i;m+="L "+g.toFixed(3)+" "+d.toFixed(3)+" "}var y={label:"Polygon Body",position:{x:h,y:l},vertices:o.fromPath(m)};if(s.chamfer){var v=s.chamfer;y.vertices=o.chamfer(y.vertices,v.radius,v.quality,v.qualityMin,v.qualityMax),delete s.chamfer}return a.create(r.extend({},y,s))},e.fromVertices=function(h,l,t,i,s,f,m,x){var P=r.getDecomp(),T=!!(P&&P.quickDecomp),g,d,y,v,w,S,C,M,I,R;for(i=i||{},d=[],s=typeof s<"u"?s:!1,f=typeof f<"u"?f:.01,m=typeof m<"u"?m:10,x=typeof x<"u"?x:.01,r.isArray(t[0])||(t=[t]),I=0;I<t.length;I+=1)if(w=t[I],y=o.isConvex(w),v=!y,v&&!T&&r.warnOnce("Bodies.fromVertices: Install the 'poly-decomp' library and use Common.setDecomp or provide 'decomp' as a global to decompose concave vertices."),y||!T)y?w=o.clockwiseSort(w):w=o.hull(w),d.push({position:{x:h,y:l},vertices:w});else{var L=w.map(function(F){return[F.x,F.y]});P.makeCCW(L),f!==!1&&P.removeCollinearPoints(L,f),x!==!1&&P.removeDuplicatePoints&&P.removeDuplicatePoints(L,x);var D=P.quickDecomp(L);for(S=0;S<D.length;S++){var k=D[S].map(function(F){return{x:F[0],y:F[1]}});m>0&&o.area(k)<m||d.push({position:o.centre(k),vertices:k})}}for(S=0;S<d.length;S++)d[S]=a.create(r.extend(d[S],i));if(s){var b=5;for(S=0;S<d.length;S++){var U=d[S];for(C=S+1;C<d.length;C++){var W=d[C];if(u.overlaps(U.bounds,W.bounds)){var G=U.vertices,N=W.vertices;for(M=0;M<U.vertices.length;M++)for(R=0;R<W.vertices.length;R++){var Q=n.magnitudeSquared(n.sub(G[(M+1)%G.length],N[R])),X=n.magnitudeSquared(n.sub(G[M],N[(R+1)%N.length]));Q<b&&X<b&&(G[M].isInternal=!0,N[R].isInternal=!0)}}}}}return d.length>1?(g=a.create(r.extend({parts:d.slice(0)},i)),a.setPosition(g,{x:h,y:l}),g):d[0]}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(0),r=c(8);(function(){e.create=function(a){return o.extend({bodies:[],collisions:[],pairs:null},a)},e.setBodies=function(a,u){a.bodies=u.slice(0)},e.clear=function(a){a.bodies=[],a.collisions=[]},e.collisions=function(a){var u=a.pairs,n=a.bodies,h=n.length,l=e.canCollide,t=r.collides,i=a.collisions,s=0,f,m;for(n.sort(e._compareBoundsX),f=0;f<h;f++){var x=n[f],P=x.bounds,T=x.bounds.max.x,g=x.bounds.max.y,d=x.bounds.min.y,y=x.isStatic||x.isSleeping,v=x.parts.length,w=v===1;for(m=f+1;m<h;m++){var S=n[m],C=S.bounds;if(C.min.x>T)break;if(!(g<C.min.y||d>C.max.y)&&!(y&&(S.isStatic||S.isSleeping))&&l(x.collisionFilter,S.collisionFilter)){var M=S.parts.length;if(w&&M===1){var I=t(x,S,u);I&&(i[s++]=I)}else for(var R=v>1?1:0,L=M>1?1:0,D=R;D<v;D++)for(var k=x.parts[D],P=k.bounds,b=L;b<M;b++){var U=S.parts[b],C=U.bounds;if(!(P.min.x>C.max.x||P.max.x<C.min.x||P.max.y<C.min.y||P.min.y>C.max.y)){var I=t(k,U,u);I&&(i[s++]=I)}}}}}return i.length!==s&&(i.length=s),i},e.canCollide=function(a,u){return a.group===u.group&&a.group!==0?a.group>0:(a.mask&u.category)!==0&&(u.mask&a.category)!==0},e._compareBoundsX=function(a,u){return a.bounds.min.x-u.bounds.min.x}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(0);(function(){e.create=function(r){var a={};return r||o.log("Mouse.create: element was undefined, defaulting to document.body","warn"),a.element=r||document.body,a.absolute={x:0,y:0},a.position={x:0,y:0},a.mousedownPosition={x:0,y:0},a.mouseupPosition={x:0,y:0},a.offset={x:0,y:0},a.scale={x:1,y:1},a.wheelDelta=0,a.button=-1,a.pixelRatio=parseInt(a.element.getAttribute("data-pixel-ratio"),10)||1,a.sourceEvents={mousemove:null,mousedown:null,mouseup:null,mousewheel:null},a.mousemove=function(u){var n=e._getRelativeMousePosition(u,a.element,a.pixelRatio);u.changedTouches&&(a.button=0,u.preventDefault()),a.absolute.x=n.x,a.absolute.y=n.y,a.position.x=a.absolute.x*a.scale.x+a.offset.x,a.position.y=a.absolute.y*a.scale.y+a.offset.y,a.sourceEvents.mousemove=u},a.mousedown=function(u){var n=e._getRelativeMousePosition(u,a.element,a.pixelRatio);u.changedTouches?(a.button=0,u.preventDefault()):a.button=u.button,a.absolute.x=n.x,a.absolute.y=n.y,a.position.x=a.absolute.x*a.scale.x+a.offset.x,a.position.y=a.absolute.y*a.scale.y+a.offset.y,a.mousedownPosition.x=a.position.x,a.mousedownPosition.y=a.position.y,a.sourceEvents.mousedown=u},a.mouseup=function(u){var n=e._getRelativeMousePosition(u,a.element,a.pixelRatio);u.changedTouches&&u.preventDefault(),a.button=-1,a.absolute.x=n.x,a.absolute.y=n.y,a.position.x=a.absolute.x*a.scale.x+a.offset.x,a.position.y=a.absolute.y*a.scale.y+a.offset.y,a.mouseupPosition.x=a.position.x,a.mouseupPosition.y=a.position.y,a.sourceEvents.mouseup=u},a.mousewheel=function(u){a.wheelDelta=Math.max(-1,Math.min(1,u.wheelDelta||-u.detail)),u.preventDefault(),a.sourceEvents.mousewheel=u},e.setElement(a,a.element),a},e.setElement=function(r,a){r.element=a,a.addEventListener("mousemove",r.mousemove,{passive:!0}),a.addEventListener("mousedown",r.mousedown,{passive:!0}),a.addEventListener("mouseup",r.mouseup,{passive:!0}),a.addEventListener("wheel",r.mousewheel,{passive:!1}),a.addEventListener("touchmove",r.mousemove,{passive:!1}),a.addEventListener("touchstart",r.mousedown,{passive:!1}),a.addEventListener("touchend",r.mouseup,{passive:!1})},e.clearSourceEvents=function(r){r.sourceEvents.mousemove=null,r.sourceEvents.mousedown=null,r.sourceEvents.mouseup=null,r.sourceEvents.mousewheel=null,r.wheelDelta=0},e.setOffset=function(r,a){r.offset.x=a.x,r.offset.y=a.y,r.position.x=r.absolute.x*r.scale.x+r.offset.x,r.position.y=r.absolute.y*r.scale.y+r.offset.y},e.setScale=function(r,a){r.scale.x=a.x,r.scale.y=a.y,r.position.x=r.absolute.x*r.scale.x+r.offset.x,r.position.y=r.absolute.y*r.scale.y+r.offset.y},e._getRelativeMousePosition=function(r,a,u){var n=a.getBoundingClientRect(),h=document.documentElement||document.body.parentNode||document.body,l=window.pageXOffset!==void 0?window.pageXOffset:h.scrollLeft,t=window.pageYOffset!==void 0?window.pageYOffset:h.scrollTop,i=r.changedTouches,s,f;return i?(s=i[0].pageX-n.left-l,f=i[0].pageY-n.top-t):(s=r.pageX-n.left-l,f=r.pageY-n.top-t),{x:s/(a.clientWidth/(a.width||a.clientWidth)*u),y:f/(a.clientHeight/(a.height||a.clientHeight)*u)}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(0);(function(){e._registry={},e.register=function(r){if(e.isPlugin(r)||o.warn("Plugin.register:",e.toString(r),"does not implement all required fields."),r.name in e._registry){var a=e._registry[r.name],u=e.versionParse(r.version).number,n=e.versionParse(a.version).number;u>n?(o.warn("Plugin.register:",e.toString(a),"was upgraded to",e.toString(r)),e._registry[r.name]=r):u<n?o.warn("Plugin.register:",e.toString(a),"can not be downgraded to",e.toString(r)):r!==a&&o.warn("Plugin.register:",e.toString(r),"is already registered to different plugin object")}else e._registry[r.name]=r;return r},e.resolve=function(r){return e._registry[e.dependencyParse(r).name]},e.toString=function(r){return typeof r=="string"?r:(r.name||"anonymous")+"@"+(r.version||r.range||"0.0.0")},e.isPlugin=function(r){return r&&r.name&&r.version&&r.install},e.isUsed=function(r,a){return r.used.indexOf(a)>-1},e.isFor=function(r,a){var u=r.for&&e.dependencyParse(r.for);return!r.for||a.name===u.name&&e.versionSatisfies(a.version,u.range)},e.use=function(r,a){if(r.uses=(r.uses||[]).concat(a||[]),r.uses.length===0){o.warn("Plugin.use:",e.toString(r),"does not specify any dependencies to install.");return}for(var u=e.dependencies(r),n=o.topologicalSort(u),h=[],l=0;l<n.length;l+=1)if(n[l]!==r.name){var t=e.resolve(n[l]);if(!t){h.push("❌ "+n[l]);continue}e.isUsed(r,t.name)||(e.isFor(t,r)||(o.warn("Plugin.use:",e.toString(t),"is for",t.for,"but installed on",e.toString(r)+"."),t._warned=!0),t.install?t.install(r):(o.warn("Plugin.use:",e.toString(t),"does not specify an install function."),t._warned=!0),t._warned?(h.push("🔶 "+e.toString(t)),delete t._warned):h.push("✅ "+e.toString(t)),r.used.push(t.name))}h.length>0&&o.info(h.join(" "))},e.dependencies=function(r,a){var u=e.dependencyParse(r),n=u.name;if(a=a||{},!(n in a)){r=e.resolve(r)||r,a[n]=o.map(r.uses||[],function(l){e.isPlugin(l)&&e.register(l);var t=e.dependencyParse(l),i=e.resolve(l);return i&&!e.versionSatisfies(i.version,t.range)?(o.warn("Plugin.dependencies:",e.toString(i),"does not satisfy",e.toString(t),"used by",e.toString(u)+"."),i._warned=!0,r._warned=!0):i||(o.warn("Plugin.dependencies:",e.toString(l),"used by",e.toString(u),"could not be resolved."),r._warned=!0),t.name});for(var h=0;h<a[n].length;h+=1)e.dependencies(a[n][h],a);return a}},e.dependencyParse=function(r){return o.isString(r)?(/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-+]+)?))?$/.test(r)||o.warn("Plugin.dependencyParse:",r,"is not a valid dependency string."),{name:r.split("@")[0],range:r.split("@")[1]||"*"}):{name:r.name,range:r.range||r.version}},e.versionParse=function(r){var a=/^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-+]+)?$/;a.test(r)||o.warn("Plugin.versionParse:",r,"is not a valid version or range.");var u=a.exec(r),n=Number(u[4]),h=Number(u[5]),l=Number(u[6]);return{isRange:!!(u[1]||u[2]),version:u[3],range:r,operator:u[1]||u[2]||"",major:n,minor:h,patch:l,parts:[n,h,l],prerelease:u[7],number:n*1e8+h*1e4+l}},e.versionSatisfies=function(r,a){a=a||"*";var u=e.versionParse(a),n=e.versionParse(r);if(u.isRange){if(u.operator==="*"||r==="*")return!0;if(u.operator===">")return n.number>u.number;if(u.operator===">=")return n.number>=u.number;if(u.operator==="~")return n.major===u.major&&n.minor===u.minor&&n.patch>=u.patch;if(u.operator==="^")return u.major>0?n.major===u.major&&n.number>=u.number:u.minor>0?n.minor===u.minor&&n.patch>=u.patch:n.patch===u.patch}return r===a||r==="*"}})()}),(function(A,E){var c={};A.exports=c,(function(){c.create=function(e){return{vertex:e,normalImpulse:0,tangentImpulse:0}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(7),r=c(18),a=c(13),u=c(19),n=c(5),h=c(6),l=c(10),t=c(0),i=c(4);(function(){e._deltaMax=1e3/60,e.create=function(s){s=s||{};var f=t.extend({positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],plugin:{},gravity:{x:0,y:1,scale:.001},timing:{timestamp:0,timeScale:1,lastDelta:0,lastElapsed:0,lastUpdatesPerFrame:0}},s);return f.world=s.world||h.create({label:"World"}),f.pairs=s.pairs||u.create(),f.detector=s.detector||a.create(),f.detector.pairs=f.pairs,f.grid={buckets:[]},f.world.gravity=f.gravity,f.broadphase=f.grid,f.metrics={},f},e.update=function(s,f){var m=t.now(),x=s.world,P=s.detector,T=s.pairs,g=s.timing,d=g.timestamp,y;f>e._deltaMax&&t.warnOnce("Matter.Engine.update: delta argument is recommended to be less than or equal to",e._deltaMax.toFixed(3),"ms."),f=typeof f<"u"?f:t._baseDelta,f*=g.timeScale,g.timestamp+=f,g.lastDelta=f;var v={timestamp:g.timestamp,delta:f};n.trigger(s,"beforeUpdate",v);var w=h.allBodies(x),S=h.allConstraints(x);for(x.isModified&&(a.setBodies(P,w),h.setModified(x,!1,!1,!0)),s.enableSleeping&&o.update(w,f),e._bodiesApplyGravity(w,s.gravity),f>0&&e._bodiesUpdate(w,f),n.trigger(s,"beforeSolve",v),l.preSolveAll(w),y=0;y<s.constraintIterations;y++)l.solveAll(S,f);l.postSolveAll(w);var C=a.collisions(P);u.update(T,C,d),s.enableSleeping&&o.afterCollisions(T.list),T.collisionStart.length>0&&n.trigger(s,"collisionStart",{pairs:T.collisionStart,timestamp:g.timestamp,delta:f});var M=t.clamp(20/s.positionIterations,0,1);for(r.preSolvePosition(T.list),y=0;y<s.positionIterations;y++)r.solvePosition(T.list,f,M);for(r.postSolvePosition(w),l.preSolveAll(w),y=0;y<s.constraintIterations;y++)l.solveAll(S,f);for(l.postSolveAll(w),r.preSolveVelocity(T.list),y=0;y<s.velocityIterations;y++)r.solveVelocity(T.list,f);return e._bodiesUpdateVelocities(w),T.collisionActive.length>0&&n.trigger(s,"collisionActive",{pairs:T.collisionActive,timestamp:g.timestamp,delta:f}),T.collisionEnd.length>0&&n.trigger(s,"collisionEnd",{pairs:T.collisionEnd,timestamp:g.timestamp,delta:f}),e._bodiesClearForces(w),n.trigger(s,"afterUpdate",v),s.timing.lastElapsed=t.now()-m,s},e.merge=function(s,f){if(t.extend(s,f),f.world){s.world=f.world,e.clear(s);for(var m=h.allBodies(s.world),x=0;x<m.length;x++){var P=m[x];o.set(P,!1),P.id=t.nextId()}}},e.clear=function(s){u.clear(s.pairs),a.clear(s.detector)},e._bodiesClearForces=function(s){for(var f=s.length,m=0;m<f;m++){var x=s[m];x.force.x=0,x.force.y=0,x.torque=0}},e._bodiesApplyGravity=function(s,f){var m=typeof f.scale<"u"?f.scale:.001,x=s.length;if(!(f.x===0&&f.y===0||m===0))for(var P=0;P<x;P++){var T=s[P];T.isStatic||T.isSleeping||(T.force.y+=T.mass*f.y*m,T.force.x+=T.mass*f.x*m)}},e._bodiesUpdate=function(s,f){for(var m=s.length,x=0;x<m;x++){var P=s[x];P.isStatic||P.isSleeping||i.update(P,f)}},e._bodiesUpdateVelocities=function(s){for(var f=s.length,m=0;m<f;m++)i.updateVelocities(s[m])}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(0),a=c(1);(function(){e._restingThresh=2,e._restingThreshTangent=Math.sqrt(6),e._positionDampen=.9,e._positionWarming=.8,e._frictionNormalMultiplier=5,e._frictionMaxStatic=Number.MAX_VALUE,e.preSolvePosition=function(u){var n,h,l,t=u.length;for(n=0;n<t;n++)h=u[n],h.isActive&&(l=h.contactCount,h.collision.parentA.totalContacts+=l,h.collision.parentB.totalContacts+=l)},e.solvePosition=function(u,n,h){var l,t,i,s,f,m,x,P,T=e._positionDampen*(h||1),g=r.clamp(n/r._baseDelta,0,1),d=u.length;for(l=0;l<d;l++)t=u[l],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,f=i.parentB,m=i.normal,t.separation=i.depth+m.x*(f.positionImpulse.x-s.positionImpulse.x)+m.y*(f.positionImpulse.y-s.positionImpulse.y));for(l=0;l<d;l++)t=u[l],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,f=i.parentB,m=i.normal,P=t.separation-t.slop*g,(s.isStatic||f.isStatic)&&(P*=2),s.isStatic||s.isSleeping||(x=T/s.totalContacts,s.positionImpulse.x+=m.x*P*x,s.positionImpulse.y+=m.y*P*x),f.isStatic||f.isSleeping||(x=T/f.totalContacts,f.positionImpulse.x-=m.x*P*x,f.positionImpulse.y-=m.y*P*x))},e.postSolvePosition=function(u){for(var n=e._positionWarming,h=u.length,l=o.translate,t=a.update,i=0;i<h;i++){var s=u[i],f=s.positionImpulse,m=f.x,x=f.y,P=s.velocity;if(s.totalContacts=0,m!==0||x!==0){for(var T=0;T<s.parts.length;T++){var g=s.parts[T];l(g.vertices,f),t(g.bounds,g.vertices,P),g.position.x+=m,g.position.y+=x}s.positionPrev.x+=m,s.positionPrev.y+=x,m*P.x+x*P.y<0?(f.x=0,f.y=0):(f.x*=n,f.y*=n)}}},e.preSolveVelocity=function(u){var n=u.length,h,l;for(h=0;h<n;h++){var t=u[h];if(!(!t.isActive||t.isSensor)){var i=t.contacts,s=t.contactCount,f=t.collision,m=f.parentA,x=f.parentB,P=f.normal,T=f.tangent;for(l=0;l<s;l++){var g=i[l],d=g.vertex,y=g.normalImpulse,v=g.tangentImpulse;if(y!==0||v!==0){var w=P.x*y+T.x*v,S=P.y*y+T.y*v;m.isStatic||m.isSleeping||(m.positionPrev.x+=w*m.inverseMass,m.positionPrev.y+=S*m.inverseMass,m.anglePrev+=m.inverseInertia*((d.x-m.position.x)*S-(d.y-m.position.y)*w)),x.isStatic||x.isSleeping||(x.positionPrev.x-=w*x.inverseMass,x.positionPrev.y-=S*x.inverseMass,x.anglePrev-=x.inverseInertia*((d.x-x.position.x)*S-(d.y-x.position.y)*w))}}}}},e.solveVelocity=function(u,n){var h=n/r._baseDelta,l=h*h*h,t=-e._restingThresh*h,i=e._restingThreshTangent,s=e._frictionNormalMultiplier*h,f=e._frictionMaxStatic,m=u.length,x,P,T,g;for(T=0;T<m;T++){var d=u[T];if(!(!d.isActive||d.isSensor)){var y=d.collision,v=y.parentA,w=y.parentB,S=y.normal.x,C=y.normal.y,M=y.tangent.x,I=y.tangent.y,R=d.inverseMass,L=d.friction*d.frictionStatic*s,D=d.contacts,k=d.contactCount,b=1/k,U=v.position.x-v.positionPrev.x,W=v.position.y-v.positionPrev.y,G=v.angle-v.anglePrev,N=w.position.x-w.positionPrev.x,Q=w.position.y-w.positionPrev.y,X=w.angle-w.anglePrev;for(g=0;g<k;g++){var F=D[g],H=F.vertex,V=H.x-v.position.x,q=H.y-v.position.y,Y=H.x-w.position.x,K=H.y-w.position.y,z=U-q*G,ct=W+V*G,ut=N-K*X,ht=Q+Y*X,ge=z-ut,ve=ct-ht,le=S*ge+C*ve,$=M*ge+I*ve,pe=d.separation+le,fe=Math.min(pe,1);fe=pe<0?0:fe;var de=fe*L;$<-de||$>de?(P=$>0?$:-$,x=d.friction*($>0?1:-1)*l,x<-P?x=-P:x>P&&(x=P)):(x=$,P=f);var me=V*C-q*S,xe=Y*C-K*S,ye=b/(R+v.inverseInertia*me*me+w.inverseInertia*xe*xe),ne=(1+d.restitution)*le*ye;if(x*=ye,le<t)F.normalImpulse=0;else{var gt=F.normalImpulse;F.normalImpulse+=ne,F.normalImpulse>0&&(F.normalImpulse=0),ne=F.normalImpulse-gt}if($<-i||$>i)F.tangentImpulse=0;else{var vt=F.tangentImpulse;F.tangentImpulse+=x,F.tangentImpulse<-P&&(F.tangentImpulse=-P),F.tangentImpulse>P&&(F.tangentImpulse=P),x=F.tangentImpulse-vt}var se=S*ne+M*x,ae=C*ne+I*x;v.isStatic||v.isSleeping||(v.positionPrev.x+=se*v.inverseMass,v.positionPrev.y+=ae*v.inverseMass,v.anglePrev+=(V*ae-q*se)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=se*w.inverseMass,w.positionPrev.y-=ae*w.inverseMass,w.anglePrev-=(Y*ae-K*se)*w.inverseInertia)}}}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(9),r=c(0);(function(){e.create=function(a){return r.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},a)},e.update=function(a,u,n){var h=o.update,l=o.create,t=o.setActive,i=a.table,s=a.list,f=s.length,m=f,x=a.collisionStart,P=a.collisionEnd,T=a.collisionActive,g=u.length,d=0,y=0,v=0,w,S,C;for(C=0;C<g;C++)w=u[C],S=w.pair,S?(S.isActive&&(T[v++]=S),h(S,w,n)):(S=l(w,n),i[S.id]=S,x[d++]=S,s[m++]=S);for(m=0,f=s.length,C=0;C<f;C++)S=s[C],S.timeUpdated>=n?s[m++]=S:(t(S,!1,n),S.collision.bodyA.sleepCounter>0&&S.collision.bodyB.sleepCounter>0?s[m++]=S:(P[y++]=S,delete i[S.id]));s.length!==m&&(s.length=m),x.length!==d&&(x.length=d),P.length!==y&&(P.length=y),T.length!==v&&(T.length=v)},e.clear=function(a){return a.table={},a.list.length=0,a.collisionStart.length=0,a.collisionActive.length=0,a.collisionEnd.length=0,a}})()}),(function(A,E,c){var e=A.exports=c(21);e.Axes=c(11),e.Bodies=c(12),e.Body=c(4),e.Bounds=c(1),e.Collision=c(8),e.Common=c(0),e.Composite=c(6),e.Composites=c(22),e.Constraint=c(10),e.Contact=c(16),e.Detector=c(13),e.Engine=c(17),e.Events=c(5),e.Grid=c(23),e.Mouse=c(14),e.MouseConstraint=c(24),e.Pair=c(9),e.Pairs=c(19),e.Plugin=c(15),e.Query=c(25),e.Render=c(26),e.Resolver=c(18),e.Runner=c(27),e.SAT=c(28),e.Sleeping=c(7),e.Svg=c(29),e.Vector=c(2),e.Vertices=c(3),e.World=c(30),e.Engine.run=e.Runner.run,e.Common.deprecated(e.Engine,"run","Engine.run ➤ use Matter.Runner.run(engine) instead")}),(function(A,E,c){var e={};A.exports=e;var o=c(15),r=c(0);(function(){e.name="matter-js",e.version="0.20.0",e.uses=[],e.used=[],e.use=function(){o.use(e,Array.prototype.slice.call(arguments))},e.before=function(a,u){return a=a.replace(/^Matter./,""),r.chainPathBefore(e,a,u)},e.after=function(a,u){return a=a.replace(/^Matter./,""),r.chainPathAfter(e,a,u)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(6),r=c(10),a=c(0),u=c(4),n=c(12),h=a.deprecated;(function(){e.stack=function(l,t,i,s,f,m,x){for(var P=o.create({label:"Stack"}),T=l,g=t,d,y=0,v=0;v<s;v++){for(var w=0,S=0;S<i;S++){var C=x(T,g,S,v,d,y);if(C){var M=C.bounds.max.y-C.bounds.min.y,I=C.bounds.max.x-C.bounds.min.x;M>w&&(w=M),u.translate(C,{x:I*.5,y:M*.5}),T=C.bounds.max.x+f,o.addBody(P,C),d=C,y+=1}else T+=f}g+=w+m,T=l}return P},e.chain=function(l,t,i,s,f,m){for(var x=l.bodies,P=1;P<x.length;P++){var T=x[P-1],g=x[P],d=T.bounds.max.y-T.bounds.min.y,y=T.bounds.max.x-T.bounds.min.x,v=g.bounds.max.y-g.bounds.min.y,w=g.bounds.max.x-g.bounds.min.x,S={bodyA:T,pointA:{x:y*t,y:d*i},bodyB:g,pointB:{x:w*s,y:v*f}},C=a.extend(S,m);o.addConstraint(l,r.create(C))}return l.label+=" Chain",l},e.mesh=function(l,t,i,s,f){var m=l.bodies,x,P,T,g,d;for(x=0;x<i;x++){for(P=1;P<t;P++)T=m[P-1+x*t],g=m[P+x*t],o.addConstraint(l,r.create(a.extend({bodyA:T,bodyB:g},f)));if(x>0)for(P=0;P<t;P++)T=m[P+(x-1)*t],g=m[P+x*t],o.addConstraint(l,r.create(a.extend({bodyA:T,bodyB:g},f))),s&&P>0&&(d=m[P-1+(x-1)*t],o.addConstraint(l,r.create(a.extend({bodyA:d,bodyB:g},f)))),s&&P<t-1&&(d=m[P+1+(x-1)*t],o.addConstraint(l,r.create(a.extend({bodyA:d,bodyB:g},f))))}return l.label+=" Mesh",l},e.pyramid=function(l,t,i,s,f,m,x){return e.stack(l,t,i,s,f,m,function(P,T,g,d,y,v){var w=Math.min(s,Math.ceil(i/2)),S=y?y.bounds.max.x-y.bounds.min.x:0;if(!(d>w)){d=w-d;var C=d,M=i-1-d;if(!(g<C||g>M))return v===1&&u.translate(y,{x:(g+(i%2===1?1:-1))*S,y:0}),x(l+(y?g*S:0)+g*f,T,g,d,y,v)}})},e.newtonsCradle=function(l,t,i,s,f){for(var m=o.create({label:"Newtons Cradle"}),x=0;x<i;x++){var P=1.9,T=n.circle(l+x*(s*P),t+f,s,{inertia:1/0,restitution:1,friction:0,frictionAir:1e-4,slop:1}),g=r.create({pointA:{x:l+x*(s*P),y:t},bodyB:T});o.addBody(m,T),o.addConstraint(m,g)}return m},h(e,"newtonsCradle","Composites.newtonsCradle ➤ moved to newtonsCradle example"),e.car=function(l,t,i,s,f){var m=u.nextGroup(!0),x=20,P=-i*.5+x,T=i*.5-x,g=0,d=o.create({label:"Car"}),y=n.rectangle(l,t,i,s,{collisionFilter:{group:m},chamfer:{radius:s*.5},density:2e-4}),v=n.circle(l+P,t+g,f,{collisionFilter:{group:m},friction:.8}),w=n.circle(l+T,t+g,f,{collisionFilter:{group:m},friction:.8}),S=r.create({bodyB:y,pointB:{x:P,y:g},bodyA:v,stiffness:1,length:0}),C=r.create({bodyB:y,pointB:{x:T,y:g},bodyA:w,stiffness:1,length:0});return o.addBody(d,y),o.addBody(d,v),o.addBody(d,w),o.addConstraint(d,S),o.addConstraint(d,C),d},h(e,"car","Composites.car ➤ moved to car example"),e.softBody=function(l,t,i,s,f,m,x,P,T,g){T=a.extend({inertia:1/0},T),g=a.extend({stiffness:.2,render:{type:"line",anchors:!1}},g);var d=e.stack(l,t,i,s,f,m,function(y,v){return n.circle(y,v,P,T)});return e.mesh(d,i,s,x,g),d.label="Soft Body",d},h(e,"softBody","Composites.softBody ➤ moved to softBody and cloth examples")})()}),(function(A,E,c){var e={};A.exports=e;var o=c(9),r=c(0),a=r.deprecated;(function(){e.create=function(u){return r.extend({buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48},u)},e.update=function(u,n,h,l){var t,i,s,f=h.world,m=u.buckets,x,P,T=!1;for(t=0;t<n.length;t++){var g=n[t];if(!(g.isSleeping&&!l)&&!(f.bounds&&(g.bounds.max.x<f.bounds.min.x||g.bounds.min.x>f.bounds.max.x||g.bounds.max.y<f.bounds.min.y||g.bounds.min.y>f.bounds.max.y))){var d=e._getRegion(u,g);if(!g.region||d.id!==g.region.id||l){(!g.region||l)&&(g.region=d);var y=e._regionUnion(d,g.region);for(i=y.startCol;i<=y.endCol;i++)for(s=y.startRow;s<=y.endRow;s++){P=e._getBucketId(i,s),x=m[P];var v=i>=d.startCol&&i<=d.endCol&&s>=d.startRow&&s<=d.endRow,w=i>=g.region.startCol&&i<=g.region.endCol&&s>=g.region.startRow&&s<=g.region.endRow;!v&&w&&w&&x&&e._bucketRemoveBody(u,x,g),(g.region===d||v&&!w||l)&&(x||(x=e._createBucket(m,P)),e._bucketAddBody(u,x,g))}g.region=d,T=!0}}}T&&(u.pairsList=e._createActivePairsList(u))},a(e,"update","Grid.update ➤ replaced by Matter.Detector"),e.clear=function(u){u.buckets={},u.pairs={},u.pairsList=[]},a(e,"clear","Grid.clear ➤ replaced by Matter.Detector"),e._regionUnion=function(u,n){var h=Math.min(u.startCol,n.startCol),l=Math.max(u.endCol,n.endCol),t=Math.min(u.startRow,n.startRow),i=Math.max(u.endRow,n.endRow);return e._createRegion(h,l,t,i)},e._getRegion=function(u,n){var h=n.bounds,l=Math.floor(h.min.x/u.bucketWidth),t=Math.floor(h.max.x/u.bucketWidth),i=Math.floor(h.min.y/u.bucketHeight),s=Math.floor(h.max.y/u.bucketHeight);return e._createRegion(l,t,i,s)},e._createRegion=function(u,n,h,l){return{id:u+","+n+","+h+","+l,startCol:u,endCol:n,startRow:h,endRow:l}},e._getBucketId=function(u,n){return"C"+u+"R"+n},e._createBucket=function(u,n){return u[n]=[]},e._bucketAddBody=function(u,n,h){var l=u.pairs,t=o.id,i=n.length,s;for(s=0;s<i;s++){var f=n[s];if(!(h.id===f.id||h.isStatic&&f.isStatic)){var m=t(h,f),x=l[m];x?x[2]+=1:l[m]=[h,f,1]}}n.push(h)},e._bucketRemoveBody=function(u,n,h){var l=u.pairs,t=o.id,i;n.splice(r.indexOf(n,h),1);var s=n.length;for(i=0;i<s;i++){var f=l[t(h,n[i])];f&&(f[2]-=1)}},e._createActivePairsList=function(u){var n,h=u.pairs,l=r.keys(h),t=l.length,i=[],s;for(s=0;s<t;s++)n=h[l[s]],n[2]>0?i.push(n):delete h[l[s]];return i}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(3),r=c(7),a=c(14),u=c(5),n=c(13),h=c(10),l=c(6),t=c(0),i=c(1);(function(){e.create=function(s,f){var m=(s?s.mouse:null)||(f?f.mouse:null);m||(s&&s.render&&s.render.canvas?m=a.create(s.render.canvas):f&&f.element?m=a.create(f.element):(m=a.create(),t.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var x=h.create({label:"Mouse Constraint",pointA:m.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),P={type:"mouseConstraint",mouse:m,element:null,body:null,constraint:x,collisionFilter:{category:1,mask:4294967295,group:0}},T=t.extend(P,f);return u.on(s,"beforeUpdate",function(){var g=l.allBodies(s.world);e.update(T,g),e._triggerEvents(T)}),T},e.update=function(s,f){var m=s.mouse,x=s.constraint,P=s.body;if(m.button===0){if(x.bodyB)r.set(x.bodyB,!1),x.pointA=m.position;else for(var T=0;T<f.length;T++)if(P=f[T],i.contains(P.bounds,m.position)&&n.canCollide(P.collisionFilter,s.collisionFilter))for(var g=P.parts.length>1?1:0;g<P.parts.length;g++){var d=P.parts[g];if(o.contains(d.vertices,m.position)){x.pointA=m.position,x.bodyB=s.body=P,x.pointB={x:m.position.x-P.position.x,y:m.position.y-P.position.y},x.angleB=P.angle,r.set(P,!1),u.trigger(s,"startdrag",{mouse:m,body:P});break}}}else x.bodyB=s.body=null,x.pointB=null,P&&u.trigger(s,"enddrag",{mouse:m,body:P})},e._triggerEvents=function(s){var f=s.mouse,m=f.sourceEvents;m.mousemove&&u.trigger(s,"mousemove",{mouse:f}),m.mousedown&&u.trigger(s,"mousedown",{mouse:f}),m.mouseup&&u.trigger(s,"mouseup",{mouse:f}),a.clearSourceEvents(f)}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(2),r=c(8),a=c(1),u=c(12),n=c(3);(function(){e.collides=function(h,l){for(var t=[],i=l.length,s=h.bounds,f=r.collides,m=a.overlaps,x=0;x<i;x++){var P=l[x],T=P.parts.length,g=T===1?0:1;if(m(P.bounds,s))for(var d=g;d<T;d++){var y=P.parts[d];if(m(y.bounds,s)){var v=f(y,h);if(v){t.push(v);break}}}}return t},e.ray=function(h,l,t,i){i=i||1e-100;for(var s=o.angle(l,t),f=o.magnitude(o.sub(l,t)),m=(t.x+l.x)*.5,x=(t.y+l.y)*.5,P=u.rectangle(m,x,f,i,{angle:s}),T=e.collides(P,h),g=0;g<T.length;g+=1){var d=T[g];d.body=d.bodyB=d.bodyA}return T},e.region=function(h,l,t){for(var i=[],s=0;s<h.length;s++){var f=h[s],m=a.overlaps(f.bounds,l);(m&&!t||!m&&t)&&i.push(f)}return i},e.point=function(h,l){for(var t=[],i=0;i<h.length;i++){var s=h[i];if(a.contains(s.bounds,l))for(var f=s.parts.length===1?0:1;f<s.parts.length;f++){var m=s.parts[f];if(a.contains(m.bounds,l)&&n.contains(m.vertices,l)){t.push(s);break}}}return t}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(4),r=c(0),a=c(6),u=c(1),n=c(5),h=c(2),l=c(14);(function(){var t,i;typeof window<"u"&&(t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(g){window.setTimeout(function(){g(r.now())},1e3/60)},i=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),e._goodFps=30,e._goodDelta=1e3/60,e.create=function(g){var d={engine:null,element:null,canvas:null,mouse:null,frameRequestId:null,timing:{historySize:60,delta:0,deltaHistory:[],lastTime:0,lastTimestamp:0,lastElapsed:0,timestampElapsed:0,timestampElapsedHistory:[],engineDeltaHistory:[],engineElapsedHistory:[],engineUpdatesHistory:[],elapsedHistory:[]},options:{width:800,height:600,pixelRatio:1,background:"#14151f",wireframeBackground:"#14151f",wireframeStrokeStyle:"#bbb",hasBounds:!!g.bounds,enabled:!0,wireframes:!0,showSleeping:!0,showDebug:!1,showStats:!1,showPerformance:!1,showBounds:!1,showVelocity:!1,showCollisions:!1,showSeparations:!1,showAxes:!1,showPositions:!1,showAngleIndicator:!1,showIds:!1,showVertexNumbers:!1,showConvexHulls:!1,showInternalEdges:!1,showMousePosition:!1}},y=r.extend(d,g);return y.canvas&&(y.canvas.width=y.options.width||y.canvas.width,y.canvas.height=y.options.height||y.canvas.height),y.mouse=g.mouse,y.engine=g.engine,y.canvas=y.canvas||m(y.options.width,y.options.height),y.context=y.canvas.getContext("2d"),y.textures={},y.bounds=y.bounds||{min:{x:0,y:0},max:{x:y.canvas.width,y:y.canvas.height}},y.controller=e,y.options.showBroadphase=!1,y.options.pixelRatio!==1&&e.setPixelRatio(y,y.options.pixelRatio),r.isElement(y.element)&&y.element.appendChild(y.canvas),y},e.run=function(g){(function d(y){g.frameRequestId=t(d),s(g,y),e.world(g,y),g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0),(g.options.showStats||g.options.showDebug)&&e.stats(g,g.context,y),(g.options.showPerformance||g.options.showDebug)&&e.performance(g,g.context,y),g.context.setTransform(1,0,0,1,0,0)})()},e.stop=function(g){i(g.frameRequestId)},e.setPixelRatio=function(g,d){var y=g.options,v=g.canvas;d==="auto"&&(d=x(v)),y.pixelRatio=d,v.setAttribute("data-pixel-ratio",d),v.width=y.width*d,v.height=y.height*d,v.style.width=y.width+"px",v.style.height=y.height+"px"},e.setSize=function(g,d,y){g.options.width=d,g.options.height=y,g.bounds.max.x=g.bounds.min.x+d,g.bounds.max.y=g.bounds.min.y+y,g.options.pixelRatio!==1?e.setPixelRatio(g,g.options.pixelRatio):(g.canvas.width=d,g.canvas.height=y)},e.lookAt=function(g,d,y,v){v=typeof v<"u"?v:!0,d=r.isArray(d)?d:[d],y=y||{x:0,y:0};for(var w={min:{x:1/0,y:1/0},max:{x:-1/0,y:-1/0}},S=0;S<d.length;S+=1){var C=d[S],M=C.bounds?C.bounds.min:C.min||C.position||C,I=C.bounds?C.bounds.max:C.max||C.position||C;M&&I&&(M.x<w.min.x&&(w.min.x=M.x),I.x>w.max.x&&(w.max.x=I.x),M.y<w.min.y&&(w.min.y=M.y),I.y>w.max.y&&(w.max.y=I.y))}var R=w.max.x-w.min.x+2*y.x,L=w.max.y-w.min.y+2*y.y,D=g.canvas.height,k=g.canvas.width/D,b=R/L,U=1,W=1;b>k?W=b/k:U=k/b,g.options.hasBounds=!0,g.bounds.min.x=w.min.x,g.bounds.max.x=w.min.x+R*U,g.bounds.min.y=w.min.y,g.bounds.max.y=w.min.y+L*W,v&&(g.bounds.min.x+=R*.5-R*U*.5,g.bounds.max.x+=R*.5-R*U*.5,g.bounds.min.y+=L*.5-L*W*.5,g.bounds.max.y+=L*.5-L*W*.5),g.bounds.min.x-=y.x,g.bounds.max.x-=y.x,g.bounds.min.y-=y.y,g.bounds.max.y-=y.y,g.mouse&&(l.setScale(g.mouse,{x:(g.bounds.max.x-g.bounds.min.x)/g.canvas.width,y:(g.bounds.max.y-g.bounds.min.y)/g.canvas.height}),l.setOffset(g.mouse,g.bounds.min))},e.startViewTransform=function(g){var d=g.bounds.max.x-g.bounds.min.x,y=g.bounds.max.y-g.bounds.min.y,v=d/g.options.width,w=y/g.options.height;g.context.setTransform(g.options.pixelRatio/v,0,0,g.options.pixelRatio/w,0,0),g.context.translate(-g.bounds.min.x,-g.bounds.min.y)},e.endViewTransform=function(g){g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0)},e.world=function(g,d){var y=r.now(),v=g.engine,w=v.world,S=g.canvas,C=g.context,M=g.options,I=g.timing,R=a.allBodies(w),L=a.allConstraints(w),D=M.wireframes?M.wireframeBackground:M.background,k=[],b=[],U,W={timestamp:v.timing.timestamp};if(n.trigger(g,"beforeRender",W),g.currentBackground!==D&&T(g,D),C.globalCompositeOperation="source-in",C.fillStyle="transparent",C.fillRect(0,0,S.width,S.height),C.globalCompositeOperation="source-over",M.hasBounds){for(U=0;U<R.length;U++){var G=R[U];u.overlaps(G.bounds,g.bounds)&&k.push(G)}for(U=0;U<L.length;U++){var N=L[U],Q=N.bodyA,X=N.bodyB,F=N.pointA,H=N.pointB;Q&&(F=h.add(Q.position,N.pointA)),X&&(H=h.add(X.position,N.pointB)),!(!F||!H)&&(u.contains(g.bounds,F)||u.contains(g.bounds,H))&&b.push(N)}e.startViewTransform(g),g.mouse&&(l.setScale(g.mouse,{x:(g.bounds.max.x-g.bounds.min.x)/g.options.width,y:(g.bounds.max.y-g.bounds.min.y)/g.options.height}),l.setOffset(g.mouse,g.bounds.min))}else b=L,k=R,g.options.pixelRatio!==1&&g.context.setTransform(g.options.pixelRatio,0,0,g.options.pixelRatio,0,0);!M.wireframes||v.enableSleeping&&M.showSleeping?e.bodies(g,k,C):(M.showConvexHulls&&e.bodyConvexHulls(g,k,C),e.bodyWireframes(g,k,C)),M.showBounds&&e.bodyBounds(g,k,C),(M.showAxes||M.showAngleIndicator)&&e.bodyAxes(g,k,C),M.showPositions&&e.bodyPositions(g,k,C),M.showVelocity&&e.bodyVelocity(g,k,C),M.showIds&&e.bodyIds(g,k,C),M.showSeparations&&e.separations(g,v.pairs.list,C),M.showCollisions&&e.collisions(g,v.pairs.list,C),M.showVertexNumbers&&e.vertexNumbers(g,k,C),M.showMousePosition&&e.mousePosition(g,g.mouse,C),e.constraints(b,C),M.hasBounds&&e.endViewTransform(g),n.trigger(g,"afterRender",W),I.lastElapsed=r.now()-y},e.stats=function(g,d,y){for(var v=g.engine,w=v.world,S=a.allBodies(w),C=0,M=55,I=44,R=0,L=0,D=0;D<S.length;D+=1)C+=S[D].parts.length;var k={Part:C,Body:S.length,Cons:a.allConstraints(w).length,Comp:a.allComposites(w).length,Pair:v.pairs.list.length};d.fillStyle="#0e0f19",d.fillRect(R,L,M*5.5,I),d.font="12px Arial",d.textBaseline="top",d.textAlign="right";for(var b in k){var U=k[b];d.fillStyle="#aaa",d.fillText(b,R+M,L+8),d.fillStyle="#eee",d.fillText(U,R+M,L+26),R+=M}},e.performance=function(g,d){var y=g.engine,v=g.timing,w=v.deltaHistory,S=v.elapsedHistory,C=v.timestampElapsedHistory,M=v.engineDeltaHistory,I=v.engineUpdatesHistory,R=v.engineElapsedHistory,L=y.timing.lastUpdatesPerFrame,D=y.timing.lastDelta,k=f(w),b=f(S),U=f(M),W=f(I),G=f(R),N=f(C)/k||0,Q=Math.round(k/D),X=1e3/k||0,F=4,H=12,V=60,q=34,Y=10,K=69;d.fillStyle="#0e0f19",d.fillRect(0,50,H*5+V*6+22,q),e.status(d,Y,K,V,F,w.length,Math.round(X)+" fps",X/e._goodFps,function(z){return w[z]/k-1}),e.status(d,Y+H+V,K,V,F,M.length,D.toFixed(2)+" dt",e._goodDelta/D,function(z){return M[z]/U-1}),e.status(d,Y+(H+V)*2,K,V,F,I.length,L+" upf",Math.pow(r.clamp(W/Q||1,0,1),4),function(z){return I[z]/W-1}),e.status(d,Y+(H+V)*3,K,V,F,R.length,G.toFixed(2)+" ut",1-L*G/e._goodFps,function(z){return R[z]/G-1}),e.status(d,Y+(H+V)*4,K,V,F,S.length,b.toFixed(2)+" rt",1-b/e._goodFps,function(z){return S[z]/b-1}),e.status(d,Y+(H+V)*5,K,V,F,C.length,N.toFixed(2)+" x",N*N*N,function(z){return(C[z]/w[z]/N||0)-1})},e.status=function(g,d,y,v,w,S,C,M,I){g.strokeStyle="#888",g.fillStyle="#444",g.lineWidth=1,g.fillRect(d,y+7,v,1),g.beginPath(),g.moveTo(d,y+7-w*r.clamp(.4*I(0),-2,2));for(var R=0;R<v;R+=1)g.lineTo(d+R,y+7-(R<S?w*r.clamp(.4*I(R),-2,2):0));g.stroke(),g.fillStyle="hsl("+r.clamp(25+95*M,0,120)+",100%,60%)",g.fillRect(d,y-7,4,4),g.font="12px Arial",g.textBaseline="middle",g.textAlign="right",g.fillStyle="#eee",g.fillText(C,d+v,y-5)},e.constraints=function(g,d){for(var y=d,v=0;v<g.length;v++){var w=g[v];if(!(!w.render.visible||!w.pointA||!w.pointB)){var S=w.bodyA,C=w.bodyB,M,I;if(S?M=h.add(S.position,w.pointA):M=w.pointA,w.render.type==="pin")y.beginPath(),y.arc(M.x,M.y,3,0,2*Math.PI),y.closePath();else{if(C?I=h.add(C.position,w.pointB):I=w.pointB,y.beginPath(),y.moveTo(M.x,M.y),w.render.type==="spring")for(var R=h.sub(I,M),L=h.perp(h.normalise(R)),D=Math.ceil(r.clamp(w.length/5,12,20)),k,b=1;b<D;b+=1)k=b%2===0?1:-1,y.lineTo(M.x+R.x*(b/D)+L.x*k*4,M.y+R.y*(b/D)+L.y*k*4);y.lineTo(I.x,I.y)}w.render.lineWidth&&(y.lineWidth=w.render.lineWidth,y.strokeStyle=w.render.strokeStyle,y.stroke()),w.render.anchors&&(y.fillStyle=w.render.strokeStyle,y.beginPath(),y.arc(M.x,M.y,3,0,2*Math.PI),y.arc(I.x,I.y,3,0,2*Math.PI),y.closePath(),y.fill())}}},e.bodies=function(g,d,y){var v=y;g.engine;var w=g.options,S=w.showInternalEdges||!w.wireframes,C,M,I,R;for(I=0;I<d.length;I++)if(C=d[I],!!C.render.visible){for(R=C.parts.length>1?1:0;R<C.parts.length;R++)if(M=C.parts[R],!!M.render.visible){if(w.showSleeping&&C.isSleeping?v.globalAlpha=.5*M.render.opacity:M.render.opacity!==1&&(v.globalAlpha=M.render.opacity),M.render.sprite&&M.render.sprite.texture&&!w.wireframes){var L=M.render.sprite,D=P(g,L.texture);v.translate(M.position.x,M.position.y),v.rotate(M.angle),v.drawImage(D,D.width*-L.xOffset*L.xScale,D.height*-L.yOffset*L.yScale,D.width*L.xScale,D.height*L.yScale),v.rotate(-M.angle),v.translate(-M.position.x,-M.position.y)}else{if(M.circleRadius)v.beginPath(),v.arc(M.position.x,M.position.y,M.circleRadius,0,2*Math.PI);else{v.beginPath(),v.moveTo(M.vertices[0].x,M.vertices[0].y);for(var k=1;k<M.vertices.length;k++)!M.vertices[k-1].isInternal||S?v.lineTo(M.vertices[k].x,M.vertices[k].y):v.moveTo(M.vertices[k].x,M.vertices[k].y),M.vertices[k].isInternal&&!S&&v.moveTo(M.vertices[(k+1)%M.vertices.length].x,M.vertices[(k+1)%M.vertices.length].y);v.lineTo(M.vertices[0].x,M.vertices[0].y),v.closePath()}w.wireframes?(v.lineWidth=1,v.strokeStyle=g.options.wireframeStrokeStyle,v.stroke()):(v.fillStyle=M.render.fillStyle,M.render.lineWidth&&(v.lineWidth=M.render.lineWidth,v.strokeStyle=M.render.strokeStyle,v.stroke()),v.fill())}v.globalAlpha=1}}},e.bodyWireframes=function(g,d,y){var v=y,w=g.options.showInternalEdges,S,C,M,I,R;for(v.beginPath(),M=0;M<d.length;M++)if(S=d[M],!!S.render.visible)for(R=S.parts.length>1?1:0;R<S.parts.length;R++){for(C=S.parts[R],v.moveTo(C.vertices[0].x,C.vertices[0].y),I=1;I<C.vertices.length;I++)!C.vertices[I-1].isInternal||w?v.lineTo(C.vertices[I].x,C.vertices[I].y):v.moveTo(C.vertices[I].x,C.vertices[I].y),C.vertices[I].isInternal&&!w&&v.moveTo(C.vertices[(I+1)%C.vertices.length].x,C.vertices[(I+1)%C.vertices.length].y);v.lineTo(C.vertices[0].x,C.vertices[0].y)}v.lineWidth=1,v.strokeStyle=g.options.wireframeStrokeStyle,v.stroke()},e.bodyConvexHulls=function(g,d,y){var v=y,w,S,C;for(v.beginPath(),S=0;S<d.length;S++)if(w=d[S],!(!w.render.visible||w.parts.length===1)){for(v.moveTo(w.vertices[0].x,w.vertices[0].y),C=1;C<w.vertices.length;C++)v.lineTo(w.vertices[C].x,w.vertices[C].y);v.lineTo(w.vertices[0].x,w.vertices[0].y)}v.lineWidth=1,v.strokeStyle="rgba(255,255,255,0.2)",v.stroke()},e.vertexNumbers=function(g,d,y){var v=y,w,S,C;for(w=0;w<d.length;w++){var M=d[w].parts;for(C=M.length>1?1:0;C<M.length;C++){var I=M[C];for(S=0;S<I.vertices.length;S++)v.fillStyle="rgba(255,255,255,0.2)",v.fillText(w+"_"+S,I.position.x+(I.vertices[S].x-I.position.x)*.8,I.position.y+(I.vertices[S].y-I.position.y)*.8)}}},e.mousePosition=function(g,d,y){var v=y;v.fillStyle="rgba(255,255,255,0.8)",v.fillText(d.position.x+" "+d.position.y,d.position.x+5,d.position.y-5)},e.bodyBounds=function(g,d,y){var v=y;g.engine;var w=g.options;v.beginPath();for(var S=0;S<d.length;S++)if(d[S].render.visible)for(var C=d[S].parts,M=C.length>1?1:0;M<C.length;M++){var I=C[M];v.rect(I.bounds.min.x,I.bounds.min.y,I.bounds.max.x-I.bounds.min.x,I.bounds.max.y-I.bounds.min.y)}w.wireframes?v.strokeStyle="rgba(255,255,255,0.08)":v.strokeStyle="rgba(0,0,0,0.1)",v.lineWidth=1,v.stroke()},e.bodyAxes=function(g,d,y){var v=y;g.engine;var w=g.options,S,C,M,I;for(v.beginPath(),C=0;C<d.length;C++){var R=d[C],L=R.parts;if(R.render.visible)if(w.showAxes)for(M=L.length>1?1:0;M<L.length;M++)for(S=L[M],I=0;I<S.axes.length;I++){var D=S.axes[I];v.moveTo(S.position.x,S.position.y),v.lineTo(S.position.x+D.x*20,S.position.y+D.y*20)}else for(M=L.length>1?1:0;M<L.length;M++)for(S=L[M],I=0;I<S.axes.length;I++)v.moveTo(S.position.x,S.position.y),v.lineTo((S.vertices[0].x+S.vertices[S.vertices.length-1].x)/2,(S.vertices[0].y+S.vertices[S.vertices.length-1].y)/2)}w.wireframes?(v.strokeStyle="indianred",v.lineWidth=1):(v.strokeStyle="rgba(255, 255, 255, 0.4)",v.globalCompositeOperation="overlay",v.lineWidth=2),v.stroke(),v.globalCompositeOperation="source-over"},e.bodyPositions=function(g,d,y){var v=y;g.engine;var w=g.options,S,C,M,I;for(v.beginPath(),M=0;M<d.length;M++)if(S=d[M],!!S.render.visible)for(I=0;I<S.parts.length;I++)C=S.parts[I],v.arc(C.position.x,C.position.y,3,0,2*Math.PI,!1),v.closePath();for(w.wireframes?v.fillStyle="indianred":v.fillStyle="rgba(0,0,0,0.5)",v.fill(),v.beginPath(),M=0;M<d.length;M++)S=d[M],S.render.visible&&(v.arc(S.positionPrev.x,S.positionPrev.y,2,0,2*Math.PI,!1),v.closePath());v.fillStyle="rgba(255,165,0,0.8)",v.fill()},e.bodyVelocity=function(g,d,y){var v=y;v.beginPath();for(var w=0;w<d.length;w++){var S=d[w];if(S.render.visible){var C=o.getVelocity(S);v.moveTo(S.position.x,S.position.y),v.lineTo(S.position.x+C.x,S.position.y+C.y)}}v.lineWidth=3,v.strokeStyle="cornflowerblue",v.stroke()},e.bodyIds=function(g,d,y){var v=y,w,S;for(w=0;w<d.length;w++)if(d[w].render.visible){var C=d[w].parts;for(S=C.length>1?1:0;S<C.length;S++){var M=C[S];v.font="12px Arial",v.fillStyle="rgba(255,255,255,0.5)",v.fillText(M.id,M.position.x+10,M.position.y-10)}}},e.collisions=function(g,d,y){var v=y,w=g.options,S,C,M,I;for(v.beginPath(),M=0;M<d.length;M++)if(S=d[M],!!S.isActive)for(C=S.collision,I=0;I<S.contactCount;I++){var R=S.contacts[I].vertex;v.rect(R.x-1.5,R.y-1.5,3.5,3.5)}for(w.wireframes?v.fillStyle="rgba(255,255,255,0.7)":v.fillStyle="orange",v.fill(),v.beginPath(),M=0;M<d.length;M++)if(S=d[M],!!S.isActive&&(C=S.collision,S.contactCount>0)){var L=S.contacts[0].vertex.x,D=S.contacts[0].vertex.y;S.contactCount===2&&(L=(S.contacts[0].vertex.x+S.contacts[1].vertex.x)/2,D=(S.contacts[0].vertex.y+S.contacts[1].vertex.y)/2),C.bodyB===C.supports[0].body||C.bodyA.isStatic===!0?v.moveTo(L-C.normal.x*8,D-C.normal.y*8):v.moveTo(L+C.normal.x*8,D+C.normal.y*8),v.lineTo(L,D)}w.wireframes?v.strokeStyle="rgba(255,165,0,0.7)":v.strokeStyle="orange",v.lineWidth=1,v.stroke()},e.separations=function(g,d,y){var v=y,w=g.options,S,C,M,I,R;for(v.beginPath(),R=0;R<d.length;R++)if(S=d[R],!!S.isActive){C=S.collision,M=C.bodyA,I=C.bodyB;var L=1;!I.isStatic&&!M.isStatic&&(L=.5),I.isStatic&&(L=0),v.moveTo(I.position.x,I.position.y),v.lineTo(I.position.x-C.penetration.x*L,I.position.y-C.penetration.y*L),L=1,!I.isStatic&&!M.isStatic&&(L=.5),M.isStatic&&(L=0),v.moveTo(M.position.x,M.position.y),v.lineTo(M.position.x+C.penetration.x*L,M.position.y+C.penetration.y*L)}w.wireframes?v.strokeStyle="rgba(255,165,0,0.5)":v.strokeStyle="orange",v.stroke()},e.inspector=function(g,d){g.engine;var y=g.selected,v=g.render,w=v.options,S;if(w.hasBounds){var C=v.bounds.max.x-v.bounds.min.x,M=v.bounds.max.y-v.bounds.min.y,I=C/v.options.width,R=M/v.options.height;d.scale(1/I,1/R),d.translate(-v.bounds.min.x,-v.bounds.min.y)}for(var L=0;L<y.length;L++){var D=y[L].data;switch(d.translate(.5,.5),d.lineWidth=1,d.strokeStyle="rgba(255,165,0,0.9)",d.setLineDash([1,2]),D.type){case"body":S=D.bounds,d.beginPath(),d.rect(Math.floor(S.min.x-3),Math.floor(S.min.y-3),Math.floor(S.max.x-S.min.x+6),Math.floor(S.max.y-S.min.y+6)),d.closePath(),d.stroke();break;case"constraint":var k=D.pointA;D.bodyA&&(k=D.pointB),d.beginPath(),d.arc(k.x,k.y,10,0,2*Math.PI),d.closePath(),d.stroke();break}d.setLineDash([]),d.translate(-.5,-.5)}g.selectStart!==null&&(d.translate(.5,.5),d.lineWidth=1,d.strokeStyle="rgba(255,165,0,0.6)",d.fillStyle="rgba(255,165,0,0.1)",S=g.selectBounds,d.beginPath(),d.rect(Math.floor(S.min.x),Math.floor(S.min.y),Math.floor(S.max.x-S.min.x),Math.floor(S.max.y-S.min.y)),d.closePath(),d.stroke(),d.fill(),d.translate(-.5,-.5)),w.hasBounds&&d.setTransform(1,0,0,1,0,0)};var s=function(g,d){var y=g.engine,v=g.timing,w=v.historySize,S=y.timing.timestamp;v.delta=d-v.lastTime||e._goodDelta,v.lastTime=d,v.timestampElapsed=S-v.lastTimestamp||0,v.lastTimestamp=S,v.deltaHistory.unshift(v.delta),v.deltaHistory.length=Math.min(v.deltaHistory.length,w),v.engineDeltaHistory.unshift(y.timing.lastDelta),v.engineDeltaHistory.length=Math.min(v.engineDeltaHistory.length,w),v.timestampElapsedHistory.unshift(v.timestampElapsed),v.timestampElapsedHistory.length=Math.min(v.timestampElapsedHistory.length,w),v.engineUpdatesHistory.unshift(y.timing.lastUpdatesPerFrame),v.engineUpdatesHistory.length=Math.min(v.engineUpdatesHistory.length,w),v.engineElapsedHistory.unshift(y.timing.lastElapsed),v.engineElapsedHistory.length=Math.min(v.engineElapsedHistory.length,w),v.elapsedHistory.unshift(v.lastElapsed),v.elapsedHistory.length=Math.min(v.elapsedHistory.length,w)},f=function(g){for(var d=0,y=0;y<g.length;y+=1)d+=g[y];return d/g.length||0},m=function(g,d){var y=document.createElement("canvas");return y.width=g,y.height=d,y.oncontextmenu=function(){return!1},y.onselectstart=function(){return!1},y},x=function(g){var d=g.getContext("2d");return(window.devicePixelRatio||1)/(d.webkitBackingStorePixelRatio||d.mozBackingStorePixelRatio||d.msBackingStorePixelRatio||d.oBackingStorePixelRatio||d.backingStorePixelRatio||1)},P=function(g,d){var y=g.textures[d];return y||(y=g.textures[d]=new Image,y.src=d,y)},T=function(g,d){var y=d;/(jpg|gif|png)$/.test(d)&&(y="url("+d+")"),g.canvas.style.background=y,g.canvas.style.backgroundSize="contain",g.currentBackground=d}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(5),r=c(17),a=c(0);(function(){e._maxFrameDelta=1e3/15,e._frameDeltaFallback=1e3/60,e._timeBufferMargin=1.5,e._elapsedNextEstimate=1,e._smoothingLowerBound=.1,e._smoothingUpperBound=.9,e.create=function(n){var h=a.extend({delta:16.666666666666668,frameDelta:null,frameDeltaSmoothing:!0,frameDeltaSnapping:!0,frameDeltaHistory:[],frameDeltaHistorySize:100,frameRequestId:null,timeBuffer:0,timeLastTick:null,maxUpdates:null,maxFrameTime:33.333333333333336,lastUpdatesDeferred:0,enabled:!0},n);return h.fps=0,h},e.run=function(n,h){return n.timeBuffer=e._frameDeltaFallback,(function l(t){n.frameRequestId=e._onNextFrame(n,l),t&&n.enabled&&e.tick(n,h,t)})(),n},e.tick=function(n,h,l){var t=a.now(),i=n.delta,s=0,f=l-n.timeLastTick;if((!f||!n.timeLastTick||f>Math.max(e._maxFrameDelta,n.maxFrameTime))&&(f=n.frameDelta||e._frameDeltaFallback),n.frameDeltaSmoothing){n.frameDeltaHistory.push(f),n.frameDeltaHistory=n.frameDeltaHistory.slice(-n.frameDeltaHistorySize);var m=n.frameDeltaHistory.slice(0).sort();f=u(n.frameDeltaHistory.slice(m.length*e._smoothingLowerBound,m.length*e._smoothingUpperBound))||f}n.frameDeltaSnapping&&(f=1e3/Math.round(1e3/f)),n.frameDelta=f,n.timeLastTick=l,n.timeBuffer+=n.frameDelta,n.timeBuffer=a.clamp(n.timeBuffer,0,n.frameDelta+i*e._timeBufferMargin),n.lastUpdatesDeferred=0;var x=n.maxUpdates||Math.ceil(n.maxFrameTime/i),P={timestamp:h.timing.timestamp};o.trigger(n,"beforeTick",P),o.trigger(n,"tick",P);for(var T=a.now();i>0&&n.timeBuffer>=i*e._timeBufferMargin;){o.trigger(n,"beforeUpdate",P),r.update(h,i),o.trigger(n,"afterUpdate",P),n.timeBuffer-=i,s+=1;var g=a.now()-t,d=a.now()-T,y=g+e._elapsedNextEstimate*d/s;if(s>=x||y>n.maxFrameTime){n.lastUpdatesDeferred=Math.round(Math.max(0,n.timeBuffer/i-e._timeBufferMargin));break}}h.timing.lastUpdatesPerFrame=s,o.trigger(n,"afterTick",P),n.frameDeltaHistory.length>=100&&(n.lastUpdatesDeferred&&Math.round(n.frameDelta/i)>x?a.warnOnce("Matter.Runner: runner reached runner.maxUpdates, see docs."):n.lastUpdatesDeferred&&a.warnOnce("Matter.Runner: runner reached runner.maxFrameTime, see docs."),typeof n.isFixed<"u"&&a.warnOnce("Matter.Runner: runner.isFixed is now redundant, see docs."),(n.deltaMin||n.deltaMax)&&a.warnOnce("Matter.Runner: runner.deltaMin and runner.deltaMax were removed, see docs."),n.fps!==0&&a.warnOnce("Matter.Runner: runner.fps was replaced by runner.delta, see docs."))},e.stop=function(n){e._cancelNextFrame(n)},e._onNextFrame=function(n,h){if(typeof window<"u"&&window.requestAnimationFrame)n.frameRequestId=window.requestAnimationFrame(h);else throw new Error("Matter.Runner: missing required global window.requestAnimationFrame.");return n.frameRequestId},e._cancelNextFrame=function(n){if(typeof window<"u"&&window.cancelAnimationFrame)window.cancelAnimationFrame(n.frameRequestId);else throw new Error("Matter.Runner: missing required global window.cancelAnimationFrame.")};var u=function(n){for(var h=0,l=n.length,t=0;t<l;t+=1)h+=n[t];return h/l||0}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(8),r=c(0).deprecated;(function(){e.collides=function(a,u){return o.collides(a,u)},r(e,"collides","SAT.collides ➤ replaced by Collision.collides")})()}),(function(A,E,c){var e={};A.exports=e,c(1);var o=c(0);(function(){e.pathToVertices=function(r,a){typeof window<"u"&&!("SVGPathSeg"in window)&&o.warn("Svg.pathToVertices: SVGPathSeg not defined, a polyfill is required.");var u,n,h,l,t,i,s,f,m,x,P=[],T,g,d=0,y=0,v=0;a=a||15;var w=function(C,M,I){var R=I%2===1&&I>1;if(!m||C!=m.x||M!=m.y){m&&R?(T=m.x,g=m.y):(T=0,g=0);var L={x:T+C,y:g+M};(R||!m)&&(m=L),P.push(L),y=T+C,v=g+M}},S=function(C){var M=C.pathSegTypeAsLetter.toUpperCase();if(M!=="Z"){switch(M){case"M":case"L":case"T":case"C":case"S":case"Q":y=C.x,v=C.y;break;case"H":y=C.x;break;case"V":v=C.y;break}w(y,v,C.pathSegType)}};for(e._svgPathToAbsolute(r),h=r.getTotalLength(),i=[],u=0;u<r.pathSegList.numberOfItems;u+=1)i.push(r.pathSegList.getItem(u));for(s=i.concat();d<h;){if(x=r.getPathSegAtLength(d),t=i[x],t!=f){for(;s.length&&s[0]!=t;)S(s.shift());f=t}switch(t.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":l=r.getPointAtLength(d),w(l.x,l.y,0);break}d+=a}for(u=0,n=s.length;u<n;++u)S(s[u]);return P},e._svgPathToAbsolute=function(r){for(var a,u,n,h,l,t,i=r.pathSegList,s=0,f=0,m=i.numberOfItems,x=0;x<m;++x){var P=i.getItem(x),T=P.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(T))"x"in P&&(s=P.x),"y"in P&&(f=P.y);else switch("x1"in P&&(n=s+P.x1),"x2"in P&&(l=s+P.x2),"y1"in P&&(h=f+P.y1),"y2"in P&&(t=f+P.y2),"x"in P&&(s+=P.x),"y"in P&&(f+=P.y),T){case"m":i.replaceItem(r.createSVGPathSegMovetoAbs(s,f),x);break;case"l":i.replaceItem(r.createSVGPathSegLinetoAbs(s,f),x);break;case"h":i.replaceItem(r.createSVGPathSegLinetoHorizontalAbs(s),x);break;case"v":i.replaceItem(r.createSVGPathSegLinetoVerticalAbs(f),x);break;case"c":i.replaceItem(r.createSVGPathSegCurvetoCubicAbs(s,f,n,h,l,t),x);break;case"s":i.replaceItem(r.createSVGPathSegCurvetoCubicSmoothAbs(s,f,l,t),x);break;case"q":i.replaceItem(r.createSVGPathSegCurvetoQuadraticAbs(s,f,n,h),x);break;case"t":i.replaceItem(r.createSVGPathSegCurvetoQuadraticSmoothAbs(s,f),x);break;case"a":i.replaceItem(r.createSVGPathSegArcAbs(s,f,P.r1,P.r2,P.angle,P.largeArcFlag,P.sweepFlag),x);break;case"z":case"Z":s=a,f=u;break}(T=="M"||T=="m")&&(a=s,u=f)}}})()}),(function(A,E,c){var e={};A.exports=e;var o=c(6);c(0),(function(){e.create=o.create,e.add=o.add,e.remove=o.remove,e.clear=o.clear,e.addComposite=o.addComposite,e.addBody=o.addBody,e.addConstraint=o.addConstraint})()})])})})),O=Re();function ke(p,B,A){return p<B?B:p>A?A:p}function J(p){const B=p.plugin.ballId;return typeof B=="number"?B:p.id}function De(p,B,A,E){return ke(Math.floor((p-B)/A),0,E-1)}var be=.18,Fe=.12,Oe=420,Ue=.12,We=180,Ne=2,Ve=5,He=600,Ge=2,ze=25e3,Xe=.15;function ue(p,B){return{x:p,y:B,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:B,anchorAgeMs:0,aliveMs:0}}var Ye=class{tracker=new Map;track(p,B,A){this.tracker.set(p,ue(B,A))}untrack(p){this.tracker.delete(p)}clear(){this.tracker.clear()}process(p,B,A){const E=[],c=new Set,e=[];for(const o of B){const r=J(o);c.add(r);const a=this.tracker.get(r)??ue(o.position.x,o.position.y),u=a.aliveMs+p;if(u>=ze||a.kickCount>=Ve){E.push(o),this.tracker.delete(r);continue}const n=o.position.x-a.x,h=o.position.y-a.y,l=Math.sqrt(n*n+h*h),t=o.velocity,i=Math.sqrt(t.x*t.x+t.y*t.y),s=o.position.y>A.worldHeight*Ue;let f=a.anchorY,m=a.anchorAgeMs+p;o.position.y>f+Ge&&(f=o.position.y,m=0);const x=s&&(i<be&&l<Fe||m>He)?a.stuckMs+p:Math.max(0,a.stuckMs-p*2),P=Math.max(0,a.kickCooldownMs-p);this.tracker.set(r,{x:o.position.x,y:o.position.y,stuckMs:x,kickCooldownMs:P,kickCount:a.kickCount,anchorY:f,anchorAgeMs:m,aliveMs:u}),x>=Oe&&P<=0&&e.push({ball:o,id:r,stuckMs:x})}this.applyKicks(e,A);for(const o of this.tracker.keys())c.has(o)||this.tracker.delete(o);return E}applyKicks(p,B){if(p.length===0)return;p.sort((E,c)=>Math.abs(c.ball.position.y-E.ball.position.y)>.1?c.ball.position.y-E.ball.position.y:c.stuckMs-E.stuckMs);const A=Math.min(Ne,p.length);for(let E=0;E<A;E++){const{ball:c,id:e}=p[E],o=this.tracker.get(e);if(!o)continue;const r=c.velocity,a=Math.abs(c.position.x-B.center)/B.halfWidth<Xe?Math.random()<.5?1:-1:c.position.x<B.center?1:-1,u=a*(.35+Math.random()*.35)+(Math.random()-.5)*.25,n=1.1+Math.random()*.5;O.Body.setVelocity(c,{x:r.x+u,y:Math.max(r.y+n,n)}),O.Body.translate(c,{x:a*(.2+Math.random()*.4),y:.25+Math.random()*.35}),this.tracker.set(e,{...o,x:c.position.x,y:c.position.y,stuckMs:0,kickCooldownMs:We,kickCount:o.kickCount+1})}}};function Ke(p){const B=Math.max(0,Math.min(1,p)),A=B**1.3;return{windStrength:A*4e-7,collisionNudge:A*.13,spawnSigmaRatio:B>0?.04-A*.035:0}}var $e=.4;function Qe(p,B,A){if(!(A<=0))for(const E of p){if(Math.sqrt(E.velocity.x*E.velocity.x+E.velocity.y*E.velocity.y)<$e)continue;const c=E.position.x-B;O.Body.applyForce(E,E.position,{x:-A*c,y:0})}}var _="plinkit-ball";function Ze(){const p=Math.random(),B=Math.random();return Math.sqrt(-2*Math.log(p||1e-15))*Math.cos(2*Math.PI*B)}function Je(p,B){const A=Math.max(p.radius+8,p.height*.06);let E;return B&&B>0?E=Ze()*p.width*B:E=(Math.random()-.5)*p.width*.08,O.Bodies.circle(p.width*.5+E,A,p.radius,{label:_,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var ee="plinkit-peg",te="plinkit-guide",re="plinkit-wall",je=.22,qe=4,_e=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new Ye;dist;removeCollisionNudge=null;removeCollisionStart=null;constructor(p){this.engine=O.Engine.create({gravity:{x:0,y:p.gravityY,scale:.001}}),this.config=p,this.dist=Ke(p.houseEdge??0),this.rebuildStaticBodies(p.width,p.height);const B=this.dist.collisionNudge;if(B>0){const A=E=>{const c=this.center,e=this.config.width*.5;for(const o of E.pairs){const r=o.bodyA.label==="plinkit-ball"?o.bodyA:o.bodyB.label==="plinkit-ball"?o.bodyB:null;if(!r||r.plugin.settled||!(o.bodyA.label===ee||o.bodyB.label===ee||o.bodyA.label===te||o.bodyB.label===te))continue;const a=(r.position.x-c)/e;O.Body.setVelocity(r,{x:r.velocity.x-B*a,y:r.velocity.y})}};O.Events.on(this.engine,"collisionEnd",A),this.removeCollisionNudge=()=>O.Events.off(this.engine,"collisionEnd",A)}if(p.onCollision){const A=p.onCollision,E=c=>{for(const e of c.pairs){const o=e.bodyA.label==="plinkit-ball"?e.bodyA:e.bodyB.label==="plinkit-ball"?e.bodyB:null;if(!o||o.plugin.settled)continue;const r=e.bodyA===o?e.bodyB.label:e.bodyA.label;let a=null;if(r===ee?a="peg":r===te&&(a="guide"),!a)continue;const u=Math.hypot(o.velocity.x,o.velocity.y);A({ballId:J(o),target:a,speed:u})}};O.Events.on(this.engine,"collisionStart",E),this.removeCollisionStart=()=>O.Events.off(this.engine,"collisionStart",E)}}resize(p,B){this.config={...this.config,width:p,height:B},this.rebuildStaticBodies(p,B)}setBallCost(p){this.config={...this.config,ballCost:p}}spawnBall(){const p=Je({width:this.config.width,height:this.config.height,radius:this.config.ballRadius},this.dist.spawnSigmaRatio);p.plugin.ballId=this.nextBallId,p.plugin.wager=this.config.ballCost,this.nextBallId+=1,this.antiStuck.track(J(p),p.position.x,p.position.y),O.World.add(this.engine.world,p)}canSpawnBall(){const p=this.config.height*je;let B=0;const A=O.Composite.allBodies(this.engine.world).filter(E=>E.label===_);for(const E of A)if(!E.plugin.settled&&E.position.y<=p&&(B+=1,B>=qe))return!1;return!0}step(p){O.Engine.update(this.engine,p);const B=O.Composite.allBodies(this.engine.world).filter(e=>e.label===_),A=B.filter(e=>!e.plugin.settled);Qe(A,this.center,this.dist.windStrength);const E=this.antiStuck.process(p,A,{center:this.center,halfWidth:this.config.width*.5,worldHeight:this.config.height}).map(e=>this.settleBall(e)),c=this.cleanupBalls(B);return E.length>0?[...E,...c]:c}snapshot(){const p=this.config.layout.mainPegs.radius;return{pegs:this.pegs.map(B=>({x:B.position.x,y:B.position.y,radius:B.circleRadius??p})),guidePegs:this.guidePegs.map(B=>({x:B.position.x,y:B.position.y,radius:B.circleRadius??p})),balls:O.Composite.allBodies(this.engine.world).filter(B=>B.label===_).map(B=>({id:J(B),x:B.position.x,y:B.position.y,radius:B.circleRadius??this.config.ballRadius})),walls:this.getWallRects(),buckets:this.buckets}}destroy(){this.removeCollisionNudge?.(),this.removeCollisionStart?.(),O.World.clear(this.engine.world,!1),O.Engine.clear(this.engine)}cleanupBalls(p){const B=[],A=this.config.height+this.config.ballRadius,E=this.getBucketTop();for(const c of p){if(c.position.y>A){this.antiStuck.untrack(J(c)),O.World.remove(this.engine.world,c);continue}if(!c.plugin.settled&&c.position.y>=E){B.push(this.settleBall(c));continue}const e=c.circleRadius??this.config.ballRadius,o=this.config.height-e-1;!c.plugin.settled&&c.position.y>=o&&B.push(this.settleBall(c))}return B}rebuildStaticBodies(p,B){this.antiStuck.clear(),this.pegs.length>0&&(O.World.remove(this.engine.world,this.pegs),this.pegs=[]),this.guidePegs.length>0&&(O.World.remove(this.engine.world,this.guidePegs),this.guidePegs=[]),this.walls&&(O.World.remove(this.engine.world,[this.walls.leftWall,this.walls.rightWall,this.walls.floor]),this.walls=null),this.center=p*.5;const A=Math.max(18,p*.02),E=p/this.config.multipliers.length,c=this.config.layout.mainPegs,e=we({...c,width:p,height:B});this.layoutGeometry=e;const o=c.radius,r=this.config.layout.edgeGuides.radius;this.pegs=Pe(e,o).map(t=>O.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:ee,restitution:.3})),this.pegBaseY=this.pegs.reduce((t,i)=>Math.max(t,i.position.y),0);const a=this.getBucketTop(),u=O.Bodies.rectangle(-A*.5,B*.5,A,B*2,{isStatic:!0,label:re,restitution:.4}),n=O.Bodies.rectangle(p+A*.5,B*.5,A,B*2,{isStatic:!0,label:re,restitution:.4}),h=O.Bodies.rectangle(p*.5,B+A*.5,p,A,{isStatic:!0,isSensor:!0,label:re});this.walls={leftWall:u,rightWall:n,floor:h},O.World.add(this.engine.world,[u,n,h]),this.guidePegs=Ce(e,r,{spread:this.config.layout.edgeGuides.spread,yOffset:this.config.layout.edgeGuides.yOffset}).map(t=>O.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:te,restitution:.3})),O.World.add(this.engine.world,this.pegs),O.World.add(this.engine.world,this.guidePegs);const l=B-a;this.buckets=this.config.multipliers.map((t,i)=>({index:i,multiplier:t,x:E*i,y:a,width:E,height:l}))}getWallRects(){return this.walls?[this.walls.leftWall,this.walls.rightWall,this.walls.floor].map(p=>({x:p.position.x,y:p.position.y,width:p.bounds.max.x-p.bounds.min.x,height:p.bounds.max.y-p.bounds.min.y})):[]}getBucketTop(){const p=this.config.layout.mainPegs.radius+this.config.ballRadius-1;return this.pegBaseY>0?Math.min(this.config.height-6,this.pegBaseY+p):this.config.height*.85}settleBall(p){p.plugin.settled=!0,O.Body.set(p,"isSensor",!0);const B=this.layoutGeometry,A=this.config.layout.mainPegs,E=B?.sidePadding??A.radius+A.sidePaddingPx,c=B?.baseSpacing??(this.config.width-E*2)/Math.max(A.bottomPegCount-1,1),e=De(p.position.x,E,c,this.config.multipliers.length),o=this.config.multipliers[e]??0,r=typeof p.plugin.wager=="number"?p.plugin.wager:this.config.ballCost;return{ballId:J(p),bucketIndex:e,multiplier:o,wager:r,payout:r*o}}},et=`
|
|
2
2
|
precision highp float;
|
|
3
3
|
in vec2 a_position;
|
|
4
4
|
uniform vec2 u_resolution;
|
|
@@ -14,7 +14,7 @@ void main() {
|
|
|
14
14
|
v_local = a_position;
|
|
15
15
|
v_uv = a_position * 0.5 + 0.5;
|
|
16
16
|
}
|
|
17
|
-
`,
|
|
17
|
+
`,tt=`
|
|
18
18
|
precision highp float;
|
|
19
19
|
uniform vec4 u_color;
|
|
20
20
|
uniform float u_shapeMode;
|
|
@@ -41,5 +41,5 @@ void main() {
|
|
|
41
41
|
outColor = vec4(u_color.rgb, u_color.a * a);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
`,
|
|
45
|
-
${
|
|
44
|
+
`,it=class{canvas;gl;program;positionBuffer;positionLocation;resolutionLocation;centerLocation;sizeLocation;colorLocation;shapeModeLocation;useTextureLocation;textureLocation;scale=1;destroyed=!1;pegTexture=null;ballTexture=null;pegTextureReady=!1;ballTextureReady=!1;constructor(p,B){this.canvas=p;const A=p.getContext("webgl2",{antialias:!0,alpha:!0});if(!A)throw new Error("WebGL2 is not supported by this browser");this.gl=A;const E=he(this.gl,this.gl.VERTEX_SHADER,et),c=he(this.gl,this.gl.FRAGMENT_SHADER,tt);this.program=at(this.gl,E,c);const e=this.gl.getAttribLocation(this.program,"a_position"),o=this.gl.getUniformLocation(this.program,"u_resolution"),r=this.gl.getUniformLocation(this.program,"u_center"),a=this.gl.getUniformLocation(this.program,"u_size"),u=this.gl.getUniformLocation(this.program,"u_color"),n=this.gl.getUniformLocation(this.program,"u_shapeMode"),h=this.gl.getUniformLocation(this.program,"u_useTexture"),l=this.gl.getUniformLocation(this.program,"u_texture");if(e<0||!o||!r||!a||!u||!n||!h||!l)throw new Error("Unable to initialize WebGL program locations");this.positionLocation=e,this.resolutionLocation=o,this.centerLocation=r,this.sizeLocation=a,this.colorLocation=u,this.shapeModeLocation=n,this.useTextureLocation=h,this.textureLocation=l,this.gl.useProgram(this.program),this.gl.uniform1i(this.textureLocation,0);const t=this.gl.createBuffer();if(!t)throw new Error("Unable to create WebGL buffer");this.positionBuffer=t,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),this.gl.STATIC_DRAW),this.gl.enable(this.gl.BLEND),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA);const i=B?.appearance;i?.pegTextureUrl&&this.startTextureLoad(i.pegTextureUrl,i.textureCrossOrigin,"peg"),i?.ballTextureUrl&&this.startTextureLoad(i.ballTextureUrl,i.textureCrossOrigin,"ball")}resize(p,B,A,E=1){this.scale=A*E,this.canvas.width=Math.floor(p*A),this.canvas.height=Math.floor(B*A),this.gl.viewport(0,0,this.canvas.width,this.canvas.height)}render(p){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionLocation),this.gl.vertexAttribPointer(this.positionLocation,2,this.gl.FLOAT,!1,0,0),this.gl.uniform2f(this.resolutionLocation,this.canvas.width,this.canvas.height),this.gl.uniform1i(this.textureLocation,0);for(const B of p.walls)this.drawRect(B,ie(54,68,102));for(const B of p.pegs)this.drawCircle(B.x,B.y,B.radius,ie(141,226,255),"peg");for(const B of p.guidePegs)this.drawCircle(B.x,B.y,B.radius,ie(255,90,120),"peg");for(const B of p.balls)this.drawCircle(B.x,B.y,B.radius,ie(250,201,95),"ball")}destroy(){this.destroyed=!0,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.pegTexture&&(this.gl.deleteTexture(this.pegTexture),this.pegTexture=null),this.ballTexture&&(this.gl.deleteTexture(this.ballTexture),this.ballTexture=null),this.pegTextureReady=!1,this.ballTextureReady=!1,this.gl.deleteBuffer(this.positionBuffer),this.gl.deleteProgram(this.program)}startTextureLoad(p,B,A){st(p,B).then(E=>{if(this.destroyed)return;const c=nt(this.gl,E);if(this.destroyed){this.gl.deleteTexture(c);return}A==="peg"?(this.pegTexture&&this.gl.deleteTexture(this.pegTexture),this.pegTexture=c,this.pegTextureReady=!0):(this.ballTexture&&this.gl.deleteTexture(this.ballTexture),this.ballTexture=c,this.ballTextureReady=!0)}).catch(()=>{})}drawRect(p,B){this.gl.uniform2f(this.centerLocation,p.x*this.scale,p.y*this.scale),this.gl.uniform2f(this.sizeLocation,p.width*this.scale*.5,p.height*this.scale*.5),this.gl.uniform4f(this.colorLocation,B.r,B.g,B.b,B.a),this.gl.uniform1f(this.shapeModeLocation,0),this.gl.uniform1f(this.useTextureLocation,0),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}drawCircle(p,B,A,E,c){this.gl.uniform2f(this.centerLocation,p*this.scale,B*this.scale),this.gl.uniform2f(this.sizeLocation,A*this.scale,A*this.scale),this.gl.uniform4f(this.colorLocation,E.r,E.g,E.b,E.a),this.gl.uniform1f(this.shapeModeLocation,1);const e=c==="peg"?this.pegTexture:this.ballTexture,o=c==="peg"?this.pegTextureReady:this.ballTextureReady;e&&o?(this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1f(this.useTextureLocation,1)):this.gl.uniform1f(this.useTextureLocation,0),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}};function ie(p,B,A,E=1){return{r:p/255,g:B/255,b:A/255,a:E}}function nt(p,B){const A=p.createTexture();if(!A)throw new Error("Unable to create WebGL texture");return p.bindTexture(p.TEXTURE_2D,A),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,p.RGBA,p.UNSIGNED_BYTE,B),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.LINEAR),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.LINEAR),p.bindTexture(p.TEXTURE_2D,null),A}function st(p,B){return new Promise((A,E)=>{const c=new Image;typeof B=="string"&&B.length>0&&(c.crossOrigin=B),c.onload=()=>A(c),c.onerror=()=>E(new Error(`Failed to load image: ${p}`)),c.src=p})}function he(p,B,A){const E=p.createShader(B);if(!E)throw new Error("Unable to create shader");if(p.shaderSource(E,`#version 300 es
|
|
45
|
+
${A}`),p.compileShader(E),!p.getShaderParameter(E,p.COMPILE_STATUS)){const c=p.getShaderInfoLog(E);throw p.deleteShader(E),new Error(`Shader compile error: ${c??"unknown"}`)}return E}function at(p,B,A){const E=p.createProgram();if(!E)throw new Error("Unable to create program");if(p.attachShader(E,B),p.attachShader(E,A),p.linkProgram(E),!p.getProgramParameter(E,p.LINK_STATUS)){const c=p.getProgramInfoLog(E);throw p.deleteProgram(E),new Error(`Program link error: ${c??"unknown"}`)}return p.deleteShader(B),p.deleteShader(A),E}var oe=1e3/120,rt=50,ot=8,lt=300,ft=class{canvas;viewport;renderer;world;loop;worldHeight;resizeObserver;dprQuery=null;onDprChange;width;height;accumulatorMs=0;lastFrameTime=0;callbacks;ballCost;showGuidePegs;balance;lastSpawnAtMs=-1/0;constructor(p){this.canvas=p.canvas,this.viewport=p.viewport,this.width=1,this.height=1,this.callbacks={onBalanceChange:p.onBalanceChange,onBallSettled:p.onBallSettled,onCollision:p.onCollision},this.ballCost=p.ballCost,this.showGuidePegs=p.showGuidePegs,this.balance=p.initialBalance,this.onDprChange=()=>this.listenDpr();const B=Ae({mainPegs:p.layout.mainPegs,ballRadius:p.ballRadius,heightPolicy:p.viewport.heightPolicy}),A={...p.layout,mainPegs:B.resolvedMainPegs};this.worldHeight=B.worldHeight,this.canvas.style.maxWidth="100%",this.renderer=new it(this.canvas,{appearance:p.appearance}),this.world=new _e({width:600,height:this.worldHeight,gravityY:p.gravityY,layout:A,ballRadius:p.ballRadius,multipliers:p.multipliers,ballCost:this.ballCost,houseEdge:p.houseEdge,onCollision:this.callbacks.onCollision?c=>this.handleCollision(c):void 0}),this.resize(),this.loop=new Se(c=>this.frame(c)),this.loop.start();const E=this.canvas.parentElement;if(!E)throw new Error("Canvas must have a parent element for viewport sizing");this.resizeObserver=new ResizeObserver(c=>{const e=c[0];if(!e)return;const o=e.contentBoxSize?.[0]?.inlineSize,r=o!=null&&o>0?o:E.getBoundingClientRect().width;this.syncViewport(r)}),this.resizeObserver.observe(E),this.listenDpr(),this.emitBalanceChange()}spawnBall(){const p=performance.now();return p-this.lastSpawnAtMs<lt?{ok:!1,reason:"SPAWN_COOLDOWN",state:this.getStateSnapshot()}:this.world.canSpawnBall()?this.balance<this.ballCost?{ok:!1,reason:"INSUFFICIENT_BALANCE",state:this.getStateSnapshot()}:(this.balance-=this.ballCost,this.lastSpawnAtMs=p,this.emitBalanceChange(),this.world.spawnBall(),{ok:!0,state:this.getStateSnapshot()}):{ok:!1,reason:"TOP_ZONE_LIMIT",state:this.getStateSnapshot()}}resize(){const p=this.canvas.parentElement;p&&this.syncViewport(p.getBoundingClientRect().width)}destroy(){this.loop.stop(),this.resizeObserver.disconnect(),this.dprQuery?.removeEventListener("change",this.onDprChange),this.dprQuery=null,this.world.destroy(),this.renderer.destroy()}getState(){return this.getStateSnapshot()}setBallCost(p){if(!Number.isFinite(p)||p<0)throw new TypeError(`Plinkit.setBallCost: expected a non-negative finite number, got ${p}`);this.ballCost!==p&&(this.ballCost=p,this.world.setBallCost(p),this.emitBalanceChange())}handleCollision(p){this.callbacks.onCollision?.(p,this.getStateSnapshot())}frame(p){if(this.lastFrameTime===0){this.lastFrameTime=p,this.renderSnapshot();return}const B=Math.min(rt,p-this.lastFrameTime);this.lastFrameTime=p,this.accumulatorMs+=B;let A=0;for(;this.accumulatorMs>=oe&&A<ot;){const E=this.world.step(oe);for(const c of E){this.balance+=c.payout;const e=this.getStateSnapshot();this.callbacks.onBallSettled?.(c,e),this.callbacks.onBalanceChange?.(e)}this.accumulatorMs-=oe,A+=1}this.renderSnapshot()}renderSnapshot(){const p=this.world.snapshot();this.showGuidePegs||(p.guidePegs=[]),this.renderer.render(p)}emitBalanceChange(){this.callbacks.onBalanceChange?.(this.getStateSnapshot())}syncViewport(p){const B=Be({parentWidthPx:p,viewport:this.viewport,worldHeight:this.worldHeight});this.width=Math.max(1,B.displayWidth),this.height=Math.max(1,B.displayHeight),this.canvas.style.width=`${this.width}px`,this.canvas.style.height=`${this.height}px`;const A=Math.min(window.devicePixelRatio||1,this.viewport.dprCap);this.renderer.resize(this.width,this.height,A,B.worldScale)}listenDpr(){this.dprQuery?.removeEventListener("change",this.onDprChange);const p=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);p.addEventListener("change",this.onDprChange),this.dprQuery=p,this.resize()}getStateSnapshot(){return{balance:this.balance,ballCost:this.ballCost}}};Z.Plinkit=ft});
|