text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("three"),require("@takram/planck-core"),require("@takram/planck-event"),require("@takram/planck-renderer")):"function"==typeof define&&define.amd?define(["exports","three","@takram/planck-core","@takram/planck-event","@takram/planck-renderer"],e):e(t.Planck=t.Planck||{},t.THREE,t.Planck,t.Planck,t.Planck)}(this,function(t,w,e,i,n){"use strict";var a,r,o,h=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},c=function(){function a(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(t,e,i){return e&&a(t.prototype,e),i&&a(t,i),t}}(),x=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},l=function t(e,i,a){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,i);if(void 0===n){var r=Object.getPrototypeOf(e);return null===r?void 0:t(r,i,a)}if("value"in n)return n.value;var o=n.get;return void 0!==o?o.call(a):void 0},p=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},d=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},s=Symbol("_cachedApplicationRef"),g=Symbol("_mixinRef"),u=Symbol("_originalMixin"),m=function(t,e){return Object.setPrototypeOf(e,t),t[u]||(t[u]=t),e},f=function(t){return new v(t)},v=function(){function e(t){h(this,e),this.superclass=t}return c(e,[{key:"with",value:function(){return Array.from(arguments).reduce(function(t,e){return e(t)},this.superclass)}}]),e}(),y=e.Namespace("SceneGraphMixin"),_=(r=m(o=function(e){return function(t){function s(){var t;h(this,s);for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];var n=d(this,(t=s.__proto__||Object.getPrototypeOf(s)).call.apply(t,[this].concat(i))),r=y(n);return r.setup=!1,r.disposed=!1,r.scene=null,n}return p(s,e),c(s,[{key:"setup",value:function(){y(this).setup=!0}},{key:"dispose",value:function(){this.parent&&this.parent.remove(this)}},{key:"addedToParent",value:function(t){var e=y(this);e.setup||(this.setup(),e.setup=!0),t instanceof w.Scene?(this.addedToScene(t),this.dispatchEvent({type:"addedToScene",scene:t})):null!==t&&null!==t.scene&&(this.addedToScene(t.scene),this.dispatchEvent({type:"addedToScene",scene:t.scene}))}},{key:"addedToScene",value:function(t){y(this).scene=t;for(var e=0;e<this.children.length;++e){var i=this.children[e];i.addedToScene(t),i.dispatchEvent({type:"addedToScene",scene:t})}}},{key:"removedFromParent",value:function(t){y(this).scene=null,t instanceof w.Scene?(this.removedFromScene(t),this.dispatchEvent({type:"removedFromScene",scene:t})):null!==t&&null!==t.scene&&(this.removedFromScene(t.scene),this.dispatchEvent({type:"removedFromScene",scene:t.scene}))}},{key:"removedFromScene",value:function(t){for(var e=0;e<this.children.length;++e){var i=this.children[e];i.removedFromScene(t),i.dispatchEvent({type:"removedFromScene",scene:t})}}},{key:"dispatchEvent",value:function(t){var e;if("added"===t.type&&!t.to){var i=y(this);return this.addedToParent(this.parent),l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"dispatchEvent",this).call(this,{type:"added",parent:this.parent}),l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"dispatchEvent",this).call(this,{type:"addedToParent",parent:this.parent}),void(i.parent=this.parent)}if("removed"===t.type&&!t.from){var a=y(this);return this.removedFromParent(a.parent),l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"dispatchEvent",this).call(this,{type:"removed",parent:a.parent}),l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"dispatchEvent",this).call(this,{type:"removedFromParent",parent:a.parent}),void delete a.parent}for(var n=arguments.length,r=Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];(e=l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"dispatchEvent",this)).call.apply(e,[this,t].concat(r))}},{key:"ancestorEventTarget",get:function(){return this.parent||l(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"ancestorEventTarget",this)},set:function(t){!function t(e,i,a,n){var r=Object.getOwnPropertyDescriptor(e,i);if(void 0===r){var o=Object.getPrototypeOf(e);null!==o&&t(o,i,a,n)}else if("value"in r&&r.writable)r.value=a;else{var s=r.set;void 0!==s&&s.call(n,a)}return a}(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"ancestorEventTarget",t,this)}},{key:"scene",get:function(){return y(this).scene}}]),s}()},function(t){var e=o(t);return e.prototype[g]=o[u],e}),Symbol.hasInstance&&!r.hasOwnProperty(Symbol.hasInstance)&&Object.defineProperty(r,Symbol.hasInstance,{value:function(t){for(var e=this[u];null!=t;){if(t.hasOwnProperty(g)&&t[g]===e)return!0;t=Object.getPrototypeOf(t)}return!1}}),m(a=r,function(t){var e=a[s];if(e||(e=a[s]=Symbol(a.name)),t.hasOwnProperty(e))return t[e];var i=a(t);return t[e]=i})),b=function(t){function e(){return h(this,e),d(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return p(e,t),e}(f(w.Group).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),k=function(t){function a(t,e){h(this,a);var i=d(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,e||new n.LineBasicMaterial));return i.material&&(i.customDepthMaterial=i.material.customDepthMaterial,i.customDistanceMaterial=i.material.customDistanceMaterial,i.customPickingMaterial=i.material.customPickingMaterial),i}return p(a,t),a}(f(w.Line).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),M=function(t){function a(t,e){h(this,a);var i=d(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,e||new n.LineBasicMaterial));return i.material&&(i.customDepthMaterial=i.material.customDepthMaterial,i.customDistanceMaterial=i.material.customDistanceMaterial,i.customPickingMaterial=i.material.customPickingMaterial),i}return p(a,t),a}(f(w.LineLoop).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),O=function(t){function a(t,e){h(this,a);var i=d(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,e||new n.LineBasicMaterial));return i.material&&(i.customDepthMaterial=i.material.customDepthMaterial,i.customDistanceMaterial=i.material.customDistanceMaterial,i.customPickingMaterial=i.material.customPickingMaterial),i}return p(a,t),a}(f(w.LineSegments).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),P=function(t){function a(t,e){h(this,a);var i=d(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,e||new w.MeshLambertMaterial));return i.castShadow=!0,i.receiveShadow=!0,i.material&&(i.customDepthMaterial=i.material.customDepthMaterial,i.customDistanceMaterial=i.material.customDistanceMaterial,i.customPickingMaterial=i.material.customPickingMaterial),i}return p(a,t),a}(f(w.Mesh).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),T=function(t){function e(){return h(this,e),d(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return p(e,t),e}(f(w.Object3D).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),S=function(t){function a(t,e){h(this,a);var i=d(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,e||new n.PointsMaterial));return i.material&&(i.customDepthMaterial=i.material.customDepthMaterial,i.customDistanceMaterial=i.material.customDistanceMaterial,i.customPickingMaterial=i.material.customPickingMaterial),i}return p(a,t),c(a,[{key:"identifierLength",get:function(){var t=this.geometry.getAttribute("position");return t?t.count+1:l(a.prototype.__proto__||Object.getPrototypeOf(a.prototype),"identifierLength",this)}}]),a}(f(w.Points).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),L=function(t){function i(t){h(this,i);var e=d(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t));return e.material&&(e.customDepthMaterial=e.material.customDepthMaterial,e.customDistanceMaterial=e.material.customDistanceMaterial,e.customPickingMaterial=e.material.customPickingMaterial),e.size=new w.Vector2,e}return p(i,t),c(i,[{key:"onBeforeRender",value:function(t,e,i,a,n,r){var o=1/i.zoom,s=this.size.x*o,h=this.size.y*o;this.scale.x===s&&this.scale.y===h||(this.scale.set(this.size.x*o,this.size.y*o,1),this.updateMatrixWorld())}}]),i}(f(w.Sprite).with(i.EventDispatcherMixin,i.EventTargetMixin,_)),j=function(){function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};h(this,n),this.color="white",this.backgroundColor="transparent",this.fontSize=10,this.fontFamily="sans-serif",this.fontWeight="normal",this.lineHeight=1,this.letterSpacing=0,this.textTransform="uppercase",this.textAlign="center",this.verticalAlign="middle";for(var e=Object.keys(t),i=0;i<e.length;++i){var a=e[i];({}).hasOwnProperty.call(this,a)&&(this[a]=t[a])}void 0===t.marginTop?this.marginTop=t.margin||0:this.marginTop=t.marginTop,void 0===t.marginRight?this.marginRight=t.margin||0:this.marginRight=t.marginRight,void 0===t.marginBottom?this.marginBottom=t.margin||0:this.marginBottom=t.marginBottom,void 0===t.marginLeft?this.marginLeft=t.margin||0:this.marginLeft=t.marginLeft,void 0===t.paddingTop?this.paddingTop=t.padding||0:this.paddingTop=t.paddingTop,void 0===t.paddingRight?this.paddingRight=t.padding||0:this.paddingRight=t.paddingRight,void 0===t.paddingBottom?this.paddingBottom=t.padding||0:this.paddingBottom=t.paddingBottom,void 0===t.paddingLeft?this.paddingLeft=t.padding||0:this.paddingLeft=t.paddingLeft}return c(n,[{key:"copy",value:function(t){return this.color=t.color,this.backgroundColor=t.backgroundColor,this.fontSize=t.fontSize,this.fontFamily=t.fontFamily,this.fontWeight=t.fontWeight,this.lineHeight=t.lineHeight,this.letterSpacing=t.letterSpacing,this.textTransform=t.textTransform,this.textAlign=t.textAlign,this.verticalAlign=t.verticalAlign,this.marginTop=t.marginTop,this.marginRight=t.marginRight,this.marginBottom=t.marginBottom,this.marginLeft=t.marginLeft,this.paddingTop=t.paddingTop,this.paddingRight=t.paddingRight,this.paddingBottom=t.paddingBottom,this.paddingLeft=t.paddingLeft,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"equals",value:function(t){return this.color===t.color&&this.backgroundColor===t.backgroundColor&&this.fontSize===t.fontSize&&this.fontFamily===t.fontFamily&&this.fontWeight===t.fontWeight&&this.lineHeight===t.lineHeight&&this.letterSpacing===t.letterSpacing&&this.textTransform===t.textTransform&&this.textAlign===t.textAlign&&this.verticalAlign===t.verticalAlign&&this.marginTop===t.marginTop&&this.marginRight===t.marginRight&&this.marginBottom===t.marginBottom&&this.marginLeft===t.marginLeft&&this.paddingTop===t.paddingTop&&this.paddingRight===t.paddingRight&&this.paddingBottom===t.paddingBottom&&this.paddingLeft===t.paddingLeft}},{key:"font",get:function(){return this.fontWeight+" "+this.fontSize+"px "+this.fontFamily}},{key:"margin",set:function(t){this.marginTop=t,this.marginRight=t,this.marginBottom=t,this.marginLeft=t}},{key:"padding",set:function(t){this.paddingTop=t,this.paddingRight=t,this.paddingBottom=t,this.paddingLeft=t}}]),n}(),D=function(t){function r(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.text,i=t.style,a=t.pixelRatio;h(this,r);var n=d(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,new w.SpriteMaterial));return n.text=e||"",n.style=new j(i),n.pixelRatio=a||window.devicePixelRatio,n.canvas=document.createElement("canvas"),n.material.transparent=!0,n.material.map=new w.CanvasTexture(n.canvas,void 0,void 0,void 0,w.NearestFilter,w.NearestFilter),n.draw(),n}return p(r,L),c(r,[{key:"draw",value:function(){var t=this.canvas.getContext("2d"),e=this.style,i=this.text.toString().split("\n"),a=this.measureLines(i,this.style),n=this.style,r=n.marginTop,o=n.marginRight,s=n.marginBottom,h=n.marginLeft,c=n.paddingTop,l=n.paddingRight,p=n.paddingBottom,d=n.paddingLeft,g=n.textAlign,u=n.verticalAlign;a.width+=d+l,a.height+=c+p;var m=x({},a);a.width+=h+o,a.height+=r+s;var f=a.width*this.pixelRatio,v=a.height*this.pixelRatio,y=this.pixelRatio;this.canvas.width=w.Math.ceilPowerOfTwo(f+2*y),this.canvas.height=w.Math.ceilPowerOfTwo(v+2*y);var _=(this.canvas.width-f)/2,b=(this.canvas.height-v)/2;switch(t.save(),t.translate(_,b),t.scale(y,y),g){case"left":case"right":t.translate(h,0);break;case"center":default:t.translate((h+o)/2,0)}switch(u){case"top":case"bottom":t.translate(0,r);break;case"middle":default:t.translate(0,(r+s)/2)}switch(this.drawBackground(m,e),this.drawLines(i,m,e),t.restore(),g){case"left":this.size.x=2*a.width,this.material.map.offset.x=(_-f)/this.canvas.width,this.material.map.repeat.x=f/this.canvas.width*2;break;case"right":this.size.x=2*a.width,this.material.map.offset.x=_/this.canvas.width,this.material.map.repeat.x=f/this.canvas.width*2;break;case"center":default:this.size.x=a.width,this.material.map.offset.x=_/this.canvas.width,this.material.map.repeat.x=f/this.canvas.width}switch(u){case"top":this.size.y=2*a.height,this.material.map.offset.y=b/this.canvas.height,this.material.map.repeat.y=v/this.canvas.height*2;break;case"bottom":this.size.y=2*a.height,this.material.map.offset.y=(b-v)/this.canvas.height,this.material.map.repeat.y=v/this.canvas.height*2;break;case"middle":default:this.size.y=a.height,this.material.map.offset.y=b/this.canvas.height,this.material.map.repeat.y=v/this.canvas.height}this.material.map.needsUpdate=!0}},{key:"drawBackground",value:function(t,e){if("transparent"!==e.backgroundColor){var i=this.canvas.getContext("2d");i.save(),i.fillStyle=e.backgroundColor,i.fillRect(0,0,t.width,t.height),i.restore()}}},{key:"drawLines",value:function(t,e,i){var a=this.canvas.getContext("2d");a.save(),a.font=i.font,a.textAlign=i.textAlign,a.fillStyle=i.color,a.textBaseline="bottom";var n=0;switch(i.textAlign){case"left":n=i.paddingLeft;break;case"right":n=e.width-i.paddingRight;break;case"center":default:n=(i.paddingLeft+e.width-i.paddingRight)/2}for(var r=i.fontSize*i.lineHeight,o=.5*(r+i.fontSize)+i.paddingTop,s=0;s<t.length;++s)a.fillText(t[s],n,o),o+=r;"transparent"===i.backgroundColor&&(a.globalCompositeOperation="source-in",a.fillStyle=i.color,a.fillRect(0,0,e.width,e.height)),a.restore()}},{key:"measureLines",value:function(t,e){var i=this.canvas.getContext("2d");i.save(),i.font=e.font;for(var a=e.fontSize*e.lineHeight*t.length,n=0,r=0;r<t.length;++r){var o=i.measureText(t[r]).width;n<o&&(n=o)}return i.restore(),{width:n,height:a}}}]),r}(),E={Group:b,Line:k,LineLoop:M,LineSegments:O,Mesh:P,Object3D:T,Points:S,SceneGraphMixin:_,Sprite:L,Text:D,TextStyle:j};t.Group=b,t.Line=k,t.LineLoop=M,t.LineSegments=O,t.Mesh=P,t.Object3D=T,t.Points=S,t.SceneGraphMixin=_,t.Sprite=L,t.Text=D,t.TextStyle=j,t.default=E,Object.defineProperty(t,"__esModule",{value:!0})});