plinkit 1.0.0-dev.0 → 1.0.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +35 -1
- package/dist/index.es.js +1546 -1347
- package/dist/plinkit.umd.js +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ce=(d,E)=>()=>(E||(d((E={exports:{}}).exports,E),d=null),E.exports),Me=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 me(d,E){const A=d.bottomPegCount-d.topPegCount+1,B=d.radius+d.sidePaddingPx,c=(E-B*2)/Math.max(d.bottomPegCount-1,1);return{rows:A,sidePadding:B,baseSpacing:c,targetVerticalStep:c*d.verticalStepRatio}}function Te(d){const{width:E,height:A,topPegCount:B}=d;if(d.bottomPegCount<B)throw new Error("bottomPegCount must be greater than or equal to topPegCount");const c=me(d,E),e=E*.5,l=d.topPaddingPx,a=Math.max(l+60,A-d.bottomPaddingPx),r=c.rows>1?(a-l)/(c.rows-1):0,h=Math.min(c.targetVerticalStep,r),n=a-h*Math.max(c.rows-1,0),u=[];for(let o=0;o<c.rows;o++){const t=B+o,i=n+o*h,s=(t-1)*c.baseSpacing,f=e-s*.5;u.push({row:o,count:t,y:i,startX:f,rowWidth:s,leftX:f,rightX:f+s})}return{rows:c.rows,center:e,minTopY:l,bottomY:a,sidePadding:c.sidePadding,baseSpacing:c.baseSpacing,verticalStep:h,startY:n,rowAnchors:u}}function Ae(d,E){const A=[];for(const B of d.rowAnchors)for(let c=0;c<B.count;c++)A.push({x:B.startX+c*d.baseSpacing,y:B.y,radius:E});return A}function Ee(d,E,A){if(d.rows<2)return[];const B=[],c=(A.spread-1)*d.baseSpacing,e=t=>t<d.center?t-c:t>d.center?t+c:t,l=d.rowAnchors[0],a=l.leftX,r=l.rightX,h=d.startY-d.minTopY,n=E*2.5,u=Math.min(d.verticalStep,Math.max(n,h/3)),o=h>=n?Math.min(3,Math.floor(h/u)):0;for(let t=1;t<=o;t++){const i=d.startY-t*u+A.yOffset,s=a-t*d.baseSpacing*.5,f=r+t*d.baseSpacing*.5;B.push({x:e(s),y:i,radius:E},{x:e(f),y:i,radius:E})}for(let t=0;t<o;t++){const i=d.startY-t*u,s=d.startY-(t+1)*u,f=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;B.push({x:e((f+m)/2),y:(i+s)/2+A.yOffset,radius:E},{x:e((x+P)/2),y:(i+s)/2+A.yOffset,radius:E})}for(let t=0;t<d.rows-1;t++){const i=d.rowAnchors[t],s=d.rowAnchors[t+1],f=(i.y+s.y)/2+A.yOffset;B.push({x:e((i.leftX+s.leftX)/2),y:f,radius:E},{x:e((i.rightX+s.rightX)/2),y:f,radius:E})}return B}var Be=-1,Ie=8;function Le(d){const{mainPegs:E,ballRadius:A,heightPolicy:B}=d;if(ke(B),Fe(E),!Number.isFinite(A)||A<=0)throw new Error("ballRadius must be greater than 0");const c=me(E,600);if(c.baseSpacing<=0)throw new Error("mainPegs produce non-positive base spacing; reduce sidePaddingPx or peg counts");const{rows:e,baseSpacing:l,targetVerticalStep:a}=c,r=a*Math.max(e-1,0),h=B.topPaddingPx,n=a*2,u=A*2+Ie,o=E.radius+A+Be,t=Math.max(B.bottomPaddingPx,o+u);return{worldHeight:h+n+r+t,resolvedMainPegs:{...E,topPaddingPx:h,bottomPaddingPx:t},rows:e,baseSpacing:l,verticalStep:a,requiredBottomPaddingPx:t}}function Re(d){const{parentWidthPx:E,viewport:A,worldHeight:B}=d;if(De(A),!Number.isFinite(E)||E<=0)throw new Error("Parent width must be greater than 0");if(!Number.isFinite(B)||B<=0)throw new Error("World height must be greater than 0");const c=E;return{displayWidth:c,displayHeight:c*(B/600),worldScale:c/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 De(d){if(!Number.isFinite(d.dprCap)||d.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function Fe(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 be=Ce(((d,E)=>{(function(B,c){typeof d=="object"&&typeof E=="object"?E.exports=c():typeof define=="function"&&define.amd?define("Matter",[],c):typeof d=="object"?d.Matter=c():B.Matter=c()})(d,function(){return(function(A){var B={};function c(e){if(B[e])return B[e].exports;var l=B[e]={i:e,l:!1,exports:{}};return A[e].call(l.exports,l,l.exports,c),l.l=!0,l.exports}return c.m=A,c.c=B,c.d=function(e,l,a){c.o(e,l)||Object.defineProperty(e,l,{enumerable:!0,get:a})},c.r=function(e){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.t=function(e,l){if(l&1&&(e=c(e)),l&8||l&4&&typeof e=="object"&&e&&e.__esModule)return e;var a=Object.create(null);if(c.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),l&2&&typeof e!="string")for(var r in e)c.d(a,r,function(h){return e[h]}.bind(null,r));return a},c.n=function(e){var l=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(l,"a",l),l},c.o=function(e,l){return Object.prototype.hasOwnProperty.call(e,l)},c.p="",c(c.s=20)})([(function(A,B){var c={};A.exports=c,(function(){c._baseDelta=1e3/60,c._nextId=0,c._seed=0,c._nowStartTime=+new Date,c._warnedOnce={},c._decomp=null,c.extend=function(l,a){var r,h;typeof a=="boolean"?(r=2,h=a):(r=1,h=!0);for(var n=r;n<arguments.length;n++){var u=arguments[n];if(u)for(var o in u)h&&u[o]&&u[o].constructor===Object&&(!l[o]||l[o].constructor===Object)?(l[o]=l[o]||{},c.extend(l[o],h,u[o])):l[o]=u[o]}return l},c.clone=function(l,a){return c.extend({},a,l)},c.keys=function(l){if(Object.keys)return Object.keys(l);var a=[];for(var r in l)a.push(r);return a},c.values=function(l){var a=[];if(Object.keys){for(var r=Object.keys(l),h=0;h<r.length;h++)a.push(l[r[h]]);return a}for(var n in l)a.push(l[n]);return a},c.get=function(l,a,r,h){a=a.split(".").slice(r,h);for(var n=0;n<a.length;n+=1)l=l[a[n]];return l},c.set=function(l,a,r,h,n){var u=a.split(".").slice(h,n);return c.get(l,a,0,-1)[u[u.length-1]]=r,r},c.shuffle=function(l){for(var a=l.length-1;a>0;a--){var r=Math.floor(c.random()*(a+1)),h=l[a];l[a]=l[r],l[r]=h}return l},c.choose=function(l){return l[Math.floor(c.random()*l.length)]},c.isElement=function(l){return typeof HTMLElement<"u"?l instanceof HTMLElement:!!(l&&l.nodeType&&l.nodeName)},c.isArray=function(l){return Object.prototype.toString.call(l)==="[object Array]"},c.isFunction=function(l){return typeof l=="function"},c.isPlainObject=function(l){return typeof l=="object"&&l.constructor===Object},c.isString=function(l){return toString.call(l)==="[object String]"},c.clamp=function(l,a,r){return l<a?a:l>r?r:l},c.sign=function(l){return l<0?-1:1},c.now=function(){if(typeof window<"u"&&window.performance){if(window.performance.now)return window.performance.now();if(window.performance.webkitNow)return window.performance.webkitNow()}return Date.now?Date.now():new Date-c._nowStartTime},c.random=function(l,a){return l=typeof l<"u"?l:0,a=typeof a<"u"?a:1,l+e()*(a-l)};var e=function(){return c._seed=(c._seed*9301+49297)%233280,c._seed/233280};c.colorToNumber=function(l){return l=l.replace("#",""),l.length==3&&(l=l.charAt(0)+l.charAt(0)+l.charAt(1)+l.charAt(1)+l.charAt(2)+l.charAt(2)),parseInt(l,16)},c.logLevel=1,c.log=function(){console&&c.logLevel>0&&c.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.info=function(){console&&c.logLevel>0&&c.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.warn=function(){console&&c.logLevel>0&&c.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},c.warnOnce=function(){var l=Array.prototype.slice.call(arguments).join(" ");c._warnedOnce[l]||(c.warn(l),c._warnedOnce[l]=!0)},c.deprecated=function(l,a,r){l[a]=c.chain(function(){c.warnOnce("🔅 deprecated 🔅",r)},l[a])},c.nextId=function(){return c._nextId++},c.indexOf=function(l,a){if(l.indexOf)return l.indexOf(a);for(var r=0;r<l.length;r++)if(l[r]===a)return r;return-1},c.map=function(l,a){if(l.map)return l.map(a);for(var r=[],h=0;h<l.length;h+=1)r.push(a(l[h]));return r},c.topologicalSort=function(l){var a=[],r=[],h=[];for(var n in l)!r[n]&&!h[n]&&c._topologicalSort(n,r,h,l,a);return a},c._topologicalSort=function(l,a,r,h,n){var u=h[l]||[];r[l]=!0;for(var o=0;o<u.length;o+=1){var t=u[o];r[t]||a[t]||c._topologicalSort(t,a,r,h,n)}r[l]=!1,a[l]=!0,n.push(l)},c.chain=function(){for(var l=[],a=0;a<arguments.length;a+=1){var r=arguments[a];r._chained?l.push.apply(l,r._chained):l.push(r)}var h=function(){for(var n,u=new Array(arguments.length),o=0,t=arguments.length;o<t;o++)u[o]=arguments[o];for(o=0;o<l.length;o+=1){var i=l[o].apply(n,u);typeof i<"u"&&(n=i)}return n};return h._chained=l,h},c.chainPathBefore=function(l,a,r){return c.set(l,a,c.chain(r,c.get(l,a)))},c.chainPathAfter=function(l,a,r){return c.set(l,a,c.chain(c.get(l,a),r))},c.setDecomp=function(l){c._decomp=l},c.getDecomp=function(){var l=c._decomp;try{!l&&typeof window<"u"&&(l=window.decomp),!l&&typeof global<"u"&&(l=global.decomp)}catch{l=null}return l}})()}),(function(A,B){var c={};A.exports=c,(function(){c.create=function(e){var l={min:{x:0,y:0},max:{x:0,y:0}};return e&&c.update(l,e),l},c.update=function(e,l,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<l.length;r++){var h=l[r];h.x>e.max.x&&(e.max.x=h.x),h.x<e.min.x&&(e.min.x=h.x),h.y>e.max.y&&(e.max.y=h.y),h.y<e.min.y&&(e.min.y=h.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)},c.contains=function(e,l){return l.x>=e.min.x&&l.x<=e.max.x&&l.y>=e.min.y&&l.y<=e.max.y},c.overlaps=function(e,l){return e.min.x<=l.max.x&&e.max.x>=l.min.x&&e.max.y>=l.min.y&&e.min.y<=l.max.y},c.translate=function(e,l){e.min.x+=l.x,e.max.x+=l.x,e.min.y+=l.y,e.max.y+=l.y},c.shift=function(e,l){var a=e.max.x-e.min.x,r=e.max.y-e.min.y;e.min.x=l.x,e.max.x=l.x+a,e.min.y=l.y,e.max.y=l.y+r}})()}),(function(A,B){var c={};A.exports=c,(function(){c.create=function(e,l){return{x:e||0,y:l||0}},c.clone=function(e){return{x:e.x,y:e.y}},c.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},c.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},c.rotate=function(e,l,a){var r=Math.cos(l),h=Math.sin(l);a||(a={});var n=e.x*r-e.y*h;return a.y=e.x*h+e.y*r,a.x=n,a},c.rotateAbout=function(e,l,a,r){var h=Math.cos(l),n=Math.sin(l);r||(r={});var u=a.x+((e.x-a.x)*h-(e.y-a.y)*n);return r.y=a.y+((e.x-a.x)*n+(e.y-a.y)*h),r.x=u,r},c.normalise=function(e){var l=c.magnitude(e);return l===0?{x:0,y:0}:{x:e.x/l,y:e.y/l}},c.dot=function(e,l){return e.x*l.x+e.y*l.y},c.cross=function(e,l){return e.x*l.y-e.y*l.x},c.cross3=function(e,l,a){return(l.x-e.x)*(a.y-e.y)-(l.y-e.y)*(a.x-e.x)},c.add=function(e,l,a){return a||(a={}),a.x=e.x+l.x,a.y=e.y+l.y,a},c.sub=function(e,l,a){return a||(a={}),a.x=e.x-l.x,a.y=e.y-l.y,a},c.mult=function(e,l){return{x:e.x*l,y:e.y*l}},c.div=function(e,l){return{x:e.x/l,y:e.y/l}},c.perp=function(e,l){return l=l===!0?-1:1,{x:l*-e.y,y:l*e.x}},c.neg=function(e){return{x:-e.x,y:-e.y}},c.angle=function(e,l){return Math.atan2(l.y-e.y,l.x-e.x)},c._temp=[c.create(),c.create(),c.create(),c.create(),c.create(),c.create()]})()}),(function(A,B,c){var e={};A.exports=e;var l=c(2),a=c(0);(function(){e.create=function(r,h){for(var n=[],u=0;u<r.length;u++){var o=r[u],t={x:o.x,y:o.y,index:u,body:h,isInternal:!1};n.push(t)}return n},e.fromPath=function(r,h){var n=/L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi,u=[];return r.replace(n,function(o,t,i){u.push({x:parseFloat(t),y:parseFloat(i)})}),e.create(u,h)},e.centre=function(r){for(var h=e.area(r,!0),n={x:0,y:0},u,o,t,i=0;i<r.length;i++)t=(i+1)%r.length,u=l.cross(r[i],r[t]),o=l.mult(l.add(r[i],r[t]),u),n=l.add(n,o);return l.div(n,6*h)},e.mean=function(r){for(var h={x:0,y:0},n=0;n<r.length;n++)h.x+=r[n].x,h.y+=r[n].y;return l.div(h,r.length)},e.area=function(r,h){for(var n=0,u=r.length-1,o=0;o<r.length;o++)n+=(r[u].x-r[o].x)*(r[u].y+r[o].y),u=o;return h?n/2:Math.abs(n)/2},e.inertia=function(r,h){for(var n=0,u=0,o=r,t,i,s=0;s<o.length;s++)i=(s+1)%o.length,t=Math.abs(l.cross(o[i],o[s])),n+=t*(l.dot(o[i],o[i])+l.dot(o[i],o[s])+l.dot(o[s],o[s])),u+=t;return h/6*(n/u)},e.translate=function(r,h,n){n=typeof n<"u"?n:1;var u=r.length,o=h.x*n,t=h.y*n,i;for(i=0;i<u;i++)r[i].x+=o,r[i].y+=t;return r},e.rotate=function(r,h,n){if(h!==0){var u=Math.cos(h),o=Math.sin(h),t=n.x,i=n.y,s=r.length,f,m,x,P;for(P=0;P<s;P++)f=r[P],m=f.x-t,x=f.y-i,f.x=t+(m*u-x*o),f.y=i+(m*o+x*u);return r}},e.contains=function(r,h){for(var n=h.x,u=h.y,o=r.length,t=r[o-1],i,s=0;s<o;s++){if(i=r[s],(n-t.x)*(i.y-t.y)+(u-t.y)*(t.x-i.x)>0)return!1;t=i}return!0},e.scale=function(r,h,n,u){if(h===1&&n===1)return r;u=u||e.centre(r);for(var o,t,i=0;i<r.length;i++)o=r[i],t=l.sub(o,u),r[i].x=u.x+t.x*h,r[i].y=u.y+t.y*n;return r},e.chamfer=function(r,h,n,u,o){typeof h=="number"?h=[h]:h=h||[8],n=typeof n<"u"?n:-1,u=u||2,o=o||14;for(var t=[],i=0;i<r.length;i++){var s=r[i-1>=0?i-1:r.length-1],f=r[i],m=r[(i+1)%r.length],x=h[i<h.length?i:h.length-1];if(x===0){t.push(f);continue}var P=l.normalise({x:f.y-s.y,y:s.x-f.x}),T=l.normalise({x:m.y-f.y,y:f.x-m.x}),g=Math.sqrt(2*Math.pow(x,2)),p=l.mult(a.clone(P),x),y=l.normalise(l.mult(l.add(P,T),.5)),v=l.sub(f,l.mult(y,g)),w=n;n===-1&&(w=Math.pow(x,.32)*1.75),w=a.clamp(w,u,o),w%2===1&&(w+=1);for(var S=Math.acos(l.dot(P,T))/w,C=0;C<w;C++)t.push(l.add(l.rotate(p,S*C),v))}return t},e.clockwiseSort=function(r){var h=e.mean(r);return r.sort(function(n,u){return l.angle(h,n)-l.angle(h,u)}),r},e.isConvex=function(r){var h=0,n=r.length,u,o,t,i;if(n<3)return null;for(u=0;u<n;u++)if(o=(u+1)%n,t=(u+2)%n,i=(r[o].x-r[u].x)*(r[t].y-r[o].y),i-=(r[o].y-r[u].y)*(r[t].x-r[o].x),i<0?h|=1:i>0&&(h|=2),h===3)return!1;return h!==0?!0:null},e.hull=function(r){var h=[],n=[],u,o;for(r=r.slice(0),r.sort(function(t,i){var s=t.x-i.x;return s!==0?s:t.y-i.y}),o=0;o<r.length;o+=1){for(u=r[o];n.length>=2&&l.cross3(n[n.length-2],n[n.length-1],u)<=0;)n.pop();n.push(u)}for(o=r.length-1;o>=0;o-=1){for(u=r[o];h.length>=2&&l.cross3(h[h.length-2],h[h.length-1],u)<=0;)h.pop();h.push(u)}return h.pop(),n.pop(),h.concat(n)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(3),a=c(2),r=c(7),h=c(0),n=c(1),u=c(11);(function(){e._timeCorrection=!0,e._inertiaScale=4,e._nextCollidingGroupId=1,e._nextNonCollidingGroupId=-1,e._nextCategory=1,e._baseDelta=1e3/60,e.create=function(t){var i={id:h.nextId(),type:"body",label:"Body",parts:[],plugin:{},angle:0,vertices:l.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=h.extend(i,t);return o(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 o=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}),l.rotate(t.vertices,t.angle,t.position),u.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":h.choose(["#f19648","#f5d259","#f55a3c","#063e7b","#ececd1"]),f=t.isStatic?"#555":"#ccc",m=t.isStatic&&t.render.fillStyle===null?1:0;t.render.fillStyle=t.render.fillStyle||s,t.render.strokeStyle=t.render.strokeStyle||f,t.render.lineWidth=t.render.lineWidth||m,t.render.sprite.xOffset+=-(t.bounds.min.x-t.position.x)/(t.bounds.max.x-t.bounds.min.x),t.render.sprite.yOffset+=-(t.bounds.min.y-t.position.y)/(t.bounds.max.y-t.bounds.min.y)};e.set=function(t,i,s){var f;typeof i=="string"&&(f=i,i={},i[f]=s);for(f in i)if(Object.prototype.hasOwnProperty.call(i,f))switch(s=i[f],f){case"isStatic":e.setStatic(t,s);break;case"isSleeping":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[f]=s}},e.setStatic=function(t,i){for(var s=0;s<t.parts.length;s++){var f=t.parts[s];i?(f.isStatic||(f._original={restitution:f.restitution,friction:f.friction,mass:f.mass,inertia:f.inertia,density:f.density,inverseMass:f.inverseMass,inverseInertia:f.inverseInertia}),f.restitution=0,f.friction=1,f.mass=f.inertia=f.density=1/0,f.inverseMass=f.inverseInertia=0,f.positionPrev.x=f.position.x,f.positionPrev.y=f.position.y,f.anglePrev=f.angle,f.angularVelocity=0,f.speed=0,f.angularSpeed=0,f.motion=0):f._original&&(f.restitution=f._original.restitution,f.friction=f._original.friction,f.mass=f._original.mass,f.inertia=f._original.inertia,f.density=f._original.density,f.inverseMass=f._original.inverseMass,f.inverseInertia=f._original.inverseInertia,f._original=null),f.isStatic=i}},e.setMass=function(t,i){t.inertia=t.inertia/(t.mass/6)*(i/6),t.inverseInertia=1/t.inertia,t.mass=i,t.inverseMass=1/t.mass,t.density=t.mass/t.area},e.setDensity=function(t,i){e.setMass(t,i*t.area),t.density=i},e.setInertia=function(t,i){t.inertia=i,t.inverseInertia=1/t.inertia},e.setVertices=function(t,i){i[0].body===t?t.vertices=i:t.vertices=l.create(i,t),t.axes=u.fromVertices(t.vertices),t.area=l.area(t.vertices),e.setMass(t,t.density*t.area);var s=l.centre(t.vertices);l.translate(t.vertices,s,-1),e.setInertia(t,e._inertiaScale*l.inertia(t.vertices,t.mass)),l.translate(t.vertices,t.position),n.update(t.bounds,t.vertices,t.velocity)},e.setParts=function(t,i,s){var f;for(i=i.slice(0),t.parts.length=0,t.parts.push(t),t.parent=t,f=0;f<i.length;f++){var m=i[f];m!==t&&(m.parent=t,t.parts.push(m))}if(t.parts.length!==1){if(s=typeof s<"u"?s:!0,s){var x=[];for(f=0;f<i.length;f++)x=x.concat(i[f].vertices);l.clockwiseSort(x);var P=l.hull(x),T=l.centre(P);e.setVertices(t,P),l.translate(t.vertices,T)}var g=e._totalProperties(t);t.area=g.area,t.parent=t,t.position.x=g.centre.x,t.position.y=g.centre.y,t.positionPrev.x=g.centre.x,t.positionPrev.y=g.centre.y,e.setMass(t,g.mass),e.setInertia(t,g.inertia),e.setPosition(t,g.centre)}},e.setCentre=function(t,i,s){s?(t.positionPrev.x+=i.x,t.positionPrev.y+=i.y,t.position.x+=i.x,t.position.y+=i.y):(t.positionPrev.x=i.x-(t.position.x-t.positionPrev.x),t.positionPrev.y=i.y-(t.position.y-t.positionPrev.y),t.position.x=i.x,t.position.y=i.y)},e.setPosition=function(t,i,s){var f=a.sub(i,t.position);s?(t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.velocity.x=f.x,t.velocity.y=f.y,t.speed=a.magnitude(f)):(t.positionPrev.x+=f.x,t.positionPrev.y+=f.y);for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.position.x+=f.x,x.position.y+=f.y,l.translate(x.vertices,f),n.update(x.bounds,x.vertices,t.velocity)}},e.setAngle=function(t,i,s){var f=i-t.angle;s?(t.anglePrev=t.angle,t.angularVelocity=f,t.angularSpeed=Math.abs(f)):t.anglePrev+=f;for(var m=0;m<t.parts.length;m++){var x=t.parts[m];x.angle+=f,l.rotate(x.vertices,f,t.position),u.rotate(x.axes,f),n.update(x.bounds,x.vertices,t.velocity),m>0&&a.rotateAbout(x.position,f,t.position,x.position)}},e.setVelocity=function(t,i){var s=t.deltaTime/e._baseDelta;t.positionPrev.x=t.position.x-i.x*s,t.positionPrev.y=t.position.y-i.y*s,t.velocity.x=(t.position.x-t.positionPrev.x)/s,t.velocity.y=(t.position.y-t.positionPrev.y)/s,t.speed=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,h.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,f){if(!s)e.setAngle(t,t.angle+i,f);else{var m=Math.cos(i),x=Math.sin(i),P=t.position.x-s.x,T=t.position.y-s.y;e.setPosition(t,{x:s.x+(P*m-T*x),y:s.y+(P*x+T*m)},f),e.setAngle(t,t.angle+i,f)}},e.scale=function(t,i,s,f){var m=0,x=0;f=f||t.position;for(var P=0;P<t.parts.length;P++){var T=t.parts[P];l.scale(T.vertices,i,s,f),T.axes=u.fromVertices(T.vertices),T.area=l.area(T.vertices),e.setMass(T,t.density*T.area),l.translate(T.vertices,{x:-T.position.x,y:-T.position.y}),e.setInertia(T,e._inertiaScale*l.inertia(T.vertices,T.mass)),l.translate(T.vertices,{x:T.position.x,y:T.position.y}),P>0&&(m+=T.area,x+=T.inertia),T.position.x=f.x+(T.position.x-f.x)*i,T.position.y=f.y+(T.position.y-f.y)*s,n.update(T.bounds,T.vertices,t.velocity)}t.parts.length>1&&(t.area=m,t.isStatic||(e.setMass(t,t.density*m),e.setInertia(t,x))),t.circleRadius&&(i===s?t.circleRadius*=i:t.circleRadius=null)},e.update=function(t,i){i=(typeof i<"u"?i:1e3/60)*t.timeScale;var s=i*i,f=e._timeCorrection?i/(t.deltaTime||i):1,m=1-t.frictionAir*(i/h._baseDelta),x=(t.position.x-t.positionPrev.x)*f,P=(t.position.y-t.positionPrev.y)*f;t.velocity.x=x*m+t.force.x/t.mass*s,t.velocity.y=P*m+t.force.y/t.mass*s,t.positionPrev.x=t.position.x,t.positionPrev.y=t.position.y,t.position.x+=t.velocity.x,t.position.y+=t.velocity.y,t.deltaTime=i,t.angularVelocity=(t.angle-t.anglePrev)*m*f+t.torque/t.inertia*s,t.anglePrev=t.angle,t.angle+=t.angularVelocity;for(var T=0;T<t.parts.length;T++){var g=t.parts[T];l.translate(g.vertices,t.velocity),T>0&&(g.position.x+=t.velocity.x,g.position.y+=t.velocity.y),t.angularVelocity!==0&&(l.rotate(g.vertices,t.angularVelocity,t.position),u.rotate(g.axes,t.angularVelocity),T>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 f={x:i.x-t.position.x,y:i.y-t.position.y};t.force.x+=s.x,t.force.y+=s.y,t.torque+=f.x*s.y-f.y*s.x},e._totalProperties=function(t){for(var i={mass:0,area:0,inertia:0,centre:{x:0,y:0}},s=t.parts.length===1?0:1;s<t.parts.length;s++){var f=t.parts[s],m=f.mass!==1/0?f.mass:1;i.mass+=m,i.area+=f.area,i.inertia+=f.inertia,i.centre=a.add(i.centre,a.mult(f.position,m))}return i.centre=a.div(i.centre,i.mass),i}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(0);(function(){e.on=function(a,r,h){for(var n=r.split(" "),u,o=0;o<n.length;o++)u=n[o],a.events=a.events||{},a.events[u]=a.events[u]||[],a.events[u].push(h);return h},e.off=function(a,r,h){if(!r){a.events={};return}typeof r=="function"&&(h=r,r=l.keys(a.events).join(" "));for(var n=r.split(" "),u=0;u<n.length;u++){var o=a.events[n[u]],t=[];if(h&&o)for(var i=0;i<o.length;i++)o[i]!==h&&t.push(o[i]);a.events[n[u]]=t}},e.trigger=function(a,r,h){var n,u,o,t,i=a.events;if(i&&l.keys(i).length>0){h||(h={}),n=r.split(" ");for(var s=0;s<n.length;s++)if(u=n[s],o=i[u],o){t=l.clone(h,!1),t.name=u,t.source=a;for(var f=0;f<o.length;f++)o[f].apply(a,[t])}}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(5),a=c(0),r=c(1),h=c(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,u,o,t){if(n.isModified=u,u&&n.cache&&(n.cache.allBodies=null,n.cache.allConstraints=null,n.cache.allComposites=null),o&&n.parent&&e.setModified(n.parent,u,o,t),t)for(var i=0;i<n.composites.length;i++){var s=n.composites[i];e.setModified(s,u,o,t)}},e.add=function(n,u){var o=[].concat(u);l.trigger(n,"beforeAdd",{object:u});for(var t=0;t<o.length;t++){var i=o[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 l.trigger(n,"afterAdd",{object:u}),n},e.remove=function(n,u,o){var t=[].concat(u);l.trigger(n,"beforeRemove",{object:u});for(var i=0;i<t.length;i++){var s=t[i];switch(s.type){case"body":e.removeBody(n,s,o);break;case"constraint":e.removeConstraint(n,s,o);break;case"composite":e.removeComposite(n,s,o);break;case"mouseConstraint":e.removeConstraint(n,s.constraint);break}}return l.trigger(n,"afterRemove",{object:u}),n},e.addComposite=function(n,u){return n.composites.push(u),u.parent=n,e.setModified(n,!0,!0,!1),n},e.removeComposite=function(n,u,o){var t=a.indexOf(n.composites,u);if(t!==-1){var i=e.allBodies(u);e.removeCompositeAt(n,t);for(var s=0;s<i.length;s++)i[s].sleepCounter=0}if(o)for(var s=0;s<n.composites.length;s++)e.removeComposite(n.composites[s],u,!0);return n},e.removeCompositeAt=function(n,u){return n.composites.splice(u,1),e.setModified(n,!0,!0,!1),n},e.addBody=function(n,u){return n.bodies.push(u),e.setModified(n,!0,!0,!1),n},e.removeBody=function(n,u,o){var t=a.indexOf(n.bodies,u);if(t!==-1&&(e.removeBodyAt(n,t),u.sleepCounter=0),o)for(var i=0;i<n.composites.length;i++)e.removeBody(n.composites[i],u,!0);return n},e.removeBodyAt=function(n,u){return n.bodies.splice(u,1),e.setModified(n,!0,!0,!1),n},e.addConstraint=function(n,u){return n.constraints.push(u),e.setModified(n,!0,!0,!1),n},e.removeConstraint=function(n,u,o){var t=a.indexOf(n.constraints,u);if(t!==-1&&e.removeConstraintAt(n,t),o)for(var i=0;i<n.composites.length;i++)e.removeConstraint(n.composites[i],u,!0);return n},e.removeConstraintAt=function(n,u){return n.constraints.splice(u,1),e.setModified(n,!0,!0,!1),n},e.clear=function(n,u,o){if(o)for(var t=0;t<n.composites.length;t++)e.clear(n.composites[t],u,!0);return u?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 u=[].concat(n.bodies),o=0;o<n.composites.length;o++)u=u.concat(e.allBodies(n.composites[o]));return n.cache&&(n.cache.allBodies=u),u},e.allConstraints=function(n){if(n.cache&&n.cache.allConstraints)return n.cache.allConstraints;for(var u=[].concat(n.constraints),o=0;o<n.composites.length;o++)u=u.concat(e.allConstraints(n.composites[o]));return n.cache&&(n.cache.allConstraints=u),u},e.allComposites=function(n){if(n.cache&&n.cache.allComposites)return n.cache.allComposites;for(var u=[].concat(n.composites),o=0;o<n.composites.length;o++)u=u.concat(e.allComposites(n.composites[o]));return n.cache&&(n.cache.allComposites=u),u},e.get=function(n,u,o){var t,i;switch(o){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()===u.toString()}),i.length===0?null:i[0]):null},e.move=function(n,u,o){return e.remove(n,u),e.add(o,u),n},e.rebase=function(n){for(var u=e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)),o=0;o<u.length;o++)u[o].id=a.nextId();return n},e.translate=function(n,u,o){for(var t=o?e.allBodies(n):n.bodies,i=0;i<t.length;i++)h.translate(t[i],u);return n},e.rotate=function(n,u,o,t){for(var i=Math.cos(u),s=Math.sin(u),f=t?e.allBodies(n):n.bodies,m=0;m<f.length;m++){var x=f[m],P=x.position.x-o.x,T=x.position.y-o.y;h.setPosition(x,{x:o.x+(P*i-T*s),y:o.y+(P*s+T*i)}),h.rotate(x,u)}return n},e.scale=function(n,u,o,t,i){for(var s=i?e.allBodies(n):n.bodies,f=0;f<s.length;f++){var m=s[f],x=m.position.x-t.x,P=m.position.y-t.y;h.setPosition(m,{x:t.x+x*u,y:t.y+P*o}),h.scale(m,u,o)}return n},e.bounds=function(n){for(var u=e.allBodies(n),o=[],t=0;t<u.length;t+=1){var i=u[t];o.push(i.bounds.min,i.bounds.max)}return r.create(o)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(4),a=c(5),r=c(0);(function(){e._motionWakeThreshold=.18,e._motionSleepThreshold=.08,e._minBias=.9,e.update=function(h,n){for(var u=n/r._baseDelta,o=e._motionSleepThreshold,t=0;t<h.length;t++){var i=h[t],s=l.getSpeed(i),f=l.getAngularSpeed(i),m=s*s+f*f;if(i.force.x!==0||i.force.y!==0){e.set(i,!1);continue}var x=Math.min(i.motion,m),P=Math.max(i.motion,m);i.motion=e._minBias*x+(1-e._minBias)*P,i.sleepThreshold>0&&i.motion<o?(i.sleepCounter+=1,i.sleepCounter>=i.sleepThreshold/u&&e.set(i,!0)):i.sleepCounter>0&&(i.sleepCounter-=1)}},e.afterCollisions=function(h){for(var n=e._motionSleepThreshold,u=0;u<h.length;u++){var o=h[u];if(o.isActive){var t=o.collision,i=t.bodyA.parent,s=t.bodyB.parent;if(!(i.isSleeping&&s.isSleeping||i.isStatic||s.isStatic)&&(i.isSleeping||s.isSleeping)){var f=i.isSleeping&&!i.isStatic?i:s,m=f===i?s:i;!f.isStatic&&m.motion>n&&e.set(f,!1)}}}},e.set=function(h,n){var u=h.isSleeping;n?(h.isSleeping=!0,h.sleepCounter=h.sleepThreshold,h.positionImpulse.x=0,h.positionImpulse.y=0,h.positionPrev.x=h.position.x,h.positionPrev.y=h.position.y,h.anglePrev=h.angle,h.speed=0,h.angularSpeed=0,h.motion=0,u||a.trigger(h,"sleepStart")):(h.isSleeping=!1,h.sleepCounter=0,u&&a.trigger(h,"sleepEnd"))}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(3),a=c(9);(function(){var r=[],h={overlap:0,axis:null},n={overlap:0,axis:null};e.create=function(u,o){return{pair:null,collided:!1,bodyA:u,bodyB:o,parentA:u.parent,parentB:o.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(u,o,t){if(e._overlapAxes(h,u.vertices,o.vertices,u.axes),h.overlap<=0||(e._overlapAxes(n,o.vertices,u.vertices,o.axes),n.overlap<=0))return null;var i=t&&t.table[a.id(u,o)],s;i?s=i.collision:(s=e.create(u,o),s.collided=!0,s.bodyA=u.id<o.id?u:o,s.bodyB=u.id<o.id?o:u,s.parentA=s.bodyA.parent,s.parentB=s.bodyB.parent),u=s.bodyA,o=s.bodyB;var f;h.overlap<n.overlap?f=h:f=n;var m=s.normal,x=s.tangent,P=s.penetration,T=s.supports,g=f.overlap,p=f.axis,y=p.x,v=p.y,w=o.position.x-u.position.x,S=o.position.y-u.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(u,o,m,1),M=0;if(l.contains(u.vertices,C[0])&&(T[M++]=C[0]),l.contains(u.vertices,C[1])&&(T[M++]=C[1]),M<2){var I=e._findSupports(o,u,m,-1);l.contains(o.vertices,I[0])&&(T[M++]=I[0]),M<2&&l.contains(o.vertices,I[1])&&(T[M++]=I[1])}return M===0&&(T[M++]=C[0]),s.supportCount=M,s},e._overlapAxes=function(u,o,t,i){var s=o.length,f=t.length,m=o[0].x,x=o[0].y,P=t[0].x,T=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,D=R.y,k=m*L+x*D,F=P*L+T*D,O=k,W=F;for(I=1;I<s;I+=1)C=o[I].x*L+o[I].y*D,C>O?O=C:C<k&&(k=C);for(I=1;I<f;I+=1)C=t[I].x*L+t[I].y*D,C>W?W=C:C<F&&(F=C);if(w=O-F,S=W-k,v=w<S?w:S,v<p&&(p=v,y=M,v<=0))break}u.axis=i[y],u.overlap=p},e._findSupports=function(u,o,t,i){var s=o.vertices,f=s.length,m=u.position.x,x=u.position.y,P=t.x*i,T=t.y*i,g=s[0],p=g,y=P*(m-p.x)+T*(x-p.y),v,w,S;for(S=1;S<f;S+=1)p=s[S],w=P*(m-p.x)+T*(x-p.y),w<y&&(y=w,g=p);return v=s[(f+g.index-1)%f],y=P*(m-v.x)+T*(x-v.y),p=s[(g.index+1)%f],P*(m-p.x)+T*(x-p.y)<y?(r[0]=g,r[1]=p,r):(r[0]=g,r[1]=v,r)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(16);(function(){e.create=function(a,r){var h=a.bodyA,n=a.bodyB,u={id:e.id(h,n),bodyA:h,bodyB:n,collision:a,contacts:[l.create(),l.create()],contactCount:0,separation:0,isActive:!0,isSensor:h.isSensor||n.isSensor,timeCreated:r,timeUpdated:r,inverseMass:0,friction:0,frictionStatic:0,restitution:0,slop:0};return e.update(u,a,r),u},e.update=function(a,r,h){var n=r.supports,u=r.supportCount,o=a.contacts,t=r.parentA,i=r.parentB;a.isActive=!0,a.timeUpdated=h,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=u,r.pair=a;var s=n[0],f=o[0],m=n[1],x=o[1];(x.vertex===s||f.vertex===m)&&(o[1]=f,o[0]=f=x,x=o[1]),f.vertex=s,x.vertex=m},e.setActive=function(a,r,h){r?(a.isActive=!0,a.timeUpdated=h):(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(A,B,c){var e={};A.exports=e;var l=c(3),a=c(2),r=c(7),h=c(1),n=c(11),u=c(0);(function(){e._warming=.4,e._torqueDampen=1,e._minLength=1e-6,e.create=function(o){var t=o;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,f=a.magnitude(a.sub(i,s));t.length=typeof t.length<"u"?t.length:f,t.id=t.id||u.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=u.extend(m,t.render),t},e.preSolveAll=function(o){for(var t=0;t<o.length;t+=1){var i=o[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(o,t){for(var i=u.clamp(t/u._baseDelta,0,1),s=0;s<o.length;s+=1){var f=o[s],m=!f.bodyA||f.bodyA&&f.bodyA.isStatic,x=!f.bodyB||f.bodyB&&f.bodyB.isStatic;(m||x)&&e.solve(o[s],i)}for(s=0;s<o.length;s+=1)f=o[s],m=!f.bodyA||f.bodyA&&f.bodyA.isStatic,x=!f.bodyB||f.bodyB&&f.bodyB.isStatic,!m&&!x&&e.solve(o[s],i)},e.solve=function(o,t){var i=o.bodyA,s=o.bodyB,f=o.pointA,m=o.pointB;if(!(!i&&!s)){i&&!i.isStatic&&(a.rotate(f,i.angle-o.angleA,f),o.angleA=i.angle),s&&!s.isStatic&&(a.rotate(m,s.angle-o.angleB,m),o.angleB=s.angle);var x=f,P=m;if(i&&(x=a.add(i.position,f)),s&&(P=a.add(s.position,m)),!(!x||!P)){var T=a.sub(x,P),g=a.magnitude(T);g<e._minLength&&(g=e._minLength);var p=(g-o.length)/g,y=o.stiffness>=1||o.length===0?o.stiffness*t:o.stiffness*t*t,v=o.damping*t,w=a.mult(T,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,D;if(v>0){var k=a.create();R=a.div(T,g),D=a.sub(s&&a.sub(s.position,s.positionPrev)||k,i&&a.sub(i.position,i.positionPrev)||k),L=a.dot(R,D)}i&&!i.isStatic&&(I=i.inverseMass/S,i.constraintImpulse.x-=w.x*I,i.constraintImpulse.y-=w.y*I,i.position.x-=w.x*I,i.position.y-=w.y*I,v>0&&(i.positionPrev.x-=v*R.x*L*I,i.positionPrev.y-=v*R.y*L*I),M=a.cross(f,w)/C*e._torqueDampen*i.inverseInertia*(1-o.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-o.angularStiffness),s.constraintImpulse.angle+=M,s.angle+=M)}}},e.postSolveAll=function(o){for(var t=0;t<o.length;t++){var i=o[t],s=i.constraintImpulse;if(!(i.isStatic||s.x===0&&s.y===0&&s.angle===0)){r.set(i,!1);for(var f=0;f<i.parts.length;f++){var m=i.parts[f];l.translate(m.vertices,s),f>0&&(m.position.x+=s.x,m.position.y+=s.y),s.angle!==0&&(l.rotate(m.vertices,s.angle,i.position),n.rotate(m.axes,s.angle),f>0&&a.rotateAbout(m.position,s.angle,i.position,m.position)),h.update(m.bounds,m.vertices,i.velocity)}s.angle*=e._warming,s.x*=e._warming,s.y*=e._warming}}},e.pointAWorld=function(o){return{x:(o.bodyA?o.bodyA.position.x:0)+(o.pointA?o.pointA.x:0),y:(o.bodyA?o.bodyA.position.y:0)+(o.pointA?o.pointA.y:0)}},e.pointBWorld=function(o){return{x:(o.bodyB?o.bodyB.position.x:0)+(o.pointB?o.pointB.x:0),y:(o.bodyB?o.bodyB.position.y:0)+(o.pointB?o.pointB.y:0)}},e.currentLength=function(o){var t=(o.bodyA?o.bodyA.position.x:0)+(o.pointA?o.pointA.x:0),i=(o.bodyA?o.bodyA.position.y:0)+(o.pointA?o.pointA.y:0),s=(o.bodyB?o.bodyB.position.x:0)+(o.pointB?o.pointB.x:0),f=(o.bodyB?o.bodyB.position.y:0)+(o.pointB?o.pointB.y:0),m=t-s,x=i-f;return Math.sqrt(m*m+x*x)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(2),a=c(0);(function(){e.fromVertices=function(r){for(var h={},n=0;n<r.length;n++){var u=(n+1)%r.length,o=l.normalise({x:r[u].y-r[n].y,y:r[n].x-r[u].x}),t=o.y===0?1/0:o.x/o.y;t=t.toFixed(3).toString(),h[t]=o}return a.values(h)},e.rotate=function(r,h){if(h!==0)for(var n=Math.cos(h),u=Math.sin(h),o=0;o<r.length;o++){var t=r[o],i=t.x*n-t.y*u;t.y=t.x*u+t.y*n,t.x=i}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(3),a=c(0),r=c(4),h=c(1),n=c(2);(function(){e.rectangle=function(u,o,t,i,s){s=s||{};var f={label:"Rectangle Body",position:{x:u,y:o},vertices:l.fromPath("L 0 0 L "+t+" 0 L "+t+" "+i+" L 0 "+i)};if(s.chamfer){var m=s.chamfer;f.vertices=l.chamfer(f.vertices,m.radius,m.quality,m.qualityMin,m.qualityMax),delete s.chamfer}return r.create(a.extend({},f,s))},e.trapezoid=function(u,o,t,i,s,f){f=f||{},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,T=P+x,g;s<.5?g="L 0 0 L "+x+" "+-i+" L "+P+" "+-i+" L "+T+" 0":g="L 0 0 L "+P+" "+-i+" L "+T+" 0";var p={label:"Trapezoid Body",position:{x:u,y:o},vertices:l.fromPath(g)};if(f.chamfer){var y=f.chamfer;p.vertices=l.chamfer(p.vertices,y.radius,y.quality,y.qualityMin,y.qualityMax),delete f.chamfer}return r.create(a.extend({},p,f))},e.circle=function(u,o,t,i,s){i=i||{};var f={label:"Circle Body",circleRadius:t};s=s||25;var m=Math.ceil(Math.max(10,Math.min(s,t)));return m%2===1&&(m+=1),e.polygon(u,o,m,t,a.extend({},f,i))},e.polygon=function(u,o,t,i,s){if(s=s||{},t<3)return e.circle(u,o,i,s);for(var f=2*Math.PI/t,m="",x=f*.5,P=0;P<t;P+=1){var T=x+P*f,g=Math.cos(T)*i,p=Math.sin(T)*i;m+="L "+g.toFixed(3)+" "+p.toFixed(3)+" "}var y={label:"Polygon Body",position:{x:u,y:o},vertices:l.fromPath(m)};if(s.chamfer){var v=s.chamfer;y.vertices=l.chamfer(y.vertices,v.radius,v.quality,v.qualityMin,v.qualityMax),delete s.chamfer}return r.create(a.extend({},y,s))},e.fromVertices=function(u,o,t,i,s,f,m,x){var P=a.getDecomp(),T=!!(P&&P.quickDecomp),g,p,y,v,w,S,C,M,I,R;for(i=i||{},p=[],s=typeof s<"u"?s:!1,f=typeof f<"u"?f:.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=l.isConvex(w),v=!y,v&&!T&&a.warnOnce("Bodies.fromVertices: Install the 'poly-decomp' library and use Common.setDecomp or provide 'decomp' as a global to decompose concave vertices."),y||!T)y?w=l.clockwiseSort(w):w=l.hull(w),p.push({position:{x:u,y:o},vertices:w});else{var L=w.map(function(b){return[b.x,b.y]});P.makeCCW(L),f!==!1&&P.removeCollinearPoints(L,f),x!==!1&&P.removeDuplicatePoints&&P.removeDuplicatePoints(L,x);var D=P.quickDecomp(L);for(S=0;S<D.length;S++){var k=D[S].map(function(b){return{x:b[0],y:b[1]}});m>0&&l.area(k)<m||p.push({position:l.centre(k),vertices:k})}}for(S=0;S<p.length;S++)p[S]=r.create(a.extend(p[S],i));if(s){var F=5;for(S=0;S<p.length;S++){var O=p[S];for(C=S+1;C<p.length;C++){var W=p[C];if(h.overlaps(O.bounds,W.bounds)){var G=O.vertices,N=W.vertices;for(M=0;M<O.vertices.length;M++)for(R=0;R<W.vertices.length;R++){var Q=n.magnitudeSquared(n.sub(G[(M+1)%G.length],N[R])),X=n.magnitudeSquared(n.sub(G[M],N[(R+1)%N.length]));Q<F&&X<F&&(G[M].isInternal=!0,N[R].isInternal=!0)}}}}}return p.length>1?(g=r.create(a.extend({parts:p.slice(0)},i)),r.setPosition(g,{x:u,y:o}),g):p[0]}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(0),a=c(8);(function(){e.create=function(r){return l.extend({bodies:[],collisions:[],pairs:null},r)},e.setBodies=function(r,h){r.bodies=h.slice(0)},e.clear=function(r){r.bodies=[],r.collisions=[]},e.collisions=function(r){var h=r.pairs,n=r.bodies,u=n.length,o=e.canCollide,t=a.collides,i=r.collisions,s=0,f,m;for(n.sort(e._compareBoundsX),f=0;f<u;f++){var x=n[f],P=x.bounds,T=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=f+1;m<u;m++){var S=n[m],C=S.bounds;if(C.min.x>T)break;if(!(g<C.min.y||p>C.max.y)&&!(y&&(S.isStatic||S.isSleeping))&&o(x.collisionFilter,S.collisionFilter)){var M=S.parts.length;if(w&&M===1){var I=t(x,S,h);I&&(i[s++]=I)}else for(var R=v>1?1:0,L=M>1?1:0,D=R;D<v;D++)for(var k=x.parts[D],P=k.bounds,F=L;F<M;F++){var O=S.parts[F],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,h);I&&(i[s++]=I)}}}}}return i.length!==s&&(i.length=s),i},e.canCollide=function(r,h){return r.group===h.group&&r.group!==0?r.group>0:(r.mask&h.category)!==0&&(h.mask&r.category)!==0},e._compareBoundsX=function(r,h){return r.bounds.min.x-h.bounds.min.x}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(0);(function(){e.create=function(a){var r={};return a||l.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(h){var n=e._getRelativeMousePosition(h,r.element,r.pixelRatio);h.changedTouches&&(r.button=0,h.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=h},r.mousedown=function(h){var n=e._getRelativeMousePosition(h,r.element,r.pixelRatio);h.changedTouches?(r.button=0,h.preventDefault()):r.button=h.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=h},r.mouseup=function(h){var n=e._getRelativeMousePosition(h,r.element,r.pixelRatio);h.changedTouches&&h.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=h},r.mousewheel=function(h){r.wheelDelta=Math.max(-1,Math.min(1,h.wheelDelta||-h.detail)),h.preventDefault(),r.sourceEvents.mousewheel=h},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,h){var n=r.getBoundingClientRect(),u=document.documentElement||document.body.parentNode||document.body,o=window.pageXOffset!==void 0?window.pageXOffset:u.scrollLeft,t=window.pageYOffset!==void 0?window.pageYOffset:u.scrollTop,i=a.changedTouches,s,f;return i?(s=i[0].pageX-n.left-o,f=i[0].pageY-n.top-t):(s=a.pageX-n.left-o,f=a.pageY-n.top-t),{x:s/(r.clientWidth/(r.width||r.clientWidth)*h),y:f/(r.clientHeight/(r.height||r.clientHeight)*h)}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(0);(function(){e._registry={},e.register=function(a){if(e.isPlugin(a)||l.warn("Plugin.register:",e.toString(a),"does not implement all required fields."),a.name in e._registry){var r=e._registry[a.name],h=e.versionParse(a.version).number,n=e.versionParse(r.version).number;h>n?(l.warn("Plugin.register:",e.toString(r),"was upgraded to",e.toString(a)),e._registry[a.name]=a):h<n?l.warn("Plugin.register:",e.toString(r),"can not be downgraded to",e.toString(a)):a!==r&&l.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 h=a.for&&e.dependencyParse(a.for);return!a.for||r.name===h.name&&e.versionSatisfies(r.version,h.range)},e.use=function(a,r){if(a.uses=(a.uses||[]).concat(r||[]),a.uses.length===0){l.warn("Plugin.use:",e.toString(a),"does not specify any dependencies to install.");return}for(var h=e.dependencies(a),n=l.topologicalSort(h),u=[],o=0;o<n.length;o+=1)if(n[o]!==a.name){var t=e.resolve(n[o]);if(!t){u.push("❌ "+n[o]);continue}e.isUsed(a,t.name)||(e.isFor(t,a)||(l.warn("Plugin.use:",e.toString(t),"is for",t.for,"but installed on",e.toString(a)+"."),t._warned=!0),t.install?t.install(a):(l.warn("Plugin.use:",e.toString(t),"does not specify an install function."),t._warned=!0),t._warned?(u.push("🔶 "+e.toString(t)),delete t._warned):u.push("✅ "+e.toString(t)),a.used.push(t.name))}u.length>0&&l.info(u.join(" "))},e.dependencies=function(a,r){var h=e.dependencyParse(a),n=h.name;if(r=r||{},!(n in r)){a=e.resolve(a)||a,r[n]=l.map(a.uses||[],function(o){e.isPlugin(o)&&e.register(o);var t=e.dependencyParse(o),i=e.resolve(o);return i&&!e.versionSatisfies(i.version,t.range)?(l.warn("Plugin.dependencies:",e.toString(i),"does not satisfy",e.toString(t),"used by",e.toString(h)+"."),i._warned=!0,a._warned=!0):i||(l.warn("Plugin.dependencies:",e.toString(o),"used by",e.toString(h),"could not be resolved."),a._warned=!0),t.name});for(var u=0;u<r[n].length;u+=1)e.dependencies(r[n][u],r);return r}},e.dependencyParse=function(a){return l.isString(a)?(/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-+]+)?))?$/.test(a)||l.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)||l.warn("Plugin.versionParse:",a,"is not a valid version or range.");var h=r.exec(a),n=Number(h[4]),u=Number(h[5]),o=Number(h[6]);return{isRange:!!(h[1]||h[2]),version:h[3],range:a,operator:h[1]||h[2]||"",major:n,minor:u,patch:o,parts:[n,u,o],prerelease:h[7],number:n*1e8+u*1e4+o}},e.versionSatisfies=function(a,r){r=r||"*";var h=e.versionParse(r),n=e.versionParse(a);if(h.isRange){if(h.operator==="*"||a==="*")return!0;if(h.operator===">")return n.number>h.number;if(h.operator===">=")return n.number>=h.number;if(h.operator==="~")return n.major===h.major&&n.minor===h.minor&&n.patch>=h.patch;if(h.operator==="^")return h.major>0?n.major===h.major&&n.number>=h.number:h.minor>0?n.minor===h.minor&&n.patch>=h.patch:n.patch===h.patch}return a===r||a==="*"}})()}),(function(A,B){var c={};A.exports=c,(function(){c.create=function(e){return{vertex:e,normalImpulse:0,tangentImpulse:0}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(7),a=c(18),r=c(13),h=c(19),n=c(5),u=c(6),o=c(10),t=c(0),i=c(4);(function(){e._deltaMax=1e3/60,e.create=function(s){s=s||{};var f=t.extend({positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],plugin:{},gravity:{x:0,y:1,scale:.001},timing:{timestamp:0,timeScale:1,lastDelta:0,lastElapsed:0,lastUpdatesPerFrame:0}},s);return f.world=s.world||u.create({label:"World"}),f.pairs=s.pairs||h.create(),f.detector=s.detector||r.create(),f.detector.pairs=f.pairs,f.grid={buckets:[]},f.world.gravity=f.gravity,f.broadphase=f.grid,f.metrics={},f},e.update=function(s,f){var m=t.now(),x=s.world,P=s.detector,T=s.pairs,g=s.timing,p=g.timestamp,y;f>e._deltaMax&&t.warnOnce("Matter.Engine.update: delta argument is recommended to be less than or equal to",e._deltaMax.toFixed(3),"ms."),f=typeof f<"u"?f:t._baseDelta,f*=g.timeScale,g.timestamp+=f,g.lastDelta=f;var v={timestamp:g.timestamp,delta:f};n.trigger(s,"beforeUpdate",v);var w=u.allBodies(x),S=u.allConstraints(x);for(x.isModified&&(r.setBodies(P,w),u.setModified(x,!1,!1,!0)),s.enableSleeping&&l.update(w,f),e._bodiesApplyGravity(w,s.gravity),f>0&&e._bodiesUpdate(w,f),n.trigger(s,"beforeSolve",v),o.preSolveAll(w),y=0;y<s.constraintIterations;y++)o.solveAll(S,f);o.postSolveAll(w);var C=r.collisions(P);h.update(T,C,p),s.enableSleeping&&l.afterCollisions(T.list),T.collisionStart.length>0&&n.trigger(s,"collisionStart",{pairs:T.collisionStart,timestamp:g.timestamp,delta:f});var M=t.clamp(20/s.positionIterations,0,1);for(a.preSolvePosition(T.list),y=0;y<s.positionIterations;y++)a.solvePosition(T.list,f,M);for(a.postSolvePosition(w),o.preSolveAll(w),y=0;y<s.constraintIterations;y++)o.solveAll(S,f);for(o.postSolveAll(w),a.preSolveVelocity(T.list),y=0;y<s.velocityIterations;y++)a.solveVelocity(T.list,f);return e._bodiesUpdateVelocities(w),T.collisionActive.length>0&&n.trigger(s,"collisionActive",{pairs:T.collisionActive,timestamp:g.timestamp,delta:f}),T.collisionEnd.length>0&&n.trigger(s,"collisionEnd",{pairs:T.collisionEnd,timestamp:g.timestamp,delta:f}),e._bodiesClearForces(w),n.trigger(s,"afterUpdate",v),s.timing.lastElapsed=t.now()-m,s},e.merge=function(s,f){if(t.extend(s,f),f.world){s.world=f.world,e.clear(s);for(var m=u.allBodies(s.world),x=0;x<m.length;x++){var P=m[x];l.set(P,!1),P.id=t.nextId()}}},e.clear=function(s){h.clear(s.pairs),r.clear(s.detector)},e._bodiesClearForces=function(s){for(var f=s.length,m=0;m<f;m++){var x=s[m];x.force.x=0,x.force.y=0,x.torque=0}},e._bodiesApplyGravity=function(s,f){var m=typeof f.scale<"u"?f.scale:.001,x=s.length;if(!(f.x===0&&f.y===0||m===0))for(var P=0;P<x;P++){var T=s[P];T.isStatic||T.isSleeping||(T.force.y+=T.mass*f.y*m,T.force.x+=T.mass*f.x*m)}},e._bodiesUpdate=function(s,f){for(var m=s.length,x=0;x<m;x++){var P=s[x];P.isStatic||P.isSleeping||i.update(P,f)}},e._bodiesUpdateVelocities=function(s){for(var f=s.length,m=0;m<f;m++)i.updateVelocities(s[m])}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(3),a=c(0),r=c(1);(function(){e._restingThresh=2,e._restingThreshTangent=Math.sqrt(6),e._positionDampen=.9,e._positionWarming=.8,e._frictionNormalMultiplier=5,e._frictionMaxStatic=Number.MAX_VALUE,e.preSolvePosition=function(h){var n,u,o,t=h.length;for(n=0;n<t;n++)u=h[n],u.isActive&&(o=u.contactCount,u.collision.parentA.totalContacts+=o,u.collision.parentB.totalContacts+=o)},e.solvePosition=function(h,n,u){var o,t,i,s,f,m,x,P,T=e._positionDampen*(u||1),g=a.clamp(n/a._baseDelta,0,1),p=h.length;for(o=0;o<p;o++)t=h[o],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,f=i.parentB,m=i.normal,t.separation=i.depth+m.x*(f.positionImpulse.x-s.positionImpulse.x)+m.y*(f.positionImpulse.y-s.positionImpulse.y));for(o=0;o<p;o++)t=h[o],!(!t.isActive||t.isSensor)&&(i=t.collision,s=i.parentA,f=i.parentB,m=i.normal,P=t.separation-t.slop*g,(s.isStatic||f.isStatic)&&(P*=2),s.isStatic||s.isSleeping||(x=T/s.totalContacts,s.positionImpulse.x+=m.x*P*x,s.positionImpulse.y+=m.y*P*x),f.isStatic||f.isSleeping||(x=T/f.totalContacts,f.positionImpulse.x-=m.x*P*x,f.positionImpulse.y-=m.y*P*x))},e.postSolvePosition=function(h){for(var n=e._positionWarming,u=h.length,o=l.translate,t=r.update,i=0;i<u;i++){var s=h[i],f=s.positionImpulse,m=f.x,x=f.y,P=s.velocity;if(s.totalContacts=0,m!==0||x!==0){for(var T=0;T<s.parts.length;T++){var g=s.parts[T];o(g.vertices,f),t(g.bounds,g.vertices,P),g.position.x+=m,g.position.y+=x}s.positionPrev.x+=m,s.positionPrev.y+=x,m*P.x+x*P.y<0?(f.x=0,f.y=0):(f.x*=n,f.y*=n)}}},e.preSolveVelocity=function(h){var n=h.length,u,o;for(u=0;u<n;u++){var t=h[u];if(!(!t.isActive||t.isSensor)){var i=t.contacts,s=t.contactCount,f=t.collision,m=f.parentA,x=f.parentB,P=f.normal,T=f.tangent;for(o=0;o<s;o++){var g=i[o],p=g.vertex,y=g.normalImpulse,v=g.tangentImpulse;if(y!==0||v!==0){var w=P.x*y+T.x*v,S=P.y*y+T.y*v;m.isStatic||m.isSleeping||(m.positionPrev.x+=w*m.inverseMass,m.positionPrev.y+=S*m.inverseMass,m.anglePrev+=m.inverseInertia*((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(h,n){var u=n/a._baseDelta,o=u*u*u,t=-e._restingThresh*u,i=e._restingThreshTangent,s=e._frictionNormalMultiplier*u,f=e._frictionMaxStatic,m=h.length,x,P,T,g;for(T=0;T<m;T++){var p=h[T];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,D=p.contacts,k=p.contactCount,F=1/k,O=v.position.x-v.positionPrev.x,W=v.position.y-v.positionPrev.y,G=v.angle-v.anglePrev,N=w.position.x-w.positionPrev.x,Q=w.position.y-w.positionPrev.y,X=w.angle-w.anglePrev;for(g=0;g<k;g++){var b=D[g],H=b.vertex,V=H.x-v.position.x,Z=H.y-v.position.y,Y=H.x-w.position.x,K=H.y-w.position.y,z=O-Z*G,xe=W+V*G,ye=N-K*X,Se=Q+Y*X,le=z-ye,fe=xe-Se,ie=S*le+C*fe,$=M*le+I*fe,ce=p.separation+ie,ne=Math.min(ce,1);ne=ce<0?0:ne;var ue=ne*L;$<-ue||$>ue?(P=$>0?$:-$,x=p.friction*($>0?1:-1)*o,x<-P?x=-P:x>P&&(x=P)):(x=$,P=f);var he=V*C-Z*S,ge=Y*C-K*S,ve=F/(R+v.inverseInertia*he*he+w.inverseInertia*ge*ge),j=(1+p.restitution)*ie*ve;if(x*=ve,ie<t)b.normalImpulse=0;else{var we=b.normalImpulse;b.normalImpulse+=j,b.normalImpulse>0&&(b.normalImpulse=0),j=b.normalImpulse-we}if($<-i||$>i)b.tangentImpulse=0;else{var Pe=b.tangentImpulse;b.tangentImpulse+=x,b.tangentImpulse<-P&&(b.tangentImpulse=-P),b.tangentImpulse>P&&(b.tangentImpulse=P),x=b.tangentImpulse-Pe}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+=(V*_-Z*q)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=q*w.inverseMass,w.positionPrev.y-=_*w.inverseMass,w.anglePrev-=(Y*_-K*q)*w.inverseInertia)}}}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(9),a=c(0);(function(){e.create=function(r){return a.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},r)},e.update=function(r,h,n){var u=l.update,o=l.create,t=l.setActive,i=r.table,s=r.list,f=s.length,m=f,x=r.collisionStart,P=r.collisionEnd,T=r.collisionActive,g=h.length,p=0,y=0,v=0,w,S,C;for(C=0;C<g;C++)w=h[C],S=w.pair,S?(S.isActive&&(T[v++]=S),u(S,w,n)):(S=o(w,n),i[S.id]=S,x[p++]=S,s[m++]=S);for(m=0,f=s.length,C=0;C<f;C++)S=s[C],S.timeUpdated>=n?s[m++]=S:(t(S,!1,n),S.collision.bodyA.sleepCounter>0&&S.collision.bodyB.sleepCounter>0?s[m++]=S:(P[y++]=S,delete i[S.id]));s.length!==m&&(s.length=m),x.length!==p&&(x.length=p),P.length!==y&&(P.length=y),T.length!==v&&(T.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(A,B,c){var e=A.exports=c(21);e.Axes=c(11),e.Bodies=c(12),e.Body=c(4),e.Bounds=c(1),e.Collision=c(8),e.Common=c(0),e.Composite=c(6),e.Composites=c(22),e.Constraint=c(10),e.Contact=c(16),e.Detector=c(13),e.Engine=c(17),e.Events=c(5),e.Grid=c(23),e.Mouse=c(14),e.MouseConstraint=c(24),e.Pair=c(9),e.Pairs=c(19),e.Plugin=c(15),e.Query=c(25),e.Render=c(26),e.Resolver=c(18),e.Runner=c(27),e.SAT=c(28),e.Sleeping=c(7),e.Svg=c(29),e.Vector=c(2),e.Vertices=c(3),e.World=c(30),e.Engine.run=e.Runner.run,e.Common.deprecated(e.Engine,"run","Engine.run ➤ use Matter.Runner.run(engine) instead")}),(function(A,B,c){var e={};A.exports=e;var l=c(15),a=c(0);(function(){e.name="matter-js",e.version="0.20.0",e.uses=[],e.used=[],e.use=function(){l.use(e,Array.prototype.slice.call(arguments))},e.before=function(r,h){return r=r.replace(/^Matter./,""),a.chainPathBefore(e,r,h)},e.after=function(r,h){return r=r.replace(/^Matter./,""),a.chainPathAfter(e,r,h)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(6),a=c(10),r=c(0),h=c(4),n=c(12),u=r.deprecated;(function(){e.stack=function(o,t,i,s,f,m,x){for(var P=l.create({label:"Stack"}),T=o,g=t,p,y=0,v=0;v<s;v++){for(var w=0,S=0;S<i;S++){var C=x(T,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),h.translate(C,{x:I*.5,y:M*.5}),T=C.bounds.max.x+f,l.addBody(P,C),p=C,y+=1}else T+=f}g+=w+m,T=o}return P},e.chain=function(o,t,i,s,f,m){for(var x=o.bodies,P=1;P<x.length;P++){var T=x[P-1],g=x[P],p=T.bounds.max.y-T.bounds.min.y,y=T.bounds.max.x-T.bounds.min.x,v=g.bounds.max.y-g.bounds.min.y,w=g.bounds.max.x-g.bounds.min.x,S={bodyA:T,pointA:{x:y*t,y:p*i},bodyB:g,pointB:{x:w*s,y:v*f}},C=r.extend(S,m);l.addConstraint(o,a.create(C))}return o.label+=" Chain",o},e.mesh=function(o,t,i,s,f){var m=o.bodies,x,P,T,g,p;for(x=0;x<i;x++){for(P=1;P<t;P++)T=m[P-1+x*t],g=m[P+x*t],l.addConstraint(o,a.create(r.extend({bodyA:T,bodyB:g},f)));if(x>0)for(P=0;P<t;P++)T=m[P+(x-1)*t],g=m[P+x*t],l.addConstraint(o,a.create(r.extend({bodyA:T,bodyB:g},f))),s&&P>0&&(p=m[P-1+(x-1)*t],l.addConstraint(o,a.create(r.extend({bodyA:p,bodyB:g},f)))),s&&P<t-1&&(p=m[P+1+(x-1)*t],l.addConstraint(o,a.create(r.extend({bodyA:p,bodyB:g},f))))}return o.label+=" Mesh",o},e.pyramid=function(o,t,i,s,f,m,x){return e.stack(o,t,i,s,f,m,function(P,T,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&&h.translate(y,{x:(g+(i%2===1?1:-1))*S,y:0}),x(o+(y?g*S:0)+g*f,T,g,p,y,v)}})},e.newtonsCradle=function(o,t,i,s,f){for(var m=l.create({label:"Newtons Cradle"}),x=0;x<i;x++){var P=1.9,T=n.circle(o+x*(s*P),t+f,s,{inertia:1/0,restitution:1,friction:0,frictionAir:1e-4,slop:1}),g=a.create({pointA:{x:o+x*(s*P),y:t},bodyB:T});l.addBody(m,T),l.addConstraint(m,g)}return m},u(e,"newtonsCradle","Composites.newtonsCradle ➤ moved to newtonsCradle example"),e.car=function(o,t,i,s,f){var m=h.nextGroup(!0),x=20,P=-i*.5+x,T=i*.5-x,g=0,p=l.create({label:"Car"}),y=n.rectangle(o,t,i,s,{collisionFilter:{group:m},chamfer:{radius:s*.5},density:2e-4}),v=n.circle(o+P,t+g,f,{collisionFilter:{group:m},friction:.8}),w=n.circle(o+T,t+g,f,{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:T,y:g},bodyA:w,stiffness:1,length:0});return l.addBody(p,y),l.addBody(p,v),l.addBody(p,w),l.addConstraint(p,S),l.addConstraint(p,C),p},u(e,"car","Composites.car ➤ moved to car example"),e.softBody=function(o,t,i,s,f,m,x,P,T,g){T=r.extend({inertia:1/0},T),g=r.extend({stiffness:.2,render:{type:"line",anchors:!1}},g);var p=e.stack(o,t,i,s,f,m,function(y,v){return n.circle(y,v,P,T)});return e.mesh(p,i,s,x,g),p.label="Soft Body",p},u(e,"softBody","Composites.softBody ➤ moved to softBody and cloth examples")})()}),(function(A,B,c){var e={};A.exports=e;var l=c(9),a=c(0),r=a.deprecated;(function(){e.create=function(h){return a.extend({buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48},h)},e.update=function(h,n,u,o){var t,i,s,f=u.world,m=h.buckets,x,P,T=!1;for(t=0;t<n.length;t++){var g=n[t];if(!(g.isSleeping&&!o)&&!(f.bounds&&(g.bounds.max.x<f.bounds.min.x||g.bounds.min.x>f.bounds.max.x||g.bounds.max.y<f.bounds.min.y||g.bounds.min.y>f.bounds.max.y))){var p=e._getRegion(h,g);if(!g.region||p.id!==g.region.id||o){(!g.region||o)&&(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(h,x,g),(g.region===p||v&&!w||o)&&(x||(x=e._createBucket(m,P)),e._bucketAddBody(h,x,g))}g.region=p,T=!0}}}T&&(h.pairsList=e._createActivePairsList(h))},r(e,"update","Grid.update ➤ replaced by Matter.Detector"),e.clear=function(h){h.buckets={},h.pairs={},h.pairsList=[]},r(e,"clear","Grid.clear ➤ replaced by Matter.Detector"),e._regionUnion=function(h,n){var u=Math.min(h.startCol,n.startCol),o=Math.max(h.endCol,n.endCol),t=Math.min(h.startRow,n.startRow),i=Math.max(h.endRow,n.endRow);return e._createRegion(u,o,t,i)},e._getRegion=function(h,n){var u=n.bounds,o=Math.floor(u.min.x/h.bucketWidth),t=Math.floor(u.max.x/h.bucketWidth),i=Math.floor(u.min.y/h.bucketHeight),s=Math.floor(u.max.y/h.bucketHeight);return e._createRegion(o,t,i,s)},e._createRegion=function(h,n,u,o){return{id:h+","+n+","+u+","+o,startCol:h,endCol:n,startRow:u,endRow:o}},e._getBucketId=function(h,n){return"C"+h+"R"+n},e._createBucket=function(h,n){return h[n]=[]},e._bucketAddBody=function(h,n,u){var o=h.pairs,t=l.id,i=n.length,s;for(s=0;s<i;s++){var f=n[s];if(!(u.id===f.id||u.isStatic&&f.isStatic)){var m=t(u,f),x=o[m];x?x[2]+=1:o[m]=[u,f,1]}}n.push(u)},e._bucketRemoveBody=function(h,n,u){var o=h.pairs,t=l.id,i;n.splice(a.indexOf(n,u),1);var s=n.length;for(i=0;i<s;i++){var f=o[t(u,n[i])];f&&(f[2]-=1)}},e._createActivePairsList=function(h){var n,u=h.pairs,o=a.keys(u),t=o.length,i=[],s;for(s=0;s<t;s++)n=u[o[s]],n[2]>0?i.push(n):delete u[o[s]];return i}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(3),a=c(7),r=c(14),h=c(5),n=c(13),u=c(10),o=c(6),t=c(0),i=c(1);(function(){e.create=function(s,f){var m=(s?s.mouse:null)||(f?f.mouse:null);m||(s&&s.render&&s.render.canvas?m=r.create(s.render.canvas):f&&f.element?m=r.create(f.element):(m=r.create(),t.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var x=u.create({label:"Mouse Constraint",pointA:m.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),P={type:"mouseConstraint",mouse:m,element:null,body:null,constraint:x,collisionFilter:{category:1,mask:4294967295,group:0}},T=t.extend(P,f);return h.on(s,"beforeUpdate",function(){var g=o.allBodies(s.world);e.update(T,g),e._triggerEvents(T)}),T},e.update=function(s,f){var m=s.mouse,x=s.constraint,P=s.body;if(m.button===0){if(x.bodyB)a.set(x.bodyB,!1),x.pointA=m.position;else for(var T=0;T<f.length;T++)if(P=f[T],i.contains(P.bounds,m.position)&&n.canCollide(P.collisionFilter,s.collisionFilter))for(var g=P.parts.length>1?1:0;g<P.parts.length;g++){var p=P.parts[g];if(l.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),h.trigger(s,"startdrag",{mouse:m,body:P});break}}}else x.bodyB=s.body=null,x.pointB=null,P&&h.trigger(s,"enddrag",{mouse:m,body:P})},e._triggerEvents=function(s){var f=s.mouse,m=f.sourceEvents;m.mousemove&&h.trigger(s,"mousemove",{mouse:f}),m.mousedown&&h.trigger(s,"mousedown",{mouse:f}),m.mouseup&&h.trigger(s,"mouseup",{mouse:f}),r.clearSourceEvents(f)}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(2),a=c(8),r=c(1),h=c(12),n=c(3);(function(){e.collides=function(u,o){for(var t=[],i=o.length,s=u.bounds,f=a.collides,m=r.overlaps,x=0;x<i;x++){var P=o[x],T=P.parts.length,g=T===1?0:1;if(m(P.bounds,s))for(var p=g;p<T;p++){var y=P.parts[p];if(m(y.bounds,s)){var v=f(y,u);if(v){t.push(v);break}}}}return t},e.ray=function(u,o,t,i){i=i||1e-100;for(var s=l.angle(o,t),f=l.magnitude(l.sub(o,t)),m=(t.x+o.x)*.5,x=(t.y+o.y)*.5,P=h.rectangle(m,x,f,i,{angle:s}),T=e.collides(P,u),g=0;g<T.length;g+=1){var p=T[g];p.body=p.bodyB=p.bodyA}return T},e.region=function(u,o,t){for(var i=[],s=0;s<u.length;s++){var f=u[s],m=r.overlaps(f.bounds,o);(m&&!t||!m&&t)&&i.push(f)}return i},e.point=function(u,o){for(var t=[],i=0;i<u.length;i++){var s=u[i];if(r.contains(s.bounds,o))for(var f=s.parts.length===1?0:1;f<s.parts.length;f++){var m=s.parts[f];if(r.contains(m.bounds,o)&&n.contains(m.vertices,o)){t.push(s);break}}}return t}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(4),a=c(0),r=c(6),h=c(1),n=c(5),u=c(2),o=c(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,D=g.canvas.height,k=g.canvas.width/D,F=R/L,O=1,W=1;F>k?W=F/k:O=k/F,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*W,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*W*.5,g.bounds.max.y+=L*.5-L*W*.5),g.bounds.min.x-=y.x,g.bounds.max.x-=y.x,g.bounds.min.y-=y.y,g.bounds.max.y-=y.y,g.mouse&&(o.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}),o.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),D=M.wireframes?M.wireframeBackground:M.background,k=[],F=[],O,W={timestamp:v.timing.timestamp};if(n.trigger(g,"beforeRender",W),g.currentBackground!==D&&T(g,D),C.globalCompositeOperation="source-in",C.fillStyle="transparent",C.fillRect(0,0,S.width,S.height),C.globalCompositeOperation="source-over",M.hasBounds){for(O=0;O<R.length;O++){var G=R[O];h.overlaps(G.bounds,g.bounds)&&k.push(G)}for(O=0;O<L.length;O++){var N=L[O],Q=N.bodyA,X=N.bodyB,b=N.pointA,H=N.pointB;Q&&(b=u.add(Q.position,N.pointA)),X&&(H=u.add(X.position,N.pointB)),!(!b||!H)&&(h.contains(g.bounds,b)||h.contains(g.bounds,H))&&F.push(N)}e.startViewTransform(g),g.mouse&&(o.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}),o.setOffset(g.mouse,g.bounds.min))}else F=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(F,C),M.hasBounds&&e.endViewTransform(g),n.trigger(g,"afterRender",W),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,D=0;D<S.length;D+=1)C+=S[D].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 F in k){var O=k[F];p.fillStyle="#aaa",p.fillText(F,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,D=y.timing.lastDelta,k=f(w),F=f(S),O=f(M),W=f(I),G=f(R),N=f(C)/k||0,Q=Math.round(k/D),X=1e3/k||0,b=4,H=12,V=60,Z=34,Y=10,K=69;p.fillStyle="#0e0f19",p.fillRect(0,50,H*5+V*6+22,Z),e.status(p,Y,K,V,b,w.length,Math.round(X)+" fps",X/e._goodFps,function(z){return w[z]/k-1}),e.status(p,Y+H+V,K,V,b,M.length,D.toFixed(2)+" dt",e._goodDelta/D,function(z){return M[z]/O-1}),e.status(p,Y+(H+V)*2,K,V,b,I.length,L+" upf",Math.pow(a.clamp(W/Q||1,0,1),4),function(z){return I[z]/W-1}),e.status(p,Y+(H+V)*3,K,V,b,R.length,G.toFixed(2)+" ut",1-L*G/e._goodFps,function(z){return R[z]/G-1}),e.status(p,Y+(H+V)*4,K,V,b,S.length,F.toFixed(2)+" rt",1-F/e._goodFps,function(z){return S[z]/F-1}),e.status(p,Y+(H+V)*5,K,V,b,C.length,N.toFixed(2)+" x",N*N*N,function(z){return(C[z]/w[z]/N||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=u.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=u.add(C.position,w.pointB):I=w.pointB,y.beginPath(),y.moveTo(M.x,M.y),w.render.type==="spring")for(var R=u.sub(I,M),L=u.perp(u.normalise(R)),D=Math.ceil(a.clamp(w.length/5,12,20)),k,F=1;F<D;F+=1)k=F%2===0?1:-1,y.lineTo(M.x+R.x*(F/D)+L.x*k*4,M.y+R.y*(F/D)+L.y*k*4);y.lineTo(I.x,I.y)}w.render.lineWidth&&(y.lineWidth=w.render.lineWidth,y.strokeStyle=w.render.strokeStyle,y.stroke()),w.render.anchors&&(y.fillStyle=w.render.strokeStyle,y.beginPath(),y.arc(M.x,M.y,3,0,2*Math.PI),y.arc(I.x,I.y,3,0,2*Math.PI),y.closePath(),y.fill())}}},e.bodies=function(g,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,D=P(g,L.texture);v.translate(M.position.x,M.position.y),v.rotate(M.angle),v.drawImage(D,D.width*-L.xOffset*L.xScale,D.height*-L.yOffset*L.yScale,D.width*L.xScale,D.height*L.yScale),v.rotate(-M.angle),v.translate(-M.position.x,-M.position.y)}else{if(M.circleRadius)v.beginPath(),v.arc(M.position.x,M.position.y,M.circleRadius,0,2*Math.PI);else{v.beginPath(),v.moveTo(M.vertices[0].x,M.vertices[0].y);for(var k=1;k<M.vertices.length;k++)!M.vertices[k-1].isInternal||S?v.lineTo(M.vertices[k].x,M.vertices[k].y):v.moveTo(M.vertices[k].x,M.vertices[k].y),M.vertices[k].isInternal&&!S&&v.moveTo(M.vertices[(k+1)%M.vertices.length].x,M.vertices[(k+1)%M.vertices.length].y);v.lineTo(M.vertices[0].x,M.vertices[0].y),v.closePath()}w.wireframes?(v.lineWidth=1,v.strokeStyle=g.options.wireframeStrokeStyle,v.stroke()):(v.fillStyle=M.render.fillStyle,M.render.lineWidth&&(v.lineWidth=M.render.lineWidth,v.strokeStyle=M.render.strokeStyle,v.stroke()),v.fill())}v.globalAlpha=1}}},e.bodyWireframes=function(g,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 D=S.axes[I];v.moveTo(S.position.x,S.position.y),v.lineTo(S.position.x+D.x*20,S.position.y+D.y*20)}else for(M=L.length>1?1:0;M<L.length;M++)for(S=L[M],I=0;I<S.axes.length;I++)v.moveTo(S.position.x,S.position.y),v.lineTo((S.vertices[0].x+S.vertices[S.vertices.length-1].x)/2,(S.vertices[0].y+S.vertices[S.vertices.length-1].y)/2)}w.wireframes?(v.strokeStyle="indianred",v.lineWidth=1):(v.strokeStyle="rgba(255, 255, 255, 0.4)",v.globalCompositeOperation="overlay",v.lineWidth=2),v.stroke(),v.globalCompositeOperation="source-over"},e.bodyPositions=function(g,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=l.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,D=S.contacts[0].vertex.y;S.contactCount===2&&(L=(S.contacts[0].vertex.x+S.contacts[1].vertex.x)/2,D=(S.contacts[0].vertex.y+S.contacts[1].vertex.y)/2),C.bodyB===C.supports[0].body||C.bodyA.isStatic===!0?v.moveTo(L-C.normal.x*8,D-C.normal.y*8):v.moveTo(L+C.normal.x*8,D+C.normal.y*8),v.lineTo(L,D)}w.wireframes?v.strokeStyle="rgba(255,165,0,0.7)":v.strokeStyle="orange",v.lineWidth=1,v.stroke()},e.separations=function(g,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 D=y[L].data;switch(p.translate(.5,.5),p.lineWidth=1,p.strokeStyle="rgba(255,165,0,0.9)",p.setLineDash([1,2]),D.type){case"body":S=D.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=D.pointA;D.bodyA&&(k=D.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)},f=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)},T=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(A,B,c){var e={};A.exports=e;var l=c(5),a=c(17),r=c(0);(function(){e._maxFrameDelta=1e3/15,e._frameDeltaFallback=1e3/60,e._timeBufferMargin=1.5,e._elapsedNextEstimate=1,e._smoothingLowerBound=.1,e._smoothingUpperBound=.9,e.create=function(n){var u=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 u.fps=0,u},e.run=function(n,u){return n.timeBuffer=e._frameDeltaFallback,(function o(t){n.frameRequestId=e._onNextFrame(n,o),t&&n.enabled&&e.tick(n,u,t)})(),n},e.tick=function(n,u,o){var t=r.now(),i=n.delta,s=0,f=o-n.timeLastTick;if((!f||!n.timeLastTick||f>Math.max(e._maxFrameDelta,n.maxFrameTime))&&(f=n.frameDelta||e._frameDeltaFallback),n.frameDeltaSmoothing){n.frameDeltaHistory.push(f),n.frameDeltaHistory=n.frameDeltaHistory.slice(-n.frameDeltaHistorySize);var m=n.frameDeltaHistory.slice(0).sort();f=h(n.frameDeltaHistory.slice(m.length*e._smoothingLowerBound,m.length*e._smoothingUpperBound))||f}n.frameDeltaSnapping&&(f=1e3/Math.round(1e3/f)),n.frameDelta=f,n.timeLastTick=o,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:u.timing.timestamp};l.trigger(n,"beforeTick",P),l.trigger(n,"tick",P);for(var T=r.now();i>0&&n.timeBuffer>=i*e._timeBufferMargin;){l.trigger(n,"beforeUpdate",P),a.update(u,i),l.trigger(n,"afterUpdate",P),n.timeBuffer-=i,s+=1;var g=r.now()-t,p=r.now()-T,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}}u.timing.lastUpdatesPerFrame=s,l.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,u){if(typeof window<"u"&&window.requestAnimationFrame)n.frameRequestId=window.requestAnimationFrame(u);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 h=function(n){for(var u=0,o=n.length,t=0;t<o;t+=1)u+=n[t];return u/o||0}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(8),a=c(0).deprecated;(function(){e.collides=function(r,h){return l.collides(r,h)},a(e,"collides","SAT.collides ➤ replaced by Collision.collides")})()}),(function(A,B,c){var e={};A.exports=e,c(1);var l=c(0);(function(){e.pathToVertices=function(a,r){typeof window<"u"&&!("SVGPathSeg"in window)&&l.warn("Svg.pathToVertices: SVGPathSeg not defined, a polyfill is required.");var h,n,u,o,t,i,s,f,m,x,P=[],T,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?(T=m.x,g=m.y):(T=0,g=0);var L={x:T+C,y:g+M};(R||!m)&&(m=L),P.push(L),y=T+C,v=g+M}},S=function(C){var M=C.pathSegTypeAsLetter.toUpperCase();if(M!=="Z"){switch(M){case"M":case"L":case"T":case"C":case"S":case"Q":y=C.x,v=C.y;break;case"H":y=C.x;break;case"V":v=C.y;break}w(y,v,C.pathSegType)}};for(e._svgPathToAbsolute(a),u=a.getTotalLength(),i=[],h=0;h<a.pathSegList.numberOfItems;h+=1)i.push(a.pathSegList.getItem(h));for(s=i.concat();p<u;){if(x=a.getPathSegAtLength(p),t=i[x],t!=f){for(;s.length&&s[0]!=t;)S(s.shift());f=t}switch(t.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":o=a.getPointAtLength(p),w(o.x,o.y,0);break}p+=r}for(h=0,n=s.length;h<n;++h)S(s[h]);return P},e._svgPathToAbsolute=function(a){for(var r,h,n,u,o,t,i=a.pathSegList,s=0,f=0,m=i.numberOfItems,x=0;x<m;++x){var P=i.getItem(x),T=P.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(T))"x"in P&&(s=P.x),"y"in P&&(f=P.y);else switch("x1"in P&&(n=s+P.x1),"x2"in P&&(o=s+P.x2),"y1"in P&&(u=f+P.y1),"y2"in P&&(t=f+P.y2),"x"in P&&(s+=P.x),"y"in P&&(f+=P.y),T){case"m":i.replaceItem(a.createSVGPathSegMovetoAbs(s,f),x);break;case"l":i.replaceItem(a.createSVGPathSegLinetoAbs(s,f),x);break;case"h":i.replaceItem(a.createSVGPathSegLinetoHorizontalAbs(s),x);break;case"v":i.replaceItem(a.createSVGPathSegLinetoVerticalAbs(f),x);break;case"c":i.replaceItem(a.createSVGPathSegCurvetoCubicAbs(s,f,n,u,o,t),x);break;case"s":i.replaceItem(a.createSVGPathSegCurvetoCubicSmoothAbs(s,f,o,t),x);break;case"q":i.replaceItem(a.createSVGPathSegCurvetoQuadraticAbs(s,f,n,u),x);break;case"t":i.replaceItem(a.createSVGPathSegCurvetoQuadraticSmoothAbs(s,f),x);break;case"a":i.replaceItem(a.createSVGPathSegArcAbs(s,f,P.r1,P.r2,P.angle,P.largeArcFlag,P.sweepFlag),x);break;case"z":case"Z":s=r,f=h;break}(T=="M"||T=="m")&&(r=s,h=f)}}})()}),(function(A,B,c){var e={};A.exports=e;var l=c(6);c(0),(function(){e.create=l.create,e.add=l.add,e.remove=l.remove,e.clear=l.clear,e.addComposite=l.addComposite,e.addBody=l.addBody,e.addConstraint=l.addConstraint})()})])})})),U=be();function Oe(d,E,A){return d<E?E:d>A?A:d}function J(d){const E=d.plugin.ballId;return typeof E=="number"?E:d.id}function Ue(d,E,A,B){return Oe(Math.floor((d-E)/A),0,B-1)}var We=.18,Ne=.12,Ve=420,He=.12,Ge=180,ze=2,Xe=5,Ye=600,Ke=2,$e=25e3,Qe=.15;function pe(d,E){return{x:d,y:E,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:E,anchorAgeMs:0,aliveMs:0}}var Ze=class{tracker=new Map;track(d,E,A){this.tracker.set(d,pe(E,A))}untrack(d){this.tracker.delete(d)}clear(){this.tracker.clear()}process(d,E,A){const B=[],c=new Set,e=[];for(const l of E){const a=J(l);c.add(a);const r=this.tracker.get(a)??pe(l.position.x,l.position.y),h=r.aliveMs+d;if(h>=$e||r.kickCount>=Xe){B.push(l),this.tracker.delete(a);continue}const n=l.position.x-r.x,u=l.position.y-r.y,o=Math.sqrt(n*n+u*u),t=l.velocity,i=Math.sqrt(t.x*t.x+t.y*t.y),s=l.position.y>A.worldHeight*He;let f=r.anchorY,m=r.anchorAgeMs+d;l.position.y>f+Ke&&(f=l.position.y,m=0);const x=s&&(i<We&&o<Ne||m>Ye)?r.stuckMs+d:Math.max(0,r.stuckMs-d*2),P=Math.max(0,r.kickCooldownMs-d);this.tracker.set(a,{x:l.position.x,y:l.position.y,stuckMs:x,kickCooldownMs:P,kickCount:r.kickCount,anchorY:f,anchorAgeMs:m,aliveMs:h}),x>=Ve&&P<=0&&e.push({ball:l,id:a,stuckMs:x})}this.applyKicks(e,A);for(const l of this.tracker.keys())c.has(l)||this.tracker.delete(l);return B}applyKicks(d,E){if(d.length===0)return;d.sort((B,c)=>Math.abs(c.ball.position.y-B.ball.position.y)>.1?c.ball.position.y-B.ball.position.y:c.stuckMs-B.stuckMs);const A=Math.min(ze,d.length);for(let B=0;B<A;B++){const{ball:c,id:e}=d[B],l=this.tracker.get(e);if(!l)continue;const a=c.velocity,r=Math.abs(c.position.x-E.center)/E.halfWidth<Qe?Math.random()<.5?1:-1:c.position.x<E.center?1:-1,h=r*(.35+Math.random()*.35)+(Math.random()-.5)*.25,n=1.1+Math.random()*.5;U.Body.setVelocity(c,{x:a.x+h,y:Math.max(a.y+n,n)}),U.Body.translate(c,{x:r*(.2+Math.random()*.4),y:.25+Math.random()*.35}),this.tracker.set(e,{...l,x:c.position.x,y:c.position.y,stuckMs:0,kickCooldownMs:Ge,kickCount:l.kickCount+1})}}};function Je(d){const E=Math.max(0,Math.min(1,d))*.5,A=E**1.5;return{windStrength:Math.min(A*8e-7,3e-7),collisionNudge:A*.1,spawnSigmaRatio:E>0?.04-A*.038:0}}var je=.4;function qe(d,E,A){if(!(A<=0))for(const B of d){if(Math.sqrt(B.velocity.x*B.velocity.x+B.velocity.y*B.velocity.y)<je)continue;const c=B.position.x-E;U.Body.applyForce(B,B.position,{x:-A*c,y:0})}}var te="plinkit-ball";function _e(){const d=Math.random(),E=Math.random();return Math.sqrt(-2*Math.log(d||1e-15))*Math.cos(2*Math.PI*E)}function et(d,E){const A=Math.max(d.radius+8,d.height*.06);let B;return E&&E>0?B=_e()*d.width*E:B=(Math.random()-.5)*d.width*.08,U.Bodies.circle(d.width*.5+B,A,d.radius,{label:te,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var se="plinkit-peg",re="plinkit-guide",ae="plinkit-wall",tt=.22,it=4,nt=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new Ze;dist;removeCollisionNudge=null;constructor(d){this.engine=U.Engine.create({gravity:{x:0,y:d.gravityY,scale:.001}}),this.config=d,this.dist=Je(d.houseEdge??0),this.rebuildStaticBodies(d.width,d.height);const E=this.dist.collisionNudge;if(E>0){const A=B=>{const c=this.center,e=this.config.width*.5;for(const l of B.pairs){const a=l.bodyA.label==="plinkit-ball"?l.bodyA:l.bodyB.label==="plinkit-ball"?l.bodyB:null;if(!a||a.plugin.settled||!(l.bodyA.label===se||l.bodyB.label===se||l.bodyA.label===re||l.bodyB.label===re))continue;const r=(a.position.x-c)/e;U.Body.setVelocity(a,{x:a.velocity.x-E*r,y:a.velocity.y})}};U.Events.on(this.engine,"collisionEnd",A),this.removeCollisionNudge=()=>U.Events.off(this.engine,"collisionEnd",A)}}resize(d,E){this.config={...this.config,width:d,height:E},this.rebuildStaticBodies(d,E)}spawnBall(){const d=et({width:this.config.width,height:this.config.height,radius:this.config.ballRadius},this.dist.spawnSigmaRatio);d.plugin.ballId=this.nextBallId,this.nextBallId+=1,this.antiStuck.track(J(d),d.position.x,d.position.y),U.World.add(this.engine.world,d)}canSpawnBall(){const d=this.config.height*tt;let E=0;const A=U.Composite.allBodies(this.engine.world).filter(B=>B.label===te);for(const B of A)if(!B.plugin.settled&&B.position.y<=d&&(E+=1,E>=it))return!1;return!0}step(d){U.Engine.update(this.engine,d);const E=U.Composite.allBodies(this.engine.world).filter(e=>e.label===te),A=E.filter(e=>!e.plugin.settled);qe(A,this.center,this.dist.windStrength);const B=this.antiStuck.process(d,A,{center:this.center,halfWidth:this.config.width*.5,worldHeight:this.config.height}).map(e=>this.settleBall(e)),c=this.cleanupBalls(E);return B.length>0?[...B,...c]:c}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:U.Composite.allBodies(this.engine.world).filter(E=>E.label===te).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?.(),U.World.clear(this.engine.world,!1),U.Engine.clear(this.engine)}cleanupBalls(d){const E=[],A=this.config.height+this.config.ballRadius,B=this.getBucketTop();for(const c of d){if(c.position.y>A){this.antiStuck.untrack(J(c)),U.World.remove(this.engine.world,c);continue}if(!c.plugin.settled&&c.position.y>=B){E.push(this.settleBall(c));continue}const e=c.circleRadius??this.config.ballRadius,l=this.config.height-e-1;!c.plugin.settled&&c.position.y>=l&&E.push(this.settleBall(c))}return E}rebuildStaticBodies(d,E){this.antiStuck.clear(),this.pegs.length>0&&(U.World.remove(this.engine.world,this.pegs),this.pegs=[]),this.guidePegs.length>0&&(U.World.remove(this.engine.world,this.guidePegs),this.guidePegs=[]),this.walls&&(U.World.remove(this.engine.world,[this.walls.leftWall,this.walls.rightWall,this.walls.floor]),this.walls=null),this.center=d*.5;const A=Math.max(18,d*.02),B=d/this.config.multipliers.length,c=this.config.layout.mainPegs,e=Te({...c,width:d,height:E});this.layoutGeometry=e;const l=c.radius,a=this.config.layout.edgeGuides.radius;this.pegs=Ae(e,l).map(t=>U.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:se,restitution:.3})),this.pegBaseY=this.pegs.reduce((t,i)=>Math.max(t,i.position.y),0);const r=this.getBucketTop(),h=U.Bodies.rectangle(-A*.5,E*.5,A,E*2,{isStatic:!0,label:ae,restitution:.4}),n=U.Bodies.rectangle(d+A*.5,E*.5,A,E*2,{isStatic:!0,label:ae,restitution:.4}),u=U.Bodies.rectangle(d*.5,E+A*.5,d,A,{isStatic:!0,isSensor:!0,label:ae});this.walls={leftWall:h,rightWall:n,floor:u},U.World.add(this.engine.world,[h,n,u]),this.guidePegs=Ee(e,a,{spread:this.config.layout.edgeGuides.spread,yOffset:this.config.layout.edgeGuides.yOffset}).map(t=>U.Bodies.circle(t.x,t.y,t.radius,{isStatic:!0,label:re,restitution:.3})),U.World.add(this.engine.world,this.pegs),U.World.add(this.engine.world,this.guidePegs);const o=E-r;this.buckets=this.config.multipliers.map((t,i)=>({index:i,multiplier:t,x:B*i,y:r,width:B,height:o}))}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,U.Body.set(d,"isSensor",!0);const E=this.layoutGeometry,A=this.config.layout.mainPegs,B=E?.sidePadding??A.radius+A.sidePaddingPx,c=E?.baseSpacing??(this.config.width-B*2)/Math.max(A.bottomPegCount-1,1),e=Ue(d.position.x,B,c,this.config.multipliers.length),l=this.config.multipliers[e]??0;return{ballId:J(d),bucketIndex:e,multiplier:l,wager:this.config.ballCost,payout:this.config.ballCost*l}}},st=`
|
|
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=`
|
|
2
2
|
precision highp float;
|
|
3
3
|
in vec2 a_position;
|
|
4
4
|
uniform vec2 u_resolution;
|
|
@@ -14,7 +14,7 @@ void main() {
|
|
|
14
14
|
v_local = a_position;
|
|
15
15
|
v_uv = a_position * 0.5 + 0.5;
|
|
16
16
|
}
|
|
17
|
-
`,
|
|
17
|
+
`,xt=`
|
|
18
18
|
precision highp float;
|
|
19
19
|
uniform vec4 u_color;
|
|
20
20
|
uniform float u_shapeMode;
|
|
@@ -41,5 +41,5 @@ void main() {
|
|
|
41
41
|
outColor = vec4(u_color.rgb, u_color.a * a);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
`,
|
|
45
|
-
${
|
|
44
|
+
`,yt=class{canvas;gl;program;positionBuffer;positionLocation;resolutionLocation;centerLocation;sizeLocation;colorLocation;shapeModeLocation;useTextureLocation;textureLocation;scale=1;destroyed=!1;pegTexture=null;ballTexture=null;pegTextureReady=!1;ballTextureReady=!1;constructor(d,E){this.canvas=d;const T=d.getContext("webgl2",{antialias:!0,alpha:!0});if(!T)throw new Error("WebGL2 is not supported by this browser");this.gl=T;const A=ye(this.gl,this.gl.VERTEX_SHADER,mt),f=ye(this.gl,this.gl.FRAGMENT_SHADER,xt);this.program=Pt(this.gl,A,f);const e=this.gl.getAttribLocation(this.program,"a_position"),o=this.gl.getUniformLocation(this.program,"u_resolution"),a=this.gl.getUniformLocation(this.program,"u_center"),r=this.gl.getUniformLocation(this.program,"u_size"),c=this.gl.getUniformLocation(this.program,"u_color"),n=this.gl.getUniformLocation(this.program,"u_shapeMode"),h=this.gl.getUniformLocation(this.program,"u_useTexture"),l=this.gl.getUniformLocation(this.program,"u_texture");if(e<0||!o||!a||!r||!c||!n||!h||!l)throw new Error("Unable to initialize WebGL program locations");this.positionLocation=e,this.resolutionLocation=o,this.centerLocation=a,this.sizeLocation=r,this.colorLocation=c,this.shapeModeLocation=n,this.useTextureLocation=h,this.textureLocation=l,this.gl.useProgram(this.program),this.gl.uniform1i(this.textureLocation,0);const t=this.gl.createBuffer();if(!t)throw new Error("Unable to create WebGL buffer");this.positionBuffer=t,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),this.gl.STATIC_DRAW),this.gl.enable(this.gl.BLEND),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA);const i=E?.appearance;i?.pegTextureUrl&&this.startTextureLoad(i.pegTextureUrl,i.textureCrossOrigin,"peg"),i?.ballTextureUrl&&this.startTextureLoad(i.ballTextureUrl,i.textureCrossOrigin,"ball")}resize(d,E,T,A=1){this.scale=T*A,this.canvas.width=Math.floor(d*T),this.canvas.height=Math.floor(E*T),this.gl.viewport(0,0,this.canvas.width,this.canvas.height)}render(d){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionLocation),this.gl.vertexAttribPointer(this.positionLocation,2,this.gl.FLOAT,!1,0,0),this.gl.uniform2f(this.resolutionLocation,this.canvas.width,this.canvas.height),this.gl.uniform1i(this.textureLocation,0);for(const E of d.walls)this.drawRect(E,ie(54,68,102));for(const E of d.pegs)this.drawCircle(E.x,E.y,E.radius,ie(141,226,255),"peg");for(const E of d.guidePegs)this.drawCircle(E.x,E.y,E.radius,ie(255,90,120),"peg");for(const E of d.balls)this.drawCircle(E.x,E.y,E.radius,ie(250,201,95),"ball")}destroy(){this.destroyed=!0,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.pegTexture&&(this.gl.deleteTexture(this.pegTexture),this.pegTexture=null),this.ballTexture&&(this.gl.deleteTexture(this.ballTexture),this.ballTexture=null),this.pegTextureReady=!1,this.ballTextureReady=!1,this.gl.deleteBuffer(this.positionBuffer),this.gl.deleteProgram(this.program)}startTextureLoad(d,E,T){wt(d,E).then(A=>{if(this.destroyed)return;const f=St(this.gl,A);if(this.destroyed){this.gl.deleteTexture(f);return}T==="peg"?(this.pegTexture&&this.gl.deleteTexture(this.pegTexture),this.pegTexture=f,this.pegTextureReady=!0):(this.ballTexture&&this.gl.deleteTexture(this.ballTexture),this.ballTexture=f,this.ballTextureReady=!0)}).catch(()=>{})}drawRect(d,E){this.gl.uniform2f(this.centerLocation,d.x*this.scale,d.y*this.scale),this.gl.uniform2f(this.sizeLocation,d.width*this.scale*.5,d.height*this.scale*.5),this.gl.uniform4f(this.colorLocation,E.r,E.g,E.b,E.a),this.gl.uniform1f(this.shapeModeLocation,0),this.gl.uniform1f(this.useTextureLocation,0),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}drawCircle(d,E,T,A,f){this.gl.uniform2f(this.centerLocation,d*this.scale,E*this.scale),this.gl.uniform2f(this.sizeLocation,T*this.scale,T*this.scale),this.gl.uniform4f(this.colorLocation,A.r,A.g,A.b,A.a),this.gl.uniform1f(this.shapeModeLocation,1);const e=f==="peg"?this.pegTexture:this.ballTexture,o=f==="peg"?this.pegTextureReady:this.ballTextureReady;e&&o?(this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1f(this.useTextureLocation,1)):this.gl.uniform1f(this.useTextureLocation,0),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}};function ie(d,E,T,A=1){return{r:d/255,g:E/255,b:T/255,a:A}}function St(d,E){const T=d.createTexture();if(!T)throw new Error("Unable to create WebGL texture");return d.bindTexture(d.TEXTURE_2D,T),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,E),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.bindTexture(d.TEXTURE_2D,null),T}function wt(d,E){return new Promise((T,A)=>{const f=new Image;typeof E=="string"&&E.length>0&&(f.crossOrigin=E),f.onload=()=>T(f),f.onerror=()=>A(new Error(`Failed to load image: ${d}`)),f.src=d})}function ye(d,E,T){const A=d.createShader(E);if(!A)throw new Error("Unable to create shader");if(d.shaderSource(A,`#version 300 es
|
|
45
|
+
${T}`),d.compileShader(A),!d.getShaderParameter(A,d.COMPILE_STATUS)){const f=d.getShaderInfoLog(A);throw d.deleteShader(A),new Error(`Shader compile error: ${f??"unknown"}`)}return A}function Pt(d,E,T){const A=d.createProgram();if(!A)throw new Error("Unable to create program");if(d.attachShader(A,E),d.attachShader(A,T),d.linkProgram(A),!d.getProgramParameter(A,d.LINK_STATUS)){const f=d.getProgramInfoLog(A);throw d.deleteProgram(A),new Error(`Program link error: ${f??"unknown"}`)}return d.deleteShader(E),d.deleteShader(T),A}var le=1e3/120,Ct=50,Mt=8,Tt=300,Bt=class{canvas;viewport;renderer;world;loop;worldHeight;resizeObserver;dprQuery=null;onDprChange;width;height;accumulatorMs=0;lastFrameTime=0;callbacks;ballCost;showGuidePegs;balance;lastSpawnAtMs=-1/0;audio;constructor(d){this.canvas=d.canvas,this.viewport=d.viewport,this.width=1,this.height=1,this.callbacks={onBalanceChange:d.onBalanceChange,onBallSettled:d.onBallSettled},this.ballCost=d.ballCost,this.showGuidePegs=d.showGuidePegs,this.balance=d.initialBalance,this.onDprChange=()=>this.listenDpr(),this.audio=d.audio?new Fe({pegHitUrl:d.audio.pegHitUrl,bucketHitUrl:d.audio.bucketHitUrl,uiTapUrl:d.audio.uiTapUrl,masterVolume:d.audio.masterVolume??1,muted:d.audio.muted??!1}):null;const E=ze({mainPegs:d.layout.mainPegs,ballRadius:d.ballRadius,heightPolicy:d.viewport.heightPolicy}),T={...d.layout,mainPegs:E.resolvedMainPegs};this.worldHeight=E.worldHeight,this.canvas.style.maxWidth="100%",this.renderer=new yt(this.canvas,{appearance:d.appearance}),this.world=new pt({width:600,height:this.worldHeight,gravityY:d.gravityY,layout:T,ballRadius:d.ballRadius,multipliers:d.multipliers,ballCost:this.ballCost,houseEdge:d.houseEdge,onCollision:this.audio?f=>this.handleCollision(f):void 0}),this.resize(),this.loop=new Oe(f=>this.frame(f)),this.loop.start();const A=this.canvas.parentElement;if(!A)throw new Error("Canvas must have a parent element for viewport sizing");this.resizeObserver=new ResizeObserver(f=>{const e=f[0];if(!e)return;const o=e.contentBoxSize?.[0]?.inlineSize,a=o!=null&&o>0?o:A.getBoundingClientRect().width;this.syncViewport(a)}),this.resizeObserver.observe(A),this.listenDpr(),this.emitBalanceChange()}spawnBall(){const d=performance.now();return d-this.lastSpawnAtMs<Tt?{ok:!1,reason:"SPAWN_COOLDOWN",state:this.getStateSnapshot()}:this.world.canSpawnBall()?this.balance<this.ballCost?{ok:!1,reason:"INSUFFICIENT_BALANCE",state:this.getStateSnapshot()}:(this.balance-=this.ballCost,this.lastSpawnAtMs=d,this.emitBalanceChange(),this.audio?.resume(),this.world.spawnBall(),{ok:!0,state:this.getStateSnapshot()}):{ok:!1,reason:"TOP_ZONE_LIMIT",state:this.getStateSnapshot()}}resize(){const d=this.canvas.parentElement;d&&this.syncViewport(d.getBoundingClientRect().width)}destroy(){this.loop.stop(),this.resizeObserver.disconnect(),this.dprQuery?.removeEventListener("change",this.onDprChange),this.dprQuery=null,this.world.destroy(),this.renderer.destroy(),this.audio?.destroy()}getState(){return this.getStateSnapshot()}setBallCost(d){if(!Number.isFinite(d)||d<0)throw new TypeError(`Plinkit.setBallCost: expected a non-negative finite number, got ${d}`);this.ballCost!==d&&(this.ballCost=d,this.world.setBallCost(d),this.emitBalanceChange())}setMuted(d){this.audio?.setMuted(d)}isMuted(){return this.audio?.isMuted()??!0}setVolume(d){this.audio?.setVolume(d)}playUiTap(){this.audio?.playUiTap()}handleCollision(d){this.audio?.playPegHit(d.ballId,d.speed)}frame(d){if(this.lastFrameTime===0){this.lastFrameTime=d,this.renderSnapshot();return}const E=Math.min(Ct,d-this.lastFrameTime);this.lastFrameTime=d,this.accumulatorMs+=E;let T=0;for(;this.accumulatorMs>=le&&T<Mt;){const A=this.world.step(le);for(const f of A){this.balance+=f.payout;const e=this.getStateSnapshot();this.callbacks.onBallSettled?.(f,e),this.callbacks.onBalanceChange?.(e),this.audio?.playBucketHit()}this.accumulatorMs-=le,T+=1}this.renderSnapshot()}renderSnapshot(){const d=this.world.snapshot();this.showGuidePegs||(d.guidePegs=[]),this.renderer.render(d)}emitBalanceChange(){this.callbacks.onBalanceChange?.(this.getStateSnapshot())}syncViewport(d){const E=Xe({parentWidthPx:d,viewport:this.viewport,worldHeight:this.worldHeight});this.width=Math.max(1,E.displayWidth),this.height=Math.max(1,E.displayHeight),this.canvas.style.width=`${this.width}px`,this.canvas.style.height=`${this.height}px`;const T=Math.min(window.devicePixelRatio||1,this.viewport.dprCap);this.renderer.resize(this.width,this.height,T,E.worldScale)}listenDpr(){this.dprQuery?.removeEventListener("change",this.onDprChange);const d=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);d.addEventListener("change",this.onDprChange),this.dprQuery=d,this.resize()}getStateSnapshot(){return{balance:this.balance,ballCost:this.ballCost}}};exports.Plinkit=Bt;
|