UNPKG

@chronosai/three-mesh-ui

Version:

a library on top of three.js to help in creating 3D user interfaces

1 lines 69.7 kB
import*as e from"three";var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};t.d(s,{k2:()=>a,eB:()=>ye,dJ:()=>r,VB:()=>ce,hW:()=>Ie,A9:()=>i,s3:()=>De,EY:()=>Re,nO:()=>o,Sw:()=>n,Ay:()=>Ge,yo:()=>He});var r={};t.r(r),t.d(r,{COLUMN:()=>d,COLUMN_REVERSE:()=>u,ROW:()=>c,ROW_REVERSE:()=>l,contentDirection:()=>p});var a={};t.r(a),t.d(a,{CENTER:()=>C,END:()=>g,START:()=>w,STRETCH:()=>f,alignItems:()=>m,warnAboutDeprecatedAlignItems:()=>b});var i={};t.r(i),t.d(i,{CENTER:()=>k,END:()=>_,SPACE_AROUND:()=>U,SPACE_BETWEEN:()=>S,SPACE_EVENLY:()=>T,START:()=>y,justifyContent:()=>P});var n={};t.r(n),t.d(n,{NORMAL:()=>O,NOWRAP:()=>F,PRE:()=>E,PRE_LINE:()=>z,PRE_WRAP:()=>A,WHITE_CHARS:()=>B,collapseWhitespaceOnInlines:()=>H,collapseWhitespaceOnString:()=>M,newlineBreakability:()=>L,shouldBreak:()=>D});var o={};t.r(o),t.d(o,{CENTER:()=>X,JUSTIFY:()=>Y,JUSTIFY_CENTER:()=>K,JUSTIFY_LEFT:()=>J,JUSTIFY_RIGHT:()=>q,LEFT:()=>j,RIGHT:()=>V,textAlign:()=>$});const h=(e=>{var s={};return t.d(s,e),s})({BufferAttribute:()=>e.BufferAttribute,BufferGeometry:()=>e.BufferGeometry,CanvasTexture:()=>e.CanvasTexture,Color:()=>e.Color,FileLoader:()=>e.FileLoader,LinearFilter:()=>e.LinearFilter,Mesh:()=>e.Mesh,Object3D:()=>e.Object3D,Plane:()=>e.Plane,PlaneGeometry:()=>e.PlaneGeometry,ShaderMaterial:()=>e.ShaderMaterial,TextureLoader:()=>e.TextureLoader,Vector2:()=>e.Vector2,Vector3:()=>e.Vector3}),c="row",l="row-reverse",d="column",u="column-reverse";function p(e,t,s,r){let a=s,i="getWidth",n="x",o="y";0===t.indexOf(d)&&(i="getHeight",n="y",o="x");for(let t=0;t<e.childrenBoxes.length;t++){const s=e.childrenBoxes[t],h=s.id,c=s[i](),l=s.margin||0;a+=l*r,e.childrenPos[h]={[n]:a+c/2*r,[o]:0},a+=r*(c+l)}}const w="start",C="center",g="end",f="stretch";function m(e,t){const s=e.getAlignItems();-1===x.indexOf(s)&&console.warn(`alignItems === '${s}' is not supported`);let r="getWidth",a="x";0===t.indexOf(c)&&(r="getHeight",a="y");const i=e[r]()/2-(e.padding||0);e.childrenBoxes.forEach((n=>{let o;switch(s){case g:case"right":case"bottom":o=0===t.indexOf(c)?-i+n[r]()/2+(n.margin||0):i-n[r]()/2-(n.margin||0);break;case w:case"left":case"top":o=0===t.indexOf(c)?i-n[r]()/2-(n.margin||0):-i+n[r]()/2+(n.margin||0)}e.childrenPos[n.id][a]=o||0}))}function b(e){-1!==v.indexOf(e)&&console.warn(`alignItems === '${e}' is deprecated and will be remove in 7.x.x. Fallback are 'start'|'end'`)}const x=[w,C,g,f,"top","right","bottom","left"],v=["top","right","bottom","left"],y="start",k="center",_="end",U="space-around",S="space-between",T="space-evenly";function P(e,t,s,r){const a=e.getJustifyContent();-1===R.indexOf(a)&&console.warn(`justifyContent === '${a}' is not supported`);const i=0===t.indexOf("row")?"width":"height",n=e.getChildrenSideSum(i),o=("width"===i?e.getInnerWidth():e.getInnerHeight())-n,h=function(e,t){switch(e){case _:return t;case k:return t/2}return 0}(a,2*s-n*Math.sign(s)),c=function(e,t,s,r){const a=Array(e.length).fill(0);if(t>0)switch(s){case S:if(e.length>1){const s=t/(e.length-1)*r;a[0]=0;for(let t=1;t<e.length;t++)a[t]=s*t}break;case T:if(e.length>1){const s=t/(e.length+1)*r;for(let t=0;t<e.length;t++)a[t]=s*(t+1)}break;case U:if(e.length>1){const s=t/e.length*r,i=s/2;a[0]=i;for(let t=1;t<e.length;t++)a[t]=i+s*t}}return a}(e.childrenBoxes,o,a,r),l=0===t.indexOf("row")?"x":"y";e.childrenBoxes.forEach(((t,s)=>{e.childrenPos[t.id][l]-=h-c[s]}))}const R=[y,k,_,U,S,T];function I(e){return class extends e{constructor(e){super(e),this.isBoxComponent=!0,this.childrenPos={}}getInnerWidth(){const e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.width-(2*this.padding||0)||this.getChildrenSideSum("width");case"column":case"column-reverse":return this.getHighestChildSizeOn("width");default:console.error(`Invalid contentDirection : ${e}`)}}getInnerHeight(){const e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.getHighestChildSizeOn("height");case"column":case"column-reverse":return this.height-(2*this.padding||0)||this.getChildrenSideSum("height");default:console.error(`Invalid contentDirection : ${e}`)}}getChildrenSideSum(e){return this.childrenBoxes.reduce(((t,s)=>{const r=2*s.margin||0;return t+("width"===e?s.getWidth()+r:s.getHeight()+r)}),0)}setPosFromParentRecords(){this.parentUI&&this.parentUI.childrenPos[this.id]&&(this.position.x=this.parentUI.childrenPos[this.id].x,this.position.y=this.parentUI.childrenPos[this.id].y)}computeChildrenPosition(){if(this.children.length>0){const e=this.getContentDirection();let t;switch(e){case c:t=-this.getInnerWidth()/2;break;case l:t=this.getInnerWidth()/2;break;case d:t=this.getInnerHeight()/2;break;case u:t=-this.getInnerHeight()/2}const s=-Math.sign(t);p(this,e,t,s),P(this,e,t,s),m(this,e)}}getHighestChildSizeOn(e){return this.childrenBoxes.reduce(((t,s)=>{const r=s.margin||0,a="width"===e?s.getWidth()+2*r:s.getHeight()+2*r;return Math.max(t,a)}),0)}getWidth(){return this.parentUI&&"stretch"===this.parentUI.getAlignItems()&&-1!==this.parentUI.getContentDirection().indexOf("column")?this.parentUI.getWidth()-(2*this.parentUI.padding||0):this.width||this.getInnerWidth()+(2*this.padding||0)}getHeight(){return this.parentUI&&"stretch"===this.parentUI.getAlignItems()&&-1!==this.parentUI.getContentDirection().indexOf("row")?this.parentUI.getHeight()-(2*this.parentUI.padding||0):this.height||this.getInnerHeight()+(2*this.padding||0)}}}const B={"\t":"\t","\n":"\n","\r":"\r"," ":" "},O="normal",F="nowrap",E="pre",z="pre-line",A="pre-wrap",M=function(e,t){switch(t){case F:case O:e=e.replace(/\n/g," ");case z:e=e.replace(/[ ]{2,}/g," ")}return e},L=function(e){switch(e){case E:case A:case z:return"mandatory"}},D=function(e,t,s,r){const a=e[t];switch(r.WHITESPACE){case O:case z:case A:if("mandatory"===a.lineBreak)return!0;const i=a.kerning?a.kerning:0,n=a.xoffset?a.xoffset:0;if(s+(a.xadvance?a.xadvance:a.width)+n+i>r.INNER_WIDTH)return!0;const o=N(e,t,r);return function(e,t,s,r){return!(!e||!e.glyph)&&(!(t+s<r.INNER_WIDTH)&&r.BREAKON.indexOf(e.glyph)>-1)}(e[t-1],s,o,r);case E:return"mandatory"===a.lineBreak;default:return!1}},H=function(e,t){const s=e[0],r=e[e.length-1];switch(t){case A:s.glyph&&"\n"===s.glyph&&e.length>1&&G([s],e[1]),r.glyph&&"\n"===r.glyph&&e.length>1&&W([r],e[e.length-2]);break;case z:case F:case O:let a,i=[];for(let t=0;t<e.length;t++){const s=e[t];if(!(s.glyph&&B[s.glyph]&&e.length>t))break;i.push(s),a=e[t+1]}G(i,a),i=[],a=null;for(let t=e.length-1;t>0;t--){const s=e[t];if(!(s.glyph&&B[s.glyph]&&t>0))break;i.push(s),a=e[t-1]}W(i,a);break;case E:break;default:return console.warn(`whiteSpace: '${t}' is not valid`),0}return s.offsetX};function W(e,t){if(t)for(let s=0;s<e.length;s++){const r=e[s];r.width=0,r.height=0,r.offsetX=t.offsetX+t.width}}function G(e,t){if(t)for(let s=0;s<e.length;s++){const r=e[s];r.width=0,r.height=0,r.offsetX=t.offsetX}}function N(e,t,s,r){if(r=r||0,!e[t])return r;const a=e[t],i=a.kerning?a.kerning:0,n=a.xoffset?a.xoffset:0,o=a.xadvance?a.xadvance:a.width;return a.lineBreak?r+o:N(e,t+1,s,r+o+s.LETTERSPACING+n+i)}const j="left",V="right",X="center",Y="justify",J="justify-left",q="justify-right",K="justify-center";function $(e,t,s){for(let r=0;r<e.length;r++){const a=e[r],i=Z(a,t,s,r===e.length-1);for(let e=0;e<a.length;e++)a[e].offsetX+=i;a.x=i}if(0===t.indexOf(Y))for(let r=0;r<e.length;r++){const a=e[r];if(-1!==t.indexOf("-")&&r===e.length-1)return;const i=s-a.width;if(i<=0)return;let n=0;for(let e=1;e<a.length-1;e++)n+=" "===a[e].glyph?1:0;const o=i/n;let h=1;t===q&&(a.reverse(),h=-1);let c=0;for(let e=1;e<=a.length-1;e++){const t=a[e];t.offsetX+=c*h,c+=" "===t.glyph?o:0}t===q&&a.reverse()}}const Z=(e,t,s,r)=>{switch(t){case J:case Y:case j:return-s/2;case q:case V:return-e.width+s/2;case X:return-e.width/2;case K:return r?-e.width/2:-s/2;default:console.warn(`textAlign: '${t}' is not valid`)}};function Q(e){return class extends e{computeInlinesPosition(){const e=this.getWidth()-(2*this.padding||0),t=this.getHeight()-(2*this.padding||0),s=this.getJustifyContent(),r=this.getTextAlign(),a=this.getInterLine(),i=this.computeLines();i.interLine=a;const n=Math.abs(i.height),o=(()=>{switch(s){case"start":return t/2;case"end":return n-t/2;case"center":return n/2;default:console.warn(`justifyContent: '${s}' is not valid`)}})();i.forEach((e=>{e.y+=o,e.forEach((e=>{e.offsetY+=o}))})),$(i,r,e),this.lines=i}calculateBestFit(e){if(0!==this.childrenInlines.length)switch(e){case"grow":this.calculateGrowFit();break;case"shrink":this.calculateShrinkFit();break;case"auto":this.calculateAutoFit()}}calculateGrowFit(){const e=this.getHeight()-(2*this.padding||0);let t=1;const s=this.childrenInlines.find((e=>e.isText));let r,a=1,i=2,n=s._fitFontSize?s._fitFontSize/s.getFontSize():1;do{if(r=this.calculateHeight(n),r>e){if(n<=a){this.childrenInlines.forEach((e=>{e.isInlineBlock||(e._fitFontSize=e.getFontSize())}));break}i=n,n-=(i-a)/2}else{if(Math.abs(e-r)<.075)break;Math.abs(n-i)<5e-10&&(i*=2),a=n,n+=(i-a)/2}}while(++t<=10)}calculateShrinkFit(){const e=this.getHeight()-(2*this.padding||0);let t=1;const s=this.childrenInlines.find((e=>e.isText));let r,a=0,i=1,n=s._fitFontSize?s._fitFontSize/s.getFontSize():1;do{if(r=this.calculateHeight(n),r>e)i=n,n-=(i-a)/2;else{if(n>=i){this.childrenInlines.forEach((e=>{e.isInlineBlock||(e._fitFontSize=e.getFontSize())}));break}if(Math.abs(e-r)<.075)break;a=n,n+=(i-a)/2}}while(++t<=10)}calculateAutoFit(){const e=this.getHeight()-(2*this.padding||0);let t=1;const s=this.childrenInlines.find((e=>e.isText));let r,a=0,i=2,n=s._fitFontSize?s._fitFontSize/s.getFontSize():1;do{if(r=this.calculateHeight(n),r>e)i=n,n-=(i-a)/2;else{if(Math.abs(e-r)<.075)break;Math.abs(n-i)<5e-10&&(i*=2),a=n,n+=(i-a)/2}}while(++t<=10)}computeLines(){const e=this.getWidth()-(2*this.padding||0),t=[[]];t.height=0;const s=this.getInterLine();this.childrenInlines.reduce(((s,r)=>{if(!r.inlines)return;const a=r._fitFontSize||r.getFontSize(),i=r.isText?r.getLetterSpacing()*a:0,n=r.getWhiteSpace(),o=r.getBreakOn(),h={WHITESPACE:n,LETTERSPACING:i,BREAKON:o,INNER_WIDTH:e};return r.inlines.reduce(((e,s,r,a)=>{const n=s.kerning?s.kerning:0,o=s.xoffset?s.xoffset:0,c=s.xadvance?s.xadvance:s.width;return D(a,r,e,h)?(t.push([s]),s.offsetX=o,0===s.width?0:c+i):(t[t.length-1].push(s),s.offsetX=e+o+n,e+c+n+i)}),s)}),0);let r=0,a=0,i=-s/2;return t.forEach((e=>{e.lineHeight=e.reduce(((e,t)=>{const s=void 0!==t.lineHeight?t.lineHeight:t.height;return Math.max(e,s)}),0),e.lineBase=e.reduce(((e,t)=>{const s=void 0!==t.lineBase?t.lineBase:t.height;return Math.max(e,s)}),0),e.width=0,e.height=e.lineHeight;if(e[0]){const t=this.getWhiteSpace(),n=H(e,t);e.forEach((e=>{e.offsetX-=n})),e.width=this.computeLineWidth(e),e.width>r&&(r=e.width),e.forEach((t=>{t.offsetY=i-t.height-t.anchor,t.lineHeight<e.lineHeight&&(t.offsetY-=e.lineBase-t.lineBase)})),e.y=i,a+=e.lineHeight+s,i-=e.lineHeight+s}})),t.height=a,t.width=r,t}calculateHeight(e){this.childrenInlines.forEach((t=>{t.isInlineBlock||(t._fitFontSize=t.getFontSize()*e,t.calculateInlines(t._fitFontSize))}));const t=this.computeLines();return Math.abs(t.height)}computeLineWidth(e){const t=e[0],s=e[e.length-1];return s.offsetX+s.width+t.offsetX}}}const ee=new h.FileLoader,te=[],se={},re=new h.TextureLoader,ae=[],ie={},ne={};function oe(e){if(e._kernings)return;const t={};for(let s=0;s<e.kernings.length;s++){const r=e.kernings[s];if(0===r.amount)continue;t[String.fromCharCode(r.first,r.second)]=r.amount}e._kernings=t}const he={setFontFamily:function(e,t){"string"==typeof t?function(e,t){-1===te.indexOf(t)&&(te.push(t),ee.load(t,(e=>{const s=JSON.parse(e);oe(s),se[t]=s;for(const e of Object.keys(ne))t===ne[e].jsonURL&&ne[e].component._updateFontFamily(s)})));ne[e.id]||(ne[e.id]={component:e});ne[e.id].jsonURL=t,se[t]&&e._updateFontFamily(se[t])}(e,t):(ne[e.id]||(ne[e.id]={component:e}),oe(t),ne[e.id].json=t,e._updateFontFamily(t))},setFontTexture:function(e,t){-1===ae.indexOf(t)&&(ae.push(t),re.load(t,(e=>{e.generateMipmaps=!1,e.minFilter=h.LinearFilter,e.magFilter=h.LinearFilter,ie[t]=e;for(const s of Object.keys(ne))t===ne[s].textureURL&&ne[s].component._updateFontTexture(e)}))),ne[e.id]||(ne[e.id]={component:e}),ne[e.id].textureURL=t,ie[t]&&e._updateFontTexture(ie[t])},getFontOf:function e(t){const s=ne[t.id];return!s&&t.parentUI?e(t.parentUI):s},addFont:function(e,t,s){s.generateMipmaps=!1,s.minFilter=h.LinearFilter,s.magFilter=h.LinearFilter,te.push(e),se[e]=t,oe(t),s&&(ae.push(e),ie[e]=s)}},ce=he;class le{static requestUpdate(e,t,s,r){e.traverse((e=>{e.isUI&&(this.requestedUpdates[e.id]?(t&&(this.requestedUpdates[e.id].updateParsing=!0),s&&(this.requestedUpdates[e.id].updateLayout=!0),r&&(this.requestedUpdates[e.id].updateInner=!0)):this.requestedUpdates[e.id]={updateParsing:t,updateLayout:s,updateInner:r,needCallback:t||s||r})}))}static register(e){this.components.includes(e)||this.components.push(e)}static disposeOf(e){const t=this.components.indexOf(e);t>-1&&this.components.splice(t,1)}static update(){if(Object.keys(this.requestedUpdates).length>0){const e=this.components.filter((e=>!e.parentUI));e.forEach((e=>this.traverseParsing(e))),e.forEach((e=>this.traverseUpdates(e)))}}static traverseParsing(e){const t=this.requestedUpdates[e.id];t&&t.updateParsing&&(e.parseParams(),t.updateParsing=!1),e.childrenUIs.forEach((e=>this.traverseParsing(e)))}static traverseUpdates(e){const t=this.requestedUpdates[e.id];delete this.requestedUpdates[e.id],t&&t.updateLayout&&(t.updateLayout=!1,e.updateLayout()),t&&t.updateInner&&(t.updateInner=!1,e.updateInner()),e.childrenUIs.forEach((e=>{this.traverseUpdates(e)})),t&&t.needCallback&&e.onAfterUpdate()}}le.components=[],le.requestedUpdates={};const de={container:null,fontFamily:null,fontSize:.05,fontKerning:"normal",bestFit:"none",offset:.01,interLine:.01,breakOn:"- ,.:?!\n",whiteSpace:z,contentDirection:d,alignItems:C,justifyContent:y,textAlign:X,textType:"MSDF",fontColor:new h.Color(16777215),fontOpacity:1,fontPXRange:4,fontSupersampling:!0,borderRadius:.01,borderWidth:0,borderColor:new h.Color("black"),borderOpacity:1,backgroundSize:"cover",backgroundColor:new h.Color(2236962),backgroundWhiteColor:new h.Color(16777215),backgroundOpacity:.8,backgroundOpaqueOpacity:1,getDefaultTexture:function(){if(!ue){const e=document.createElement("canvas").getContext("2d");e.canvas.width=1,e.canvas.height=1,e.fillStyle="#ffffff",e.fillRect(0,0,1,1),ue=new h.CanvasTexture(e.canvas),ue.isDefault=!0}return ue},hiddenOverflow:!1,letterSpacing:0};let ue;function pe(e){return class extends e{constructor(e){super(e),this.states={},this.currentState=void 0,this.isUI=!0,this.autoLayout=!0,this.childrenUIs=[],this.childrenBoxes=[],this.childrenTexts=[],this.childrenInlines=[],this.parentUI=null,this.addEventListener("added",this._rebuildParentUI),this.addEventListener("removed",this._rebuildParentUI)}getClippingPlanes(){const e=[];if(this.parentUI){if(this.isBlock&&this.parentUI.getHiddenOverflow()){const t=this.parentUI.getHeight()/2-(this.parentUI.padding||0),s=this.parentUI.getWidth()/2-(this.parentUI.padding||0),r=[new h.Plane(new h.Vector3(0,1,0),t),new h.Plane(new h.Vector3(0,-1,0),t),new h.Plane(new h.Vector3(1,0,0),s),new h.Plane(new h.Vector3(-1,0,0),s)];r.forEach((e=>{e.applyMatrix4(this.parent.matrixWorld)})),e.push(...r)}this.parentUI.parentUI&&e.push(...this.parentUI.getClippingPlanes())}return e}getHighestParent(){return this.parentUI?this.parent.getHighestParent():this}_getProperty(e){return void 0===this[e]&&this.parentUI?this.parent._getProperty(e):void 0!==this[e]?this[e]:de[e]}getFontSize(){return this._getProperty("fontSize")}getFontKerning(){return this._getProperty("fontKerning")}getLetterSpacing(){return this._getProperty("letterSpacing")}getFontTexture(){return void 0===this.fontTexture&&this.parentUI?this.parent._getProperty("fontTexture"):void 0!==this.fontTexture?this.fontTexture:de.getDefaultTexture()}getFontFamily(){return this._getProperty("fontFamily")}getBreakOn(){return this._getProperty("breakOn")}getWhiteSpace(){return this._getProperty("whiteSpace")}getTextAlign(){return this._getProperty("textAlign")}getTextType(){return this._getProperty("textType")}getFontColor(){return this._getProperty("fontColor")}getFontSupersampling(){return this._getProperty("fontSupersampling")}getFontOpacity(){return this._getProperty("fontOpacity")}getFontPXRange(){return this._getProperty("fontPXRange")}getBorderRadius(){return this._getProperty("borderRadius")}getBorderWidth(){return this._getProperty("borderWidth")}getBorderColor(){return this._getProperty("borderColor")}getBorderOpacity(){return this._getProperty("borderOpacity")}getContainer(){return!this.threeOBJ&&this.parent?this.parent.getContainer():this.threeOBJ?this:de.container}getParentsNumber(e){return e=e||0,this.parentUI?this.parentUI.getParentsNumber(e+1):e}getBackgroundOpacity(){return this.backgroundOpacity||0===this.backgroundOpacity?this.backgroundOpacity:de.backgroundOpacity}getBackgroundColor(){return this.backgroundColor||de.backgroundColor}getBackgroundTexture(){return this.backgroundTexture||de.getDefaultTexture()}getAlignContent(){return this.alignContent||de.alignContent}getAlignItems(){return this.alignItems||de.alignItems}getContentDirection(){return this.contentDirection||de.contentDirection}getJustifyContent(){return this.justifyContent||de.justifyContent}getInterLine(){return void 0===this.interLine?de.interLine:this.interLine}getOffset(){return void 0===this.offset?de.offset:this.offset}getBackgroundSize(){return void 0===this.backgroundSize?de.backgroundSize:this.backgroundSize}getHiddenOverflow(){return void 0===this.hiddenOverflow?de.hiddenOverflow:this.hiddenOverflow}getBestFit(){return void 0===this.bestFit?de.bestFit:this.bestFit}_rebuildChildrenLists(){this.childrenUIs=this.children.filter((e=>e.isUI)),this.childrenBoxes=this.children.filter((e=>e.isBoxComponent)),this.childrenInlines=this.children.filter((e=>e.isInline)),this.childrenTexts=this.children.filter((e=>e.isText))}_rebuildParentUI=()=>{this.parent&&this.parent.isUI?this.parentUI=this.parent:this.parentUI=null};add(){for(const e of Object.keys(arguments))arguments[e].isInline&&this.update(null,!0);const e=super.add(...arguments);return this._rebuildChildrenLists(),e}remove(){for(const e of Object.keys(arguments))arguments[e].isInline&&this.update(null,!0);const e=super.remove(...arguments);return this._rebuildChildrenLists(),e}update(e,t,s){le.requestUpdate(this,e,t,s)}onAfterUpdate(){}_updateFontFamily(e){this.fontFamily=e,this.traverse((e=>{e.isUI&&e.update(!0,!0,!1)})),this.getHighestParent().update(!1,!0,!1)}_updateFontTexture(e){this.fontTexture=e,this.getHighestParent().update(!1,!0,!1)}set(e){let t,s,r;if(le.register(this),e&&JSON.stringify(e)!==JSON.stringify({})){e.alignContent&&(e.alignItems=e.alignContent,e.textAlign||(e.textAlign=e.alignContent),console.warn("`alignContent` property has been deprecated, please rely on `alignItems` and `textAlign` instead."),delete e.alignContent),e.alignItems&&b(e.alignItems);for(const a of Object.keys(e))if(this[a]!=e[a])switch(a){case"content":case"fontSize":case"fontKerning":case"breakOn":case"whiteSpace":this.isText&&(t=!0),s=!0,this[a]=e[a];break;case"bestFit":this.isBlock&&(t=!0,s=!0),this[a]=e[a];break;case"width":case"height":case"padding":(this.isInlineBlock||this.isBlock&&"none"!=this.getBestFit())&&(t=!0),s=!0,this[a]=e[a];break;case"letterSpacing":case"interLine":this.isBlock&&"none"!=this.getBestFit()&&(t=!0),s=!0,this[a]=e[a];break;case"margin":case"contentDirection":case"justifyContent":case"alignContent":case"alignItems":case"textAlign":case"textType":s=!0,this[a]=e[a];break;case"fontColor":case"fontOpacity":case"fontSupersampling":case"offset":case"backgroundColor":case"backgroundOpacity":case"backgroundTexture":case"backgroundSize":case"borderRadius":case"borderWidth":case"borderColor":case"borderOpacity":r=!0,this[a]=e[a];break;case"hiddenOverflow":case"billboard":case"sizeAttenuation":this[a]=e[a]}e.fontFamily&&ce.setFontFamily(this,e.fontFamily),e.fontTexture&&ce.setFontTexture(this,e.fontTexture),this.parentUI&&"none"!=this.parentUI.getBestFit()&&this.parentUI.update(!0,!0,!1),this.update(t,s,r),s&&this.getHighestParent().update(!1,!0,!1)}}setupState(e){this.states[e.state]={attributes:e.attributes,onSet:e.onSet}}setState(e){const t=this.states[e];t?e!==this.currentState&&(this.currentState=e,t.onSet&&t.onSet(),t.attributes&&this.set(t.attributes)):console.warn(`state "${e}" does not exist within this component:`,this.name)}clear(){this.traverse((e=>{le.disposeOf(e),e.material&&e.material.dispose(),e.geometry&&e.geometry.dispose()}))}}}function we(e){return class extends e{constructor(e){super(e),this.textUniforms={u_texture:{value:this.getFontTexture()},u_color:{value:this.getFontColor()},u_opacity:{value:this.getFontOpacity()},u_pxRange:{value:this.getFontPXRange()},u_useRGSS:{value:this.getFontSupersampling()}},this.backgroundUniforms={u_texture:{value:this.getBackgroundTexture()},u_color:{value:this.getBackgroundColor()},u_opacity:{value:this.getBackgroundOpacity()},u_backgroundMapping:{value:this.getBackgroundSize()},u_borderWidth:{value:this.getBorderWidth()},u_borderColor:{value:this.getBorderColor()},u_borderRadiusTopLeft:{value:this.getBorderRadius()},u_borderRadiusTopRight:{value:this.getBorderRadius()},u_borderRadiusBottomRight:{value:this.getBorderRadius()},u_borderRadiusBottomLeft:{value:this.getBorderRadius()},u_borderOpacity:{value:this.getBorderOpacity()},u_size:{value:new h.Vector2(1,1)},u_tSize:{value:new h.Vector2(1,1)}}}updateBackgroundMaterial(){this.backgroundUniforms.u_texture.value=this.getBackgroundTexture(),this.backgroundUniforms.u_tSize.value.set(this.backgroundUniforms.u_texture.value.image.width,this.backgroundUniforms.u_texture.value.image.height),this.size&&this.backgroundUniforms.u_size.value.copy(this.size),this.backgroundUniforms.u_texture.value.isDefault?(this.backgroundUniforms.u_color.value=this.getBackgroundColor(),this.backgroundUniforms.u_opacity.value=this.getBackgroundOpacity()):(this.backgroundUniforms.u_color.value=this.backgroundColor||de.backgroundWhiteColor,this.backgroundUniforms.u_opacity.value=this.backgroundOpacity||0===this.backgroundOpacity?this.backgroundOpacity:de.backgroundOpaqueOpacity),this.backgroundUniforms.u_backgroundMapping.value=(()=>{switch(this.getBackgroundSize()){case"stretch":return 0;case"contain":return 1;case"cover":return 2}})();const e=this.getBorderRadius();this.backgroundUniforms.u_borderWidth.value=this.getBorderWidth(),this.backgroundUniforms.u_borderColor.value=this.getBorderColor(),this.backgroundUniforms.u_borderOpacity.value=this.getBorderOpacity(),Array.isArray(e)?(this.backgroundUniforms.u_borderRadiusTopLeft.value=e[0],this.backgroundUniforms.u_borderRadiusTopRight.value=e[1],this.backgroundUniforms.u_borderRadiusBottomRight.value=e[2],this.backgroundUniforms.u_borderRadiusBottomLeft.value=e[3]):(this.backgroundUniforms.u_borderRadiusTopLeft.value=e,this.backgroundUniforms.u_borderRadiusTopRight.value=e,this.backgroundUniforms.u_borderRadiusBottomRight.value=e,this.backgroundUniforms.u_borderRadiusBottomLeft.value=e)}updateTextMaterial(){this.textUniforms.u_texture.value=this.getFontTexture(),this.textUniforms.u_color.value=this.getFontColor(),this.textUniforms.u_opacity.value=this.getFontOpacity(),this.textUniforms.u_pxRange.value=this.getFontPXRange(),this.textUniforms.u_useRGSS.value=this.getFontSupersampling()}getBackgroundMaterial(){return this.backgroundMaterial&&this.backgroundUniforms||(this.backgroundMaterial=this._makeBackgroundMaterial()),this.backgroundMaterial}getFontMaterial(){return this.fontMaterial&&this.textUniforms||(this.fontMaterial=this._makeTextMaterial()),this.fontMaterial}_makeTextMaterial(){const e={};return this.billboard&&(e.USE_BILLBOARD=!0),this.sizeAttenuation&&(e.USE_SIZE_ATTENUATION=!0),new h.ShaderMaterial({uniforms:this.textUniforms,transparent:!0,clipping:!0,vertexShader:Ce,fragmentShader:ge,extensions:{derivatives:!0},defines:e})}_makeBackgroundMaterial(){const e={};return this.billboard&&(e.USE_BILLBOARD=!0),this.sizeAttenuation&&(e.USE_SIZE_ATTENUATION=!0),new h.ShaderMaterial({uniforms:this.backgroundUniforms,transparent:!0,clipping:!0,vertexShader:fe,fragmentShader:me,extensions:{derivatives:!0},defines:e})}updateClippingPlanes(e){const t=void 0!==e?e:this.getClippingPlanes();JSON.stringify(t)!==JSON.stringify(this.clippingPlanes)&&(this.clippingPlanes=t,this.fontMaterial&&(this.fontMaterial.clippingPlanes=this.clippingPlanes),this.backgroundMaterial&&(this.backgroundMaterial.clippingPlanes=this.clippingPlanes))}}}const Ce="\n#include <common>\n\nvarying vec2 vUv;\nfloat rotation = 0.0;\nvec2 center = vec2(0.5, 0.5);\n\nvoid main() {\n\n\tvUv = uv;\n\tvec4 mvPosition;\n\n\t#ifdef USE_BILLBOARD\n\t\tmvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\tvec2 scale;\n\t\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\t\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n\t\t#ifndef USE_SIZE_ATTENUATION\n\t\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\n\t\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t\t#endif\n\n\t\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\n\t\tvec2 rotatedPosition;\n\t\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\t\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n\t\tmvPosition.xy += rotatedPosition;\n\n\t#else\n\t\tmvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t#endif\n\tgl_Position = projectionMatrix * mvPosition;\n\n}\n",ge="\n\nuniform sampler2D u_texture;\nuniform vec3 u_color;\nuniform float u_opacity;\nuniform float u_pxRange;\nuniform bool u_useRGSS;\n\nvarying vec2 vUv;\n\n#include <clipping_planes_pars_fragment>\n\n// functions from the original msdf repo:\n// https://github.com/Chlumsky/msdfgen#using-a-multi-channel-distance-field\n\nfloat median(float r, float g, float b) {\n\treturn max(min(r, g), min(max(r, g), b));\n}\n\nfloat screenPxRange() {\n\tvec2 unitRange = vec2(u_pxRange)/vec2(textureSize(u_texture, 0));\n\tvec2 screenTexSize = vec2(1.0)/fwidth(vUv);\n\treturn max(0.5*dot(unitRange, screenTexSize), 1.0);\n}\n\nfloat tap(vec2 offsetUV) {\n\tvec3 msd = texture( u_texture, offsetUV ).rgb;\n\tfloat sd = median(msd.r, msd.g, msd.b);\n\tfloat screenPxDistance = screenPxRange() * (sd - 0.5);\n\tfloat alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);\n\treturn alpha;\n}\n\nvoid main() {\n\n\tfloat alpha;\n\n\tif ( u_useRGSS ) {\n\n\t\t// shader-based supersampling based on https://bgolus.medium.com/sharper-mipmapping-using-shader-based-supersampling-ed7aadb47bec\n\t\t// per pixel partial derivatives\n\t\tvec2 dx = dFdx(vUv);\n\t\tvec2 dy = dFdy(vUv);\n\n\t\t// rotated grid uv offsets\n\t\tvec2 uvOffsets = vec2(0.125, 0.375);\n\t\tvec2 offsetUV = vec2(0.0, 0.0);\n\n\t\t// supersampled using 2x2 rotated grid\n\t\talpha = 0.0;\n\t\toffsetUV.xy = vUv + uvOffsets.x * dx + uvOffsets.y * dy;\n\t\talpha += tap(offsetUV);\n\t\toffsetUV.xy = vUv - uvOffsets.x * dx - uvOffsets.y * dy;\n\t\talpha += tap(offsetUV);\n\t\toffsetUV.xy = vUv + uvOffsets.y * dx - uvOffsets.x * dy;\n\t\talpha += tap(offsetUV);\n\t\toffsetUV.xy = vUv - uvOffsets.y * dx + uvOffsets.x * dy;\n\t\talpha += tap(offsetUV);\n\t\talpha *= 0.25;\n\n\t} else {\n\n\t\talpha = tap( vUv );\n\n\t}\n\n\n\t// apply the opacity\n\talpha *= u_opacity;\n\n\t// this is useful to avoid z-fighting when quads overlap because of kerning\n\tif ( alpha < 0.02) discard;\n\n\n\tgl_FragColor = vec4( u_color, alpha );\n\n\t#include <clipping_planes_fragment>\n\n}\n",fe="\n#include <common>\n\nvarying vec2 vUv;\n\nfloat rotation = 0.0;\nvec2 center = vec2(0.5, 0.5);\n\nvoid main() {\n\n\tvUv = uv;\n\tvec4 mvPosition;\n\n\t#ifdef USE_BILLBOARD\n\t\tmvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\tmvPosition.z -= 0.0001;\n\n\t\tvec2 scale;\n\t\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\t\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n\t\t#ifndef USE_SIZE_ATTENUATION\n\t\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t\t#endif\n\n\t\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\n\t\tvec2 rotatedPosition;\n\t\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\t\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n\t\tmvPosition.xy += rotatedPosition;\n\t#else\n\t\tmvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\tmvPosition.z -= 0.0001;\n\t#endif\n\n\tgl_Position = projectionMatrix * mvPosition;\n}\n",me="\n\nuniform sampler2D u_texture;\nuniform vec3 u_color;\nuniform float u_opacity;\n\nuniform float u_borderRadiusTopLeft;\nuniform float u_borderRadiusTopRight;\nuniform float u_borderRadiusBottomLeft;\nuniform float u_borderRadiusBottomRight;\nuniform float u_borderWidth;\nuniform vec3 u_borderColor;\nuniform float u_borderOpacity;\nuniform vec2 u_size;\nuniform vec2 u_tSize;\nuniform int u_backgroundMapping;\n\nvarying vec2 vUv;\n\n#include <clipping_planes_pars_fragment>\n\nfloat getEdgeDist() {\n\tvec2 ndc = vec2( vUv.x * 2.0 - 1.0, vUv.y * 2.0 - 1.0 );\n\tvec2 planeSpaceCoord = vec2( u_size.x * 0.5 * ndc.x, u_size.y * 0.5 * ndc.y );\n\tvec2 corner = u_size * 0.5;\n\tvec2 offsetCorner = corner - abs( planeSpaceCoord );\n\tfloat innerRadDist = min( offsetCorner.x, offsetCorner.y ) * -1.0;\n\tif (vUv.x < 0.5 && vUv.y >= 0.5) {\n\t\tfloat roundedDist = length( max( abs( planeSpaceCoord ) - u_size * 0.5 + u_borderRadiusTopLeft, 0.0 ) ) - u_borderRadiusTopLeft;\n\t\tfloat s = step( innerRadDist * -1.0, u_borderRadiusTopLeft );\n\t\treturn mix( innerRadDist, roundedDist, s );\n\t}\n\tif (vUv.x >= 0.5 && vUv.y >= 0.5) {\n\t\tfloat roundedDist = length( max( abs( planeSpaceCoord ) - u_size * 0.5 + u_borderRadiusTopRight, 0.0 ) ) - u_borderRadiusTopRight;\n\t\tfloat s = step( innerRadDist * -1.0, u_borderRadiusTopRight );\n\t\treturn mix( innerRadDist, roundedDist, s );\n\t}\n\tif (vUv.x >= 0.5 && vUv.y < 0.5) {\n\t\tfloat roundedDist = length( max( abs( planeSpaceCoord ) - u_size * 0.5 + u_borderRadiusBottomRight, 0.0 ) ) - u_borderRadiusBottomRight;\n\t\tfloat s = step( innerRadDist * -1.0, u_borderRadiusBottomRight );\n\t\treturn mix( innerRadDist, roundedDist, s );\n\t}\n\tif (vUv.x < 0.5 && vUv.y < 0.5) {\n\t\tfloat roundedDist = length( max( abs( planeSpaceCoord ) - u_size * 0.5 + u_borderRadiusBottomLeft, 0.0 ) ) - u_borderRadiusBottomLeft;\n\t\tfloat s = step( innerRadDist * -1.0, u_borderRadiusBottomLeft );\n\t\treturn mix( innerRadDist, roundedDist, s );\n\t}\n}\n\nvec4 sampleTexture() {\n\tfloat textureRatio = u_tSize.x / u_tSize.y;\n\tfloat panelRatio = u_size.x / u_size.y;\n\tvec2 uv = vUv;\n\tif ( u_backgroundMapping == 1 ) { // contain\n\t\tif ( textureRatio < panelRatio ) { // repeat on X\n\t\t\tfloat newX = uv.x * ( panelRatio / textureRatio );\n\t\t\tnewX += 0.5 - 0.5 * ( panelRatio / textureRatio );\n\t\t\tuv.x = newX;\n\t\t} else { // repeat on Y\n\t\t\tfloat newY = uv.y * ( textureRatio / panelRatio );\n\t\t\tnewY += 0.5 - 0.5 * ( textureRatio / panelRatio );\n\t\t\tuv.y = newY;\n\t\t}\n\t} else if ( u_backgroundMapping == 2 ) { // cover\n\t\tif ( textureRatio < panelRatio ) { // stretch on Y\n\t\t\tfloat newY = uv.y * ( textureRatio / panelRatio );\n\t\t\tnewY += 0.5 - 0.5 * ( textureRatio / panelRatio );\n\t\t\tuv.y = newY;\n\t\t} else { // stretch on X\n\t\t\tfloat newX = uv.x * ( panelRatio / textureRatio );\n\t\t\tnewX += 0.5 - 0.5 * ( panelRatio / textureRatio );\n\t\t\tuv.x = newX;\n\t\t}\n\t}\n\treturn texture2D( u_texture, uv ).rgba;\n}\n\nvoid main() {\n\n\tfloat edgeDist = getEdgeDist();\n\tfloat change = fwidth( edgeDist );\n\n\tvec4 textureSample = sampleTexture();\n\tvec3 blendedColor = textureSample.rgb * u_color;\n\n\tfloat alpha = smoothstep( change, 0.0, edgeDist );\n\tfloat blendedOpacity = u_opacity * textureSample.a * alpha;\n\n\tvec4 frameColor = vec4( blendedColor, blendedOpacity );\n\n\tif ( u_borderWidth <= 0.0 ) {\n\t\tgl_FragColor = frameColor;\n\t} else {\n\t\tvec4 borderColor = vec4( u_borderColor, u_borderOpacity * alpha );\n\t\tfloat stp = smoothstep( edgeDist + change, edgeDist, u_borderWidth * -1.0 );\n\t\tgl_FragColor = mix( frameColor, borderColor, stp );\n\t}\n\n\t#include <clipping_planes_fragment>\n}\n";class be extends h.Mesh{constructor(e){super(new h.PlaneGeometry,e),this.castShadow=!0,this.receiveShadow=!0,this.name="MeshUI-Frame"}}let xe=null;function ve(...e){if(!xe)throw new Error("Cannot use mixins with Base null");let t=xe;xe=null;let s,r=e.length;for(;--r>=0;)s=e[r],t=s(t);return t}ve.withBase=e=>(xe=e,ve);class ye extends(ve.withBase(h.Object3D)(I,Q,we,pe)){constructor(e){super(e),this.isBlock=!0,this.size=new h.Vector2(1,1),this.set(e),this.frame=new be(this.getBackgroundMaterial()),this.frame.onBeforeRender=()=>{this.updateClippingPlanes&&this.updateClippingPlanes()},this.add(this.frame),this.set(e)}parseParams(){const e=this.getBestFit();"none"!=e&&this.childrenTexts.length?this.calculateBestFit(e):this.childrenTexts.forEach((e=>{e._fitFontSize=void 0}))}updateLayout(){const e=this.getWidth(),t=this.getHeight();e&&t?(this.size.set(e,t),this.frame.scale.set(e,t,1),this.frame&&this.updateBackgroundMaterial(),this.frame.renderOrder=this.getParentsNumber(),this.autoLayout&&this.setPosFromParentRecords(),this.childrenInlines.length&&this.computeInlinesPosition(),this.computeChildrenPosition(),this.parentUI&&(this.position.z=this.getOffset())):console.warn("Block got no dimension from its parameters or from children parameters")}updateInner(){this.parentUI&&(this.position.z=this.getOffset()),this.frame&&this.updateBackgroundMaterial()}}function ke(e){return class extends e{constructor(e){super(e),this.isInline=!0}}}function _e(e){let t,s,r,a=-1,i=0;for(let n=0;n<e.length;++n){const o=e[n];if(void 0===t&&(t=o.array.constructor),t!==o.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(void 0===s&&(s=o.itemSize),s!==o.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(void 0===r&&(r=o.normalized),r!==o.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(-1===a&&(a=o.gpuType),a!==o.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;i+=o.count*s}const n=new t(i),o=new h.BufferAttribute(n,s,r);let c=0;for(let t=0;t<e.length;++t){const r=e[t];if(r.isInterleavedBufferAttribute){const e=c/s;for(let t=0,a=r.count;t<a;t++)for(let a=0;a<s;a++){const s=r.getComponent(t,a);o.setComponent(t+e,a,s)}}else n.set(r.array,c);c+=r.count*s}return void 0!==a&&(o.gpuType=a),o}class Ue extends h.PlaneGeometry{constructor(e,t){const s=e.glyph,r=e.fontSize;super(e.width,e.height),null===s.match(/\s/g)?(-1===t.info.charset.indexOf(s)&&console.error(`The character '${s}' is not included in the font characters set.`),this.mapUVs(t,s),this.transformGeometry(e)):(this.nullifyUVs(),this.scale(0,0,1),this.translate(0,r/2,0))}mapUVs(e,t){const s=e.chars.find((e=>e.char===t)),r=e.common,a=s.x/r.scaleW,i=(s.x+s.width)/r.scaleW,n=1-(s.y+s.height)/r.scaleH,o=1-s.y/r.scaleH,h=this.attributes.uv;for(let e=0;e<h.count;e++){let t=h.getX(e),s=h.getY(e);[t,s]=(()=>{switch(e){case 0:return[a,o];case 1:return[i,o];case 2:return[a,n];case 3:return[i,n]}})(),h.setXY(e,t,s)}}nullifyUVs(){const e=this.attributes.uv;for(let t=0;t<e.count;t++)e.setXY(t,0,0)}transformGeometry(e){this.translate(e.width/2,e.height/2,0)}}const Se={getGlyphDimensions:function(e){const t=e.font,s=e.fontSize,r=e.glyph,a=s/t.info.size,i=t.chars.find((e=>e.char===r));let n=i?i.width*a:s/3,o=i?i.height*a:0;0===n&&(n=i?i.xadvance*a:s),0===o&&(o=.7*s),"\n"===r&&(n=0);const h=i?i.xadvance*a:n,c=i?i.xoffset*a:0;return{width:n,height:o,anchor:i?i.yoffset*a:0,xadvance:h,xoffset:c}},getGlyphPairKerning:function(e,t){const s=e._kernings;return s[t]?s[t]:0},buildText:function(){const e=[];this.inlines.forEach(((t,s)=>{e[s]=new Ue(t,this.getFontFamily()),e[s].translate(t.offsetX,t.offsetY,0)}));const t=function(e,t=!1){const s=null!==e[0].index,r=new Set(Object.keys(e[0].attributes)),a=new Set(Object.keys(e[0].morphAttributes)),i={},n={},o=e[0].morphTargetsRelative,c=new h.BufferGeometry;let l=0;for(let h=0;h<e.length;++h){const d=e[h];let u=0;if(s!==(null!==d.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const e in d.attributes){if(!r.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+e+'" attribute exists among all geometries, or in none of them.'),null;void 0===i[e]&&(i[e]=[]),i[e].push(d.attributes[e]),u++}if(u!==r.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(o!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const e in d.morphAttributes){if(!a.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;void 0===n[e]&&(n[e]=[]),n[e].push(d.morphAttributes[e])}if(t){let e;if(s)e=d.index.count;else{if(void 0===d.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;e=d.attributes.position.count}c.addGroup(l,e,h),l+=e}}if(s){let t=0;const s=[];for(let r=0;r<e.length;++r){const a=e[r].index;for(let e=0;e<a.count;++e)s.push(a.getX(e)+t);t+=e[r].attributes.position.count}c.setIndex(s)}for(const e in i){const t=_e(i[e]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" attribute."),null;c.setAttribute(e,t)}for(const e in n){const t=n[e][0].length;if(0===t)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[e]=[];for(let s=0;s<t;++s){const t=[];for(let r=0;r<n[e].length;++r)t.push(n[e][r][s]);const r=_e(t);if(!r)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" morphAttribute."),null;c.morphAttributes[e].push(r)}}return c}(e);return new h.Mesh(t,this.getFontMaterial())}};function Te(e){return class extends e{createText(){const e=this,t=(()=>{if("MSDF"===this.getTextType())return Se.buildText.call(this);console.warn(`'${this.getTextType()}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type`)})();return t.renderOrder=1/0,t.onBeforeRender=function(){e.updateClippingPlanes&&e.updateClippingPlanes()},t}getGlyphDimensions(e){if("MSDF"===e.textType)return Se.getGlyphDimensions(e);console.warn(`'${e.textType}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type`)}getGlyphPairKerning(e,t,s){if("MSDF"===e)return Se.getGlyphPairKerning(t,s);console.warn(`'${e}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type`)}}}const Pe=function e(t){t.children.forEach((s=>{s.children.length>0&&e(s),t.remove(s),le.disposeOf(s),s.material&&s.material.dispose(),s.geometry&&s.geometry.dispose()})),t.children=[]};class Re extends(ve.withBase(h.Object3D)(ke,Te,we,pe)){constructor(e){super(e),this.isText=!0,this.set(e)}parseParams(){this.calculateInlines(this._fitFontSize||this.getFontSize())}updateLayout(){Pe(this),this.inlines&&(this.textContent=this.createText(),this.updateTextMaterial(),this.add(this.textContent))}updateInner(){this.textContent&&this.updateTextMaterial()}calculateInlines(e){const t=this.content,s=this.getFontFamily(),r=this.getBreakOn(),a=this.getTextType(),i=this.getWhiteSpace();if(!s||"string"==typeof s)return void(ce.getFontOf(this)||console.warn("no font was found"));if(!this.content)return void(this.inlines=null);if(!a)return void console.error("You must provide a 'textType' attribute so three-mesh-ui knows how to render your text.\n See https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type");const n=M(t,i),o=Array.from?Array.from(n):String(n).split(""),h=e/s.info.size,c=s.common.lineHeight*h,l=s.common.base*h,d=o.map((t=>{const n=this.getGlyphDimensions({textType:a,glyph:t,font:s,fontSize:e});let o=null;return i!==F&&(r.includes(t)||t.match(/\s/g))&&(o="possible"),t.match(/\n/g)&&(o=L(i)),{height:n.height,width:n.width,anchor:n.anchor,xadvance:n.xadvance,xoffset:n.xoffset,lineBreak:o,glyph:t,fontSize:e,lineHeight:c,lineBase:l}}));if("none"!==this.getFontKerning())for(let t=1;t<d.length;t++){const r=d[t],i=d[t-1].glyph+d[t].glyph,n=this.getGlyphPairKerning(a,s,i);r.kerning=n*(e/s.info.size)}this.inlines=d}}class Ie extends(ve.withBase(h.Object3D)(ke,I,Q,we,pe)){constructor(e){super(e),this.isInlineBlock=!0,this.size=new h.Vector2(1,1),this.frame=new be(this.getBackgroundMaterial()),this.frame.onBeforeRender=()=>{this.updateClippingPlanes&&this.updateClippingPlanes()},this.add(this.frame),this.set(e)}parseParams(){this.width||console.warn("inlineBlock has no width. Set to 0.3 by default"),this.height||console.warn("inlineBlock has no height. Set to 0.3 by default"),this.inlines=[{height:this.height||.3,width:this.width||.3,anchor:0,lineBreak:"possible"}]}updateLayout(){const e=this.getWidth(),t=this.getHeight();if(this.inlines){const e=this.inlines[0];this.position.set(e.width/2,e.height/2,0),this.position.x+=e.offsetX,this.position.y+=e.offsetY}this.size.set(e,t),this.frame.scale.set(e,t,1),this.frame&&this.updateBackgroundMaterial(),this.frame.renderOrder=this.getParentsNumber(),this.childrenInlines.length&&this.computeInlinesPosition(),this.computeChildrenPosition(),this.position.z=this.getOffset()}updateInner(){this.position.z=this.getOffset(),this.frame&&this.updateBackgroundMaterial()}}const Be=[[[{width:.1,chars:[{lowerCase:"a",upperCase:"A"}]},{width:.1,chars:[{lowerCase:"z",upperCase:"Z"}]},{width:.1,chars:[{lowerCase:"e",upperCase:"E"}]},{width:.1,chars:[{lowerCase:"r",upperCase:"R"}]},{width:.1,chars:[{lowerCase:"t",upperCase:"T"}]},{width:.1,chars:[{lowerCase:"y",upperCase:"Y"}]},{width:.1,chars:[{lowerCase:"u",upperCase:"U"}]},{width:.1,chars:[{lowerCase:"i",upperCase:"I"}]},{width:.1,chars:[{lowerCase:"o",upperCase:"O"}]},{width:.1,chars:[{lowerCase:"p",upperCase:"P"}]}],[{width:.1,chars:[{lowerCase:"q",upperCase:"Q"}]},{width:.1,chars:[{lowerCase:"s",upperCase:"S"}]},{width:.1,chars:[{lowerCase:"d",upperCase:"D"}]},{width:.1,chars:[{lowerCase:"f",upperCase:"F"}]},{width:.1,chars:[{lowerCase:"g",upperCase:"G"}]},{width:.1,chars:[{lowerCase:"h",upperCase:"H"}]},{width:.1,chars:[{lowerCase:"j",upperCase:"J"}]},{width:.1,chars:[{lowerCase:"k",upperCase:"K"}]},{width:.1,chars:[{lowerCase:"l",upperCase:"L"}]},{width:.1,chars:[{lowerCase:"m",upperCase:"M"}]}],[{width:.2,command:"shift",chars:[{icon:"shift"}]},{width:.1,chars:[{lowerCase:"w",upperCase:"W"}]},{width:.1,chars:[{lowerCase:"x",upperCase:"X"}]},{width:.1,chars:[{lowerCase:"c",upperCase:"C"}]},{width:.1,chars:[{lowerCase:"v",upperCase:"V"}]},{width:.1,chars:[{lowerCase:"b",upperCase:"B"}]},{width:.1,chars:[{lowerCase:"n",upperCase:"N"}]},{width:.2,command:"backspace",chars:[{icon:"backspace"}]}],[{width:.2,command:"switch",chars:[{lowerCase:".?12"}]},{width:.1,chars:[{lowerCase:","}]},{width:.4,command:"space",chars:[{icon:"space"}]},{width:.1,chars:[{lowerCase:"."}]},{width:.2,command:"enter",chars:[{icon:"enter"}]}]],[[{width:.1,chars:[{lowerCase:"1"}]},{width:.1,chars:[{lowerCase:"2"}]},{width:.1,chars:[{lowerCase:"3"}]},{width:.1,chars:[{lowerCase:"4"}]},{width:.1,chars:[{lowerCase:"5"}]},{width:.1,chars:[{lowerCase:"6"}]},{width:.1,chars:[{lowerCase:"7"}]},{width:.1,chars:[{lowerCase:"8"}]},{width:.1,chars:[{lowerCase:"9"}]},{width:.1,chars:[{lowerCase:"0"}]}],[{width:.1,chars:[{lowerCase:"@"}]},{width:.1,chars:[{lowerCase:"#"}]},{width:.1,chars:[{lowerCase:"|"}]},{width:.1,chars:[{lowerCase:"_"}]},{width:.1,chars:[{lowerCase:"&"}]},{width:.1,chars:[{lowerCase:"-"}]},{width:.1,chars:[{lowerCase:"+"}]},{width:.1,chars:[{lowerCase:"("}]},{width:.1,chars:[{lowerCase:")"}]},{width:.1,chars:[{lowerCase:"/"}]}],[{width:.1,chars:[{lowerCase:"="}]},{width:.1,chars:[{lowerCase:"*"}]},{width:.1,chars:[{lowerCase:'"'}]},{width:.1,chars:[{lowerCase:"'"}]},{width:.1,chars:[{lowerCase:":"}]},{width:.1,chars:[{lowerCase:";"}]},{width:.1,chars:[{lowerCase:"!"}]},{width:.1,chars:[{lowerCase:"?"}]},{width:.2,command:"backspace",chars:[{icon:"backspace"}]}],[{width:.2,command:"switch",chars:[{lowerCase:".?12"}]},{width:.1,chars:[{lowerCase:","}]},{width:.4,command:"space",chars:[{icon:"space"}]},{width:.1,chars:[{lowerCase:"."}]},{width:.2,command:"enter",chars:[{icon:"enter"}]}]]],Oe=[[[{width:.1,chars:[{lowerCase:"q",upperCase:"Q"}]},{width:.1,chars:[{lowerCase:"w",upperCase:"W"}]},{width:.1,chars:[{lowerCase:"e",upperCase:"E"}]},{width:.1,chars:[{lowerCase:"r",upperCase:"R"}]},{width:.1,chars:[{lowerCase:"t",upperCase:"T"}]},{width:.1,chars:[{lowerCase:"y",upperCase:"Y"}]},{width:.1,chars:[{lowerCase:"u",upperCase:"U"}]},{width:.1,chars:[{lowerCase:"i",upperCase:"I"}]},{width:.1,chars:[{lowerCase:"o",upperCase:"O"}]},{width:.1,chars:[{lowerCase:"p",upperCase:"P"}]}],[{width:.1,chars:[{lowerCase:"a",upperCase:"A"}]},{width:.1,chars:[{lowerCase:"s",upperCase:"S"}]},{width:.1,chars:[{lowerCase:"d",upperCase:"D"}]},{width:.1,chars:[{lowerCase:"f",upperCase:"F"}]},{width:.1,chars:[{lowerCase:"g",upperCase:"G"}]},{width:.1,chars:[{lowerCase:"h",upperCase:"H"}]},{width:.1,chars:[{lowerCase:"j",upperCase:"J"}]},{width:.1,chars:[{lowerCase:"k",upperCase:"K"}]},{width:.1,chars:[{lowerCase:"l",upperCase:"L"}]}],[{width:.15,command:"shift",chars:[{icon:"shift"}]},{width:.1,chars:[{lowerCase:"z",upperCase:"Z"}]},{width:.1,chars:[{lowerCase:"x",upperCase:"X"}]},{width:.1,chars:[{lowerCase:"c",upperCase:"C"}]},{width:.1,chars:[{lowerCase:"v",upperCase:"V"}]},{width:.1,chars:[{lowerCase:"b",upperCase:"B"}]},{width:.1,chars:[{lowerCase:"n",upperCase:"N"}]},{width:.1,chars:[{lowerCase:"m",upperCase:"M"}]},{width:.15,command:"backspace",chars:[{icon:"backspace"}]}],[{width:.2,command:"switch",chars:[{lowerCase:".?12"}]},{width:.1,chars:[{lowerCase:","}]},{width:.4,command:"space",chars:[{icon:"space"}]},{width:.1,chars:[{lowerCase:"."}]},{width:.2,command:"enter",chars:[{icon:"enter"}]}]],[[{width:.1,chars:[{lowerCase:"1"}]},{width:.1,chars:[{lowerCase:"2"}]},{width:.1,chars:[{lowerCase:"3"}]},{width:.1,chars:[{lowerCase:"4"}]},{width:.1,chars:[{lowerCase:"5"}]},{width:.1,chars:[{lowerCase:"6"}]},{width:.1,chars:[{lowerCase:"7"}]},{width:.1,chars:[{lowerCase:"8"}]},{width:.1,chars:[{lowerCase:"9"}]},{width:.1,chars:[{lowerCase:"0"}]}],[{width:.1,chars:[{lowerCase:"@"}]},{width:.1,chars:[{lowerCase:"#"}]},{width:.1,chars:[{lowerCase:"|"}]},{width:.1,chars:[{lowerCase:"_"}]},{width:.1,chars:[{lowerCase:"&"}]},{width:.1,chars:[{lowerCase:"-"}]},{width:.1,chars:[{lowerCase:"+"}]},{width:.1,chars:[{lowerCase:"("}]},{width:.1,chars:[{lowerCase:")"}]},{width:.1,chars:[{lowerCase:"/"}]}],[{width:.1,chars:[{lowerCase:"="}]},{width:.1,chars:[{lowerCase:"*"}]},{width:.1,chars:[{lowerCase:'"'}]},{width:.1,chars:[{lowerCase:"'"}]},{width:.1,chars:[{lowerCase:":"}]},{width:.1,chars:[{lowerCase:";"}]},{width:.1,chars:[{lowerCase:"!"}]},{width:.1,chars:[{lowerCase:"?"}]},{width:.2,command:"backspace",chars:[{icon:"backspace"}]}],[{width:.2,command:"switch",chars:[{lowerCase:".?12"}]},{width:.1,chars:[{lowerCase:","}]},{width:.4,command:"space",chars:[{icon:"space"}]},{width:.1,chars:[{lowerCase:"."}]},{width:.2,command:"enter",chars:[{icon:"enter"}]}]]],Fe=[[[{width:1/12,chars:[{lowerCase:"й",upperCase:"Й"},{lowerCase:"q",upperCase:"Q"}]},{width:1/12,chars:[{lowerCase:"ц",upperCase:"Ц"},{lowerCase:"w",upperCase:"W"}]},{width:1/12,chars:[{lowerCase:"у",upperCase:"У"},{lowerCase:"e",upperCase:"E"}]},{width:1/12,chars:[{lowerCase:"к",upperCase:"К"},{lowerCase:"r",upperCase:"R"}]},{width:1/12,chars:[{lowerCase:"е",upperCase:"Е"},{lowerCase:"t",upperCase:"T"}]},{width:1/12,chars:[{lowerCase:"н",upperCase:"Н"},{lowerCase:"y",upperCase:"Y"}]},{width:1/12,chars:[{lowerCase:"г",upperCase:"Г"},{lowerCase:"u",upperCase:"U"}]},{width:1/12,chars:[{lowerCase:"ш",upperCase:"Ш"},{lowerCase:"i",upperCase:"I"}]},{width:1/12,chars:[{lowerCase:"щ",upperCase:"Щ"},{lowerCase:"o",upperCase:"O"}]},{width:1/12,chars:[{lowerCase:"з",upperCase:"З"},{lowerCase:"p",upperCase:"P"}]},{width:1/12,chars:[{lowerCase:"х",upperCase:"Х"},{lowerCase:"{",upperCase:"["}]},{width:1/12,chars:[{lowerCase:"ъ",upperCase:"Ъ"},{lowerCase:"}",upperCase:"]"}]}],[{width:1/12,chars:[{lowerCase:"ф",upperCase:"Ф"},{lowerCase:"a",upperCase:"A"}]},{width: