0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-17 12:42:17 -05:00
liabru-matter-js/demo/js/matter-demo.matter-tools.97f38a.min.js

117 lines
367 KiB
JavaScript
Raw Normal View History

2021-02-11 17:42:32 -05:00
/*!
2023-02-16 09:19:15 -05:00
* matter-demo bundle 0.19.0 by @liabru
2021-02-11 17:42:32 -05:00
* http://brm.io/matter-js/
* License MIT
*/
(this.webpackJsonpMatterDemo=this.webpackJsonpMatterDemo||[]).push([[2],{akk5:function(e,t,n){
/*!
* matter-tools 0.14.0 by @liabru
* https://github.com/liabru/matter-tools
* License MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Liam Brummitt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var r;r=function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/demo/lib/",n(n.s=6)}([function(t,n){t.exports=e},function(e,t,n){"use strict";const r=e.exports={};r.injectStyles=function(e,t){if(document.getElementById(t))return;let n=document.createElement("div");n.innerHTML=`<style id="${t}" type="text/css">${e}</style>`;let i=document.head.querySelector("style:last-of-type");i?r.domInsertBefore(n.firstElementChild,i):document.head.appendChild(n.firstElementChild)},r.injectScript=function(e,t,n){if(document.getElementById(t))return;let r=document.createElement("script");r.id=t,r.src=e,r.onload=n,document.body.appendChild(r)},r.domRemove=function(e){return e.parentElement.removeChild(e)},r.domInsertBefore=function(e,t){return t.parentNode.insertBefore(e,t.previousElementSibling)}},function(e,t,n){"use strict";const r=e.exports={},i=n(8),o=n(0),s=o.Common,a=o.Engine;r.create=function(){let e=new i({prefix:"$",cleanup:!0});return e.parse=e.resurrect,e},r.clone=function(e,t){var n=e.parse(r.serialise(e,t));return n.id=s.nextId(),n},r.saveState=function(e,t,n){localStorage.setItem(n,r.serialise(e,t.world))},r.loadState=function(e,t,n){var r=e.parse(localStorage.getItem(n));r&&a.merge(t,{world:r})},r.serialise=function(e,t,n){return n=n||0,e.stringify(t,(function(e,t){if(!/^#/.exec(e)&&"number"==typeof t){var n=parseFloat(t.toFixed(3));return 0===n&&0!==t?t:n}return t}),n)}},function(e,t,n){"use strict";const r=e.exports={},i=n(7),o=n(1),s=n(2),a=n(0),l=a.Engine,d=a.Detector,c=a.Grid,h=a.World,u=a.Bodies,p=a.Events,f=a.Composite;r.create=function(e,t,r){i.GUI.TEXT_CLOSED="▲",i.GUI.TEXT_OPEN="▼";var a={engine:e,runner:t,render:r,datGui:new i.GUI({autoPlace:!1}),broadphase:"grid",broadphaseCache:{grid:e.broadphase.controller===c?e.broadphase:c.create(),bruteForce:{detector:d.bruteForce}},amount:1,size:40,sides:4,density:.001,restitution:0,friction:.1,frictionStatic:.5,frictionAir:.01,offset:{x:0,y:0},renderer:"canvas",chamfer:0,isRecording:!1};s&&(a.serializer=s.create());let l=n(9);return o.injectStyles(l,"matter-gui-style"),g(a),a},r.update=function(e){var t,n=e.datGui;for(t in n.__folders)r.update(e,n.__folders[t]);for(t in n.__controllers){var i=n.__controllers[t];i.updateDisplay&&i.updateDisplay()}},r.closeAll=function(e){var t=e.datGui;for(var n in t.__folders)t.__folders[n].close()},r.destroy=function(e){e.datGui.domElement.parentElement.removeChild(e.datGui.domElement),e.datGui.destroy()};var g=function(e){var t=e.engine,n=e.runner,r=e.datGui,i={addBody:function(){_(e)},clear:function(){m(e)},save:function(){s.saveState(e.serializer,t,"guiState"),p.trigger(e,"save")},load:function(){s.loadState(e.serializer,t,"guiState"),p.trigger(e,"load")}},o=r.addFolder("Metrics");if(n&&o.add(n,"fps").listen(),t.metrics.extended&&(n&&(o.add(n,"delta").listen(),o.add(n,"correction").listen()),t&&(o.add(t.metrics,"bodies").listen(),o.add(t.metrics,"collisions").listen(),o.add(t.metrics,"pairs").listen(),o.add(t.metrics,"broadEff").listen(),o.add(t.metrics,"midEff").listen(),o.add(t.metrics,"narrowEff").listen(),o.add(t.metrics,"narrowReuse").listen()),o.open()),t){var a=r.addFolder("Add Body");a.add(e,"amount",1,5).step(1),a.add(e,"size",5,150).step(1),a.add(e,"sides",1,8).step
/**
* # ResurrectJS
* @version 1.0.3
* @license Public Domain
*
* ResurrectJS preserves object behavior (prototypes) and reference
* circularity with a special JSON encoding. Unlike regular JSON,
* Date, RegExp, DOM objects, and `undefined` are also properly
* preserved.
*
* ## Examples
*
* function Foo() {}
* Foo.prototype.greet = function() { return "hello"; };
*
* // Behavior is preserved:
* var necromancer = new Resurrect();
* var json = necromancer.stringify(new Foo());
* var foo = necromancer.resurrect(json);
* foo.greet(); // => "hello"
*
* // References to the same object are preserved:
* json = necromancer.stringify([foo, foo]);
* var array = necromancer.resurrect(json);
* array[0] === array[1]; // => true
* array[1].greet(); // => "hello"
*
* // Dates are restored properly
* json = necromancer.stringify(new Date());
* var date = necromancer.resurrect(json);
* Object.prototype.toString.call(date); // => "[object Date]"
*
* ## Options
*
* Options are provided to the constructor as an object with these
* properties:
*
* prefix ('#'): A prefix string used for temporary properties added
* to objects during serialization and deserialization. It is
* important that you don't use any properties beginning with this
* string. This option must be consistent between both
* serialization and deserialization.
*
* cleanup (false): Perform full property cleanup after both
* serialization and deserialization using the `delete`
* operator. This may cause performance penalties (breaking hidden
* classes in V8) on objects that ResurrectJS touches, so enable
* with care.
*
* revive (true): Restore behavior (__proto__) to objects that have
* been resurrected. If this is set to false during serialization,
* resurrection information will not be encoded. You still get
* circularity and Date support.
*
* resolver (Resurrect.NamespaceResolver(window)): Converts between
* a name and a prototype. Create a custom resolver if your
* constructors are not stored in global variables. The resolver
* has two methods: getName(object) and getPrototype(string).
*
* For example,
*
* var necromancer = new Resurrect({
* prefix: '__#',
* cleanup: true
* });
*
* ## Caveats
*
* * With the default resolver, all constructors must be named and
* stored in the global variable under that name. This is required
* so that the prototypes can be looked up and reconnected at
* resurrection time.
*
* * The wrapper objects Boolean, String, and Number will be
* unwrapped. This means extra properties added to these objects
* will not be preserved.
*
* * Functions cannot ever be serialized. Resurrect will throw an
* error if a function is found when traversing a data structure.
*
* @see http://nullprogram.com/blog/2013/03/28/
*/
function n(e){for(var t in this.table=null,this.prefix="#",this.cleanup=!1,this.revive=!0,e)e.hasOwnProperty(t)&&(this[t]=e[t]);this.refcode=this.prefix+"id",this.origcode=this.prefix+"original",this.buildcode=this.prefix+".",this.valuecode=this.prefix+"v"}e.exports=n,n.GLOBAL=(0,eval)("this"),n.escapeRegExp=function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},n.prototype.Error=function(e){this.message=e||"",this.stack=(new Error).stack},n.prototype.Error.prototype=Object.create(Error.prototype),n.prototype.Error.prototype.name="ResurrectError",n.NamespaceResolver=function(e){this.scope=e},n.NamespaceResolver.prototype.getPrototype=function(e){var t=this.scope[e];if(t)return t.prototype;throw new n.prototype.Error("Unknown constructor: "+e)},n.NamespaceResolver.prototype.getName=function(e){var t=e.constructor.name;if(null==t&&(t=/^\s*function\s*([A-Za-z0-9_$]*)/.exec(e.constructor)[1]),""===t)throw new n.prototype.Error("Can't serialize objects with anonymous constructors.");return"Object"===t||"Array"===t?null:t},n.prototype.resolver=new n.NamespaceResolver(n.GLOBAL),n.Node=function(e){var t=document.createElement("div");return t.innerHTML=e,t.firstChild},n.is=function(e){var t="[object "+e+"]";return function(e){return Object.prototype.toString.call(e)===t}},n.isArray=n.is("Array"),n.isString=n.is("String"),n.isBoolean=n.is("Boolean"),n.isNumber=n.is("Number"),n.isFunction=n.is("Function"),n.isDate=n.is("Date"),n.isRegExp=n.is("RegExp"),n.isObject=n.is("Object"),n.isAtom=function(e){return!n.isObject(e)&&!n.isArray(e)},n.isPrimitive=function(e){return null==e||n.isNumber(e)||n.isString(e)||n.isBoolean(e)},n.prototype.ref=function(e){var t={};return t[this.prefix]=void 0===e?-1:e[this.refcode],t},n.prototype.deref=function(e){return this.table[e[this.prefix]]},n.prototype.tag=function(e){if(this.revive){var t=this.resolver.getName(e);if(t){var n=Object.getPrototypeOf(e);if(this.resolver.getPrototype(t)!==n)throw new this.Error("Constructor mismatch!");e[this.prefix]=t}}return e[this.refcode]=this.table.length,this.table.push(e),e[this.refcode]},n.prototype.builder=function(e,t){var n={};return n[this.buildcode]=e,n[this.valuecode]=t,n},n.prototype.build=function(e){var t=e[this.buildcode].split(/\./).reduce((function(e,t){return e[t]}),n.GLOBAL),r=[null].concat(e[this.valuecode]),i=new(t.bind.apply(t,r));return n.isPrimitive(i)?i.valueOf():i},n.prototype.decode=function(e){if(this.prefix in e)return this.deref(e);if(this.buildcode in e)return this.build(e);throw new this.Error("Unknown encoding.")},n.prototype.isTagged=function(e){return this.refcode in e&&null!=e[this.refcode]},n.prototype.visit=function(e,t,r){if(n.isAtom(e))return t(e);if(this.isTagged(e))return this.ref(e);var i=null;if(n.isArray(e)){i=[],e[this.refcode]=this.tag(i);for(var o=0;o<e.length;o++)i.push(this.visit(e[o],t,r))}else for(var s in i=Object.create(Object.getPrototypeOf(e)),e[this.refcode]=this.tag(i),e){var a=e[s];if(e.hasOwnProperty(s)){if(r&&void 0!==a&&void 0===(a=r.call(e,s,e[s])))continue;i[s]=this.visit(a,t,r)}}return i[this.origcode]=e,this.ref(i)},n.prototype.handleAtom=function(e){var t=n.GLOBAL.Node||function(){};if(n.isFunction(e))throw new this.Error("Can't serialize functions.");if(e instanceof t){var r=new XMLSerializer;return this.builder("Resurrect.Node",[r.serializeToString(e)])}if(n.isDate(e))return this.builder("Date",[e.toISOString()]);if(n.isRegExp(e)){var i=e.toString().match(/\/(.+)\/([gimy]*)/).slice(1);return this.builder("RegExp",i)}return void 0===e?this.ref(void 0):!n.isNumber(e)||!isNaN(e)&&isFinite(e)?e:this.builder("Number",[e.toString()])},n.prototype.replacerWrapper=function(e){var t=new RegExp("^"+n.escapeRegExp(this.prefix));return function(n,r){return t.test(n)?r:e(n,r)}},n.prototype.stringify=function(e,t,r){if(n.isFunction(t))t=this.replacerWrapper(t);else if(n.isArray(t)){var i=t;t=function(e,t){return i.indexOf(e)>=0?t:void 0}}if(n.isAtom(e))return JSON.stringify(this.handleAtom(e),t,r);this.table=[],this.visit(e,this.handleAtom.bind(this),t);for(var o=0;o<this.table.length;o++)