plinkit 1.0.0-dev.2 → 1.0.0-dev.4
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/dist/index.cjs +1 -1
- package/dist/index.es.js +4 -4
- package/dist/plinkit.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Be=(d,E)=>()=>(E||(d((E={exports:{}}).exports,E),d=null),E.exports),Ee=35,Ae=24,Ie=.08,Le=6,Re=.85,pe=.7,ke=.16,be=.92,De=256,Ue=1e3,Fe=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=me(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=me(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<Ee||(this.lastHitByBall.set(d,A),this.maybeCleanupLastHits(A),this.activePegVoices>=Ae))return;const e=Math.max(Ie,Math.min(1,E/Le));this.playSample("peg",e,!0)}playBucketHit(){this.playSample("bucket",Re,!1)}playUiTap(){if(!(this.destroyed||this.muted)){if(this.ensureContext(),this.unlockedOnce){this.playSample("uiTap",pe,!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=be+Math.random()*ke;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",pe,!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<=De))for(const[E,T]of this.lastHitByBall)d-T>Ue&&this.lastHitByBall.delete(E)}};function me(d){return!Number.isFinite(d)||d<0?0:d>1?1:d}function ae(){}var Oe=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 Se(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 He(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=Se(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 Ve(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 Ne(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 We=-1,Ge=8;function ze(d){const{mainPegs:E,ballRadius:T,heightPolicy:A}=d;if(Ke(A),$e(E),!Number.isFinite(T)||T<=0)throw new Error("ballRadius must be greater than 0");const f=Se(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+Ge,l=E.radius+T+We,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 Xe(d){const{parentWidthPx:E,viewport:T,worldHeight:A}=d;if(Ye(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 Ke(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 Ye(d){if(!Number.isFinite(d.dprCap)||d.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function $e(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 Qe=Be(((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,F=k,H=D;for(I=1;I<s;I+=1)C=l[I].x*L+l[I].y*b,C>F?F=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=F-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 F=p[S];for(C=S+1;C<p.length;C++){var H=p[C];if(c.overlaps(F.bounds,H.bounds)){var G=F.vertices,V=H.vertices;for(M=0;M<F.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 F=S.parts[D],C=F.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,F,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,F=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,J=W.y-v.position.y,K=W.x-w.position.x,Y=W.y-w.position.y,z=F-J*G,we=H+N*G,Pe=V-Y*X,Ce=Q+K*X,ue=z-Pe,fe=we-Ce,se=S*ue+C*fe,$=M*ue+I*fe,ce=p.separation+se,re=Math.min(ce,1);re=ce<0?0:re;var he=re*L;$<-he||$>he?(P=$>0?$:-$,x=p.friction*($>0?1:-1)*l,x<-P?x=-P:x>P&&(x=P)):(x=$,P=u);var ge=N*C-J*S,de=K*C-Y*S,ve=D/(R+v.inverseInertia*ge*ge+w.inverseInertia*de*de),j=(1+p.restitution)*se*ve;if(x*=ve,se<t)U.normalImpulse=0;else{var Me=U.normalImpulse;U.normalImpulse+=j,U.normalImpulse>0&&(U.normalImpulse=0),j=U.normalImpulse-Me}if($<-i||$>i)U.tangentImpulse=0;else{var Te=U.tangentImpulse;U.tangentImpulse+=x,U.tangentImpulse<-P&&(U.tangentImpulse=-P),U.tangentImpulse>P&&(U.tangentImpulse=P),x=U.tangentImpulse-Te}var q=S*j+M*x,_=C*j+I*x;v.isStatic||v.isSleeping||(v.positionPrev.x+=q*v.inverseMass,v.positionPrev.y+=_*v.inverseMass,v.anglePrev+=(N*_-J*q)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=q*w.inverseMass,w.positionPrev.y-=_*w.inverseMass,w.anglePrev-=(K*_-Y*q)*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,F=1,H=1;D>k?H=D/k:F=k/D,g.options.hasBounds=!0,g.bounds.min.x=w.min.x,g.bounds.max.x=w.min.x+R*F,g.bounds.min.y=w.min.y,g.bounds.max.y=w.min.y+L*H,v&&(g.bounds.min.x+=R*.5-R*F*.5,g.bounds.max.x+=R*.5-R*F*.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=[],F,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(F=0;F<R.length;F++){var G=R[F];c.overlaps(G.bounds,g.bounds)&&k.push(G)}for(F=0;F<L.length;F++){var V=L[F],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 F=k[D];p.fillStyle="#aaa",p.fillText(D,R+M,L+8),p.fillStyle="#eee",p.fillText(F,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),F=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,J=34,K=10,Y=69;p.fillStyle="#0e0f19",p.fillRect(0,50,W*5+N*6+22,J),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]/F-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})()})])})})),O=Qe();function Ze(d,E,T){return d<E?E:d>T?T:d}function Z(d){const E=d.plugin.ballId;return typeof E=="number"?E:d.id}function Je(d,E,T,A){return Ze(Math.floor((d-E)/T),0,A-1)}var je=.18,qe=.12,_e=420,et=.12,tt=180,it=2,nt=5,st=600,rt=2,at=25e3,ot=.15;function xe(d,E){return{x:d,y:E,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:E,anchorAgeMs:0,aliveMs:0}}var lt=class{tracker=new Map;track(d,E,T){this.tracker.set(d,xe(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=Z(o);f.add(a);const r=this.tracker.get(a)??xe(o.position.x,o.position.y),c=r.aliveMs+d;if(c>=at||r.kickCount>=nt){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*et;let u=r.anchorY,m=r.anchorAgeMs+d;o.position.y>u+rt&&(u=o.position.y,m=0);const x=s&&(i<je&&l<qe||m>st)?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>=_e&&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(it,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<ot?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;O.Body.setVelocity(f,{x:a.x+c,y:Math.max(a.y+n,n)}),O.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:tt,kickCount:o.kickCount+1})}}};function ut(d){const E=Math.max(0,Math.min(1,d))*.5,T=E**1.5;return{windStrength:Math.min(T*8e-7,3e-7),collisionNudge:T*.1,spawnSigmaRatio:E>0?.04-T*.038:0}}var ft=.4;function ct(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)<ft)continue;const f=A.position.x-E;O.Body.applyForce(A,A.position,{x:-T*f,y:0})}}var ne="plinkit-ball";function ht(){const d=Math.random(),E=Math.random();return Math.sqrt(-2*Math.log(d||1e-15))*Math.cos(2*Math.PI*E)}function gt(d,E){const T=Math.max(d.radius+8,d.height*.06);let A;return E&&E>0?A=ht()*d.width*E:A=(Math.random()-.5)*d.width*.08,O.Bodies.circle(d.width*.5+A,T,d.radius,{label:ne,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var ee="plinkit-peg",te="plinkit-guide",oe="plinkit-wall",dt=.22,vt=4,pt=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new lt;dist;removeCollisionNudge=null;removeCollisionStart=null;constructor(d){this.engine=O.Engine.create({gravity:{x:0,y:d.gravityY,scale:.001}}),this.config=d,this.dist=ut(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;O.Body.setVelocity(a,{x:a.velocity.x-E*r,y:a.velocity.y})}};O.Events.on(this.engine,"collisionEnd",T),this.removeCollisionNudge=()=>O.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:Z(o),target:r,speed:c})}};O.Events.on(this.engine,"collisionStart",A),this.removeCollisionStart=()=>O.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=gt({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(Z(d),d.position.x,d.position.y),O.World.add(this.engine.world,d)}canSpawnBall(){const d=this.config.height*dt;let E=0;const T=O.Composite.allBodies(this.engine.world).filter(A=>A.label===ne);for(const A of T)if(!A.plugin.settled&&A.position.y<=d&&(E+=1,E>=vt))return!1;return!0}step(d){O.Engine.update(this.engine,d);const E=O.Composite.allBodies(this.engine.world).filter(e=>e.label===ne),T=E.filter(e=>!e.plugin.settled);ct(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:O.Composite.allBodies(this.engine.world).filter(E=>E.label===ne).map(E=>({id:Z(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?.(),O.World.clear(this.engine.world,!1),O.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(Z(f)),O.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&&(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=d*.5;const T=Math.max(18,d*.02),A=d/this.config.multipliers.length,f=this.config.layout.mainPegs,e=He({...f,width:d,height:E});this.layoutGeometry=e;const o=f.radius,a=this.config.layout.edgeGuides.radius;this.pegs=Ve(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 r=this.getBucketTop(),c=O.Bodies.rectangle(-T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),n=O.Bodies.rectangle(d+T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),h=O.Bodies.rectangle(d*.5,E+T*.5,d,T,{isStatic:!0,isSensor:!0,label:oe});this.walls={leftWall:c,rightWall:n,floor:h},O.World.add(this.engine.world,[c,n,h]),this.guidePegs=Ne(e,a,{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=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,O.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=Je(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:Z(d),bucketIndex:e,multiplier:o,wager:a,payout:a*o}}},mt=`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Be=(d,E)=>()=>(E||(d((E={exports:{}}).exports,E),d=null),E.exports),Ee=35,Ae=24,Ie=.08,Le=6,Re=.85,pe=.7,ke=.16,be=.92,De=256,Ue=1e3,Fe=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=me(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=me(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<Ee||(this.lastHitByBall.set(d,A),this.maybeCleanupLastHits(A),this.activePegVoices>=Ae))return;const e=Math.max(Ie,Math.min(1,E/Le));this.playSample("peg",e,!0)}playBucketHit(){this.playSample("bucket",Re,!1)}playUiTap(){if(!(this.destroyed||this.muted)){if(this.ensureContext(),this.unlockedOnce){this.playSample("uiTap",pe,!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=be+Math.random()*ke;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",pe,!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<=De))for(const[E,T]of this.lastHitByBall)d-T>Ue&&this.lastHitByBall.delete(E)}};function me(d){return!Number.isFinite(d)||d<0?0:d>1?1:d}function ae(){}var Oe=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 Se(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 He(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=Se(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 Ve(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 Ne(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 We=-1,Ge=8;function ze(d){const{mainPegs:E,ballRadius:T,heightPolicy:A}=d;if(Ke(A),$e(E),!Number.isFinite(T)||T<=0)throw new Error("ballRadius must be greater than 0");const f=Se(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+Ge,l=E.radius+T+We,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 Xe(d){const{parentWidthPx:E,viewport:T,worldHeight:A}=d;if(Ye(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 Ke(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 Ye(d){if(!Number.isFinite(d.dprCap)||d.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function $e(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 Qe=Be(((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,F=k,H=D;for(I=1;I<s;I+=1)C=l[I].x*L+l[I].y*b,C>F?F=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=F-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 F=p[S];for(C=S+1;C<p.length;C++){var H=p[C];if(c.overlaps(F.bounds,H.bounds)){var G=F.vertices,V=H.vertices;for(M=0;M<F.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 F=S.parts[D],C=F.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,F,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,F=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,J=W.y-v.position.y,K=W.x-w.position.x,Y=W.y-w.position.y,z=F-J*G,we=H+N*G,Pe=V-Y*X,Ce=Q+K*X,ue=z-Pe,fe=we-Ce,se=S*ue+C*fe,$=M*ue+I*fe,ce=p.separation+se,re=Math.min(ce,1);re=ce<0?0:re;var he=re*L;$<-he||$>he?(P=$>0?$:-$,x=p.friction*($>0?1:-1)*l,x<-P?x=-P:x>P&&(x=P)):(x=$,P=u);var ge=N*C-J*S,de=K*C-Y*S,ve=D/(R+v.inverseInertia*ge*ge+w.inverseInertia*de*de),j=(1+p.restitution)*se*ve;if(x*=ve,se<t)U.normalImpulse=0;else{var Me=U.normalImpulse;U.normalImpulse+=j,U.normalImpulse>0&&(U.normalImpulse=0),j=U.normalImpulse-Me}if($<-i||$>i)U.tangentImpulse=0;else{var Te=U.tangentImpulse;U.tangentImpulse+=x,U.tangentImpulse<-P&&(U.tangentImpulse=-P),U.tangentImpulse>P&&(U.tangentImpulse=P),x=U.tangentImpulse-Te}var q=S*j+M*x,_=C*j+I*x;v.isStatic||v.isSleeping||(v.positionPrev.x+=q*v.inverseMass,v.positionPrev.y+=_*v.inverseMass,v.anglePrev+=(N*_-J*q)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=q*w.inverseMass,w.positionPrev.y-=_*w.inverseMass,w.anglePrev-=(K*_-Y*q)*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,F=1,H=1;D>k?H=D/k:F=k/D,g.options.hasBounds=!0,g.bounds.min.x=w.min.x,g.bounds.max.x=w.min.x+R*F,g.bounds.min.y=w.min.y,g.bounds.max.y=w.min.y+L*H,v&&(g.bounds.min.x+=R*.5-R*F*.5,g.bounds.max.x+=R*.5-R*F*.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=[],F,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(F=0;F<R.length;F++){var G=R[F];c.overlaps(G.bounds,g.bounds)&&k.push(G)}for(F=0;F<L.length;F++){var V=L[F],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 F=k[D];p.fillStyle="#aaa",p.fillText(D,R+M,L+8),p.fillStyle="#eee",p.fillText(F,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),F=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,J=34,K=10,Y=69;p.fillStyle="#0e0f19",p.fillRect(0,50,W*5+N*6+22,J),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]/F-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})()})])})})),O=Qe();function Ze(d,E,T){return d<E?E:d>T?T:d}function Z(d){const E=d.plugin.ballId;return typeof E=="number"?E:d.id}function Je(d,E,T,A){return Ze(Math.floor((d-E)/T),0,A-1)}var je=.18,qe=.12,_e=420,et=.12,tt=180,it=2,nt=5,st=600,rt=2,at=25e3,ot=.15;function xe(d,E){return{x:d,y:E,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:E,anchorAgeMs:0,aliveMs:0}}var lt=class{tracker=new Map;track(d,E,T){this.tracker.set(d,xe(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=Z(o);f.add(a);const r=this.tracker.get(a)??xe(o.position.x,o.position.y),c=r.aliveMs+d;if(c>=at||r.kickCount>=nt){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*et;let u=r.anchorY,m=r.anchorAgeMs+d;o.position.y>u+rt&&(u=o.position.y,m=0);const x=s&&(i<je&&l<qe||m>st)?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>=_e&&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(it,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<ot?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;O.Body.setVelocity(f,{x:a.x+c,y:Math.max(a.y+n,n)}),O.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:tt,kickCount:o.kickCount+1})}}};function ut(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 ft=.4;function ct(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)<ft)continue;const f=A.position.x-E;O.Body.applyForce(A,A.position,{x:-T*f,y:0})}}var ne="plinkit-ball";function ht(){const d=Math.random(),E=Math.random();return Math.sqrt(-2*Math.log(d||1e-15))*Math.cos(2*Math.PI*E)}function gt(d,E){const T=Math.max(d.radius+8,d.height*.06);let A;return E&&E>0?A=ht()*d.width*E:A=(Math.random()-.5)*d.width*.08,O.Bodies.circle(d.width*.5+A,T,d.radius,{label:ne,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var ee="plinkit-peg",te="plinkit-guide",oe="plinkit-wall",dt=.22,vt=4,pt=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new lt;dist;removeCollisionNudge=null;removeCollisionStart=null;constructor(d){this.engine=O.Engine.create({gravity:{x:0,y:d.gravityY,scale:.001}}),this.config=d,this.dist=ut(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;O.Body.setVelocity(a,{x:a.velocity.x-E*r,y:a.velocity.y})}};O.Events.on(this.engine,"collisionEnd",T),this.removeCollisionNudge=()=>O.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:Z(o),target:r,speed:c})}};O.Events.on(this.engine,"collisionStart",A),this.removeCollisionStart=()=>O.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=gt({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(Z(d),d.position.x,d.position.y),O.World.add(this.engine.world,d)}canSpawnBall(){const d=this.config.height*dt;let E=0;const T=O.Composite.allBodies(this.engine.world).filter(A=>A.label===ne);for(const A of T)if(!A.plugin.settled&&A.position.y<=d&&(E+=1,E>=vt))return!1;return!0}step(d){O.Engine.update(this.engine,d);const E=O.Composite.allBodies(this.engine.world).filter(e=>e.label===ne),T=E.filter(e=>!e.plugin.settled);ct(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:O.Composite.allBodies(this.engine.world).filter(E=>E.label===ne).map(E=>({id:Z(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?.(),O.World.clear(this.engine.world,!1),O.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(Z(f)),O.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&&(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=d*.5;const T=Math.max(18,d*.02),A=d/this.config.multipliers.length,f=this.config.layout.mainPegs,e=He({...f,width:d,height:E});this.layoutGeometry=e;const o=f.radius,a=this.config.layout.edgeGuides.radius;this.pegs=Ve(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 r=this.getBucketTop(),c=O.Bodies.rectangle(-T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),n=O.Bodies.rectangle(d+T*.5,E*.5,T,E*2,{isStatic:!0,label:oe,restitution:.4}),h=O.Bodies.rectangle(d*.5,E+T*.5,d,T,{isStatic:!0,isSensor:!0,label:oe});this.walls={leftWall:c,rightWall:n,floor:h},O.World.add(this.engine.world,[c,n,h]),this.guidePegs=Ne(e,a,{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=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,O.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=Je(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:Z(d),bucketIndex:e,multiplier:o,wager:a,payout:a*o}}},mt=`
|
|
2
2
|
precision highp float;
|
|
3
3
|
in vec2 a_position;
|
|
4
4
|
uniform vec2 u_resolution;
|
package/dist/index.es.js
CHANGED
|
@@ -2957,11 +2957,11 @@ var lt = class {
|
|
|
2957
2957
|
}
|
|
2958
2958
|
};
|
|
2959
2959
|
function ut(d) {
|
|
2960
|
-
const E = Math.max(0, Math.min(1, d))
|
|
2960
|
+
const E = Math.max(0, Math.min(1, d)), T = E ** 1.3;
|
|
2961
2961
|
return {
|
|
2962
|
-
windStrength:
|
|
2963
|
-
collisionNudge: T * 0.
|
|
2964
|
-
spawnSigmaRatio: E > 0 ? 0.04 - T * 0.
|
|
2962
|
+
windStrength: T * 4e-7,
|
|
2963
|
+
collisionNudge: T * 0.13,
|
|
2964
|
+
spawnSigmaRatio: E > 0 ? 0.04 - T * 0.035 : 0
|
|
2965
2965
|
};
|
|
2966
2966
|
}
|
|
2967
2967
|
var ft = 0.4;
|
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))*.5,T=E**1.5;return{windStrength:Math.min(T*8e-7,3e-7),collisionNudge:T*.1,spawnSigmaRatio:E>0?.04-T*.038: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=(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=`
|
|
2
2
|
precision highp float;
|
|
3
3
|
in vec2 a_position;
|
|
4
4
|
uniform vec2 u_resolution;
|