// Version 1.10.0 three-spritetext - https://github.com/vasturiano/three-spritetext !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpriteText=e(t.THREE)}(this,function(t){"use strict";function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r0&&void 0!==arguments[0]?arguments[0]:"",o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"rgba(255, 255, 255, 1)";return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=r(this,e,[new c.SpriteMaterial]))._text="".concat(n),t._textHeight=o,t._color=i,t._backgroundColor=!1,t._padding=0,t._borderWidth=0,t._borderRadius=0,t._borderColor="white",t._offsetX=0,t._offsetY=0,t._strokeWidth=0,t._strokeColor="white",t._fontFace="system-ui",t._fontSize=90,t._fontWeight="normal",t._canvas=document.createElement("canvas"),t._genCanvas(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(e,t),n(e,[{key:"text",get:function(){return this._text},set:function(t){this._text=t,this._genCanvas()}},{key:"textHeight",get:function(){return this._textHeight},set:function(t){this._textHeight=t,this._genCanvas()}},{key:"color",get:function(){return this._color},set:function(t){this._color=t,this._genCanvas()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(t){this._backgroundColor=t,this._genCanvas()}},{key:"padding",get:function(){return this._padding},set:function(t){this._padding=t,this._genCanvas()}},{key:"borderWidth",get:function(){return this._borderWidth},set:function(t){this._borderWidth=t,this._genCanvas()}},{key:"borderRadius",get:function(){return this._borderRadius},set:function(t){this._borderRadius=t,this._genCanvas()}},{key:"borderColor",get:function(){return this._borderColor},set:function(t){this._borderColor=t,this._genCanvas()}},{key:"offsetX",get:function(){return this._offsetX},set:function(t){this._offsetX=t,this._genCanvas()}},{key:"offsetY",get:function(){return this._offsetY},set:function(t){this._offsetY=t,this._genCanvas()}},{key:"fontFace",get:function(){return this._fontFace},set:function(t){this._fontFace=t,this._genCanvas()}},{key:"fontSize",get:function(){return this._fontSize},set:function(t){this._fontSize=t,this._genCanvas()}},{key:"fontWeight",get:function(){return this._fontWeight},set:function(t){this._fontWeight=t,this._genCanvas()}},{key:"strokeWidth",get:function(){return this._strokeWidth},set:function(t){this._strokeWidth=t,this._genCanvas()}},{key:"strokeColor",get:function(){return this._strokeColor},set:function(t){this._strokeColor=t,this._genCanvas()}},{key:"_genCanvas",value:function(){var t=this,e=this._canvas,r=e.getContext("2d"),n=1/this.textHeight,o=Array.isArray(this.borderWidth)?this.borderWidth:[this.borderWidth,this.borderWidth],i=o.map(function(e){return e*t.fontSize*n}),a=(Array.isArray(this.borderRadius)?this.borderRadius:[this.borderRadius,this.borderRadius,this.borderRadius,this.borderRadius]).map(function(e){return e*t.fontSize*n}),u=Array.isArray(this.padding)?this.padding:[this.padding,this.padding],h=u.map(function(e){return e*t.fontSize*n}),l=[this.offsetX,this.offsetY].map(function(e){return e*t.fontSize*n}),d=this.text.split("\n"),p="".concat(this.fontWeight," ").concat(this.fontSize,"px ").concat(this.fontFace);r.font=p;var y=Math.max.apply(Math,f(d.map(function(t){return r.measureText(t).width}))),b=this.fontSize*d.length,g=y+2*i[0]+2*h[0],v=b+2*i[1]+2*h[1];if(e.width=g+Math.abs(l[0]),e.height=v+Math.abs(l[1]),r.translate.apply(r,f(l.map(function(t){return Math.max(0,t)}))),this.borderWidth){if(r.strokeStyle=this.borderColor,i[0]){var _=i[0]/2;r.lineWidth=i[0],r.beginPath(),r.moveTo(_,a[0]),r.lineTo(_,v-a[3]),r.moveTo(g-_,a[1]),r.lineTo(g-_,v-a[2]),r.stroke()}if(i[1]){var m=i[1]/2;r.lineWidth=i[1],r.beginPath(),r.moveTo(Math.max(i[0],a[0]),m),r.lineTo(g-Math.max(i[0],a[1]),m),r.moveTo(Math.max(i[0],a[3]),v-m),r.lineTo(g-Math.max(i[0],a[2]),v-m),r.stroke()}if(this.borderRadius){var C=Math.max.apply(Math,f(i)),k=C/2;r.lineWidth=C,r.beginPath(),[!!a[0]&&[a[0],k,k,a[0]],!!a[1]&&[g-a[1],g-k,k,a[1]],!!a[2]&&[g-a[2],g-k,v-k,v-a[2]],!!a[3]&&[a[3],k,v-k,v-a[3]]].filter(function(t){return t}).forEach(function(t){var e=s(t,4),n=e[0],o=e[1],i=e[2],a=e[3];r.moveTo(n,i),r.quadraticCurveTo(o,i,o,a)}),r.stroke()}}this.backgroundColor&&(r.fillStyle=this.backgroundColor,this.borderRadius?(r.beginPath(),r.moveTo(i[0],a[0]),[[i[0],a[0],g-a[1],i[1],i[1],i[1]],[g-i[0],g-i[0],g-i[0],i[1],a[1],v-a[2]],[g-i[0],g-a[2],a[3],v-i[1],v-i[1],v-i[1]],[i[0],i[0],i[0],v-i[1],v-a[3],a[0]]].forEach(function(t){var e=s(t,6),n=e[0],o=e[1],i=e[2],a=e[3],f=e[4],u=e[5];r.quadraticCurveTo(n,a,o,f),r.lineTo(i,u)}),r.closePath(),r.fill()):r.fillRect(i[0],i[1],g-2*i[0],v-2*i[1])),r.translate.apply(r,f(i)),r.translate.apply(r,f(h)),r.font=p,r.fillStyle=this.color,r.textBaseline="bottom";var S=this.strokeWidth>0;S&&(r.lineWidth=this.strokeWidth*this.fontSize/10,r.strokeStyle=this.strokeColor),d.forEach(function(e,n){var o=(y-r.measureText(e).width)/2,i=(n+1)*t.fontSize;S&&r.strokeText(e,o,i),r.fillText(e,o,i)}),this.material.map&&this.material.map.dispose(),(this.material.map=new c.CanvasTexture(e)).colorSpace=c.SRGBColorSpace;var x=this.textHeight*d.length+2*o[1]+2*u[1]+Math.abs(this.offsetY);this.scale.set(x*e.width/e.height,x,0)}},{key:"clone",value:function(){return new this.constructor(this.text,this.textHeight,this.color).copy(this)}},{key:"copy",value:function(t){return c.Sprite.prototype.copy.call(this,t),this.color=t.color,this.backgroundColor=t.backgroundColor,this.padding=t.padding,this.borderWidth=t.borderWidth,this.borderColor=t.borderColor,this.offsetX=t.offsetX,this.offsetY=t.offsetY,this.fontFace=t.fontFace,this.fontSize=t.fontSize,this.fontWeight=t.fontWeight,this.strokeWidth=t.strokeWidth,this.strokeColor=t.strokeColor,this}}])}(c.Sprite);return l});