plinkit 1.0.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ (function(Z,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(Z=typeof globalThis<"u"?globalThis:Z||self,J(Z.Plinkit={}))})(this,function(Z){Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"});var J=(d,E)=>()=>(E||(d((E={exports:{}}).exports,E),d=null),E.exports),Se=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 ue(d,E){const A=d.bottomPegCount-d.topPegCount+1,B=d.radius+d.sidePaddingPx,u=(E-B*2)/Math.max(d.bottomPegCount-1,1);return{rows:A,sidePadding:B,baseSpacing:u,targetVerticalStep:u*d.verticalStepRatio}}function we(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 u=ue(d,E),e=E*.5,l=d.topPaddingPx,a=Math.max(l+60,A-d.bottomPaddingPx),r=u.rows>1?(a-l)/(u.rows-1):0,h=Math.min(u.targetVerticalStep,r),n=a-h*Math.max(u.rows-1,0),c=[];for(let o=0;o<u.rows;o++){const t=B+o,i=n+o*h,s=(t-1)*u.baseSpacing,f=e-s*.5;c.push({row:o,count:t,y:i,startX:f,rowWidth:s,leftX:f,rightX:f+s})}return{rows:u.rows,center:e,minTopY:l,bottomY:a,sidePadding:u.sidePadding,baseSpacing:u.baseSpacing,verticalStep:h,startY:n,rowAnchors:c}}function Pe(d,E){const A=[];for(const B of d.rowAnchors)for(let u=0;u<B.count;u++)A.push({x:B.startX+u*d.baseSpacing,y:B.y,radius:E});return A}function Ce(d,E,A){if(d.rows<2)return[];const B=[],u=(A.spread-1)*d.baseSpacing,e=t=>t<d.center?t-u:t>d.center?t+u:t,l=d.rowAnchors[0],a=l.leftX,r=l.rightX,h=d.startY-d.minTopY,n=E*2.5,c=Math.min(d.verticalStep,Math.max(n,h/3)),o=h>=n?Math.min(3,Math.floor(h/c)):0;for(let t=1;t<=o;t++){const i=d.startY-t*c+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*c,s=d.startY-(t+1)*c,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 pt=600,Me=-1,Te=8;function Ae(d){const{mainPegs:E,ballRadius:A,heightPolicy:B}=d;if(Be(B),Le(E),!Number.isFinite(A)||A<=0)throw new Error("ballRadius must be greater than 0");const u=ue(E,600);if(u.baseSpacing<=0)throw new Error("mainPegs produce non-positive base spacing; reduce sidePaddingPx or peg counts");const{rows:e,baseSpacing:l,targetVerticalStep:a}=u,r=a*Math.max(e-1,0),h=B.topPaddingPx,n=a*2,c=A*2+Te,o=E.radius+A+Me,t=Math.max(B.bottomPaddingPx,o+c);return{worldHeight:h+n+r+t,resolvedMainPegs:{...E,topPaddingPx:h,bottomPaddingPx:t},rows:e,baseSpacing:l,verticalStep:a,requiredBottomPaddingPx:t}}function Ee(d){const{parentWidthPx:E,viewport:A,worldHeight:B}=d;if(Ie(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 u=E;return{displayWidth:u,displayHeight:u*(B/600),worldScale:u/600}}function Be(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 Ie(d){if(!Number.isFinite(d.dprCap)||d.dprCap<=0)throw new Error("viewport.dprCap must be greater than 0")}function Le(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 Re=J(((d,E)=>{(function(B,u){typeof d=="object"&&typeof E=="object"?E.exports=u():typeof define=="function"&&define.amd?define("Matter",[],u):typeof d=="object"?d.Matter=u():B.Matter=u()})(d,function(){return(function(A){var B={};function u(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,u),l.l=!0,l.exports}return u.m=A,u.c=B,u.d=function(e,l,a){u.o(e,l)||Object.defineProperty(e,l,{enumerable:!0,get:a})},u.r=function(e){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,l){if(l&1&&(e=u(e)),l&8||l&4&&typeof e=="object"&&e&&e.__esModule)return e;var a=Object.create(null);if(u.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),l&2&&typeof e!="string")for(var r in e)u.d(a,r,function(h){return e[h]}.bind(null,r));return a},u.n=function(e){var l=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(l,"a",l),l},u.o=function(e,l){return Object.prototype.hasOwnProperty.call(e,l)},u.p="",u(u.s=20)})([(function(A,B){var u={};A.exports=u,(function(){u._baseDelta=1e3/60,u._nextId=0,u._seed=0,u._nowStartTime=+new Date,u._warnedOnce={},u._decomp=null,u.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 c=arguments[n];if(c)for(var o in c)h&&c[o]&&c[o].constructor===Object&&(!l[o]||l[o].constructor===Object)?(l[o]=l[o]||{},u.extend(l[o],h,c[o])):l[o]=c[o]}return l},u.clone=function(l,a){return u.extend({},a,l)},u.keys=function(l){if(Object.keys)return Object.keys(l);var a=[];for(var r in l)a.push(r);return a},u.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},u.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},u.set=function(l,a,r,h,n){var c=a.split(".").slice(h,n);return u.get(l,a,0,-1)[c[c.length-1]]=r,r},u.shuffle=function(l){for(var a=l.length-1;a>0;a--){var r=Math.floor(u.random()*(a+1)),h=l[a];l[a]=l[r],l[r]=h}return l},u.choose=function(l){return l[Math.floor(u.random()*l.length)]},u.isElement=function(l){return typeof HTMLElement<"u"?l instanceof HTMLElement:!!(l&&l.nodeType&&l.nodeName)},u.isArray=function(l){return Object.prototype.toString.call(l)==="[object Array]"},u.isFunction=function(l){return typeof l=="function"},u.isPlainObject=function(l){return typeof l=="object"&&l.constructor===Object},u.isString=function(l){return toString.call(l)==="[object String]"},u.clamp=function(l,a,r){return l<a?a:l>r?r:l},u.sign=function(l){return l<0?-1:1},u.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-u._nowStartTime},u.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 u._seed=(u._seed*9301+49297)%233280,u._seed/233280};u.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)},u.logLevel=1,u.log=function(){console&&u.logLevel>0&&u.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},u.info=function(){console&&u.logLevel>0&&u.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},u.warn=function(){console&&u.logLevel>0&&u.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},u.warnOnce=function(){var l=Array.prototype.slice.call(arguments).join(" ");u._warnedOnce[l]||(u.warn(l),u._warnedOnce[l]=!0)},u.deprecated=function(l,a,r){l[a]=u.chain(function(){u.warnOnce("🔅 deprecated 🔅",r)},l[a])},u.nextId=function(){return u._nextId++},u.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},u.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},u.topologicalSort=function(l){var a=[],r=[],h=[];for(var n in l)!r[n]&&!h[n]&&u._topologicalSort(n,r,h,l,a);return a},u._topologicalSort=function(l,a,r,h,n){var c=h[l]||[];r[l]=!0;for(var o=0;o<c.length;o+=1){var t=c[o];r[t]||a[t]||u._topologicalSort(t,a,r,h,n)}r[l]=!1,a[l]=!0,n.push(l)},u.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,c=new Array(arguments.length),o=0,t=arguments.length;o<t;o++)c[o]=arguments[o];for(o=0;o<l.length;o+=1){var i=l[o].apply(n,c);typeof i<"u"&&(n=i)}return n};return h._chained=l,h},u.chainPathBefore=function(l,a,r){return u.set(l,a,u.chain(r,u.get(l,a)))},u.chainPathAfter=function(l,a,r){return u.set(l,a,u.chain(u.get(l,a),r))},u.setDecomp=function(l){u._decomp=l},u.getDecomp=function(){var l=u._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 u={};A.exports=u,(function(){u.create=function(e){var l={min:{x:0,y:0},max:{x:0,y:0}};return e&&u.update(l,e),l},u.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)},u.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},u.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},u.translate=function(e,l){e.min.x+=l.x,e.max.x+=l.x,e.min.y+=l.y,e.max.y+=l.y},u.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 u={};A.exports=u,(function(){u.create=function(e,l){return{x:e||0,y:l||0}},u.clone=function(e){return{x:e.x,y:e.y}},u.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},u.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},u.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},u.rotateAbout=function(e,l,a,r){var h=Math.cos(l),n=Math.sin(l);r||(r={});var c=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=c,r},u.normalise=function(e){var l=u.magnitude(e);return l===0?{x:0,y:0}:{x:e.x/l,y:e.y/l}},u.dot=function(e,l){return e.x*l.x+e.y*l.y},u.cross=function(e,l){return e.x*l.y-e.y*l.x},u.cross3=function(e,l,a){return(l.x-e.x)*(a.y-e.y)-(l.y-e.y)*(a.x-e.x)},u.add=function(e,l,a){return a||(a={}),a.x=e.x+l.x,a.y=e.y+l.y,a},u.sub=function(e,l,a){return a||(a={}),a.x=e.x-l.x,a.y=e.y-l.y,a},u.mult=function(e,l){return{x:e.x*l,y:e.y*l}},u.div=function(e,l){return{x:e.x/l,y:e.y/l}},u.perp=function(e,l){return l=l===!0?-1:1,{x:l*-e.y,y:l*e.x}},u.neg=function(e){return{x:-e.x,y:-e.y}},u.angle=function(e,l){return Math.atan2(l.y-e.y,l.x-e.x)},u._temp=[u.create(),u.create(),u.create(),u.create(),u.create(),u.create()]})()}),(function(A,B,u){var e={};A.exports=e;var l=u(2),a=u(0);(function(){e.create=function(r,h){for(var n=[],c=0;c<r.length;c++){var o=r[c],t={x:o.x,y:o.y,index:c,body:h,isInternal:!1};n.push(t)}return n},e.fromPath=function(r,h){var n=/L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi,c=[];return r.replace(n,function(o,t,i){c.push({x:parseFloat(t),y:parseFloat(i)})}),e.create(c,h)},e.centre=function(r){for(var h=e.area(r,!0),n={x:0,y:0},c,o,t,i=0;i<r.length;i++)t=(i+1)%r.length,c=l.cross(r[i],r[t]),o=l.mult(l.add(r[i],r[t]),c),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,c=r.length-1,o=0;o<r.length;o++)n+=(r[c].x-r[o].x)*(r[c].y+r[o].y),c=o;return h?n/2:Math.abs(n)/2},e.inertia=function(r,h){for(var n=0,c=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])),c+=t;return h/6*(n/c)},e.translate=function(r,h,n){n=typeof n<"u"?n:1;var c=r.length,o=h.x*n,t=h.y*n,i;for(i=0;i<c;i++)r[i].x+=o,r[i].y+=t;return r},e.rotate=function(r,h,n){if(h!==0){var c=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*c-x*o),f.y=i+(m*o+x*c);return r}},e.contains=function(r,h){for(var n=h.x,c=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)+(c-t.y)*(t.x-i.x)>0)return!1;t=i}return!0},e.scale=function(r,h,n,c){if(h===1&&n===1)return r;c=c||e.centre(r);for(var o,t,i=0;i<r.length;i++)o=r[i],t=l.sub(o,c),r[i].x=c.x+t.x*h,r[i].y=c.y+t.y*n;return r},e.chamfer=function(r,h,n,c,o){typeof h=="number"?h=[h]:h=h||[8],n=typeof n<"u"?n:-1,c=c||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,c,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,c){return l.angle(h,n)-l.angle(h,c)}),r},e.isConvex=function(r){var h=0,n=r.length,c,o,t,i;if(n<3)return null;for(c=0;c<n;c++)if(o=(c+1)%n,t=(c+2)%n,i=(r[o].x-r[c].x)*(r[t].y-r[o].y),i-=(r[o].y-r[c].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=[],c,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(c=r[o];n.length>=2&&l.cross3(n[n.length-2],n[n.length-1],c)<=0;)n.pop();n.push(c)}for(o=r.length-1;o>=0;o-=1){for(c=r[o];h.length>=2&&l.cross3(h[h.length-2],h[h.length-1],c)<=0;)h.pop();h.push(c)}return h.pop(),n.pop(),h.concat(n)}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(3),a=u(2),r=u(7),h=u(0),n=u(1),c=u(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),c.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=c.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),c.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=c.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),c.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,u){var e={};A.exports=e;var l=u(0);(function(){e.on=function(a,r,h){for(var n=r.split(" "),c,o=0;o<n.length;o++)c=n[o],a.events=a.events||{},a.events[c]=a.events[c]||[],a.events[c].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(" "),c=0;c<n.length;c++){var o=a.events[n[c]],t=[];if(h&&o)for(var i=0;i<o.length;i++)o[i]!==h&&t.push(o[i]);a.events[n[c]]=t}},e.trigger=function(a,r,h){var n,c,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(c=n[s],o=i[c],o){t=l.clone(h,!1),t.name=c,t.source=a;for(var f=0;f<o.length;f++)o[f].apply(a,[t])}}}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(5),a=u(0),r=u(1),h=u(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,c,o,t){if(n.isModified=c,c&&n.cache&&(n.cache.allBodies=null,n.cache.allConstraints=null,n.cache.allComposites=null),o&&n.parent&&e.setModified(n.parent,c,o,t),t)for(var i=0;i<n.composites.length;i++){var s=n.composites[i];e.setModified(s,c,o,t)}},e.add=function(n,c){var o=[].concat(c);l.trigger(n,"beforeAdd",{object:c});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:c}),n},e.remove=function(n,c,o){var t=[].concat(c);l.trigger(n,"beforeRemove",{object:c});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:c}),n},e.addComposite=function(n,c){return n.composites.push(c),c.parent=n,e.setModified(n,!0,!0,!1),n},e.removeComposite=function(n,c,o){var t=a.indexOf(n.composites,c);if(t!==-1){var i=e.allBodies(c);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],c,!0);return n},e.removeCompositeAt=function(n,c){return n.composites.splice(c,1),e.setModified(n,!0,!0,!1),n},e.addBody=function(n,c){return n.bodies.push(c),e.setModified(n,!0,!0,!1),n},e.removeBody=function(n,c,o){var t=a.indexOf(n.bodies,c);if(t!==-1&&(e.removeBodyAt(n,t),c.sleepCounter=0),o)for(var i=0;i<n.composites.length;i++)e.removeBody(n.composites[i],c,!0);return n},e.removeBodyAt=function(n,c){return n.bodies.splice(c,1),e.setModified(n,!0,!0,!1),n},e.addConstraint=function(n,c){return n.constraints.push(c),e.setModified(n,!0,!0,!1),n},e.removeConstraint=function(n,c,o){var t=a.indexOf(n.constraints,c);if(t!==-1&&e.removeConstraintAt(n,t),o)for(var i=0;i<n.composites.length;i++)e.removeConstraint(n.composites[i],c,!0);return n},e.removeConstraintAt=function(n,c){return n.constraints.splice(c,1),e.setModified(n,!0,!0,!1),n},e.clear=function(n,c,o){if(o)for(var t=0;t<n.composites.length;t++)e.clear(n.composites[t],c,!0);return c?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 c=[].concat(n.bodies),o=0;o<n.composites.length;o++)c=c.concat(e.allBodies(n.composites[o]));return n.cache&&(n.cache.allBodies=c),c},e.allConstraints=function(n){if(n.cache&&n.cache.allConstraints)return n.cache.allConstraints;for(var c=[].concat(n.constraints),o=0;o<n.composites.length;o++)c=c.concat(e.allConstraints(n.composites[o]));return n.cache&&(n.cache.allConstraints=c),c},e.allComposites=function(n){if(n.cache&&n.cache.allComposites)return n.cache.allComposites;for(var c=[].concat(n.composites),o=0;o<n.composites.length;o++)c=c.concat(e.allComposites(n.composites[o]));return n.cache&&(n.cache.allComposites=c),c},e.get=function(n,c,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()===c.toString()}),i.length===0?null:i[0]):null},e.move=function(n,c,o){return e.remove(n,c),e.add(o,c),n},e.rebase=function(n){for(var c=e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)),o=0;o<c.length;o++)c[o].id=a.nextId();return n},e.translate=function(n,c,o){for(var t=o?e.allBodies(n):n.bodies,i=0;i<t.length;i++)h.translate(t[i],c);return n},e.rotate=function(n,c,o,t){for(var i=Math.cos(c),s=Math.sin(c),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,c)}return n},e.scale=function(n,c,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*c,y:t.y+P*o}),h.scale(m,c,o)}return n},e.bounds=function(n){for(var c=e.allBodies(n),o=[],t=0;t<c.length;t+=1){var i=c[t];o.push(i.bounds.min,i.bounds.max)}return r.create(o)}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(4),a=u(5),r=u(0);(function(){e._motionWakeThreshold=.18,e._motionSleepThreshold=.08,e._minBias=.9,e.update=function(h,n){for(var c=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/c&&e.set(i,!0)):i.sleepCounter>0&&(i.sleepCounter-=1)}},e.afterCollisions=function(h){for(var n=e._motionSleepThreshold,c=0;c<h.length;c++){var o=h[c];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 c=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,c||a.trigger(h,"sleepStart")):(h.isSleeping=!1,h.sleepCounter=0,c&&a.trigger(h,"sleepEnd"))}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(3),a=u(9);(function(){var r=[],h={overlap:0,axis:null},n={overlap:0,axis:null};e.create=function(c,o){return{pair:null,collided:!1,bodyA:c,bodyB:o,parentA:c.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(c,o,t){if(e._overlapAxes(h,c.vertices,o.vertices,c.axes),h.overlap<=0||(e._overlapAxes(n,o.vertices,c.vertices,o.axes),n.overlap<=0))return null;var i=t&&t.table[a.id(c,o)],s;i?s=i.collision:(s=e.create(c,o),s.collided=!0,s.bodyA=c.id<o.id?c:o,s.bodyB=c.id<o.id?o:c,s.parentA=s.bodyA.parent,s.parentB=s.bodyB.parent),c=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-c.position.x,S=o.position.y-c.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(c,o,m,1),M=0;if(l.contains(c.vertices,C[0])&&(T[M++]=C[0]),l.contains(c.vertices,C[1])&&(T[M++]=C[1]),M<2){var I=e._findSupports(o,c,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(c,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}c.axis=i[y],c.overlap=p},e._findSupports=function(c,o,t,i){var s=o.vertices,f=s.length,m=c.position.x,x=c.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,u){var e={};A.exports=e;var l=u(16);(function(){e.create=function(a,r){var h=a.bodyA,n=a.bodyB,c={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(c,a,r),c},e.update=function(a,r,h){var n=r.supports,c=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=c,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,u){var e={};A.exports=e;var l=u(3),a=u(2),r=u(7),h=u(1),n=u(11),c=u(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||c.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=c.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=c.clamp(t/c._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,u){var e={};A.exports=e;var l=u(2),a=u(0);(function(){e.fromVertices=function(r){for(var h={},n=0;n<r.length;n++){var c=(n+1)%r.length,o=l.normalise({x:r[c].y-r[n].y,y:r[n].x-r[c].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),c=Math.sin(h),o=0;o<r.length;o++){var t=r[o],i=t.x*n-t.y*c;t.y=t.x*c+t.y*n,t.x=i}}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(3),a=u(0),r=u(4),h=u(1),n=u(2);(function(){e.rectangle=function(c,o,t,i,s){s=s||{};var f={label:"Rectangle Body",position:{x:c,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(c,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:c,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(c,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(c,o,m,t,a.extend({},f,i))},e.polygon=function(c,o,t,i,s){if(s=s||{},t<3)return e.circle(c,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:c,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(c,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:c,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:c,y:o}),g):p[0]}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(0),a=u(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,c=n.length,o=e.canCollide,t=a.collides,i=r.collisions,s=0,f,m;for(n.sort(e._compareBoundsX),f=0;f<c;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<c;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,u){var e={};A.exports=e;var l=u(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(),c=document.documentElement||document.body.parentNode||document.body,o=window.pageXOffset!==void 0?window.pageXOffset:c.scrollLeft,t=window.pageYOffset!==void 0?window.pageYOffset:c.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,u){var e={};A.exports=e;var l=u(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),c=[],o=0;o<n.length;o+=1)if(n[o]!==a.name){var t=e.resolve(n[o]);if(!t){c.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?(c.push("🔶 "+e.toString(t)),delete t._warned):c.push("✅ "+e.toString(t)),a.used.push(t.name))}c.length>0&&l.info(c.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 c=0;c<r[n].length;c+=1)e.dependencies(r[n][c],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]),c=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:c,patch:o,parts:[n,c,o],prerelease:h[7],number:n*1e8+c*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 u={};A.exports=u,(function(){u.create=function(e){return{vertex:e,normalImpulse:0,tangentImpulse:0}}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(7),a=u(18),r=u(13),h=u(19),n=u(5),c=u(6),o=u(10),t=u(0),i=u(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||c.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=c.allBodies(x),S=c.allConstraints(x);for(x.isModified&&(r.setBodies(P,w),c.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=c.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,u){var e={};A.exports=e;var l=u(3),a=u(0),r=u(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,c,o,t=h.length;for(n=0;n<t;n++)c=h[n],c.isActive&&(o=c.contactCount,c.collision.parentA.totalContacts+=o,c.collision.parentB.totalContacts+=o)},e.solvePosition=function(h,n,c){var o,t,i,s,f,m,x,P,T=e._positionDampen*(c||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,c=h.length,o=l.translate,t=r.update,i=0;i<c;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,c,o;for(c=0;c<n;c++){var t=h[c];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 c=n/a._baseDelta,o=c*c*c,t=-e._restingThresh*c,i=e._restingThreshTangent,s=e._frictionNormalMultiplier*c,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,q=H.y-v.position.y,Y=H.x-w.position.x,K=H.y-w.position.y,z=O-q*G,ut=W+V*G,ct=N-K*X,ht=Q+Y*X,ge=z-ct,ve=ut-ht,le=S*ge+C*ve,$=M*ge+I*ve,pe=p.separation+le,fe=Math.min(pe,1);fe=pe<0?0:fe;var de=fe*L;$<-de||$>de?(P=$>0?$:-$,x=p.friction*($>0?1:-1)*o,x<-P?x=-P:x>P&&(x=P)):(x=$,P=f);var me=V*C-q*S,xe=Y*C-K*S,ye=F/(R+v.inverseInertia*me*me+w.inverseInertia*xe*xe),te=(1+p.restitution)*le*ye;if(x*=ye,le<t)b.normalImpulse=0;else{var gt=b.normalImpulse;b.normalImpulse+=te,b.normalImpulse>0&&(b.normalImpulse=0),te=b.normalImpulse-gt}if($<-i||$>i)b.tangentImpulse=0;else{var vt=b.tangentImpulse;b.tangentImpulse+=x,b.tangentImpulse<-P&&(b.tangentImpulse=-P),b.tangentImpulse>P&&(b.tangentImpulse=P),x=b.tangentImpulse-vt}var ie=S*te+M*x,ne=C*te+I*x;v.isStatic||v.isSleeping||(v.positionPrev.x+=ie*v.inverseMass,v.positionPrev.y+=ne*v.inverseMass,v.anglePrev+=(V*ne-q*ie)*v.inverseInertia),w.isStatic||w.isSleeping||(w.positionPrev.x-=ie*w.inverseMass,w.positionPrev.y-=ne*w.inverseMass,w.anglePrev-=(Y*ne-K*ie)*w.inverseInertia)}}}}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(9),a=u(0);(function(){e.create=function(r){return a.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},r)},e.update=function(r,h,n){var c=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),c(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,u){var e=A.exports=u(21);e.Axes=u(11),e.Bodies=u(12),e.Body=u(4),e.Bounds=u(1),e.Collision=u(8),e.Common=u(0),e.Composite=u(6),e.Composites=u(22),e.Constraint=u(10),e.Contact=u(16),e.Detector=u(13),e.Engine=u(17),e.Events=u(5),e.Grid=u(23),e.Mouse=u(14),e.MouseConstraint=u(24),e.Pair=u(9),e.Pairs=u(19),e.Plugin=u(15),e.Query=u(25),e.Render=u(26),e.Resolver=u(18),e.Runner=u(27),e.SAT=u(28),e.Sleeping=u(7),e.Svg=u(29),e.Vector=u(2),e.Vertices=u(3),e.World=u(30),e.Engine.run=e.Runner.run,e.Common.deprecated(e.Engine,"run","Engine.run ➤ use Matter.Runner.run(engine) instead")}),(function(A,B,u){var e={};A.exports=e;var l=u(15),a=u(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,u){var e={};A.exports=e;var l=u(6),a=u(10),r=u(0),h=u(4),n=u(12),c=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},c(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},c(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},c(e,"softBody","Composites.softBody ➤ moved to softBody and cloth examples")})()}),(function(A,B,u){var e={};A.exports=e;var l=u(9),a=u(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,c,o){var t,i,s,f=c.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 c=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(c,o,t,i)},e._getRegion=function(h,n){var c=n.bounds,o=Math.floor(c.min.x/h.bucketWidth),t=Math.floor(c.max.x/h.bucketWidth),i=Math.floor(c.min.y/h.bucketHeight),s=Math.floor(c.max.y/h.bucketHeight);return e._createRegion(o,t,i,s)},e._createRegion=function(h,n,c,o){return{id:h+","+n+","+c+","+o,startCol:h,endCol:n,startRow:c,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,c){var o=h.pairs,t=l.id,i=n.length,s;for(s=0;s<i;s++){var f=n[s];if(!(c.id===f.id||c.isStatic&&f.isStatic)){var m=t(c,f),x=o[m];x?x[2]+=1:o[m]=[c,f,1]}}n.push(c)},e._bucketRemoveBody=function(h,n,c){var o=h.pairs,t=l.id,i;n.splice(a.indexOf(n,c),1);var s=n.length;for(i=0;i<s;i++){var f=o[t(c,n[i])];f&&(f[2]-=1)}},e._createActivePairsList=function(h){var n,c=h.pairs,o=a.keys(c),t=o.length,i=[],s;for(s=0;s<t;s++)n=c[o[s]],n[2]>0?i.push(n):delete c[o[s]];return i}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(3),a=u(7),r=u(14),h=u(5),n=u(13),c=u(10),o=u(6),t=u(0),i=u(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=c.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,u){var e={};A.exports=e;var l=u(2),a=u(8),r=u(1),h=u(12),n=u(3);(function(){e.collides=function(c,o){for(var t=[],i=o.length,s=c.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,c);if(v){t.push(v);break}}}}return t},e.ray=function(c,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,c),g=0;g<T.length;g+=1){var p=T[g];p.body=p.bodyB=p.bodyA}return T},e.region=function(c,o,t){for(var i=[],s=0;s<c.length;s++){var f=c[s],m=r.overlaps(f.bounds,o);(m&&!t||!m&&t)&&i.push(f)}return i},e.point=function(c,o){for(var t=[],i=0;i<c.length;i++){var s=c[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,u){var e={};A.exports=e;var l=u(4),a=u(0),r=u(6),h=u(1),n=u(5),c=u(2),o=u(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=c.add(Q.position,N.pointA)),X&&(H=c.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,q=34,Y=10,K=69;p.fillStyle="#0e0f19",p.fillRect(0,50,H*5+V*6+22,q),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=c.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=c.add(C.position,w.pointB):I=w.pointB,y.beginPath(),y.moveTo(M.x,M.y),w.render.type==="spring")for(var R=c.sub(I,M),L=c.perp(c.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,u){var e={};A.exports=e;var l=u(5),a=u(17),r=u(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 c=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 c.fps=0,c},e.run=function(n,c){return n.timeBuffer=e._frameDeltaFallback,(function o(t){n.frameRequestId=e._onNextFrame(n,o),t&&n.enabled&&e.tick(n,c,t)})(),n},e.tick=function(n,c,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:c.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(c,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}}c.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,c){if(typeof window<"u"&&window.requestAnimationFrame)n.frameRequestId=window.requestAnimationFrame(c);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 c=0,o=n.length,t=0;t<o;t+=1)c+=n[t];return c/o||0}})()}),(function(A,B,u){var e={};A.exports=e;var l=u(8),a=u(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,u){var e={};A.exports=e,u(1);var l=u(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,c,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),c=a.getTotalLength(),i=[],h=0;h<a.pathSegList.numberOfItems;h+=1)i.push(a.pathSegList.getItem(h));for(s=i.concat();p<c;){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,c,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&&(c=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,c,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,c),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,u){var e={};A.exports=e;var l=u(6);u(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=Re();function ke(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 De(d,E,A,B){return ke(Math.floor((d-E)/A),0,B-1)}var Fe=.18,be=.12,Oe=420,Ue=.12,We=180,Ne=2,Ve=5,He=600,Ge=2,ze=25e3,Xe=.15;function ce(d,E){return{x:d,y:E,stuckMs:0,kickCooldownMs:0,kickCount:0,anchorY:E,anchorAgeMs:0,aliveMs:0}}var Ye=class{tracker=new Map;track(d,E,A){this.tracker.set(d,ce(E,A))}untrack(d){this.tracker.delete(d)}clear(){this.tracker.clear()}process(d,E,A){const B=[],u=new Set,e=[];for(const l of E){const a=j(l);u.add(a);const r=this.tracker.get(a)??ce(l.position.x,l.position.y),h=r.aliveMs+d;if(h>=ze||r.kickCount>=Ve){B.push(l),this.tracker.delete(a);continue}const n=l.position.x-r.x,c=l.position.y-r.y,o=Math.sqrt(n*n+c*c),t=l.velocity,i=Math.sqrt(t.x*t.x+t.y*t.y),s=l.position.y>A.worldHeight*Ue;let f=r.anchorY,m=r.anchorAgeMs+d;l.position.y>f+Ge&&(f=l.position.y,m=0);const x=s&&(i<Fe&&o<be||m>He)?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>=Oe&&P<=0&&e.push({ball:l,id:a,stuckMs:x})}this.applyKicks(e,A);for(const l of this.tracker.keys())u.has(l)||this.tracker.delete(l);return B}applyKicks(d,E){if(d.length===0)return;d.sort((B,u)=>Math.abs(u.ball.position.y-B.ball.position.y)>.1?u.ball.position.y-B.ball.position.y:u.stuckMs-B.stuckMs);const A=Math.min(Ne,d.length);for(let B=0;B<A;B++){const{ball:u,id:e}=d[B],l=this.tracker.get(e);if(!l)continue;const a=u.velocity,r=Math.abs(u.position.x-E.center)/E.halfWidth<Xe?Math.random()<.5?1:-1:u.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(u,{x:a.x+h,y:Math.max(a.y+n,n)}),U.Body.translate(u,{x:r*(.2+Math.random()*.4),y:.25+Math.random()*.35}),this.tracker.set(e,{...l,x:u.position.x,y:u.position.y,stuckMs:0,kickCooldownMs:We,kickCount:l.kickCount+1})}}};function Ke(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 $e=.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)<$e)continue;const u=B.position.x-E;U.Body.applyForce(B,B.position,{x:-A*u,y:0})}}var _="plinkit-ball";function Ze(){const d=Math.random(),E=Math.random();return Math.sqrt(-2*Math.log(d||1e-15))*Math.cos(2*Math.PI*E)}function Je(d,E){const A=Math.max(d.radius+8,d.height*.06);let B;return E&&E>0?B=Ze()*d.width*E:B=(Math.random()-.5)*d.width*.08,U.Bodies.circle(d.width*.5+B,A,d.radius,{label:_,restitution:.65,frictionAir:.001,friction:.001,frictionStatic:0})}var se="plinkit-peg",re="plinkit-guide",ae="plinkit-wall",je=.22,qe=4,_e=class{engine;config;pegs=[];guidePegs=[];walls=null;buckets=[];nextBallId=1;pegBaseY=0;center=0;layoutGeometry=null;antiStuck=new Ye;dist;removeCollisionNudge=null;constructor(d){this.engine=U.Engine.create({gravity:{x:0,y:d.gravityY,scale:.001}}),this.config=d,this.dist=Ke(d.houseEdge??0),this.rebuildStaticBodies(d.width,d.height);const E=this.dist.collisionNudge;if(E>0){const A=B=>{const u=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-u)/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=Je({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*je;let E=0;const A=U.Composite.allBodies(this.engine.world).filter(B=>B.label===_);for(const B of A)if(!B.plugin.settled&&B.position.y<=d&&(E+=1,E>=qe))return!1;return!0}step(d){U.Engine.update(this.engine,d);const E=U.Composite.allBodies(this.engine.world).filter(e=>e.label===_),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)),u=this.cleanupBalls(E);return B.length>0?[...B,...u]:u}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===_).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 u of d){if(u.position.y>A){this.antiStuck.untrack(j(u)),U.World.remove(this.engine.world,u);continue}if(!u.plugin.settled&&u.position.y>=B){E.push(this.settleBall(u));continue}const e=u.circleRadius??this.config.ballRadius,l=this.config.height-e-1;!u.plugin.settled&&u.position.y>=l&&E.push(this.settleBall(u))}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,u=this.config.layout.mainPegs,e=we({...u,width:d,height:E});this.layoutGeometry=e;const l=u.radius,a=this.config.layout.edgeGuides.radius;this.pegs=Pe(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}),c=U.Bodies.rectangle(d*.5,E+A*.5,d,A,{isStatic:!0,isSensor:!0,label:ae});this.walls={leftWall:h,rightWall:n,floor:c},U.World.add(this.engine.world,[h,n,c]),this.guidePegs=Ce(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,u=E?.baseSpacing??(this.config.width-B*2)/Math.max(A.bottomPegCount-1,1),e=De(d.position.x,B,u,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}}},et=`
2
+ precision highp float;
3
+ in vec2 a_position;
4
+ uniform vec2 u_resolution;
5
+ uniform vec2 u_center;
6
+ uniform vec2 u_size;
7
+ out vec2 v_local;
8
+ out vec2 v_uv;
9
+
10
+ void main() {
11
+ vec2 world = u_center + a_position * u_size;
12
+ vec2 clip = (world / u_resolution) * 2.0 - 1.0;
13
+ gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
14
+ v_local = a_position;
15
+ v_uv = a_position * 0.5 + 0.5;
16
+ }
17
+ `,tt=`
18
+ precision highp float;
19
+ uniform vec4 u_color;
20
+ uniform float u_shapeMode;
21
+ uniform float u_useTexture;
22
+ uniform vec2 u_size;
23
+ uniform sampler2D u_texture;
24
+ in vec2 v_local;
25
+ in vec2 v_uv;
26
+ out vec4 outColor;
27
+
28
+ void main() {
29
+ if (u_shapeMode < 0.5) {
30
+ outColor = u_color;
31
+ return;
32
+ }
33
+ float radiusPx = max(min(u_size.x, u_size.y), 1.0);
34
+ float edgePx = (length(v_local) - 1.0) * radiusPx;
35
+ float a = 1.0 - smoothstep(-1.0, 1.0, edgePx);
36
+ if (a < 0.001) discard;
37
+ if (u_useTexture > 0.5) {
38
+ vec4 texel = texture(u_texture, v_uv);
39
+ outColor = vec4(texel.rgb, texel.a * a * u_color.a);
40
+ } else {
41
+ outColor = vec4(u_color.rgb, u_color.a * a);
42
+ }
43
+ }
44
+ `,it=class{canvas;gl;program;positionBuffer;positionLocation;resolutionLocation;centerLocation;sizeLocation;colorLocation;shapeModeLocation;useTextureLocation;textureLocation;scale=1;destroyed=!1;pegTexture=null;ballTexture=null;pegTextureReady=!1;ballTextureReady=!1;constructor(d,E){this.canvas=d;const A=d.getContext("webgl2",{antialias:!0,alpha:!0});if(!A)throw new Error("WebGL2 is not supported by this browser");this.gl=A;const B=he(this.gl,this.gl.VERTEX_SHADER,et),u=he(this.gl,this.gl.FRAGMENT_SHADER,tt);this.program=rt(this.gl,B,u);const e=this.gl.getAttribLocation(this.program,"a_position"),l=this.gl.getUniformLocation(this.program,"u_resolution"),a=this.gl.getUniformLocation(this.program,"u_center"),r=this.gl.getUniformLocation(this.program,"u_size"),h=this.gl.getUniformLocation(this.program,"u_color"),n=this.gl.getUniformLocation(this.program,"u_shapeMode"),c=this.gl.getUniformLocation(this.program,"u_useTexture"),o=this.gl.getUniformLocation(this.program,"u_texture");if(e<0||!l||!a||!r||!h||!n||!c||!o)throw new Error("Unable to initialize WebGL program locations");this.positionLocation=e,this.resolutionLocation=l,this.centerLocation=a,this.sizeLocation=r,this.colorLocation=h,this.shapeModeLocation=n,this.useTextureLocation=c,this.textureLocation=o,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,A,B=1){this.scale=A*B,this.canvas.width=Math.floor(d*A),this.canvas.height=Math.floor(E*A),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,ee(54,68,102));for(const E of d.pegs)this.drawCircle(E.x,E.y,E.radius,ee(141,226,255),"peg");for(const E of d.guidePegs)this.drawCircle(E.x,E.y,E.radius,ee(255,90,120),"peg");for(const E of d.balls)this.drawCircle(E.x,E.y,E.radius,ee(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,A){st(d,E).then(B=>{if(this.destroyed)return;const u=nt(this.gl,B);if(this.destroyed){this.gl.deleteTexture(u);return}A==="peg"?(this.pegTexture&&this.gl.deleteTexture(this.pegTexture),this.pegTexture=u,this.pegTextureReady=!0):(this.ballTexture&&this.gl.deleteTexture(this.ballTexture),this.ballTexture=u,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,A,B,u){this.gl.uniform2f(this.centerLocation,d*this.scale,E*this.scale),this.gl.uniform2f(this.sizeLocation,A*this.scale,A*this.scale),this.gl.uniform4f(this.colorLocation,B.r,B.g,B.b,B.a),this.gl.uniform1f(this.shapeModeLocation,1);const e=u==="peg"?this.pegTexture:this.ballTexture,l=u==="peg"?this.pegTextureReady:this.ballTextureReady;e&&l?(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 ee(d,E,A,B=1){return{r:d/255,g:E/255,b:A/255,a:B}}function nt(d,E){const A=d.createTexture();if(!A)throw new Error("Unable to create WebGL texture");return d.bindTexture(d.TEXTURE_2D,A),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),A}function st(d,E){return new Promise((A,B)=>{const u=new Image;typeof E=="string"&&E.length>0&&(u.crossOrigin=E),u.onload=()=>A(u),u.onerror=()=>B(new Error(`Failed to load image: ${d}`)),u.src=d})}function he(d,E,A){const B=d.createShader(E);if(!B)throw new Error("Unable to create shader");if(d.shaderSource(B,`#version 300 es
45
+ ${A}`),d.compileShader(B),!d.getShaderParameter(B,d.COMPILE_STATUS)){const u=d.getShaderInfoLog(B);throw d.deleteShader(B),new Error(`Shader compile error: ${u??"unknown"}`)}return B}function rt(d,E,A){const B=d.createProgram();if(!B)throw new Error("Unable to create program");if(d.attachShader(B,E),d.attachShader(B,A),d.linkProgram(B),!d.getProgramParameter(B,d.LINK_STATUS)){const u=d.getProgramInfoLog(B);throw d.deleteProgram(B),new Error(`Program link error: ${u??"unknown"}`)}return d.deleteShader(E),d.deleteShader(A),B}var oe=1e3/120,at=50,ot=8,lt=300,ft=class{canvas;viewport;renderer;world;loop;worldHeight;resizeObserver;dprQuery=null;onDprChange;width;height;accumulatorMs=0;lastFrameTime=0;callbacks;ballCost;showGuidePegs;balance;lastSpawnAtMs=-1/0;constructor(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();const E=Ae({mainPegs:d.layout.mainPegs,ballRadius:d.ballRadius,heightPolicy:d.viewport.heightPolicy}),A={...d.layout,mainPegs:E.resolvedMainPegs};this.worldHeight=E.worldHeight,this.canvas.style.maxWidth="100%",this.renderer=new it(this.canvas,{appearance:d.appearance}),this.world=new _e({width:600,height:this.worldHeight,gravityY:d.gravityY,layout:A,ballRadius:d.ballRadius,multipliers:d.multipliers,ballCost:this.ballCost,houseEdge:d.houseEdge}),this.resize(),this.loop=new Se(u=>this.frame(u)),this.loop.start();const B=this.canvas.parentElement;if(!B)throw new Error("Canvas must have a parent element for viewport sizing");this.resizeObserver=new ResizeObserver(u=>{const e=u[0];if(!e)return;const l=e.contentBoxSize?.[0]?.inlineSize,a=l!=null&&l>0?l:B.getBoundingClientRect().width;this.syncViewport(a)}),this.resizeObserver.observe(B),this.listenDpr(),this.emitBalanceChange()}spawnBall(){const d=performance.now();return d-this.lastSpawnAtMs<lt?{ok:!1,reason:"SPAWN_COOLDOWN",state:this.getStateSnapshot()}:this.world.canSpawnBall()?this.balance<this.ballCost?{ok:!1,reason:"INSUFFICIENT_BALANCE",state:this.getStateSnapshot()}:(this.balance-=this.ballCost,this.lastSpawnAtMs=d,this.emitBalanceChange(),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()}getState(){return this.getStateSnapshot()}frame(d){if(this.lastFrameTime===0){this.lastFrameTime=d,this.renderSnapshot();return}const E=Math.min(at,d-this.lastFrameTime);this.lastFrameTime=d,this.accumulatorMs+=E;let A=0;for(;this.accumulatorMs>=oe&&A<ot;){const B=this.world.step(oe);for(const u of B){this.balance+=u.payout;const e=this.getStateSnapshot();this.callbacks.onBallSettled?.(u,e),this.callbacks.onBalanceChange?.(e)}this.accumulatorMs-=oe,A+=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=Ee({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 A=Math.min(window.devicePixelRatio||1,this.viewport.dprCap);this.renderer.resize(this.width,this.height,A,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}}};Z.Plinkit=ft});
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "plinkit",
3
+ "version": "1.0.0-dev.0",
4
+ "description": "WebGL Plinko engine/library",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.es.js",
8
+ "browser": "./dist/plinkit.umd.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.es.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/plinkit.umd.js"
16
+ },
17
+ "./dist/*": "./dist/*"
18
+ },
19
+ "files": [
20
+ "dist/index.es.js",
21
+ "dist/index.cjs",
22
+ "dist/plinkit.umd.js",
23
+ "dist/index.d.ts",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "sideEffects": false,
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "clean": "rimraf dist",
34
+ "build": "vite build && npm run build:internal",
35
+ "build:internal": "esbuild src/internal.ts --bundle --format=esm --minify --outfile=dist/internal.es.js --platform=node",
36
+ "lint": "biome check src tests vite.config.ts",
37
+ "lint:fix": "biome check --write src tests vite.config.ts",
38
+ "format": "biome format --write .",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "test:smoke": "npm run build && node --test tests/*.test.js",
41
+ "verify": "npm run lint && npm run typecheck && npm run test:smoke",
42
+ "pack:check": "npm pack --dry-run",
43
+ "prepublishOnly": "npm run clean && npm run verify"
44
+ },
45
+ "keywords": [
46
+ "webgl",
47
+ "plinko",
48
+ "game",
49
+ "physics"
50
+ ],
51
+ "author": "",
52
+ "license": "MIT",
53
+ "devDependencies": {
54
+ "@biomejs/biome": "2.4.15",
55
+ "@microsoft/api-extractor": "^7.58.7",
56
+ "@types/matter-js": "0.20.2",
57
+ "esbuild": "0.28.0",
58
+ "rimraf": "6.1.3",
59
+ "typescript": "6.0.3",
60
+ "vite": "8.0.14",
61
+ "vite-plugin-dts": "5.0.1"
62
+ },
63
+ "dependencies": {
64
+ "matter-js": "0.20.0"
65
+ }
66
+ }