{"version":3,"file":"Physics.BMnskzGR.mjs","names":["Matter","e","React"],"sources":["https:/framerusercontent.com/modules/J5dvZmKgCR2VeJUGUW9R/NOka49dL3NFIzOG8ITuA/Physics.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import React from\"react\";import Matter from\"matter-js\";import{addPropertyControls,ControlType}from\"framer\";import{makeWalls}from\"https://framerusercontent.com/modules/KYVdEKqNHqMXAKLjSKCy/Ok6wam0uM9G4VUuXWgpR/MakeWalls.js\";import{makeBodies}from\"https://framerusercontent.com/modules/6UgWtAa26OCy0CE59gub/LTuIQWugGJr30ZUS1CV9/MakeBodies.js\";/**\n * These annotations control how your component sizes\n * Learn more: https://www.framer.com/docs/guides/auto-sizing\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */ export default function Physics(props){var ref;let engine;React.useEffect(()=>{if(!engine){engine=Matter.Engine.create({enableSleeping:props.sleeping,gravity:{y:props.gravY,x:props.gravX}});const containerBounding=containerRef.current.getBoundingClientRect();makeWalls(containerBounding,engine.world,props.wallOptions);if(props.debug){var render=Matter.Render.create({element:containerRef.current,engine:engine,options:{height:containerBounding.height,width:containerBounding.width,showAngleIndicator:true,showVelocity:true}});Matter.Render.run(render);}let mouseConstraint=null;if(props.mouseOptions.enable){let mouse=Matter.Mouse.create(containerRef.current);mouseConstraint=Matter.MouseConstraint.create(engine,{mouse:mouse,constraint:{angularStiffness:props.mouseOptions.angularStiffness,stiffness:props.mouseOptions.stiffness}});Matter.Composite.add(engine.world,mouseConstraint);// Remove the many event listeners preventing scroll/drag\nmouseConstraint.mouse.element.removeEventListener(\"mousewheel\",mouseConstraint.mouse.mousewheel);mouseConstraint.mouse.element.removeEventListener(\"DOMMouseScroll\",mouseConstraint.mouse.mousewheel);mouseConstraint.mouse.element.removeEventListener(\"touchstart\",mouseConstraint.mouse.mousedown);mouseConstraint.mouse.element.removeEventListener(\"touchmove\",mouseConstraint.mouse.mousemove);mouseConstraint.mouse.element.removeEventListener(\"touchend\",mouseConstraint.mouse.mouseup);mouseConstraint.mouse.element.addEventListener(\"touchstart\",mouseConstraint.mouse.mousedown,{passive:true});mouseConstraint.mouse.element.addEventListener(\"touchmove\",e=>{if(mouseConstraint.body){mouseConstraint.mouse.mousemove(e);}});mouseConstraint.mouse.element.addEventListener(\"touchend\",e=>{if(mouseConstraint.body){mouseConstraint.mouse.mouseup(e);}});containerRef.current.addEventListener(\"mouseleave\",()=>{mouseConstraint.mouse.mouseup(event);});}let stack=makeBodies(containerRef.current,engine.world,containerRef.current.children,props.frictionOptions,props.densityOptions);(function update(){requestAnimationFrame(update);stack.bodies.forEach((block,i)=>{let el=containerRef.current.children[i];let{x,y}=block.vertices[0];el.style.visibility=\"visible\";el.style.top=`${y}px`;el.style.left=`${x}px`;el.style.transform=`\n                          translate(-50%, -50%)\n                          rotate(${block.angle}rad) \n                          translate(50%, 50%)\n                          `;});//\nMatter.Engine.update(engine);})();}},[]);const containerRef=React.useRef(null);return /*#__PURE__*/ _jsx(\"div\",{style:containerStyle,ref:containerRef,draggable:\"false\",onDragStart:e=>{e.preventDefault();},children:((ref=props.children)===null||ref===void 0?void 0:ref.length)>0?props.children.map((el,i)=>{return /*#__PURE__*/ _jsx(\"div\",{style:bodyStyle,id:\"physics-body\",draggable:\"false\",children:el});}):/*#__PURE__*/ _jsx(\"div\",{style:bodyStyle,id:\"physics-body\",draggable:\"false\",children:props.children})});};// Styles are written in object syntax\n// Learn more: https://reactjs.org/docs/dom-elements.html#style\nconst containerStyle={height:\"100%\",width:\"100%\",overflow:\"hidden\"};const bodyStyle={position:\"absolute\",visibility:\"hidden\"};Physics.defaultProps={gravX:0,gravY:1,children:{},wallOptions:{top:true,bottom:true,right:true,left:true},frictionOptions:{friction:.1,frictionAir:.01},mouseOptions:{angularStiffnes:0,stiffness:.2,enable:true},densityOptions:{enable:true,density:.001},sleeping:false};addPropertyControls(Physics,{children:{type:ControlType.Array,control:{type:ControlType.ComponentInstance}},gravY:{type:ControlType.Number,defaultValue:1,max:5,min:-5,step:.25,title:\"Gravity Y\"},gravX:{type:ControlType.Number,defaultValue:0,max:5,min:-5,step:.25,title:\"Gravity X\"},wallOptions:{title:\"Walls\",type:ControlType.Object,controls:{top:{type:ControlType.Boolean,defaultValue:true},bottom:{type:ControlType.Boolean,defaultValue:true},right:{type:ControlType.Boolean,defaultValue:true},left:{type:ControlType.Boolean,defaultValue:true}}},mouseOptions:{title:\"Mouse\",type:ControlType.Object,controls:{enable:{title:\"Enable\",type:ControlType.Boolean,defaultValue:true},angularStiffness:{title:\"Angular stiffness\",description:\"A value of 0 allows objects to swing when held by the mouse\",type:ControlType.Number,defaultValue:0,min:0,max:1,step:.01},stiffness:{title:\"Stiffness\",description:\"Click + drag creates a moving constraint (spring) that follows the mouse. This describes the stiffness of that spring\",type:ControlType.Number,defaultValue:.2,min:.001,max:1,step:.01}}},friction:{type:ControlType.Object,controls:{friction:{title:\"Body friction\",type:ControlType.Number,min:0,max:1,defaultValue:.1,step:.01},frictionAir:{title:\"Air friction\",type:ControlType.Number,min:0,max:1,defaultValue:.01,step:.01}}},densityOptions:{title:\"Density\",type:ControlType.Object,controls:{enable:{type:ControlType.Boolean,defaultValue:true,description:\"Enabling density will cause mass to be calculated based on width and height\"},density:{type:ControlType.Number,defaultValue:.001,min:.001,max:1,step:.01}}},sleeping:{title:\"Sleeping\",description:\"Improves performance at the cost of simulation accuracy\",type:ControlType.Boolean,defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Physics\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Physics.map"],"mappings":"sPAMI,SAAwB,EAAQ,EAAM,CAAS,IAAI,EAAO,EAAM,cAAc,CAAC,GAAG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