@splinetool/loader 1.9.44 → 1.9.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- var z1=Object.create;var zl=Object.defineProperty;var G1=Object.getOwnPropertyDescriptor;var F1=Object.getOwnPropertyNames;var j1=Object.getPrototypeOf,k1=Object.prototype.hasOwnProperty;var U1=(n,r,e)=>r in n?zl(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var bs=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),H1=(n,r)=>{for(var e in r)zl(n,e,{get:r[e],enumerable:!0})},W1=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of F1(r))!k1.call(n,o)&&o!==e&&zl(n,o,{get:()=>r[o],enumerable:!(t=G1(r,o))||t.enumerable});return n};var vs=(n,r,e)=>(e=n!=null?z1(j1(n)):{},W1(r||!n||!n.__esModule?zl(e,"default",{value:n,enumerable:!0}):e,n));var $r=(n,r,e)=>(U1(n,typeof r!="symbol"?r+"":r,e),e);var Gx=bs((Np,zx)=>{(function(n,r){typeof Np=="object"?zx.exports=r():typeof define=="function"&&define.amd?define(r):n.Alea=r()})(Np,function(){"use strict";return n.importState=function(e){var t=new n;return t.importState(e),t},n;function n(){return function(e){var t=0,o=0,i=0,a=1;e.length==0&&(e=[+new Date]);var s=r();t=s(" "),o=s(" "),i=s(" ");for(var l=0;l<e.length;l++)t-=s(e[l]),t<0&&(t+=1),o-=s(e[l]),o<0&&(o+=1),i-=s(e[l]),i<0&&(i+=1);s=null;var c=function(){var u=2091639*t+a*23283064365386963e-26;return t=o,o=i,i=u-(a=u|0)};return c.next=c,c.uint32=function(){return c()*4294967296},c.fract53=function(){return c()+(c()*2097152|0)*11102230246251565e-32},c.version="Alea 0.9",c.args=e,c.exportState=function(){return[t,o,i,a]},c.importState=function(u){t=+u[0]||0,o=+u[1]||0,i=+u[2]||0,a=+u[3]||0},c}(Array.prototype.slice.call(arguments))}function r(){var e=4022871197,t=function(o){o=o.toString();for(var i=0;i<o.length;i++){e+=o.charCodeAt(i);var a=.02519603282416938*e;e=a>>>0,a-=e,a*=e,e=a>>>0,a-=e,e+=a*4294967296}return(e>>>0)*23283064365386963e-26};return t.version="Mash 0.9",t}})});var Hx=bs((nu,Ux)=>{(function(n,r){typeof nu=="object"&&typeof Ux<"u"?r(nu):typeof define=="function"&&define.amd?define(["exports"],r):r((n=typeof globalThis<"u"?globalThis:n||self).SVDJS={})})(nu,function(n){"use strict";n.SVD=function(r,e,t,o,i){if(e=e===void 0||e,t=t===void 0||t,i=1e-64/(o=o||Math.pow(2,-52)),!r)throw new TypeError("Matrix a is not defined");var a,s,l,c,u,p,d,h,f,m,y,g,v=r[0].length,w=r.length;if(w<v)throw new TypeError("Invalid matrix: m < n");for(var O=[],S=[],C=[],T=e==="f"?w:v,x=m=d=0;x<w;x++)S[x]=new Array(T).fill(0);for(x=0;x<v;x++)C[x]=new Array(v).fill(0);var N,E=new Array(v).fill(0);for(x=0;x<w;x++)for(a=0;a<v;a++)S[x][a]=r[x][a];for(x=0;x<v;x++){for(O[x]=d,f=0,l=x+1,a=x;a<w;a++)f+=Math.pow(S[a][x],2);if(f<i)d=0;else for(h=(p=S[x][x])*(d=p<0?Math.sqrt(f):-Math.sqrt(f))-f,S[x][x]=p-d,a=l;a<v;a++){for(f=0,s=x;s<w;s++)f+=S[s][x]*S[s][a];for(p=f/h,s=x;s<w;s++)S[s][a]=S[s][a]+p*S[s][x]}for(E[x]=d,f=0,a=l;a<v;a++)f+=Math.pow(S[x][a],2);if(f<i)d=0;else{for(h=(p=S[x][x+1])*(d=p<0?Math.sqrt(f):-Math.sqrt(f))-f,S[x][x+1]=p-d,a=l;a<v;a++)O[a]=S[x][a]/h;for(a=l;a<w;a++){for(f=0,s=l;s<v;s++)f+=S[a][s]*S[x][s];for(s=l;s<v;s++)S[a][s]=S[a][s]+f*O[s]}}m<(y=Math.abs(E[x])+Math.abs(O[x]))&&(m=y)}if(t)for(x=v-1;0<=x;x--){if(d!==0){for(h=S[x][x+1]*d,a=l;a<v;a++)C[a][x]=S[x][a]/h;for(a=l;a<v;a++){for(f=0,s=l;s<v;s++)f+=S[x][s]*C[s][a];for(s=l;s<v;s++)C[s][a]=C[s][a]+f*C[s][x]}}for(a=l;a<v;a++)C[x][a]=0,C[a][x]=0;C[x][x]=1,d=O[x],l=x}if(e){if(e==="f")for(x=v;x<w;x++){for(a=v;a<w;a++)S[x][a]=0;S[x][x]=1}for(x=v-1;0<=x;x--){for(l=x+1,d=E[x],a=l;a<T;a++)S[x][a]=0;if(d!==0){for(h=S[x][x]*d,a=l;a<T;a++){for(f=0,s=l;s<w;s++)f+=S[s][x]*S[s][a];for(p=f/h,s=x;s<w;s++)S[s][a]=S[s][a]+p*S[s][x]}for(a=x;a<w;a++)S[a][x]=S[a][x]/d}else for(a=x;a<w;a++)S[a][x]=0;S[x][x]=S[x][x]+1}}for(o*=m,s=v-1;0<=s;s--)for(var M=0;M<50;M++){for(N=!1,l=s;0<=l;l--){if(Math.abs(O[l])<=o){N=!0;break}if(Math.abs(E[l-1])<=o)break}if(!N){for(u=0,c=l-(f=1),x=l;x<s+1&&(p=f*O[x],O[x]=u*O[x],!(Math.abs(p)<=o));x++)if(d=E[x],E[x]=Math.sqrt(p*p+d*d),u=d/(h=E[x]),f=-p/h,e)for(a=0;a<w;a++)y=S[a][c],g=S[a][x],S[a][c]=y*u+g*f,S[a][x]=-y*f+g*u}if(g=E[s],l===s){if(g<0&&(E[s]=-g,t))for(a=0;a<v;a++)C[a][s]=-C[a][s];break}for(m=E[l],p=(((y=E[s-1])-g)*(y+g)+((d=O[s-1])-(h=O[s]))*(d+h))/(2*h*y),d=Math.sqrt(p*p+1),p=((m-g)*(m+g)+h*(y/(p<0?p-d:p+d)-h))/m,x=l+(f=u=1);x<s+1;x++){if(d=O[x],y=E[x],h=f*d,d*=u,g=Math.sqrt(p*p+h*h),p=m*(u=p/(O[x-1]=g))+d*(f=h/g),d=-m*f+d*u,h=y*f,y*=u,t)for(a=0;a<v;a++)m=C[a][x-1],g=C[a][x],C[a][x-1]=m*u+g*f,C[a][x]=-m*f+g*u;if(g=Math.sqrt(p*p+h*h),p=(u=p/(E[x-1]=g))*d+(f=h/g)*y,m=-f*d+u*y,e)for(a=0;a<w;a++)y=S[a][x-1],g=S[a][x],S[a][x-1]=y*u+g*f,S[a][x]=-y*f+g*u}O[l]=0,O[s]=p,E[s]=m}for(x=0;x<v;x++)E[x]<o&&(E[x]=0);return{u:S,q:E,v:C}},n.VERSION="1.1.1",Object.defineProperty(n,"__esModule",{value:!0})})});var uS=bs((Rle,cS)=>{"use strict";function j3(n,r){function e(){this.constructor=n}e.prototype=r.prototype,n.prototype=new e}function hi(n,r,e,t){this.message=n,this.expected=r,this.found=e,this.location=t,this.name="SyntaxError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,hi)}j3(hi,Error);hi.buildMessage=function(n,r){var e={literal:function(c){return'"'+o(c.text)+'"'},class:function(c){var u="",p;for(p=0;p<c.parts.length;p++)u+=c.parts[p]instanceof Array?i(c.parts[p][0])+"-"+i(c.parts[p][1]):i(c.parts[p]);return"["+(c.inverted?"^":"")+u+"]"},any:function(c){return"any character"},end:function(c){return"end of input"},other:function(c){return c.description}};function t(c){return c.charCodeAt(0).toString(16).toUpperCase()}function o(c){return c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+t(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+t(u)})}function i(c){return c.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+t(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+t(u)})}function a(c){return e[c.type](c)}function s(c){var u=new Array(c.length),p,d;for(p=0;p<c.length;p++)u[p]=a(c[p]);if(u.sort(),u.length>0){for(p=1,d=1;p<u.length;p++)u[p-1]!==u[p]&&(u[d]=u[p],d++);u.length=d}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}function l(c){return c?'"'+o(c)+'"':"end of input"}return"Expected "+s(n)+" but "+l(r)+" found."};function k3(n,r){r=r!==void 0?r:{};var e={},t={svg_path:xs},o=xs,i=function(b){if(!b)return[];for(var P=[],R=0;R<b.length;R++)P=P.concat.apply(P,b[R]);var I=P[0];return I&&I.code=="m"&&(delete I.relative,I.code="M"),P},a=function(b,P){return V1(b,P)},s=/^[Mm]/,l=Xe(["M","m"],!1,!1),c=function(b,P,R){var I=bi(b,[P]);return R&&(I=I.concat(bi(b=="M"?"L":"l",R[1]))),I},u=/^[Zz]/,p=Xe(["Z","z"],!1,!1),d=function(){return bi("Z")},h=/^[Ll]/,f=Xe(["L","l"],!1,!1),m=function(b,P){return bi(b,P)},y=/^[Hh]/,g=Xe(["H","h"],!1,!1),v=function(b,P){return bi(b,P.map(function(R){return{x:R}}))},w=/^[Vv]/,O=Xe(["V","v"],!1,!1),S=function(b,P){return bi(b,P.map(function(R){return{y:R}}))},C=/^[Cc]/,T=Xe(["C","c"],!1,!1),x=function(b,P,R){return{x1:b.x,y1:b.y,x2:P.x,y2:P.y,x:R.x,y:R.y}},N=/^[Ss]/,E=Xe(["S","s"],!1,!1),M=function(b,P){return{x2:b.x,y2:b.y,x:P.x,y:P.y}},D=/^[Qq]/,_=Xe(["Q","q"],!1,!1),B=function(b,P){return{x1:b.x,y1:b.y,x:P.x,y:P.y}},V=/^[Tt]/,k=Xe(["T","t"],!1,!1),L=/^[Aa]/,W=Xe(["A","a"],!1,!1),F=function(b,P,R,I,z,oe){return{rx:b,ry:P,xAxisRotation:R,largeArc:I,sweep:z,x:oe.x,y:oe.y}},j=function(b,P){return{x:b,y:P}},H=function(b){return b*1},q=function(b){return b.join("")*1},re=/^[01]/,ee=Xe(["0","1"],!1,!1),X=function(b){return b=="1"},te=function(){return""},K=",",Z=ot(",",!1),Q=function(b){return b.join("")},$=".",ue=ot(".",!1),le=/^[eE]/,ne=Xe(["e","E"],!1,!1),ce=/^[+\-]/,ae=Xe(["+","-"],!1,!1),me=/^[0-9]/,pe=Xe([["0","9"]],!1,!1),he=function(b){return b.join("")},xe=/^[ \t\n\r]/,ye=Xe([" "," ",`
2
- `,"\r"],!1,!1),A=0,ie=0,De=[{line:1,column:1}],Ve=0,_e=[],Pe=0,vt;if("startRule"in r){if(!(r.startRule in t))throw new Error(`Can't start parsing from rule "`+r.startRule+'".');o=t[r.startRule]}function Ie(){return n.substring(ie,A)}function gt(){return zn(ie,A)}function St(b,P){throw P=P!==void 0?P:zn(ie,A),hr([_d(b)],n.substring(ie,A),P)}function Vn(b,P){throw P=P!==void 0?P:zn(ie,A),Bd(b,P)}function ot(b,P){return{type:"literal",text:b,ignoreCase:P}}function Xe(b,P,R){return{type:"class",parts:b,inverted:P,ignoreCase:R}}function Mr(){return{type:"any"}}function Dd(){return{type:"end"}}function _d(b){return{type:"other",description:b}}function _l(b){var P=De[b],R;if(P)return P;for(R=b-1;!De[R];)R--;for(P=De[R],P={line:P.line,column:P.column};R<b;)n.charCodeAt(R)===10?(P.line++,P.column=1):P.column++,R++;return De[b]=P,P}function zn(b,P){var R=_l(b),I=_l(P);return{start:{offset:b,line:R.line,column:R.column},end:{offset:P,line:I.line,column:I.column}}}function ct(b){A<Ve||(A>Ve&&(Ve=A,_e=[]),_e.push(b))}function Bd(b,P){return new hi(b,null,null,P)}function hr(b,P,R){return new hi(hi.buildMessage(b,P),b,P,R)}function xs(){var b,P,R,I,z;for(b=A,P=[],R=ze();R!==e;)P.push(R),R=ze();if(P!==e)if(R=Ut(),R===e&&(R=null),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(ie=b,P=i(R),b=P):(A=b,b=e)}else A=b,b=e;else A=b,b=e;return b}function Ut(){var b,P,R,I,z,oe;if(b=A,P=Gn(),P!==e){for(R=[],I=A,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();for(z!==e?(oe=Gn(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;){for(R.push(I),I=A,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();z!==e?(oe=Gn(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e)}R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function Gn(){var b,P,R,I,z,oe;if(b=A,P=gi(),P!==e){for(R=[],I=A,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();for(z!==e?(oe=Bl(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;){for(R.push(I),I=A,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();z!==e?(oe=Bl(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e)}R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function Bl(){var b;return b=w1(),b===e&&(b=P1(),b===e&&(b=C1(),b===e&&(b=O1(),b===e&&(b=A1(),b===e&&(b=I1(),b===e&&(b=E1(),b===e&&(b=D1(),b===e&&(b=B1())))))))),b}function gi(){var b,P,R,I,z,oe,vi;if(b=A,s.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(l)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Wt(),I!==e?(z=A,oe=et(),oe===e&&(oe=null),oe!==e?(vi=Wh(),vi!==e?(oe=[oe,vi],z=oe):(A=z,z=e)):(A=z,z=e),z===e&&(z=null),z!==e?(ie=b,P=c(P,I,z),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function w1(){var b,P;return b=A,u.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(p)),P!==e&&(ie=b,P=d()),b=P,b}function P1(){var b,P,R,I;if(b=A,h.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(f)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Wh(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function Wh(){var b,P,R,I,z,oe;if(b=A,P=Wt(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function C1(){var b,P,R,I;if(b=A,y.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(g)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=qh(),I!==e?(ie=b,P=v(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function qh(){var b,P,R,I,z,oe;if(b=A,P=xi(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=xi(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=xi(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function O1(){var b,P,R,I;if(b=A,w.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(O)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=qh(),I!==e?(ie=b,P=S(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function A1(){var b,P,R,I;if(b=A,C.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(T)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=T1(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function T1(){var b,P,R,I,z,oe;if(b=A,P=Rd(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=Rd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=Rd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function Rd(){var b,P,R,I,z,oe;return b=A,P=Wt(),P!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(ie=b,P=x(P,I,oe),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e),b}function I1(){var b,P,R,I;if(b=A,N.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(E)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=M1(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function M1(){var b,P,R,I,z,oe;if(b=A,P=Ld(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=Ld(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=Ld(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function Ld(){var b,P,R,I;return b=A,P=Wt(),P!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(ie=b,P=M(P,I),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e),b}function E1(){var b,P,R,I;if(b=A,D.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(_)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=N1(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function N1(){var b,P,R,I,z,oe;if(b=A,P=Vd(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=Vd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=Vd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function Vd(){var b,P,R,I;return b=A,P=Wt(),P!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(ie=b,P=B(P,I),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e),b}function D1(){var b,P,R,I;if(b=A,V.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(k)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=_1(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function _1(){var b,P,R,I,z,oe;if(b=A,P=Wt(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function B1(){var b,P,R,I;if(b=A,L.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(W)),P!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=R1(),I!==e?(ie=b,P=m(P,I),b=P):(A=b,b=e)):(A=b,b=e)}else A=b,b=e;return b}function R1(){var b,P,R,I,z,oe;if(b=A,P=zd(),P!==e){for(R=[],I=A,z=et(),z===e&&(z=null),z!==e?(oe=zd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);I!==e;)R.push(I),I=A,z=et(),z===e&&(z=null),z!==e?(oe=zd(),oe!==e?(z=[z,oe],I=z):(A=I,I=e)):(A=I,I=e);R!==e?(ie=b,P=a(P,R),b=P):(A=b,b=e)}else A=b,b=e;return b}function zd(){var b,P,R,I,z,oe,vi,Fd,Ll,jd,Vl,kd;return b=A,P=$h(),P!==e?(R=et(),R===e&&(R=null),R!==e?(I=$h(),I!==e?(z=et(),z===e&&(z=null),z!==e?(oe=xi(),oe!==e?(vi=et(),vi!==e?(Fd=Yh(),Fd!==e?(Ll=et(),Ll===e&&(Ll=null),Ll!==e?(jd=Yh(),jd!==e?(Vl=et(),Vl===e&&(Vl=null),Vl!==e?(kd=Wt(),kd!==e?(ie=b,P=F(P,I,oe,Fd,jd,kd),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e)):(A=b,b=e),b}function Wt(){var b,P,R,I;return b=A,P=xi(),P!==e?(R=et(),R===e&&(R=null),R!==e?(I=xi(),I!==e?(ie=b,P=j(P,I),b=P):(A=b,b=e)):(A=b,b=e)):(A=b,b=e),b}function $h(){var b,P;return b=A,P=Kh(),P===e&&(P=Fn()),P!==e&&(ie=b,P=H(P)),b=P,b}function xi(){var b,P,R,I;return b=A,P=A,R=Gd(),R===e&&(R=null),R!==e?(I=Kh(),I!==e?(R=[R,I],P=R):(A=P,P=e)):(A=P,P=e),P===e&&(P=A,R=Gd(),R===e&&(R=null),R!==e?(I=Fn(),I!==e?(R=[R,I],P=R):(A=P,P=e)):(A=P,P=e)),P!==e&&(ie=b,P=q(P)),b=P,b}function Yh(){var b,P;return b=A,re.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(ee)),P!==e&&(ie=b,P=X(P)),b=P,b}function et(){var b,P,R,I,z;if(b=A,P=[],R=ze(),R!==e)for(;R!==e;)P.push(R),R=ze();else P=e;if(P!==e)if(R=Xh(),R===e&&(R=null),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(P=[P,R,I],b=P):(A=b,b=e)}else A=b,b=e;else A=b,b=e;if(b===e){if(b=A,P=A,R=Xh(),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(R=[R,I],P=R):(A=P,P=e)}else A=P,P=e;P!==e&&(ie=b,P=te()),b=P}return b}function Xh(){var b;return n.charCodeAt(A)===44?(b=K,A++):(b=e,Pe===0&&ct(Z)),b}function Kh(){var b,P,R,I;return b=A,P=A,R=L1(),R!==e?(I=Qh(),I===e&&(I=null),I!==e?(R=[R,I],P=R):(A=P,P=e)):(A=P,P=e),P===e&&(P=A,R=Fn(),R!==e?(I=Qh(),I!==e?(R=[R,I],P=R):(A=P,P=e)):(A=P,P=e)),P!==e&&(ie=b,P=Q(P)),b=P,b}function L1(){var b,P,R,I,z;return b=A,P=A,R=Fn(),R===e&&(R=null),R!==e?(n.charCodeAt(A)===46?(I=$,A++):(I=e,Pe===0&&ct(ue)),I!==e?(z=Fn(),z!==e?(R=[R,I,z],P=R):(A=P,P=e)):(A=P,P=e)):(A=P,P=e),P===e&&(P=A,R=Fn(),R!==e?(n.charCodeAt(A)===46?(I=$,A++):(I=e,Pe===0&&ct(ue)),I!==e?(R=[R,I],P=R):(A=P,P=e)):(A=P,P=e)),P!==e&&(ie=b,P=Q(P)),b=P,b}function Qh(){var b,P,R,I,z;return b=A,P=A,le.test(n.charAt(A))?(R=n.charAt(A),A++):(R=e,Pe===0&&ct(ne)),R!==e?(I=Gd(),I===e&&(I=null),I!==e?(z=Fn(),z!==e?(R=[R,I,z],P=R):(A=P,P=e)):(A=P,P=e)):(A=P,P=e),P!==e&&(ie=b,P=Q(P)),b=P,b}function Gd(){var b;return ce.test(n.charAt(A))?(b=n.charAt(A),A++):(b=e,Pe===0&&ct(ae)),b}function Fn(){var b,P,R;if(b=A,P=[],me.test(n.charAt(A))?(R=n.charAt(A),A++):(R=e,Pe===0&&ct(pe)),R!==e)for(;R!==e;)P.push(R),me.test(n.charAt(A))?(R=n.charAt(A),A++):(R=e,Pe===0&&ct(pe));else P=e;return P!==e&&(ie=b,P=he(P)),b=P,b}function ze(){var b,P;return b=A,xe.test(n.charAt(A))?(P=n.charAt(A),A++):(P=e,Pe===0&&ct(ye)),P!==e&&(ie=b,P=te()),b=P,b}function V1(b,P){if(!P)return[b];for(var R=[b],I=0,z=P.length;I<z;I++)R[I+1]=P[I][1];return R}var Rl={m:"moveto",l:"lineto",h:"horizontal lineto",v:"vertical lineto",c:"curveto",s:"smooth curveto",q:"quadratic curveto",t:"smooth quadratic curveto",a:"elliptical arc",z:"closepath"};for(var Zh in Rl)Rl[Zh.toUpperCase()]=Rl[Zh];function bi(b,P){P||(P=[{}]);for(var R=P.length;R--;){var I={code:b,command:Rl[b]};b==b.toLowerCase()&&(I.relative=!0);for(var z in P[R])I[z]=P[R][z];P[R]=I}return P}if(vt=o(),vt!==e&&A===n.length)return vt;throw vt!==e&&A<n.length&&ct(Dd()),hr(_e,Ve<n.length?n.charAt(Ve):null,Ve<n.length?zn(Ve,Ve+1):zn(Ve,Ve))}cS.exports={SyntaxError:hi,parse:k3}});var Ch=bs((Lle,dS)=>{var hd=uS().parse;hd.parseSVG=hd;hd.makeAbsolute=U3;dS.exports=hd;function U3(n){var r,e={x:0,y:0},t={x:"x0",y:"y0",x1:"x0",y1:"y0",x2:"x0",y2:"y0"};return n.forEach(function(o){o.command==="moveto"&&(r=o),o.x0=e.x,o.y0=e.y;for(var i in t)i in o&&(o[i]+=o.relative?o[t[i]]:0);"x"in o||(o.x=e.x),"y"in o||(o.y=e.y),o.relative=!1,o.code=o.code.toUpperCase(),o.command=="closepath"&&(o.x=r.x,o.y=r.y),e=o}),n}});var b1=bs((Rme,x1)=>{x1.exports=function(r,e){for(var t=r.split("."),o=e.split("."),i=0;i<3;i++){var a=Number(t[i]),s=Number(o[i]);if(a>s)return 1;if(s>a)return-1;if(!isNaN(a)&&isNaN(s))return 1;if(isNaN(a)&&!isNaN(s))return-1}return 0}});import{FileLoader as MB,Loader as EB}from"three";function Gl(n){for(let r of Object.keys(n))n[r]===void 0&&delete n[r];return n}function Lt(n,r){return Object.setPrototypeOf(n,r),n}function Fl(n){return Array.isArray(n)?n:[n]}function jl(n,r){let e=0;for(;e<n.length&&e<r.length;){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1;e+=1}return e!==r.length?-1:e!==n.length?1:0}var q1=typeof global=="object"&&global&&global.Object===Object&&global,kl=q1;var $1=typeof self=="object"&&self&&self.Object===Object&&self,Y1=kl||$1||Function("return this")(),ut=Y1;var X1=ut.Symbol,Tt=X1;var Jh=Object.prototype,K1=Jh.hasOwnProperty,Q1=Jh.toString,Ss=Tt?Tt.toStringTag:void 0;function Z1(n){var r=K1.call(n,Ss),e=n[Ss];try{n[Ss]=void 0;var t=!0}catch{}var o=Q1.call(n);return t&&(r?n[Ss]=e:delete n[Ss]),o}var em=Z1;var J1=Object.prototype,ew=J1.toString;function tw(n){return ew.call(n)}var tm=tw;var rw="[object Null]",ow="[object Undefined]",rm=Tt?Tt.toStringTag:void 0;function nw(n){return n==null?n===void 0?ow:rw:rm&&rm in Object(n)?em(n):tm(n)}var sr=nw;function iw(n){return n!=null&&typeof n=="object"}var Vt=iw;var aw="[object Symbol]";function sw(n){return typeof n=="symbol"||Vt(n)&&sr(n)==aw}var Ko=sw;function lw(n,r){for(var e=-1,t=n==null?0:n.length,o=Array(t);++e<t;)o[e]=r(n[e],e,n);return o}var Ul=lw;var cw=Array.isArray,dt=cw;var uw=1/0,om=Tt?Tt.prototype:void 0,nm=om?om.toString:void 0;function im(n){if(typeof n=="string")return n;if(dt(n))return Ul(n,im)+"";if(Ko(n))return nm?nm.call(n):"";var r=n+"";return r=="0"&&1/n==-uw?"-0":r}var am=im;var dw=/\s/;function pw(n){for(var r=n.length;r--&&dw.test(n.charAt(r)););return r}var sm=pw;var fw=/^\s+/;function hw(n){return n&&n.slice(0,sm(n)+1).replace(fw,"")}var lm=hw;function mw(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}var It=mw;var cm=0/0,yw=/^[-+]0x[0-9a-f]+$/i,gw=/^0b[01]+$/i,xw=/^0o[0-7]+$/i,bw=parseInt;function vw(n){if(typeof n=="number")return n;if(Ko(n))return cm;if(It(n)){var r=typeof n.valueOf=="function"?n.valueOf():n;n=It(r)?r+"":r}if(typeof n!="string")return n===0?n:+n;n=lm(n);var e=gw.test(n);return e||xw.test(n)?bw(n.slice(2),e?2:8):yw.test(n)?cm:+n}var Ud=vw;function Sw(n){return n}var um=Sw;var ww="[object AsyncFunction]",Pw="[object Function]",Cw="[object GeneratorFunction]",Ow="[object Proxy]";function Aw(n){if(!It(n))return!1;var r=sr(n);return r==Pw||r==Cw||r==ww||r==Ow}var Hl=Aw;var Tw=ut["__core-js_shared__"],Wl=Tw;var dm=function(){var n=/[^.]+$/.exec(Wl&&Wl.keys&&Wl.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""}();function Iw(n){return!!dm&&dm in n}var pm=Iw;var Mw=Function.prototype,Ew=Mw.toString;function Nw(n){if(n!=null){try{return Ew.call(n)}catch{}try{return n+""}catch{}}return""}var vo=Nw;var Dw=/[\\^$.*+?()[\]{}|]/g,_w=/^\[object .+?Constructor\]$/,Bw=Function.prototype,Rw=Object.prototype,Lw=Bw.toString,Vw=Rw.hasOwnProperty,zw=RegExp("^"+Lw.call(Vw).replace(Dw,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Gw(n){if(!It(n)||pm(n))return!1;var r=Hl(n)?zw:_w;return r.test(vo(n))}var fm=Gw;function Fw(n,r){return n?.[r]}var hm=Fw;function jw(n,r){var e=hm(n,r);return fm(e)?e:void 0}var Qt=jw;var kw=Qt(ut,"WeakMap"),ql=kw;var mm=Object.create,Uw=function(){function n(){}return function(r){if(!It(r))return{};if(mm)return mm(r);n.prototype=r;var e=new n;return n.prototype=void 0,e}}(),ym=Uw;function Hw(n,r,e){switch(e.length){case 0:return n.call(r);case 1:return n.call(r,e[0]);case 2:return n.call(r,e[0],e[1]);case 3:return n.call(r,e[0],e[1],e[2])}return n.apply(r,e)}var gm=Hw;function Ww(n,r){var e=-1,t=n.length;for(r||(r=Array(t));++e<t;)r[e]=n[e];return r}var xm=Ww;var qw=800,$w=16,Yw=Date.now;function Xw(n){var r=0,e=0;return function(){var t=Yw(),o=$w-(t-e);if(e=t,o>0){if(++r>=qw)return arguments[0]}else r=0;return n.apply(void 0,arguments)}}var bm=Xw;function Kw(n){return function(){return n}}var vm=Kw;var Qw=function(){try{var n=Qt(Object,"defineProperty");return n({},"",{}),n}catch{}}(),Si=Qw;var Zw=Si?function(n,r){return Si(n,"toString",{configurable:!0,enumerable:!1,value:vm(r),writable:!0})}:um,Sm=Zw;var Jw=bm(Sm),wm=Jw;function e2(n,r){for(var e=-1,t=n==null?0:n.length;++e<t&&r(n[e],e,n)!==!1;);return n}var Pm=e2;var t2=9007199254740991,r2=/^(?:0|[1-9]\d*)$/;function o2(n,r){var e=typeof n;return r=r??t2,!!r&&(e=="number"||e!="symbol"&&r2.test(n))&&n>-1&&n%1==0&&n<r}var wi=o2;function n2(n,r,e){r=="__proto__"&&Si?Si(n,r,{configurable:!0,enumerable:!0,value:e,writable:!0}):n[r]=e}var $l=n2;function i2(n,r){return n===r||n!==n&&r!==r}var Pi=i2;var a2=Object.prototype,s2=a2.hasOwnProperty;function l2(n,r,e){var t=n[r];(!(s2.call(n,r)&&Pi(t,e))||e===void 0&&!(r in n))&&$l(n,r,e)}var Ci=l2;function c2(n,r,e,t){var o=!e;e||(e={});for(var i=-1,a=r.length;++i<a;){var s=r[i],l=t?t(e[s],n[s],s,e,n):void 0;l===void 0&&(l=n[s]),o?$l(e,s,l):Ci(e,s,l)}return e}var Yr=c2;var Cm=Math.max;function u2(n,r,e){return r=Cm(r===void 0?n.length-1:r,0),function(){for(var t=arguments,o=-1,i=Cm(t.length-r,0),a=Array(i);++o<i;)a[o]=t[r+o];o=-1;for(var s=Array(r+1);++o<r;)s[o]=t[o];return s[r]=e(a),gm(n,this,s)}}var Om=u2;var d2=9007199254740991;function p2(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=d2}var Oi=p2;function f2(n){return n!=null&&Oi(n.length)&&!Hl(n)}var Yl=f2;var h2=Object.prototype;function m2(n){var r=n&&n.constructor,e=typeof r=="function"&&r.prototype||h2;return n===e}var Ai=m2;function y2(n,r){for(var e=-1,t=Array(n);++e<n;)t[e]=r(e);return t}var Am=y2;var g2="[object Arguments]";function x2(n){return Vt(n)&&sr(n)==g2}var Hd=x2;var Tm=Object.prototype,b2=Tm.hasOwnProperty,v2=Tm.propertyIsEnumerable,S2=Hd(function(){return arguments}())?Hd:function(n){return Vt(n)&&b2.call(n,"callee")&&!v2.call(n,"callee")},Ti=S2;function w2(){return!1}var Im=w2;var Nm=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Mm=Nm&&typeof module=="object"&&module&&!module.nodeType&&module,P2=Mm&&Mm.exports===Nm,Em=P2?ut.Buffer:void 0,C2=Em?Em.isBuffer:void 0,O2=C2||Im,jn=O2;var A2="[object Arguments]",T2="[object Array]",I2="[object Boolean]",M2="[object Date]",E2="[object Error]",N2="[object Function]",D2="[object Map]",_2="[object Number]",B2="[object Object]",R2="[object RegExp]",L2="[object Set]",V2="[object String]",z2="[object WeakMap]",G2="[object ArrayBuffer]",F2="[object DataView]",j2="[object Float32Array]",k2="[object Float64Array]",U2="[object Int8Array]",H2="[object Int16Array]",W2="[object Int32Array]",q2="[object Uint8Array]",$2="[object Uint8ClampedArray]",Y2="[object Uint16Array]",X2="[object Uint32Array]",tt={};tt[j2]=tt[k2]=tt[U2]=tt[H2]=tt[W2]=tt[q2]=tt[$2]=tt[Y2]=tt[X2]=!0;tt[A2]=tt[T2]=tt[G2]=tt[I2]=tt[F2]=tt[M2]=tt[E2]=tt[N2]=tt[D2]=tt[_2]=tt[B2]=tt[R2]=tt[L2]=tt[V2]=tt[z2]=!1;function K2(n){return Vt(n)&&Oi(n.length)&&!!tt[sr(n)]}var Dm=K2;function Q2(n){return function(r){return n(r)}}var Ii=Q2;var _m=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ws=_m&&typeof module=="object"&&module&&!module.nodeType&&module,Z2=ws&&ws.exports===_m,Wd=Z2&&kl.process,J2=function(){try{var n=ws&&ws.require&&ws.require("util").types;return n||Wd&&Wd.binding&&Wd.binding("util")}catch{}}(),So=J2;var Bm=So&&So.isTypedArray,eP=Bm?Ii(Bm):Dm,Xl=eP;var tP=Object.prototype,rP=tP.hasOwnProperty;function oP(n,r){var e=dt(n),t=!e&&Ti(n),o=!e&&!t&&jn(n),i=!e&&!t&&!o&&Xl(n),a=e||t||o||i,s=a?Am(n.length,String):[],l=s.length;for(var c in n)(r||rP.call(n,c))&&!(a&&(c=="length"||o&&(c=="offset"||c=="parent")||i&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||wi(c,l)))&&s.push(c);return s}var Kl=oP;function nP(n,r){return function(e){return n(r(e))}}var Ql=nP;var iP=Ql(Object.keys,Object),Rm=iP;var aP=Object.prototype,sP=aP.hasOwnProperty;function lP(n){if(!Ai(n))return Rm(n);var r=[];for(var e in Object(n))sP.call(n,e)&&e!="constructor"&&r.push(e);return r}var Lm=lP;function cP(n){return Yl(n)?Kl(n):Lm(n)}var Mi=cP;function uP(n){var r=[];if(n!=null)for(var e in Object(n))r.push(e);return r}var Vm=uP;var dP=Object.prototype,pP=dP.hasOwnProperty;function fP(n){if(!It(n))return Vm(n);var r=Ai(n),e=[];for(var t in n)t=="constructor"&&(r||!pP.call(n,t))||e.push(t);return e}var zm=fP;function hP(n){return Yl(n)?Kl(n,!0):zm(n)}var Ei=hP;var mP=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,yP=/^\w*$/;function gP(n,r){if(dt(n))return!1;var e=typeof n;return e=="number"||e=="symbol"||e=="boolean"||n==null||Ko(n)?!0:yP.test(n)||!mP.test(n)||r!=null&&n in Object(r)}var Gm=gP;var xP=Qt(Object,"create"),wo=xP;function bP(){this.__data__=wo?wo(null):{},this.size=0}var Fm=bP;function vP(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}var jm=vP;var SP="__lodash_hash_undefined__",wP=Object.prototype,PP=wP.hasOwnProperty;function CP(n){var r=this.__data__;if(wo){var e=r[n];return e===SP?void 0:e}return PP.call(r,n)?r[n]:void 0}var km=CP;var OP=Object.prototype,AP=OP.hasOwnProperty;function TP(n){var r=this.__data__;return wo?r[n]!==void 0:AP.call(r,n)}var Um=TP;var IP="__lodash_hash_undefined__";function MP(n,r){var e=this.__data__;return this.size+=this.has(n)?0:1,e[n]=wo&&r===void 0?IP:r,this}var Hm=MP;function Ni(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}Ni.prototype.clear=Fm;Ni.prototype.delete=jm;Ni.prototype.get=km;Ni.prototype.has=Um;Ni.prototype.set=Hm;var qd=Ni;function EP(){this.__data__=[],this.size=0}var Wm=EP;function NP(n,r){for(var e=n.length;e--;)if(Pi(n[e][0],r))return e;return-1}var Qo=NP;var DP=Array.prototype,_P=DP.splice;function BP(n){var r=this.__data__,e=Qo(r,n);if(e<0)return!1;var t=r.length-1;return e==t?r.pop():_P.call(r,e,1),--this.size,!0}var qm=BP;function RP(n){var r=this.__data__,e=Qo(r,n);return e<0?void 0:r[e][1]}var $m=RP;function LP(n){return Qo(this.__data__,n)>-1}var Ym=LP;function VP(n,r){var e=this.__data__,t=Qo(e,n);return t<0?(++this.size,e.push([n,r])):e[t][1]=r,this}var Xm=VP;function Di(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}Di.prototype.clear=Wm;Di.prototype.delete=qm;Di.prototype.get=$m;Di.prototype.has=Ym;Di.prototype.set=Xm;var Zo=Di;var zP=Qt(ut,"Map"),Jo=zP;function GP(){this.size=0,this.__data__={hash:new qd,map:new(Jo||Zo),string:new qd}}var Km=GP;function FP(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}var Qm=FP;function jP(n,r){var e=n.__data__;return Qm(r)?e[typeof r=="string"?"string":"hash"]:e.map}var en=jP;function kP(n){var r=en(this,n).delete(n);return this.size-=r?1:0,r}var Zm=kP;function UP(n){return en(this,n).get(n)}var Jm=UP;function HP(n){return en(this,n).has(n)}var ey=HP;function WP(n,r){var e=en(this,n),t=e.size;return e.set(n,r),this.size+=e.size==t?0:1,this}var ty=WP;function _i(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}_i.prototype.clear=Km;_i.prototype.delete=Zm;_i.prototype.get=Jm;_i.prototype.has=ey;_i.prototype.set=ty;var kn=_i;var qP="Expected a function";function $d(n,r){if(typeof n!="function"||r!=null&&typeof r!="function")throw new TypeError(qP);var e=function(){var t=arguments,o=r?r.apply(this,t):t[0],i=e.cache;if(i.has(o))return i.get(o);var a=n.apply(this,t);return e.cache=i.set(o,a)||i,a};return e.cache=new($d.Cache||kn),e}$d.Cache=kn;var ry=$d;var $P=500;function YP(n){var r=ry(n,function(t){return e.size===$P&&e.clear(),t}),e=r.cache;return r}var oy=YP;var XP=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,KP=/\\(\\)?/g,QP=oy(function(n){var r=[];return n.charCodeAt(0)===46&&r.push(""),n.replace(XP,function(e,t,o,i){r.push(o?i.replace(KP,"$1"):t||e)}),r}),ny=QP;function ZP(n){return n==null?"":am(n)}var iy=ZP;function JP(n,r){return dt(n)?n:Gm(n,r)?[n]:ny(iy(n))}var mr=JP;var eC=1/0;function tC(n){if(typeof n=="string"||Ko(n))return n;var r=n+"";return r=="0"&&1/n==-eC?"-0":r}var tn=tC;function rC(n,r){r=mr(r,n);for(var e=0,t=r.length;n!=null&&e<t;)n=n[tn(r[e++])];return e&&e==t?n:void 0}var Zl=rC;function oC(n,r){for(var e=-1,t=r.length,o=n.length;++e<t;)n[o+e]=r[e];return n}var Bi=oC;var ay=Tt?Tt.isConcatSpreadable:void 0;function nC(n){return dt(n)||Ti(n)||!!(ay&&n&&n[ay])}var sy=nC;function ly(n,r,e,t,o){var i=-1,a=n.length;for(e||(e=sy),o||(o=[]);++i<a;){var s=n[i];r>0&&e(s)?r>1?ly(s,r-1,e,t,o):Bi(o,s):t||(o[o.length]=s)}return o}var cy=ly;function iC(n){var r=n==null?0:n.length;return r?cy(n,1):[]}var uy=iC;function aC(n){return wm(Om(n,void 0,uy),n+"")}var Jl=aC;var sC=Ql(Object.getPrototypeOf,Object),Ri=sC;var lC="[object Object]",cC=Function.prototype,uC=Object.prototype,dy=cC.toString,dC=uC.hasOwnProperty,pC=dy.call(Object);function fC(n){if(!Vt(n)||sr(n)!=lC)return!1;var r=Ri(n);if(r===null)return!0;var e=dC.call(r,"constructor")&&r.constructor;return typeof e=="function"&&e instanceof e&&dy.call(e)==pC}var py=fC;function hC(n,r,e){var t=-1,o=n.length;r<0&&(r=-r>o?0:o+r),e=e>o?o:e,e<0&&(e+=o),o=r>e?0:e-r>>>0,r>>>=0;for(var i=Array(o);++t<o;)i[t]=n[t+r];return i}var fy=hC;function mC(){this.__data__=new Zo,this.size=0}var hy=mC;function yC(n){var r=this.__data__,e=r.delete(n);return this.size=r.size,e}var my=yC;function gC(n){return this.__data__.get(n)}var yy=gC;function xC(n){return this.__data__.has(n)}var gy=xC;var bC=200;function vC(n,r){var e=this.__data__;if(e instanceof Zo){var t=e.__data__;if(!Jo||t.length<bC-1)return t.push([n,r]),this.size=++e.size,this;e=this.__data__=new kn(t)}return e.set(n,r),this.size=e.size,this}var xy=vC;function Li(n){var r=this.__data__=new Zo(n);this.size=r.size}Li.prototype.clear=hy;Li.prototype.delete=my;Li.prototype.get=yy;Li.prototype.has=gy;Li.prototype.set=xy;var Vi=Li;function SC(n,r){return n&&Yr(r,Mi(r),n)}var by=SC;function wC(n,r){return n&&Yr(r,Ei(r),n)}var vy=wC;var Cy=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Sy=Cy&&typeof module=="object"&&module&&!module.nodeType&&module,PC=Sy&&Sy.exports===Cy,wy=PC?ut.Buffer:void 0,Py=wy?wy.allocUnsafe:void 0;function CC(n,r){if(r)return n.slice();var e=n.length,t=Py?Py(e):new n.constructor(e);return n.copy(t),t}var Oy=CC;function OC(n,r){for(var e=-1,t=n==null?0:n.length,o=0,i=[];++e<t;){var a=n[e];r(a,e,n)&&(i[o++]=a)}return i}var Ay=OC;function AC(){return[]}var ec=AC;var TC=Object.prototype,IC=TC.propertyIsEnumerable,Ty=Object.getOwnPropertySymbols,MC=Ty?function(n){return n==null?[]:(n=Object(n),Ay(Ty(n),function(r){return IC.call(n,r)}))}:ec,zi=MC;function EC(n,r){return Yr(n,zi(n),r)}var Iy=EC;var NC=Object.getOwnPropertySymbols,DC=NC?function(n){for(var r=[];n;)Bi(r,zi(n)),n=Ri(n);return r}:ec,tc=DC;function _C(n,r){return Yr(n,tc(n),r)}var My=_C;function BC(n,r,e){var t=r(n);return dt(n)?t:Bi(t,e(n))}var rc=BC;function RC(n){return rc(n,Mi,zi)}var Ps=RC;function LC(n){return rc(n,Ei,tc)}var oc=LC;var VC=Qt(ut,"DataView"),nc=VC;var zC=Qt(ut,"Promise"),ic=zC;var GC=Qt(ut,"Set"),ac=GC;var Ey="[object Map]",FC="[object Object]",Ny="[object Promise]",Dy="[object Set]",_y="[object WeakMap]",By="[object DataView]",jC=vo(nc),kC=vo(Jo),UC=vo(ic),HC=vo(ac),WC=vo(ql),Un=sr;(nc&&Un(new nc(new ArrayBuffer(1)))!=By||Jo&&Un(new Jo)!=Ey||ic&&Un(ic.resolve())!=Ny||ac&&Un(new ac)!=Dy||ql&&Un(new ql)!=_y)&&(Un=function(n){var r=sr(n),e=r==FC?n.constructor:void 0,t=e?vo(e):"";if(t)switch(t){case jC:return By;case kC:return Ey;case UC:return Ny;case HC:return Dy;case WC:return _y}return r});var Po=Un;var qC=Object.prototype,$C=qC.hasOwnProperty;function YC(n){var r=n.length,e=new n.constructor(r);return r&&typeof n[0]=="string"&&$C.call(n,"index")&&(e.index=n.index,e.input=n.input),e}var Ry=YC;var XC=ut.Uint8Array,Gi=XC;function KC(n){var r=new n.constructor(n.byteLength);return new Gi(r).set(new Gi(n)),r}var Fi=KC;function QC(n,r){var e=r?Fi(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.byteLength)}var Ly=QC;var ZC=/\w*$/;function JC(n){var r=new n.constructor(n.source,ZC.exec(n));return r.lastIndex=n.lastIndex,r}var Vy=JC;var zy=Tt?Tt.prototype:void 0,Gy=zy?zy.valueOf:void 0;function eO(n){return Gy?Object(Gy.call(n)):{}}var Fy=eO;function tO(n,r){var e=r?Fi(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.length)}var jy=tO;var rO="[object Boolean]",oO="[object Date]",nO="[object Map]",iO="[object Number]",aO="[object RegExp]",sO="[object Set]",lO="[object String]",cO="[object Symbol]",uO="[object ArrayBuffer]",dO="[object DataView]",pO="[object Float32Array]",fO="[object Float64Array]",hO="[object Int8Array]",mO="[object Int16Array]",yO="[object Int32Array]",gO="[object Uint8Array]",xO="[object Uint8ClampedArray]",bO="[object Uint16Array]",vO="[object Uint32Array]";function SO(n,r,e){var t=n.constructor;switch(r){case uO:return Fi(n);case rO:case oO:return new t(+n);case dO:return Ly(n,e);case pO:case fO:case hO:case mO:case yO:case gO:case xO:case bO:case vO:return jy(n,e);case nO:return new t;case iO:case lO:return new t(n);case aO:return Vy(n);case sO:return new t;case cO:return Fy(n)}}var ky=SO;function wO(n){return typeof n.constructor=="function"&&!Ai(n)?ym(Ri(n)):{}}var Uy=wO;var PO="[object Map]";function CO(n){return Vt(n)&&Po(n)==PO}var Hy=CO;var Wy=So&&So.isMap,OO=Wy?Ii(Wy):Hy,qy=OO;var AO="[object Set]";function TO(n){return Vt(n)&&Po(n)==AO}var $y=TO;var Yy=So&&So.isSet,IO=Yy?Ii(Yy):$y,Xy=IO;var MO=1,EO=2,NO=4,Ky="[object Arguments]",DO="[object Array]",_O="[object Boolean]",BO="[object Date]",RO="[object Error]",Qy="[object Function]",LO="[object GeneratorFunction]",VO="[object Map]",zO="[object Number]",Zy="[object Object]",GO="[object RegExp]",FO="[object Set]",jO="[object String]",kO="[object Symbol]",UO="[object WeakMap]",HO="[object ArrayBuffer]",WO="[object DataView]",qO="[object Float32Array]",$O="[object Float64Array]",YO="[object Int8Array]",XO="[object Int16Array]",KO="[object Int32Array]",QO="[object Uint8Array]",ZO="[object Uint8ClampedArray]",JO="[object Uint16Array]",eA="[object Uint32Array]",Je={};Je[Ky]=Je[DO]=Je[HO]=Je[WO]=Je[_O]=Je[BO]=Je[qO]=Je[$O]=Je[YO]=Je[XO]=Je[KO]=Je[VO]=Je[zO]=Je[Zy]=Je[GO]=Je[FO]=Je[jO]=Je[kO]=Je[QO]=Je[ZO]=Je[JO]=Je[eA]=!0;Je[RO]=Je[Qy]=Je[UO]=!1;function sc(n,r,e,t,o,i){var a,s=r&MO,l=r&EO,c=r&NO;if(e&&(a=o?e(n,t,o,i):e(n)),a!==void 0)return a;if(!It(n))return n;var u=dt(n);if(u){if(a=Ry(n),!s)return xm(n,a)}else{var p=Po(n),d=p==Qy||p==LO;if(jn(n))return Oy(n,s);if(p==Zy||p==Ky||d&&!o){if(a=l||d?{}:Uy(n),!s)return l?My(n,vy(a,n)):Iy(n,by(a,n))}else{if(!Je[p])return o?n:{};a=ky(n,p,s)}}i||(i=new Vi);var h=i.get(n);if(h)return h;i.set(n,a),Xy(n)?n.forEach(function(y){a.add(sc(y,r,e,y,n,i))}):qy(n)&&n.forEach(function(y,g){a.set(g,sc(y,r,e,g,n,i))});var f=c?l?oc:Ps:l?Ei:Mi,m=u?void 0:f(n);return Pm(m||n,function(y,g){m&&(g=y,y=n[g]),Ci(a,g,sc(y,r,e,g,n,i))}),a}var lc=sc;var tA=1,rA=4;function oA(n){return lc(n,tA|rA)}var Co=oA;var nA="__lodash_hash_undefined__";function iA(n){return this.__data__.set(n,nA),this}var Jy=iA;function aA(n){return this.__data__.has(n)}var eg=aA;function cc(n){var r=-1,e=n==null?0:n.length;for(this.__data__=new kn;++r<e;)this.add(n[r])}cc.prototype.add=cc.prototype.push=Jy;cc.prototype.has=eg;var tg=cc;function sA(n,r){for(var e=-1,t=n==null?0:n.length;++e<t;)if(r(n[e],e,n))return!0;return!1}var rg=sA;function lA(n,r){return n.has(r)}var og=lA;var cA=1,uA=2;function dA(n,r,e,t,o,i){var a=e&cA,s=n.length,l=r.length;if(s!=l&&!(a&&l>s))return!1;var c=i.get(n),u=i.get(r);if(c&&u)return c==r&&u==n;var p=-1,d=!0,h=e&uA?new tg:void 0;for(i.set(n,r),i.set(r,n);++p<s;){var f=n[p],m=r[p];if(t)var y=a?t(m,f,p,r,n,i):t(f,m,p,n,r,i);if(y!==void 0){if(y)continue;d=!1;break}if(h){if(!rg(r,function(g,v){if(!og(h,v)&&(f===g||o(f,g,e,t,i)))return h.push(v)})){d=!1;break}}else if(!(f===m||o(f,m,e,t,i))){d=!1;break}}return i.delete(n),i.delete(r),d}var uc=dA;function pA(n){var r=-1,e=Array(n.size);return n.forEach(function(t,o){e[++r]=[o,t]}),e}var ng=pA;function fA(n){var r=-1,e=Array(n.size);return n.forEach(function(t){e[++r]=t}),e}var ig=fA;var hA=1,mA=2,yA="[object Boolean]",gA="[object Date]",xA="[object Error]",bA="[object Map]",vA="[object Number]",SA="[object RegExp]",wA="[object Set]",PA="[object String]",CA="[object Symbol]",OA="[object ArrayBuffer]",AA="[object DataView]",ag=Tt?Tt.prototype:void 0,Yd=ag?ag.valueOf:void 0;function TA(n,r,e,t,o,i,a){switch(e){case AA:if(n.byteLength!=r.byteLength||n.byteOffset!=r.byteOffset)return!1;n=n.buffer,r=r.buffer;case OA:return!(n.byteLength!=r.byteLength||!i(new Gi(n),new Gi(r)));case yA:case gA:case vA:return Pi(+n,+r);case xA:return n.name==r.name&&n.message==r.message;case SA:case PA:return n==r+"";case bA:var s=ng;case wA:var l=t&hA;if(s||(s=ig),n.size!=r.size&&!l)return!1;var c=a.get(n);if(c)return c==r;t|=mA,a.set(n,r);var u=uc(s(n),s(r),t,o,i,a);return a.delete(n),u;case CA:if(Yd)return Yd.call(n)==Yd.call(r)}return!1}var sg=TA;var IA=1,MA=Object.prototype,EA=MA.hasOwnProperty;function NA(n,r,e,t,o,i){var a=e&IA,s=Ps(n),l=s.length,c=Ps(r),u=c.length;if(l!=u&&!a)return!1;for(var p=l;p--;){var d=s[p];if(!(a?d in r:EA.call(r,d)))return!1}var h=i.get(n),f=i.get(r);if(h&&f)return h==r&&f==n;var m=!0;i.set(n,r),i.set(r,n);for(var y=a;++p<l;){d=s[p];var g=n[d],v=r[d];if(t)var w=a?t(v,g,d,r,n,i):t(g,v,d,n,r,i);if(!(w===void 0?g===v||o(g,v,e,t,i):w)){m=!1;break}y||(y=d=="constructor")}if(m&&!y){var O=n.constructor,S=r.constructor;O!=S&&"constructor"in n&&"constructor"in r&&!(typeof O=="function"&&O instanceof O&&typeof S=="function"&&S instanceof S)&&(m=!1)}return i.delete(n),i.delete(r),m}var lg=NA;var DA=1,cg="[object Arguments]",ug="[object Array]",dc="[object Object]",_A=Object.prototype,dg=_A.hasOwnProperty;function BA(n,r,e,t,o,i){var a=dt(n),s=dt(r),l=a?ug:Po(n),c=s?ug:Po(r);l=l==cg?dc:l,c=c==cg?dc:c;var u=l==dc,p=c==dc,d=l==c;if(d&&jn(n)){if(!jn(r))return!1;a=!0,u=!1}if(d&&!u)return i||(i=new Vi),a||Xl(n)?uc(n,r,e,t,o,i):sg(n,r,l,e,t,o,i);if(!(e&DA)){var h=u&&dg.call(n,"__wrapped__"),f=p&&dg.call(r,"__wrapped__");if(h||f){var m=h?n.value():n,y=f?r.value():r;return i||(i=new Vi),o(m,y,e,t,i)}}return d?(i||(i=new Vi),lg(n,r,e,t,o,i)):!1}var pg=BA;function fg(n,r,e,t,o){return n===r?!0:n==null||r==null||!Vt(n)&&!Vt(r)?n!==n&&r!==r:pg(n,r,e,t,fg,o)}var hg=fg;function RA(n,r){return n!=null&&r in Object(n)}var mg=RA;function LA(n,r,e){r=mr(r,n);for(var t=-1,o=r.length,i=!1;++t<o;){var a=tn(r[t]);if(!(i=n!=null&&e(n,a)))break;n=n[a]}return i||++t!=o?i:(o=n==null?0:n.length,!!o&&Oi(o)&&wi(a,o)&&(dt(n)||Ti(n)))}var yg=LA;function VA(n,r){return n!=null&&yg(n,r,mg)}var gg=VA;var zA=function(){return ut.Date.now()},pc=zA;var GA="Expected a function",FA=Math.max,jA=Math.min;function kA(n,r,e){var t,o,i,a,s,l,c=0,u=!1,p=!1,d=!0;if(typeof n!="function")throw new TypeError(GA);r=Ud(r)||0,It(e)&&(u=!!e.leading,p="maxWait"in e,i=p?FA(Ud(e.maxWait)||0,r):i,d="trailing"in e?!!e.trailing:d);function h(C){var T=t,x=o;return t=o=void 0,c=C,a=n.apply(x,T),a}function f(C){return c=C,s=setTimeout(g,r),u?h(C):a}function m(C){var T=C-l,x=C-c,N=r-T;return p?jA(N,i-x):N}function y(C){var T=C-l,x=C-c;return l===void 0||T>=r||T<0||p&&x>=i}function g(){var C=pc();if(y(C))return v(C);s=setTimeout(g,m(C))}function v(C){return s=void 0,d&&t?h(C):(t=o=void 0,a)}function w(){s!==void 0&&clearTimeout(s),c=0,t=l=o=s=void 0}function O(){return s===void 0?a:v(pc())}function S(){var C=pc(),T=y(C);if(t=arguments,o=this,l=C,T){if(s===void 0)return f(l);if(p)return clearTimeout(s),s=setTimeout(g,r),h(l)}return s===void 0&&(s=setTimeout(g,r)),a}return S.cancel=w,S.flush=O,S}var fc=kA;function UA(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}var xg=UA;function HA(n,r){return r.length<2?n:Zl(n,fy(r,0,-1))}var bg=HA;function WA(n,r){return hg(n,r)}var Xd=WA;function qA(n,r){return r=mr(r,n),n=bg(n,r),n==null||delete n[tn(xg(r))]}var vg=qA;function $A(n){return py(n)?void 0:n}var Sg=$A;var YA=1,XA=2,KA=4,QA=Jl(function(n,r){var e={};if(n==null)return e;var t=!1;r=Ul(r,function(i){return i=mr(i,n),t||(t=i.length>1),i}),Yr(n,oc(n),e),t&&(e=lc(e,YA|XA|KA,Sg));for(var o=r.length;o--;)vg(e,r[o]);return e}),ji=QA;function ZA(n,r,e,t){if(!It(n))return n;r=mr(r,n);for(var o=-1,i=r.length,a=i-1,s=n;s!=null&&++o<i;){var l=tn(r[o]),c=e;if(l==="__proto__"||l==="constructor"||l==="prototype")return n;if(o!=a){var u=s[l];c=t?t(u,l,s):void 0,c===void 0&&(c=It(u)?u:wi(r[o+1])?[]:{})}Ci(s,l,c),s=s[l]}return n}var wg=ZA;function JA(n,r,e){for(var t=-1,o=r.length,i={};++t<o;){var a=r[t],s=Zl(n,a);e(s,a)&&wg(i,mr(a,n),s)}return i}var Pg=JA;function eT(n,r){return Pg(n,r,function(e,t){return gg(n,t)})}var Cg=eT;var tT=Jl(function(n,r){return n==null?{}:Cg(n,r)}),Er=tT;var fe=class{modifyById(r,e){let t=this;if(t[r]===void 0)throw new Error("not expected");{let i={...t,[r]:e};return Object.setPrototypeOf(i,fe.prototype),i}}add(r,e){return this.runOp({type:1,id:r,data:e})?.data??this}runOp(r){let e=this;if(r.type===1){let t=e[r.id],o;t===void 0?o={type:2,id:r.id}:o={type:1,id:r.id,data:t};let{id:i,data:a}=r,s={...e,[i]:a};return Object.setPrototypeOf(s,fe.prototype),{data:s,actual:r,reverse:o}}else if(r.type===2){let{id:t}=r,o=e[t];if(o===void 0)return null;{let i={...e};return Object.setPrototypeOf(i,fe.prototype),delete i[t],{data:i,actual:r,reverse:{type:1,id:t,data:o}}}}return null}};function Cs(n){if(n.deepFreeze!==void 0){n.deepFreeze(n);return}let r=Object.getOwnPropertyNames(n);for(let e of r){let t=n[e];t&&typeof t=="object"&&Cs(t)}return Object.freeze(n)}function Og(n,r){let e=0;for(;e<n.length&&e<r.length;){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1;e+=1}return e!==r.length?-1:e!==n.length?1:0}var ki=class extends Error{};function hc(n){let r={...n};return Object.setPrototypeOf(r,Object.getPrototypeOf(n)),r}function Xr(n,r,e){if(n===void 0?r===void 0?(n=0,r=10):n=r-10:r===void 0&&(r=n+10),n>r){let i=n;n=r,r=i}let t=[],o=1/(e+1);for(let i=0;i<e;i++){let a=n+(r-n)*(i+.75+Math.random()*.5)*o;t.push(a)}return t}function Ui(n){return n instanceof Uint8Array||n instanceof Uint16Array||n instanceof Uint32Array||n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array||n instanceof Float32Array||n instanceof Float64Array}function Ag(){return typeof process<"u"}function Tg(n,r){for(let e of n)r(e.id,e.data)!==!0&&Tg(e.children,r)}function Ig(n,r){if(r(n.id,n.data)!==!0)for(let e of n.children)Ig(e,r)}var Ke=class extends Array{constructor(...e){super(...e);Object.setPrototypeOf(this,Ke.prototype)}deepFreeze(){let e=0;for(;e<this.length;)Cs(this[e]),e++}fillCaches0(e,t){this.objCaches.set(e.id,e),this.parentCaches.set(e.id,t);for(let o of e.children)this.fillCaches0(o,e.id)}fillCaches(){if(this.objCaches===void 0){this.objCaches=new Map,this.parentCaches=new Map;for(let e of this)this.fillCaches0(e,null)}}randomId(){this.fillCaches();let e=Array.from(this.objCaches.keys());if(e.length!==0)return e[Math.max(0,Math.floor(Math.random()*e.length)-1)]}nonExistOrDescendantOf(e,t){if(!this.has(e))return!0;for(;e;){let o=this.parent(e);if(o===t)return!0;e=o}return!1}rootAcestor(e){for(;e;){let t=this.parent(e);if(t)e=t;else return e}return e}isDescendantOf(e,t){for(;e;){let o=this.parent(e);if(o===t)return!0;e=o}return!1}data(e){return this.get(e)?.data}has(e){return this.childrenOf(e)!==void 0}get(e){return this.fillCaches(),this.objCaches.get(e)}childrenOf(e){return e===null?this:this.get(e)?.children}traverseFrom(e,t){if(e===null)this.traverse(t);else{let o=this.get(e);o&&Ig(o,t)}}traverse(e){Tg(this,e)}totalSize(){return this.fillCaches(),this.objCaches.size}parent(e){return this.fillCaches(),this.parentCaches.get(e)}childrenArray(e){return e===null?this:this.get(e).children}modifyById(e,t){if(this.get(e)===void 0)throw new Error("not expected");{let i=this.parent(e),a=this.childrenArray(i),s=a.findIndex(u=>u.id===e);if(s<0)throw new Error("not expected");let l=a[s];return a=[...a],a[s]={...l,data:t},this.modifyArrayBy(i,a)}}modifyArrayBy(e,t){let o=e,i=t;for(;o!==null;){let s=i,l=o;if(o=this.parent(o),o===void 0)throw new Error;i=this.childrenArray(o);let c=i.findIndex(u=>u.id===l);if(c<0)throw new Error;i=[...i],i[c]={...i[c],children:s}}Object.setPrototypeOf(i,Ke.prototype);let a=i;return a.fillCaches(),a}runOp(e){switch(e.type){case 7:return this.addOp(e);case 8:return this.deleteOp(e);case 9:return this.moveOp(e)}return null}checkDuplicatedIdRec({id:e,children:t}){if(this.get(e)!==void 0)return!0;for(let o of t)if(this.checkDuplicatedIdRec(o))return!0;return!1}addOp(e){let{parent:t,fi:o,id:i,data:a,children:s}=e;if(t!==null&&this.get(t)===void 0)return null;if(this.checkDuplicatedIdRec(e))return null;{let l=t,c=this.childrenArray(l),u={fi:o,id:i,data:a,children:s};return c=[...c,u],c.sort((d,h)=>d.fi-h.fi),e.localIndex=c.indexOf(u),{data:this.modifyArrayBy(l,c),actual:e,reverse:{type:8,id:i}}}}deleteOp(e){let{id:t}=e;if(this.get(t)===null)return null;{let o=this.parent(t);if(o===void 0)return null;let i=this.childrenArray(o),a=i.findIndex(c=>c.id===t);e.localIndex=a,i=[...i];let s=i.splice(a,1)[0];return{data:this.modifyArrayBy(o,i),actual:e,reverse:{type:7,...s,parent:o}}}}moveOp(e){let{parent:t,fi:o,id:i}=e;if(t!==null&&this.get(t)===void 0)return this.deleteOp({type:8,id:i});if(t!==null){let h=t;for(;h!==null;){if(h===void 0)throw new Error;if(h===i)throw new ki("cyclic tree");h=this.parent(h)}}let a=this.parent(i);if(a===void 0)return null;let s=a,l=this.childrenArray(a),c=l.findIndex(h=>h.id===i);l=[...l];let u=l.splice(c,1)[0],p=this.modifyArrayBy(a,l);a=t,l=p.childrenArray(a);let d=u.fi;return u={...u,fi:o},l=[...l,u],l.sort((h,f)=>h.fi-f.fi),e.localIndex=l.indexOf(u),p=p.modifyArrayBy(a,l),{data:p,actual:e,reverse:{type:9,parent:s,fi:d,id:i}}}previous(e,t){if(t===null){let i=this.childrenArray(e);return i.length===0?null:i[i.length-1].id}let o=null;for(let i of this.childrenArray(e)){if(i.id===t)return o;o=i.id}return null}traverseSortNext(e){let t=this.parent(e);if(t!==void 0){let o=this.childrenArray(t),i=o.findIndex(a=>a.id===e)+1;if(i<o.length)return o[i].id;if(t)return this.traverseSortNext(t)}}sortNext(e){let t=this.childrenArray(e);return t.length>0?t[0].id:this.traverseSortNext(e)}traverseSortPrevious(e){let t=this.childrenArray(e);return t.length>0?this.traverseSortPrevious(t[t.length-1].id):e}sortPrevious(e){let t=this.parent(e);if(t!==void 0){let o=this.childrenArray(t),i=o.findIndex(a=>a.id===e)-1;return i>=0?this.traverseSortPrevious(o[i].id):t}}getAllSorted(e){let t=[];for(let o of e){let i=this.getWithSortKey(o.id);i!==void 0&&t.push({...o,...i})}t.sort((o,i)=>Og(o.sortKey,i.sortKey));for(let o of t)delete o.sortKey;return t}getWithSortKey(e){var t=e;let o=[],i=this.get(t),a=i;if(i!==void 0){for(;t;)o.splice(0,0,i.fi),t=this.parent(t),t!==null&&(i=this.get(t));return{...a,sortKey:o}}}insertBeforeHelper(e,t,o){return this.insertAfterHelper(e,this.previous(e,t),o)}insertAfterHelper(e,t,o){let i=this.childrenArray(e);if(t===null){if(i.length===0)return Xr(0,o,o);{let a=i[0].fi;return Xr(a-o,a,o)}}else{let a=this.get(t);if(a===void 0||this.parent(t)!==e)throw new Error("illegal args");let s=i.find(l=>l.fi>a.fi);if(s===void 0){let l=i[i.length-1].fi;return Xr(l,l+o,o)}else return Xr(a.fi,s.fi,o)}}};var Hi;(r=>{function n(e,t){if(t.type!==0)return null;if(Array.isArray(e)){let o=t.props,i={},a=[...e],s=!1;if(o)for(let l of Object.keys(o)){let c=parseInt(l);if(isNaN(c))throw new Error("wrong index");i[l]=a[c],a[c]=o[l],s=!0}return s?{data:a,actual:t,reverse:{type:0,props:i}}:null}else{let o=t.props,i={},a={...e},s=!1;if(o)for(let l of Object.keys(o)){i[l]=a[l];let c=o[l];c===void 0?delete a[l]:a[l]=c,s=!0}return s?{data:a,actual:t,reverse:{type:0,props:i}}:null}}r.runOp=n})(Hi||(Hi={}));var be=class extends Array{constructor(...e){super(...e);Object.setPrototypeOf(this,be.prototype)}deepFreeze(){let e=0;for(;e<this.length;)Cs(this[e]),e++}fillCaches0(e){this.objCaches.set(e.id,e)}fillCaches(){if(this.objCaches===void 0){this.objCaches=new Map,Object.getOwnPropertyDescriptor(this,"objCaches").enumerable=!1;for(let e of this)this.fillCaches0(e)}}randomId(){this.fillCaches();let e=Array.from(this.objCaches.keys());if(e.length!==0)return e[Math.max(0,Math.floor(Math.random()*e.length)-1)]}data(e){return this.get(e)?.data}get(e){return this.fillCaches(),this.objCaches.get(e)}modifyById(e,t){if(this.get(e)===void 0)throw new Error("not expected");{let i=this,a=i.findIndex(c=>c.id===e);if(a<0)throw new Error("not expected");let s=i[a];return i=[...i],i[a]={...s,data:t},this.modifyArrayBy(i)}}modifyArrayBy(e){Object.setPrototypeOf(e,be.prototype);let t=e;return Ag()||t.fillCaches(),t}runOp(e){switch(e.type){case 4:return this.addOp(e);case 5:return this.deleteOp(e);case 6:return this.moveOp(e)}return null}addOp(e){let{fi:t,id:o,data:i}=e,a=this,s={fi:t,id:o,data:i};return a=[...a,s],a.sort((c,u)=>c.fi-u.fi),e.localIndex=a.indexOf(s),{data:this.modifyArrayBy(a),actual:e,reverse:{type:5,id:o}}}deleteOp(e){let{id:t}=e,o=this,i=o.findIndex(l=>l.id===t);if(i===-1)return null;e.localIndex=i,o=[...o];let a=o.splice(i,1)[0];return{data:this.modifyArrayBy(o),actual:e,reverse:{type:4,...a}}}moveOp(e){let{fi:t,id:o}=e,i=this;i=[...i];let a=i.findIndex(u=>u.id===o);if(a===-1)return null;let s=i[a].fi,l={...i[a],fi:t};return i[a]=l,i.sort((u,p)=>u.fi-p.fi),e.localIndex=i.indexOf(l),{data:this.modifyArrayBy(i),actual:e,reverse:{type:6,fi:s,id:o}}}previous(e){if(e===null)return this.length===0?null:this[this.length-1].id;let t=null;for(let o of this){if(o.id===e)return t;t=o.id}return null}insertBeforeHelper(e,t){return this.insertAfterHelper(this.previous(e),t)}insertAfterHelper(e,t){let o=this;if(e===null){if(o.length===0)return Xr(0,t,t);{let i=o[0].fi;return Xr(i-t,i,t)}}else{let i=this.get(e);if(i===void 0)throw new Error("illegal args");let a=o.find(s=>s.fi>i.fi);if(a===void 0){let s=o[o.length-1].fi;return Xr(s,s+t,t)}else return Xr(i.fi,a.fi,t)}}};function Wi(n){return n&&typeof n=="object"&&n instanceof Qe}var Qe=class{unusedFunOverridesTable(r){}runOp(r){let e=[],t=this,o=0,i={};for(;o<r.path.length;){if(e.push(t),t=t===void 0?void 0:t[r.path[o]],t!==void 0&&!Wi(t))return null;o+=1}t=t?hc(t):new Qe;for(let[l,c]of Object.entries(r.props)){let u=t[l];i[l]=u,c===void 0?delete t[l]:t[l]=c}for(;o>0;){if(Object.keys(t).length===0){let l=e[o-1];l&&(t=hc(l),delete t[r.path[o-1]])}else{let l=e[o-1];if(l){let c=hc(l);c[r.path[o-1]]=t,t=c}else{let c=new Qe;c[r.path[o-1]]=t,t=c}}o-=1}let a=Object.setPrototypeOf(t,Qe.prototype),s={...r,props:i};return{data:a,actual:r,reverse:s}}},Kr;(t=>{function n(o,i){return Os(o,i)??o}t.apply=n;function r(o,i){return Qd(o,i)}t.merge=r;function e(o,i){let a=0,s=i.path,l=o;for(;a<s.length&&l!==void 0;){if(l=Ze.zoomOnce(l,s[a]),l===void 0)return i;if(!Wi(l))return;a+=1}if(l===void 0)return i;if(!!Wi(l))if(i.type===0){let c={...i.props};for(let u of Object.keys(l))delete c[u];return{...i,props:c}}else if(i.type===1||i.type===4||i.type===7){let c=Kd([i],l);return c?(console.log(c),c):i}else return i}t.filterOp=e})(Kr||(Kr={}));function Kd(n,r){if(r===void 0)return;let e=!1,t=n.map(o=>{let i=o.id,a=Os(o.data,r[i]);if(e=e||a!==void 0,a===void 0&&(a=o.data),o.children){let s=Kd(o.children,r);return s!==void 0?e=!0:s=o.children,{...o,id:i,data:a,children:s}}else return{...o,id:i,data:a}});if(e)return t}function rT(n,r){if(r===void 0)return;let e=!1,t=n.map(o=>{let i=o.id,a=Os(o.data,r[i]);return e=e||a!==void 0,a===void 0&&(a=o.data),{...o,id:i,data:a}});if(e)return Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t}function Os(n,r){if(!Wi(r))return r;if(n instanceof Ke){let e=Kd(n,r);return e!==void 0&&Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e}else{if(n instanceof be)return rT(n,r);if(Array.isArray(n)){let e=!1,t=n.map((o,i)=>{let a=Os(o,r[i]);return e=e||a!==void 0,a===void 0&&(a=o),a});return e?(Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t):void 0}else{if(n instanceof Qe)return Qd(n,r);if(n&&typeof n=="object"){let e={},t=!1;for(let[o,i]of Object.entries(n)){let a=Os(i,r[o]);t=t||a!==void 0,a===void 0&&(a=i),e[o]=a}return t?(Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e):void 0}}}}function Qd(n,r){if(n===void 0)return r;if(r===void 0)return n;if(!Wi(r))return r;if(!Wi(n))return Kr.apply(n,r);let e=new Set;for(let o of Object.keys(n))e.add(o);for(let o of Object.keys(r))e.add(o);let t=new Qe;for(let o of e){let i=Qd(n===void 0?void 0:n[o],r===void 0?void 0:r[o]);t[o]=i}return t}function Mg(n,r){let e={cur:[],result:[],len:0};return n=As(n,r,e)??n,[n,e.result]}function mc(n,r){return n===null?null:(n.cur[n.len]=r,n.len+=1,n)}function yc(n){n&&(n.len-=1)}function oT(n){if(n===null)return null;n.result.push(n.cur.slice(0,n.len))}function Eg(n,r,e){let t=!1,o=n.map(i=>{let a=i.id,s=r[a];if(s!==void 0&&typeof s=="string"&&(t=!0,a=s,e!==null))throw new Error("not supported");let l=As(i.data,r,mc(e,a));yc(e),t=t||l!==void 0,l===void 0&&(l=i.data);let c=Eg(i.children,r,e);return c!==void 0?t=!0:c=i.children,{...i,id:a,data:l,children:c}});if(t)return o}function nT(n,r,e){let t=!1,o=n.map(i=>{let a=i.id,s=r[a];if(s!==void 0&&typeof s=="string"&&(t=!0,a=s,e!==null))throw new Error("not supported");let l=As(i.data,r,mc(e,a));return yc(e),t=t||l!==void 0,l===void 0&&(l=i.data),{...i,id:a,data:l}});if(t)return Object.setPrototypeOf(o,Object.getPrototypeOf(n)),o}function As(n,r,e){if(n instanceof Ke){let t=Eg(n,r,e);return t!==void 0&&Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t}else{if(n instanceof be)return nT(n,r,e);if(Array.isArray(n)){let t=!1,o=n.map((i,a)=>{let s=As(i,r,mc(e,a));return yc(e),t=t||s!==void 0,s===void 0&&(s=i),s});return t?(Object.setPrototypeOf(o,Object.getPrototypeOf(n)),o):void 0}else if(n&&typeof n=="object"&&!Ui(n)){let t={},o=!1;for(let[i,a]of Object.entries(n))if(i!=="name"&&i!=="variableId"){let s=r[i];if(typeof s=="string"){if(e!==null)throw new Error("not supported");o=!0,i=s}let l=As(a,r,mc(e,i));yc(e),o=o||l!==void 0,l===void 0&&(l=a),t[i]=l}else t[i]=a;return o?(Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t):void 0}else if(typeof n=="string"){let t=r[n];return t!==void 0&&oT(e),t}else return}}var qi;(r=>{function n(e,t){let o=Ze.zoom(t,e.path);if(typeof o=="object"){let i={};for(let a of Object.keys(e.props))i[a]=o[a];return{...e,props:i}}else return{...e,props:{}}}r.replaceProps=n})(qi||(qi={}));var nt;(s=>{function n(l,c){return{...l,path:l.path.slice(c)}}s.drop=n;function r(l,c){return e(l,c)?.data??l}s.applySimple=r;function e(l,c){let u=c.path;for(var p=[];;){let d;if(l instanceof Qe&&c.type===0&&(d=l.runOp({...c,path:u.slice(p.length)}),d===null&&(d=void 0)),d===void 0&&p.length===u.length&&(l instanceof Ke||l instanceof be||l instanceof fe?d=l.runOp(c):d=Hi.runOp(l,c)),d!==void 0)if(d!==null){let m=d.data;for(let y=p.length-1;y>=0;y--){let g=u[y],v=p[y];if(v instanceof Ke){if(typeof g=="number")throw new Error("illegal arg");m=v.modifyById(g,m)}else if(v instanceof be){if(typeof g=="number")throw new Error("illegal arg");m=v.modifyById(g,m)}else if(v instanceof fe){if(typeof g=="number")throw new Error("illegal arg");m=v.modifyById(g,m)}else if(v instanceof Qe){let w={...v,[g]:m};m=Object.setPrototypeOf(w,Qe.prototype)}else if(typeof v=="object")if(Array.isArray(v)){if(typeof g=="string"&&(g=parseInt(g),isNaN(g)))throw new Error("Invalid path");let w=m;m=[...v],m[g]=w}else m={...v,[g]:m};else return null}return{data:m,actual:{...d.actual,path:u},reverse:{...d.reverse,path:u}}}else return null;let h=u[p.length],f;if(l instanceof Ke){if(typeof h=="number")throw new Error("");f=l.get(h)?.data}else if(l instanceof be){if(typeof h=="number")throw new Error("");f=l.get(h)?.data}else l!==null&&(f=l[h]);if(f!==void 0)p.push(l),l=f;else return null}}s.apply=e;function t(l,c){for(let u=0;u<l.length&&u<c.length;u++)if(l[u]!==c[u])return!0;return!1}s.pathDisjoint=t;function o(l,c){if(l.length!==c.length)return!1;for(let u=0;u<l.length;u++)if(l[u]!==c[u])return!1;return!0}s.pathEq=o;function i(l,c){return t(l.path,c.path)}s.commutative=i;function a(l,c){return l.type===0&&c.type===0&&o(l.path,c.path)?Object.keys(l.props).every(u=>c.props[u]!==void 0):!1}s.subsumed=a})(nt||(nt={}));var Ts;(l=>{function n(){return[]}l.empty=n;function r(c,u){let p=[];for(let d of c){let[h,...f]=d.path;h===u&&p.push({...d,path:f})}return p}l.removePrefix=r;function e(c,u){return c.map(p=>({...p,path:[u,...p.path]}))}l.addPrefix=e;function t(c,u){return[...c,...u]}l.concat=t;function o(c,u){return[...c.filter(d=>!u.some(h=>nt.subsumed(d,h))),...u]}l.compress=o;function i(c,u){return c.every(p=>u.every(d=>nt.commutative(p,d)))}l.commutative=i;function a(c,u){for(let p of u){let d=s(c,p);d!==null&&(c=d.data)}return c}l.applyAll=a;function s(c,u){var p=c;let d=[],h=[];for(let f of u)try{if(f.type===3||f.type===5&&f.path[f.path.length-1]==="variables"){let m,y,g;if(f.type===3?(m=Ze.zoom(p,[...f.path,f.id]),g=nt.apply(p,{...f,type:2})):(m=Ze.zoom(p,[...f.path,f.id,"value"]),g=nt.apply(p,f)),g!==null){p=g.data;let[v,w]=Mg(p,{[f.id]:m});p=v;for(let O=0;O<w.length;O++){let S=w[O],C=S.pop();if(typeof C=="number"){let T=[C];for(let N=O+1;N<w.length;N++){let E=w[N],M=E[E.length-1];if(typeof M=="number"&&Ze.equal(S,E.slice(0,E.length-1)))T.push(M),w.splice(N,1);else break}let x=Ze.zoom(p,S);y=x.map((N,E)=>T.includes(E)?f.id:N),m=x,C=S.pop()}else{if(C==="alphaOverride"||C==="alpha"){m/=100;let T=m,x=Ze.zoom(p,S.slice(0,S.length-2)),N=x.layers.map(E=>E.id===S[S.length-1]?{...E,data:{...E.data,[C]:T}}:E);Object.setPrototypeOf(N,Object.getPrototypeOf(x.layers)),x.layers=N}y=f.id}d.push({type:0,path:S,props:{[C]:m}}),h.push({type:0,path:S,props:{[C]:y}})}h.push(g.reverse),d.push(g.actual)}}else{let m=nt.apply(p,f);m!==null&&(d.push(m.actual),p=m.data,h.push(m.reverse))}}catch(m){if(m instanceof ki)return null;throw m}return{data:p,actual:d,reverse:h.reverse()}}l.apply=s})(Ts||(Ts={}));var Ng=Symbol(),iT=Symbol(),xc=Symbol(),Hn=class{reportOp(r,e,t=[]){let o=this;if(e===null)return;o._current=e.data;let i=t;for(;!(o instanceof gc);){let a=o._path,s=o._current;if(a!==""&&i.splice(0,0,a),o=o._parent,o===null)return;o.update(a,s)}o.push(i,r,e.actual,e.reverse)}deleteChildren(r){if(this._children){let e=this._children[r];if(e){let t=e[xc];t&&t(),delete this._children[r]}}}},Jd=class extends Hn{constructor(r,e,t){super(),this._parent=r,this._path=e,this._current=t}update(r,e){if(Array.isArray(this._current)){if(typeof r=="string"&&(r=parseInt(r),isNaN(r)))throw new Error("Invalid path");this._current=[...this._current],this._current[r]=e}else this._current={...this._current,[r]:e}}runOp(r){this.reportOp(r,Hi.runOp(this._current,r),r.path)}},ep=class extends Hn{constructor(r,e,t){super(),this._parent=r,this._path=e,this._current=t}update(r,e){this._current={...this._current,[r]:e},Object.setPrototypeOf(this._current,fe.prototype)}runOp(r){this.reportOp(r,this._current.runOp(r))}},Dg={get(n,r){if(r===xc)return()=>{n._parent=null};if(r===Ng)return n._current;if(r===iT)return n;let{_current:e,_children:t}=n;if(r==="push"&&Array.isArray(e))throw new Error("not supported to expand array");let o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e[r],a=bc(n,r,i);return a!==i?(t===void 0&&(t={},n._children=t),t[r]=a,a):i},has(n,r){return r in n._current},ownKeys(n){return Reflect.ownKeys(n._current)},defineProperty(){throw Error("not supported")},getPrototypeOf(n){return Object.getPrototypeOf(n._current)},setPrototypeOf(){throw Error("not supported")},getOwnPropertyDescriptor(n,r){let e=n._current,t=Reflect.getOwnPropertyDescriptor(e,r);return t&&{writable:!0,configurable:!0,enumerable:t.enumerable,value:e[r]}}},aT={...Dg,set(n,r,e){let t={type:0,props:{[r]:it(e)??e}};return n.deleteChildren(r),n.runOp(t),!0},deleteProperty(n,r){let e={type:0,props:{[r]:void 0}};return n.deleteChildren(r),n.runOp(e),!0}},sT={...Dg,set(n,r,e){return e===void 0?this.deleteProperty(n,r):(n.deleteChildren(r),n.runOp({type:1,id:r,data:e})),!0},deleteProperty(n,r){return n.runOp({type:2,id:r}),!0}},$i=class extends Hn{constructor(r,e,t){super(),this._children={},this._parent=r,this._path=e,this._current=t,this[xc]=()=>{this._parent=null}}unproxy(){return this._current}update(r,e){this._current=this._current.modifyById(r,e)}runOp(r){this.reportOp(r,this._current.runOp(r))}randomId(){return this._current.randomId()}isDescendantOf(r,e){return this._current.isDescendantOf(r,e)}childrenOf(r){return this._current.childrenOf(r)}traverse(r){return this._current.traverse(r)}get(r){return this._current.get(r)}parent(r){return this._current.parent(r)}traverse(r){this._current.traverse((e,t)=>{r(e,this.data(e))})}data(r){let{_current:e,_children:t}=this,o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e.get(r)?.data,a=bc(this,r,i);return a!==i?(t===void 0&&(t={},this._children=t),t[r]=a,a):i}add(r,e,t,o,i){this.runOp({type:7,parent:r,fi:e,id:t,data:o,children:i})}move(r,e,t){this.runOp({type:9,parent:r,fi:e,id:t})}insertAfter(r,e,t){let o=this._current.insertAfterHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.add(r,o[i],a.id,a.data,a.children)}}insertBefore(r,e,t){let o=this._current.insertBeforeHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.add(r,o[i],a.id,a.data,a.children)}}moveAfter(r,e,t){let o=this._current.insertAfterHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.move(r,o[i],a)}}moveBefore(r,e,t){let o=this._current.insertBeforeHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.move(r,o[i],a)}}delete(r){this.deleteChildren(r),this.runOp({type:8,id:r})}sortNext(r){return this._current.sortNext(r)}sortPrevious(r){return this._current.sortPrevious(r)}getAllSorted(r){return this._current.getAllSorted(r)}},Yi=class extends Hn{constructor(r,e,t){super(),this._children={},this._parent=r,this._path=e,this._current=t,this[xc]=()=>{this._parent=null}}unproxy(){return this._current}get length(){return this._current.length}forEach(r){let e=this.length;for(let t=0;t<e;t++){let o=this._current[t].id,i=this._current[t].fi;r(this.data(this._current[t].id),o,i)}}find(r){let e=this.length;for(let t=0;t<e;t++){let o=this._current[t].id;if(r(this.data(o),o))return this.get(o)}}update(r,e){this._current=this._current.modifyById(r,e)}randomId(){return this._current.randomId()}get(r){return{...this._current.get(r),data:this.data(r)}}data(r){let{_current:e,_children:t}=this,o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e.get(r)?.data,a=bc(this,r,i);return a!==i?(t===void 0&&(t={},this._children=t),t[r]=a,a):i}runOp(r){this.reportOp(r,this._current.runOp(r))}add(r,e,t){this.runOp({type:4,fi:r,id:e,data:t})}move(r,e){this.runOp({type:6,fi:r,id:e})}insertAfter(r,e){let t=this._current.insertAfterHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.add(t[o],i.id,i.data)}}insertBefore(r,e){let t=this._current.insertBeforeHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.add(t[o],i.id,i.data)}}moveAfter(r,e){let t=this._current.insertAfterHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.move(t[o],i)}}moveBefore(r,e){let t=this._current.insertBeforeHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.move(t[o],i)}}delete(r){this.deleteChildren(r),this.runOp({type:5,id:r})}};function Zd(n,r,e){if(n.length>0){let t=n[n.length-1];if(t.type===0&&r.type===0&&Ze.equal(t.path,e)){Object.assign(t.props,r.props);return}}n.push({...r,path:e})}var gc=class extends Hn{constructor(r){super(),this.ts=[],this.actual=[],this.reverse=[],this._current=r}update(r,e){if(r!=="")throw new Error("");this._current=e}push(r,e,t,o){Zd(this.ts,e,r),Zd(this.actual,t,r),Zd(this.reverse,o,r)}result(){return{data:this._current,ts:this.ts,actual:this.actual,reverse:this.reverse.reverse()}}};function bc(n,r,e){return e instanceof Ke?new $i(n,r,e):e instanceof be?new Yi(n,r,e):e instanceof fe?new Proxy(new ep(n,r,e),sT):e!==null&&typeof e=="object"?Ui(e)?e:new Proxy(new Jd(n,r,e),aT):e}function tp(n){let r=new gc(n);return[bc(r,"",n),r]}function rn(n,r){let[e,t]=tp(n);return r(e),t.result()}function it(n){return n instanceof $i||n instanceof Yi?n._current:n!==null&&typeof n=="object"?n[Ng]:n}var Ze;(o=>{function n(i,a){if(a.length===i.length)for(var s=0;s<i.length;){if(i[s]!==a[s])return!1;s+=1}else return!1;return!0}o.equal=n;function r(i,a,s){let l=t(s,i);if(l!==void 0&&typeof l=="object"&&l!==null){let c={...a};return Object.keys(l).forEach(u=>{delete c[u]}),c}else return a}o.removeOverridden=r;function e(i,a){if((i instanceof Ke||i instanceof $i)&&typeof a=="string")return i.data(a);if((i instanceof be||i instanceof Yi)&&typeof a=="string")return i.data(a);if(typeof a=="number"&&Array.isArray(i))return i[a];if(typeof a=="string"&&typeof i=="object"&&i!==null)return i[a]}o.zoomOnce=e;function t(i,a,s=0){for(;s<a.length&&i!==void 0;)i=e(i,a[s]),s+=1;return i}o.zoom=t})(Ze||(Ze={}));function _g(n,r){let e=[];if(r.length===n.length)for(var t=0;t<n.length;){if(r[t]==="*")e.push(n[t]);else if(n[t]!==r[t])return null;t+=1}else return null;return e}function Re(n,r){let e=[];if(r.length<=n.length)for(var t=0;t<r.length;){if(r[t]==="*")e.push(n[t]);else if(n[t]!==r[t])return null;t+=1}else return null;return e}var vc=class{},Is=class extends vc{constructor(e){super();this.id=e}},Ms=class extends vc{constructor(e){super();this.data=e}};var op;try{op=new TextDecoder}catch{}var de,nn,G=0;var jg=[],np=jg,ip=0,Zt={},Ue,on,yr=0,Qr=0,lr,Oo,qt=[],We,Bg={useRecords:!1,mapsAsObjects:!0},Es=class{},sp=new Es;sp.name="MessagePack 0xC1";var Xi=!1,Zr=class{constructor(r){r&&(r.useRecords===!1&&r.mapsAsObjects===void 0&&(r.mapsAsObjects=!0),r.structures?r.structures.sharedLength=r.structures.length:r.getStructures&&((r.structures=[]).uninitialized=!0,r.structures.sharedLength=0)),Object.assign(this,r)}unpack(r,e){if(de)return qg(()=>(wc(),this?this.unpack(r,e):Zr.prototype.unpack.call(Bg,r,e)));nn=e>-1?e:r.length,G=0,ip=0,Qr=0,on=null,np=jg,lr=null,de=r;try{We=r.dataView||(r.dataView=new DataView(r.buffer,r.byteOffset,r.byteLength))}catch(t){throw de=null,r instanceof Uint8Array?t:new Error("Source must be a Uint8Array or Buffer but was a "+(r&&typeof r=="object"?r.constructor.name:typeof r))}if(this instanceof Zr){if(Zt=this,this.structures)return Ue=this.structures,Sc();(!Ue||Ue.length>0)&&(Ue=[])}else Zt=Bg,(!Ue||Ue.length>0)&&(Ue=[]);return Sc()}unpackMultiple(r,e){let t,o=0;try{Xi=!0;let i=r.length,a=this?this.unpack(r,i):Oc.unpack(r,i);if(e){for(e(a);G<i;)if(o=G,e(Sc())===!1)return}else{for(t=[a];G<i;)o=G,t.push(Sc());return t}}catch(i){throw i.lastPosition=o,i.values=t,i}finally{Xi=!1,wc()}}_mergeStructures(r,e){r=r||[];for(let t=0,o=r.length;t<o;t++){let i=r[t];i&&(i.isShared=!0,t>=32&&(i.highByte=t-32>>5))}r.sharedLength=r.length;for(let t in e||[])if(t>=0){let o=r[t],i=e[t];i&&(o&&((r.restoreStructures||(r.restoreStructures=[]))[t]=o),r[t]=i)}return this.structures=r}decode(r,e){return this.unpack(r,e)}};function Sc(){try{if(!Zt.trusted&&!Xi){let r=Ue.sharedLength||0;r<Ue.length&&(Ue.length=r)}let n=pt();if(G==nn)Ue.restoreStructures&&Rg(),Ue=null,de=null,Oo&&(Oo=null);else if(G>nn){let r=new Error("Unexpected end of MessagePack data");throw r.incomplete=!0,r}else if(!Xi)throw new Error("Data read, but end of buffer not reached");return n}catch(n){throw Ue.restoreStructures&&Rg(),wc(),(n instanceof RangeError||n.message.startsWith("Unexpected end of buffer"))&&(n.incomplete=!0),n}}function Rg(){for(let n in Ue.restoreStructures)Ue[n]=Ue.restoreStructures[n];Ue.restoreStructures=null}function pt(){let n=de[G++];if(n<160)if(n<128){if(n<64)return n;{let r=Ue[n&63]||Zt.getStructures&&kg()[n&63];return r?(r.read||(r.read=lp(r,n&63)),r.read()):n}}else if(n<144)if(n-=128,Zt.mapsAsObjects){let r={};for(let e=0;e<n;e++)r[Hg()]=pt();return r}else{let r=new Map;for(let e=0;e<n;e++)r.set(pt(),pt());return r}else{n-=144;let r=new Array(n);for(let e=0;e<n;e++)r[e]=pt();return r}else if(n<192){let r=n-160;if(Qr>=G)return on.slice(G-yr,(G+=r)-yr);if(Qr==0&&nn<140){let e=r<16?cp(r):Ug(r);if(e!=null)return e}return ap(r)}else{let r;switch(n){case 192:return null;case 193:return lr?(r=pt(),r>0?lr[1].slice(lr.position1,lr.position1+=r):lr[0].slice(lr.position0,lr.position0-=r)):sp;case 194:return!1;case 195:return!0;case 196:return rp(de[G++]);case 197:return r=We.getUint16(G),G+=2,rp(r);case 198:return r=We.getUint32(G),G+=4,rp(r);case 199:return Wn(de[G++]);case 200:return r=We.getUint16(G),G+=2,Wn(r);case 201:return r=We.getUint32(G),G+=4,Wn(r);case 202:if(r=We.getFloat32(G),Zt.useFloat32>2){let e=Cc[(de[G]&127)<<1|de[G+1]>>7];return G+=4,(e*r+(r>0?.5:-.5)>>0)/e}return G+=4,r;case 203:return r=We.getFloat64(G),G+=8,r;case 204:return de[G++];case 205:return r=We.getUint16(G),G+=2,r;case 206:return r=We.getUint32(G),G+=4,r;case 207:return Zt.int64AsNumber?(r=We.getUint32(G)*4294967296,r+=We.getUint32(G+4)):r=We.getBigUint64(G),G+=8,r;case 208:return We.getInt8(G++);case 209:return r=We.getInt16(G),G+=2,r;case 210:return r=We.getInt32(G),G+=4,r;case 211:return Zt.int64AsNumber?(r=We.getInt32(G)*4294967296,r+=We.getUint32(G+4)):r=We.getBigInt64(G),G+=8,r;case 212:if(r=de[G++],r==114)return Fg(de[G++]&63);{let e=qt[r];if(e)return e.read?(G++,e.read(pt())):e.noBuffer?(G++,e()):e(de.subarray(G,++G));throw new Error("Unknown extension "+r)}case 213:return r=de[G],r==114?(G++,Fg(de[G++]&63,de[G++])):Wn(2);case 214:return Wn(4);case 215:return Wn(8);case 216:return Wn(16);case 217:return r=de[G++],Qr>=G?on.slice(G-yr,(G+=r)-yr):cT(r);case 218:return r=We.getUint16(G),G+=2,Qr>=G?on.slice(G-yr,(G+=r)-yr):uT(r);case 219:return r=We.getUint32(G),G+=4,Qr>=G?on.slice(G-yr,(G+=r)-yr):dT(r);case 220:return r=We.getUint16(G),G+=2,Vg(r);case 221:return r=We.getUint32(G),G+=4,Vg(r);case 222:return r=We.getUint16(G),G+=2,zg(r);case 223:return r=We.getUint32(G),G+=4,zg(r);default:if(n>=224)return n-256;if(n===void 0){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+n)}}}var lT=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function lp(n,r){function e(){if(e.count++>2){let o=n.read=new Function("r","return function(){return {"+n.map(i=>lT.test(i)?i+":r()":"["+JSON.stringify(i)+"]:r()").join(",")+"}}")(pt);return n.highByte===0&&(n.read=Lg(r,n.read)),o()}let t={};for(let o=0,i=n.length;o<i;o++){let a=n[o];t[a]=pt()}return t}return e.count=0,n.highByte===0?Lg(r,e):e}var Lg=(n,r)=>function(){let e=de[G++];if(e===0)return r();let t=n<32?-(n+(e<<5)):n+(e<<5),o=Ue[t]||kg()[t];if(!o)throw new Error("Record id is not defined for "+t);return o.read||(o.read=lp(o,n)),o.read()};function kg(){let n=qg(()=>(de=null,Zt.getStructures()));return Ue=Zt._mergeStructures(n,Ue)}var ap=Pc,cT=Pc,uT=Pc,dT=Pc;function Pc(n){let r;if(n<16&&(r=cp(n)))return r;if(n>64&&op)return op.decode(de.subarray(G,G+=n));let e=G+n,t=[];for(r="";G<e;){let o=de[G++];if((o&128)===0)t.push(o);else if((o&224)===192){let i=de[G++]&63;t.push((o&31)<<6|i)}else if((o&240)===224){let i=de[G++]&63,a=de[G++]&63;t.push((o&31)<<12|i<<6|a)}else if((o&248)===240){let i=de[G++]&63,a=de[G++]&63,s=de[G++]&63,l=(o&7)<<18|i<<12|a<<6|s;l>65535&&(l-=65536,t.push(l>>>10&1023|55296),l=56320|l&1023),t.push(l)}else t.push(o);t.length>=4096&&(r+=Mt.apply(String,t),t.length=0)}return t.length>0&&(r+=Mt.apply(String,t)),r}function Vg(n){let r=new Array(n);for(let e=0;e<n;e++)r[e]=pt();return r}function zg(n){if(Zt.mapsAsObjects){let r={};for(let e=0;e<n;e++)r[Hg()]=pt();return r}else{let r=new Map;for(let e=0;e<n;e++)r.set(pt(),pt());return r}}var Mt=String.fromCharCode;function Ug(n){let r=G,e=new Array(n);for(let t=0;t<n;t++){let o=de[G++];if((o&128)>0){G=r;return}e[t]=o}return Mt.apply(String,e)}function cp(n){if(n<4)if(n<2){if(n===0)return"";{let r=de[G++];if((r&128)>1){G-=1;return}return Mt(r)}}else{let r=de[G++],e=de[G++];if((r&128)>0||(e&128)>0){G-=2;return}if(n<3)return Mt(r,e);let t=de[G++];if((t&128)>0){G-=3;return}return Mt(r,e,t)}else{let r=de[G++],e=de[G++],t=de[G++],o=de[G++];if((r&128)>0||(e&128)>0||(t&128)>0||(o&128)>0){G-=4;return}if(n<6){if(n===4)return Mt(r,e,t,o);{let i=de[G++];if((i&128)>0){G-=5;return}return Mt(r,e,t,o,i)}}else if(n<8){let i=de[G++],a=de[G++];if((i&128)>0||(a&128)>0){G-=6;return}if(n<7)return Mt(r,e,t,o,i,a);let s=de[G++];if((s&128)>0){G-=7;return}return Mt(r,e,t,o,i,a,s)}else{let i=de[G++],a=de[G++],s=de[G++],l=de[G++];if((i&128)>0||(a&128)>0||(s&128)>0||(l&128)>0){G-=8;return}if(n<10){if(n===8)return Mt(r,e,t,o,i,a,s,l);{let c=de[G++];if((c&128)>0){G-=9;return}return Mt(r,e,t,o,i,a,s,l,c)}}else if(n<12){let c=de[G++],u=de[G++];if((c&128)>0||(u&128)>0){G-=10;return}if(n<11)return Mt(r,e,t,o,i,a,s,l,c,u);let p=de[G++];if((p&128)>0){G-=11;return}return Mt(r,e,t,o,i,a,s,l,c,u,p)}else{let c=de[G++],u=de[G++],p=de[G++],d=de[G++];if((c&128)>0||(u&128)>0||(p&128)>0||(d&128)>0){G-=12;return}if(n<14){if(n===12)return Mt(r,e,t,o,i,a,s,l,c,u,p,d);{let h=de[G++];if((h&128)>0){G-=13;return}return Mt(r,e,t,o,i,a,s,l,c,u,p,d,h)}}else{let h=de[G++],f=de[G++];if((h&128)>0||(f&128)>0){G-=14;return}if(n<15)return Mt(r,e,t,o,i,a,s,l,c,u,p,d,h,f);let m=de[G++];if((m&128)>0){G-=15;return}return Mt(r,e,t,o,i,a,s,l,c,u,p,d,h,f,m)}}}}}function rp(n){return Zt.copyBuffers?Uint8Array.prototype.slice.call(de,G,G+=n):de.subarray(G,G+=n)}function Wn(n){let r=de[G++];if(qt[r])return qt[r](de.subarray(G,G+=n));throw new Error("Unknown extension type "+r)}var Gg=new Array(4096);function Hg(){let n=de[G++];if(n>=160&&n<192){if(n=n-160,Qr>=G)return on.slice(G-yr,(G+=n)-yr);if(!(Qr==0&&nn<180))return ap(n)}else return G--,pt();let r=(n<<5^(n>1?We.getUint16(G):n>0?de[G]:0))&4095,e=Gg[r],t=G,o=G+n-3,i,a=0;if(e&&e.bytes==n){for(;t<o;){if(i=We.getUint32(t),i!=e[a++]){t=1879048192;break}t+=4}for(o+=3;t<o;)if(i=de[t++],i!=e[a++]){t=1879048192;break}if(t===o)return G=t,e.string;o-=3,t=G}for(e=[],Gg[r]=e,e.bytes=n;t<o;)i=We.getUint32(t),e.push(i),t+=4;for(o+=3;t<o;)i=de[t++],e.push(i);let s=n<16?cp(n):Ug(n);return s!=null?e.string=s:e.string=ap(n)}var Fg=(n,r)=>{var e=pt();let t=n;r!==void 0&&(n=n<32?-((r<<5)+n):(r<<5)+n,e.highByte=r);let o=Ue[n];return o&&o.isShared&&((Ue.restoreStructures||(Ue.restoreStructures=[]))[n]=o),Ue[n]=e,e.read=lp(e,t),e.read()},Wg=typeof self=="object"?self:global;qt[0]=()=>{};qt[0].noBuffer=!0;qt[101]=()=>{let n=pt();return(Wg[n[0]]||Error)(n[1])};qt[105]=n=>{let r=We.getUint32(G-4);Oo||(Oo=new Map);let e=de[G],t;e>=144&&e<160||e==220||e==221?t=[]:t={};let o={target:t};Oo.set(r,o);let i=pt();return o.used?Object.assign(t,i):(o.target=i,i)};qt[112]=n=>{let r=We.getUint32(G-4),e=Oo.get(r);return e.used=!0,e.target};qt[115]=()=>new Set(pt());var up=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(n=>n+"Array");qt[116]=n=>{let r=n[0],e=up[r];if(!e)throw new Error("Could not find typed array for code "+r);return new Wg[e](Uint8Array.prototype.slice.call(n,1).buffer)};qt[120]=()=>{let n=pt();return new RegExp(n[0],n[1])};qt[98]=n=>{let r=(n[0]<<24)+(n[1]<<16)+(n[2]<<8)+n[3],e=G;G+=r-4,lr=[pt(),pt()],lr.position0=0,lr.position1=0;let t=G;G=e;try{return pt()}finally{G=t}};qt[255]=n=>n.length==4?new Date((n[0]*16777216+(n[1]<<16)+(n[2]<<8)+n[3])*1e3):n.length==8?new Date(((n[0]<<22)+(n[1]<<14)+(n[2]<<6)+(n[3]>>2))/1e6+((n[3]&3)*4294967296+n[4]*16777216+(n[5]<<16)+(n[6]<<8)+n[7])*1e3):n.length==12?new Date(((n[0]<<24)+(n[1]<<16)+(n[2]<<8)+n[3])/1e6+((n[4]&128?-281474976710656:0)+n[6]*1099511627776+n[7]*4294967296+n[8]*16777216+(n[9]<<16)+(n[10]<<8)+n[11])*1e3):new Date("invalid");function qg(n){let r=nn,e=G,t=ip,o=yr,i=Qr,a=on,s=np,l=Oo,c=lr,u=new Uint8Array(de.slice(0,nn)),p=Ue,d=Ue.slice(0,Ue.length),h=Zt,f=Xi,m=n();return nn=r,G=e,ip=t,yr=o,Qr=i,on=a,np=s,Oo=l,lr=c,de=u,Xi=f,Ue=p,Ue.splice(0,Ue.length,...d),Zt=h,We=new DataView(de.buffer,de.byteOffset,de.byteLength),m}function wc(){de=null,Oo=null,Ue=null}function $g(n){n.unpack?qt[n.type]=n.unpack:qt[n.type]=n}var Cc=new Array(147);for(let n=0;n<256;n++)Cc[n]=+("1e"+Math.floor(45.15-n*.30103));var Oc=new Zr({useRecords:!1}),pT=Oc.unpack,fT=Oc.unpackMultiple,hT=Oc.unpack,Ac={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},mT=new Float32Array(1),c4=new Uint8Array(mT.buffer,0,4);var Tc;try{Tc=new TextEncoder}catch{}var Ic,pp,Mc=typeof Buffer<"u",dp=Mc?Buffer.allocUnsafeSlow:Uint8Array,Qg=Mc?Buffer:Uint8Array,Yg=Mc?4294967296:2144337920,Y,ht,U=0,Jr,eo=null,yT=/[\u0080-\uFFFF]/,Ns=Symbol("record-id"),qn=class extends Zr{constructor(r){super(r),this.offset=0;let e,t,o,i,a,s,l=0,c=Qg.prototype.utf8Write?function(x,N,E){return Y.utf8Write(x,N,E)}:Tc&&Tc.encodeInto?function(x,N){return Tc.encodeInto(x,Y.subarray(N)).written}:!1,u=this;r||(r={});let p=r&&r.sequential,d=r.structures||r.saveStructures,h=r.maxSharedStructures;if(h==null&&(h=d?32:0),h>8160)throw new Error("Maximum maxSharedStructure is 8160");let f=r.maxOwnStructures;f==null&&(f=d?32:64),p&&!r.saveStructures&&(this.structures=[]);let m=h>32||f+h>64,y=h+64,g=h+f+64;if(g>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let v=[],w=0,O=0;this.pack=this.encode=function(x,N){if(Y||(Y=new dp(8192),ht=new DataView(Y.buffer,0,8192),U=0),Jr=Y.length-10,Jr-U<2048?(Y=new dp(Y.length),ht=new DataView(Y.buffer,0,Y.length),Jr=Y.length-10,U=0):U=U+7&2147483640,t=U,s=u.structuredClone?new Map:null,u.bundleStrings?(eo=["",""],Y[U++]=214,Y[U++]=98,eo.position=U-t,U+=4):eo=null,o=u.structures,o){o.uninitialized&&(o=u._mergeStructures(u.getStructures()));let E=o.sharedLength||0;if(E>h)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+o.sharedLength);if(!o.transitions){o.transitions=Object.create(null);for(let M=0;M<E;M++){let D=o[M];if(!D)continue;let _,B=o.transitions;for(let V=0,k=D.length;V<k;V++){let L=D[V];_=B[L],_||(_=B[L]=Object.create(null)),B=_}B[Ns]=M+64}l=E}p||(o.nextId=E+64)}i&&(i=!1),a=o||[];try{if(S(x),eo){ht.setUint32(eo.position+t,U-eo.position-t);let E=eo;eo=null,S(E[0]),S(E[1])}if(u.offset=U,s&&s.idsToInsert){U+=s.idsToInsert.length*6,U>Jr&&T(U),u.offset=U;let E=xT(Y.subarray(t,U),s.idsToInsert);return s=null,E}return N&Jg?(Y.start=t,Y.end=U,Y):Y.subarray(t,U)}finally{if(o){if(O<10&&O++,w>1e4)o.transitions=null,O=0,w=0,v.length>0&&(v=[]);else if(v.length>0&&!p){for(let E=0,M=v.length;E<M;E++)v[E][Ns]=0;v=[]}if(i&&u.saveStructures){let E=o.sharedLength||h;o.length>E&&(o=o.slice(0,E));let M=Y.subarray(t,U);return u.saveStructures(o,l)===!1?(u._mergeStructures(u.getStructures()),u.pack(x)):(l=E,M)}}N&OT&&(U=t)}};let S=x=>{U>Jr&&(Y=T(U));var N=typeof x,E;if(N==="string"){let M=x.length;if(eo&&M>=8&&M<4096){let B=yT.test(x);eo[B?0:1]+=x,Y[U++]=193,S(B?-M:M);return}let D;M<32?D=1:M<256?D=2:M<65536?D=3:D=5;let _=M*3;if(U+_>Jr&&(Y=T(U+_)),M<64||!c){let B,V,k,L=U+D;for(B=0;B<M;B++)V=x.charCodeAt(B),V<128?Y[L++]=V:V<2048?(Y[L++]=V>>6|192,Y[L++]=V&63|128):(V&64512)===55296&&((k=x.charCodeAt(B+1))&64512)===56320?(V=65536+((V&1023)<<10)+(k&1023),B++,Y[L++]=V>>18|240,Y[L++]=V>>12&63|128,Y[L++]=V>>6&63|128,Y[L++]=V&63|128):(Y[L++]=V>>12|224,Y[L++]=V>>6&63|128,Y[L++]=V&63|128);E=L-U-D}else E=c(x,U+D,_);E<32?Y[U++]=160|E:E<256?(D<2&&Y.copyWithin(U+2,U+1,U+1+E),Y[U++]=217,Y[U++]=E):E<65536?(D<3&&Y.copyWithin(U+3,U+2,U+2+E),Y[U++]=218,Y[U++]=E>>8,Y[U++]=E&255):(D<5&&Y.copyWithin(U+5,U+3,U+3+E),Y[U++]=219,ht.setUint32(U,E),U+=4),U+=E}else if(N==="number")if(x>>>0===x)x<64?Y[U++]=x:x<256?(Y[U++]=204,Y[U++]=x):x<65536?(Y[U++]=205,Y[U++]=x>>8,Y[U++]=x&255):(Y[U++]=206,ht.setUint32(U,x),U+=4);else if(x>>0===x)x>=-32?Y[U++]=256+x:x>=-128?(Y[U++]=208,Y[U++]=x+256):x>=-32768?(Y[U++]=209,ht.setInt16(U,x),U+=2):(Y[U++]=210,ht.setInt32(U,x),U+=4);else{let M;if((M=this.useFloat32)>0&&x<4294967296&&x>=-2147483648){Y[U++]=202,ht.setFloat32(U,x);let D;if(M<4||(D=x*Cc[(Y[U]&127)<<1|Y[U+1]>>7])>>0===D){U+=4;return}else U--}Y[U++]=203,ht.setFloat64(U,x),U+=8}else if(N==="object")if(!x)Y[U++]=192;else{if(s){let D=s.get(x);if(D){if(!D.id){let _=s.idsToInsert||(s.idsToInsert=[]);D.id=_.push(D)}Y[U++]=214,Y[U++]=112,ht.setUint32(U,D.id),U+=4;return}else s.set(x,{offset:U-t})}let M=x.constructor;if(M===Object)C(x,!0);else if(M===Array){E=x.length,E<16?Y[U++]=144|E:E<65536?(Y[U++]=220,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=221,ht.setUint32(U,E),U+=4);for(let D=0;D<E;D++)S(x[D])}else if(M===Map){E=x.size,E<16?Y[U++]=128|E:E<65536?(Y[U++]=222,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=223,ht.setUint32(U,E),U+=4);for(let[D,_]of x)S(D),S(_)}else{for(let D=0,_=Ic.length;D<_;D++){let B=pp[D];if(x instanceof B){let V=Ic[D];if(V.write){V.type&&(Y[U++]=212,Y[U++]=V.type,Y[U++]=0),S(V.write.call(this,x));return}let k=Y,L=ht,W=U;Y=null;let F;try{F=V.pack.call(this,x,j=>(Y=k,k=null,U+=j,U>Jr&&T(U),{target:Y,targetView:ht,position:U-j}),S)}finally{k&&(Y=k,ht=L,U=W,Jr=Y.length-10)}F&&(F.length+U>Jr&&T(F.length+U),U=gT(F,Y,U,V.type));return}}C(x,!x.hasOwnProperty)}}else if(N==="boolean")Y[U++]=x?195:194;else if(N==="bigint"){if(x<BigInt(1)<<BigInt(63)&&x>=-(BigInt(1)<<BigInt(63)))Y[U++]=211,ht.setBigInt64(U,x);else if(x<BigInt(1)<<BigInt(64)&&x>0)Y[U++]=207,ht.setBigUint64(U,x);else if(this.largeBigIntToFloat)Y[U++]=203,ht.setFloat64(U,Number(x));else throw new RangeError(x+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");U+=8}else if(N==="undefined")this.encodeUndefinedAsNil?Y[U++]=192:(Y[U++]=212,Y[U++]=0,Y[U++]=0);else if(N==="function")S(this.writeFunction&&this.writeFunction());else throw new Error("Unknown type: "+N)},C=this.useRecords===!1?this.variableMapSize?x=>{let N=Object.keys(x),E=N.length;E<16?Y[U++]=128|E:E<65536?(Y[U++]=222,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=223,ht.setUint32(U,E),U+=4);let M;for(let D=0;D<E;D++)S(M=N[D]),S(x[M])}:(x,N)=>{Y[U++]=222;let E=U-t;U+=2;let M=0;for(let D in x)(N||x.hasOwnProperty(D))&&(S(D),S(x[D]),M++);Y[E+++t]=M>>8,Y[E+t]=M&255}:x=>{let N=Object.keys(x),E,M=a.transitions||(a.transitions=Object.create(null)),D=0;for(let B=0,V=N.length;B<V;B++){let k=N[B];E=M[k],E||(E=M[k]=Object.create(null),D++),M=E}let _=M[Ns];if(_)_>=96&&m?(Y[U++]=((_-=96)&31)+96,Y[U++]=_>>5):Y[U++]=_;else{_=a.nextId,_||(_=64),_<y&&this.shouldShareStructure&&!this.shouldShareStructure(N)?(_=a.nextOwnId,_<g||(_=y),a.nextOwnId=_+1):(_>=g&&(_=y),a.nextId=_+1);let B=N.highByte=_>=96&&m?_-96>>5:-1;M[Ns]=_,a[_-64]=N,_<y?(N.isShared=!0,a.sharedLength=_-63,i=!0,B>=0?(Y[U++]=(_&31)+96,Y[U++]=B):Y[U++]=_):(B>=0?(Y[U++]=213,Y[U++]=114,Y[U++]=(_&31)+96,Y[U++]=B):(Y[U++]=212,Y[U++]=114,Y[U++]=_),D&&(w+=O*D),v.length>=f&&(v.shift()[Ns]=0),v.push(M),S(N))}for(let B=0,V=N.length;B<V;B++)S(x[N[B]])},T=x=>{let N;if(x>16777216){if(x-t>Yg)throw new Error("Packed buffer would be larger than maximum buffer size");N=Math.min(Yg,Math.round(Math.max((x-t)*(x>67108864?1.25:2),4194304)/4096)*4096)}else N=(Math.max(x-t<<2,Y.length-1)>>12)+1<<12;let E=new dp(N);return ht=new DataView(E.buffer,0,N),Y.copy?Y.copy(E,0,t,x):E.set(Y.slice(t,x)),U-=t,t=0,Jr=E.length-10,Y=E}}useBuffer(r){Y=r,ht=new DataView(Y.buffer,Y.byteOffset,Y.byteLength),U=0}};pp=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,Es];Ic=[{pack(n,r,e){let t=n.getTime()/1e3;if((this.useTimestamp32||n.getMilliseconds()===0)&&t>=0&&t<4294967296){let{target:o,targetView:i,position:a}=r(6);o[a++]=214,o[a++]=255,i.setUint32(a,t)}else if(t>0&&t<17179869184){let{target:o,targetView:i,position:a}=r(10);o[a++]=215,o[a++]=255,i.setUint32(a,n.getMilliseconds()*4e6+(t/1e3/4294967296>>0)),i.setUint32(a+4,t)}else if(isNaN(t)){if(this.onInvalidDate)return r(0),e(this.onInvalidDate());let{target:o,targetView:i,position:a}=r(3);o[a++]=212,o[a++]=255,o[a++]=255}else{let{target:o,targetView:i,position:a}=r(15);o[a++]=199,o[a++]=12,o[a++]=255,i.setUint32(a,n.getMilliseconds()*1e6),i.setBigInt64(a+4,BigInt(Math.floor(t)))}}},{pack(n,r,e){let t=Array.from(n),{target:o,position:i}=r(this.structuredClone?3:0);this.structuredClone&&(o[i++]=212,o[i++]=115,o[i++]=0),e(t)}},{pack(n,r,e){let{target:t,position:o}=r(this.structuredClone?3:0);this.structuredClone&&(t[o++]=212,t[o++]=101,t[o++]=0),e([n.name,n.message])}},{pack(n,r,e){let{target:t,position:o}=r(this.structuredClone?3:0);this.structuredClone&&(t[o++]=212,t[o++]=120,t[o++]=0),e([n.source,n.flags])}},{pack(n,r){this.structuredClone?Xg(n,16,r):Kg(Mc?Buffer.from(n):new Uint8Array(n),r)}},{pack(n,r){let e=n.constructor;e!==Qg&&this.structuredClone?Xg(n,up.indexOf(e.name),r):Kg(n,r)}},{pack(n,r){let{target:e,position:t}=r(1);e[t]=193}}];function Xg(n,r,e,t){let o=n.byteLength;if(o+1<256){var{target:i,position:a}=e(4+o);i[a++]=199,i[a++]=o+1}else if(o+1<65536){var{target:i,position:a}=e(5+o);i[a++]=200,i[a++]=o+1>>8,i[a++]=o+1&255}else{var{target:i,position:a,targetView:s}=e(7+o);i[a++]=201,s.setUint32(a,o+1),a+=4}i[a++]=116,i[a++]=r,i.set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),a)}function Kg(n,r){let e=n.byteLength;var t,o;if(e<256){var{target:t,position:o}=r(e+2);t[o++]=196,t[o++]=e}else if(e<65536){var{target:t,position:o}=r(e+3);t[o++]=197,t[o++]=e>>8,t[o++]=e&255}else{var{target:t,position:o,targetView:i}=r(e+5);t[o++]=198,i.setUint32(o,e),o+=4}t.set(n,o)}function gT(n,r,e,t){let o=n.length;switch(o){case 1:r[e++]=212;break;case 2:r[e++]=213;break;case 4:r[e++]=214;break;case 8:r[e++]=215;break;case 16:r[e++]=216;break;default:o<256?(r[e++]=199,r[e++]=o):o<65536?(r[e++]=200,r[e++]=o>>8,r[e++]=o&255):(r[e++]=201,r[e++]=o>>24,r[e++]=o>>16&255,r[e++]=o>>8&255,r[e++]=o&255)}return r[e++]=t,r.set(n,e),e+=o,e}function xT(n,r){let e,t=r.length*6,o=n.length-t;for(r.sort((i,a)=>i.offset>a.offset?1:-1);e=r.pop();){let i=e.offset,a=e.id;n.copyWithin(i+t,i,o),t-=6;let s=i+t;n[s++]=214,n[s++]=105,n[s++]=a>>24,n[s++]=a>>16&255,n[s++]=a>>8&255,n[s++]=a&255,o=i}return n}function an(n){if(n.Class){if(!n.pack&&!n.write)throw new Error("Extension has no pack or write function");if(n.pack&&!n.type)throw new Error("Extension has no type (numeric code to identify the extension)");pp.unshift(n.Class),Ic.unshift(n)}$g(n)}var Zg=new qn({useRecords:!1}),bT=Zg.pack,vT=Zg.pack;var{NEVER:ST,ALWAYS:wT,DECIMAL_ROUND:PT,DECIMAL_FIT:CT}=Ac,Jg=512,OT=1024;var ex=new qn({structuredClone:!0});an({Class:fe.prototype.constructor,type:1,write(n){return{...n}},read(n){return Object.setPrototypeOf(n,fe.prototype),n}});an({Class:be.prototype.constructor,type:2,write(n){return[...n]},read(n){return Object.setPrototypeOf(n,be.prototype),n}});an({Class:Ke.prototype.constructor,type:3,write(n){return[...n]},read(n){return Object.setPrototypeOf(n,Ke.prototype),n}});an({Class:Is.prototype.constructor,type:4,write(n){return n.id},read(n){return new Is(n)}});an({Class:Ms.prototype.constructor,type:5,write(n){return n.data},read(n){return new Ms(n)}});an({Class:Qe.prototype.constructor,type:6,write(n){return{...n}},read(n){return Object.setPrototypeOf(n,Qe.prototype),n}});function AT(n){var r=0;if(n.length===0)return r;for(let e=0;e<n.length;e++){let t=n[e];r=(r<<5)-r+t,r=r&r}return r}function fp(n){if(Ui(n))return n;if(Array.isArray(n))return n.map(fp);if(typeof n=="object"&&n!==null){let r={};for(let e of Object.keys(n).sort())r[e]=fp(n[e]);return Object.setPrototypeOf(r,Object.getPrototypeOf(n)),r}else return n}var Ec;(t=>{function n(o){return ex.pack(o)}t.serialize=n;function r(o){return ex.unpack(o)}t.deserialize=r;function e(o){return AT(n(fp(o))).toString()}t.checksum=e})(Ec||(Ec={}));var cn="personal camera",un="a218fcc3-276b-49b9-b485-49037fd14f5f",ax=2960946,mt=5526619;var Ki;(h=>{function n(f,m){return f[0]===m[0]&&f[1]===m[1]}h.isEqual=n;function r(f,m,y){return[f[0]+(m[0]-f[0])*y,f[1]+(m[1]-f[1])*y]}h.lerp=r;function e(f,m){return[f[0]+m[0],f[1]+m[1]]}h.add=e;function t(f,m){return[f[0]-m[0],f[1]-m[1]]}h.sub=t;function o(f,m){return[f[0]*m[0],f[1]*m[1]]}h.multiply=o;function i(f,m){return[f[0]/m[0],f[1]/m[1]]}h.divide=i;function a(f,m){return Math.pow(m[0]-f[0],2)+Math.pow(m[1]-f[1],2)}h.distanceSquared=a;function s(f,m){return Math.sqrt(a(f,m))}h.distance=s;function l(f,m){return f[0]*m[0]+f[1]*m[1]}h.dot=l;function c(f,m){return[f[0]*m,f[1]*m]}h.scalarMultiply=c;function u(f,m,y){let g=h.sub(m,f),v=h.sub(y,f),w=h.dot(g,v)/h.dot(g,g),O=h.scalarMultiply(g,w);return h.add(f,O)}h.projectionOnto=u;function p(f,m,y){return s(f,u(f,m,y))}h.projectionOntoDistance=p;function d(f,m){return[(f[0]+m[0])*.5,(f[1]+m[1])*.5]}h.center=d})(Ki||(Ki={}));var sn;(s=>{function n(l,c){return l[0]===c[0]&&l[1]===c[1]&&l[2]===c[2]}s.isEqual=n;function r(l,c){return[l[0]+c[0],l[1]+c[1],l[2]+c[2]]}s.add=r;function e(l,c){return[l[0]-c[0],l[1]-c[1],l[2]-c[2]]}s.sub=e;function t(l,c){return[l[0]/c[0],l[1]/c[1],l[2]/c[2]]}s.div=t;function o(l,c){return[l[0]*c[0],l[1]*c[1],l[2]*c[2]]}s.mul=o;function i(l,c){return Math.hypot(l[0]-c[0],l[1]-c[1],l[2]-c[2])}s.dist=i;function a(l,c,u){return[l[0]+(c[0]-l[0])*u,l[1]+(c[1]-l[1])*u,l[2]+(c[2]-l[2])*u]}s.lerp=a})(sn||(sn={}));var tx;(e=>{function n(t,o){return t[0]===o[0]&&t[1]===o[1]&&t[2]===o[2]&&t[3]===o[3]}e.isEqual=n;function r(t,o,i){return[t[0]+(o[0]-t[0])*i,t[1]+(o[1]-t[1])*i,t[2]+(o[2]-t[2])*i,t[3]+(o[3]-t[3])*i]}e.lerp=r})(tx||(tx={}));var rx;(a=>{let n=180/Math.PI,r=Math.PI/180;function e(s){return typeof s=="number"?s*n:s}function t(s){return typeof s=="number"?s*r:s}function o(s){return[e(s[0]),e(s[1]),e(s[2])]}a.radToDeg=o;function i(s){return[t(s[0]),t(s[1]),t(s[2])]}a.degToRad=i})(rx||(rx={}));var ln;(o=>{o.identity=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function r(i,a){for(let s=0;s<16;s++)if(i[s]!==a[s])return!1;return!0}o.isEqual=r;function e(i){return i??o.identity}o.simplify=e;function t(i,a){let s=a.slice(0);for(var l=0,c=a.length;l<c;l+=3){let u=i[3]*a[l]+i[7]*a[l+1]+i[11]*a[l+2]+i[15];s[l]=(i[0]*a[l]+i[4]*a[l+1]+i[8]*a[l+2]+i[12])/u,s[l+1]=(i[1]*a[l]+i[5]*a[l+1]+i[9]*a[l+2]+i[13])/u,s[l+2]=(i[2]*a[l]+i[6]*a[l+1]+i[10]*a[l+2]+i[14])/u}return s}o.applyMatrix4=t})(ln||(ln={}));var wt;(p=>{function n(d){return typeof d=="object"&&typeof d.r=="number"&&typeof d.g=="number"&&typeof d.b=="number"}p.isRGB=n,p.white={r:1,g:1,b:1},p.red={r:1,g:0,b:0},p.black={r:0,g:0,b:0};function o(d){return{r:Math.round(d.r*255),g:Math.round(d.g*255),b:Math.round(d.b*255),a:1}}p.toRgb255a1=o;function i(d){return{r:d.r,g:d.g,b:d.b}}p.clone=i;function a(d){return d=Math.floor(d),{r:(d>>16&255)/255,g:(d>>8&255)/255,b:(d&255)/255}}p.fromHex=a;function s(d){return Math.round(d.r*255)*65536+Math.round(d.g*255)*256+Math.round(d.b*255)}p.toHex=s;function l(d,h){return d.r===h.r&&d.g===h.g&&d.b===h.b}p.equals=l;function c(d,h){return d.r.toFixed(2)===h.r.toFixed(2)&&d.g.toFixed(2)===h.g.toFixed(2)&&d.b.toFixed(2)===h.b.toFixed(2)}p.equalsFixed=c;function u(d,h,f){return{r:d.r+(h.r-d.r)*f,g:d.g+(h.g-d.g)*f,b:d.b+(h.b-d.b)*f}}p.lerp=u})(wt||(wt={}));var Me;(c=>{c.white={...wt.white,a:1},c.transparent={...wt.white,a:0};function e(u){return{r:u[0],g:u[1],b:u[2],a:u[3]}}c.from0to1=e;function t(u,p){return{...wt.fromHex(u),a:p}}c.fromHexAndA=t;function o(u){return{r:Math.round(u.r*255),g:Math.round(u.g*255),b:Math.round(u.b*255),a:u.a}}c.toRgb255a1=o;function i(u,p){return wt.equals(u,p)&&u.a===p.a}c.equals=i;function a(u,p){return wt.equalsFixed(u,p)&&u.a.toFixed(2)===p.a.toFixed(2)}c.equalsFixed=a;function s(u,p,d){return{r:u.r+(p.r-u.r)*d,g:u.g+(p.g-u.g)*d,b:u.b+(p.b-u.b)*d,a:u.a+(p.a-u.a)*d}}c.lerp=s;function l({r:u,g:p,b:d,a:h}=c.white){return`rgba(${u*255}, ${p*255}, ${d*255}, ${h})`}c.toStyle=l})(Me||(Me={}));var Nc;(r=>r.identity={position:[0,0,0],rotation:[0,0,0],scale:[1,1,1]})(Nc||(Nc={}));var ox;(r=>r.defaultData={mass:1,stiffness:80,damping:10,velocity:0})(ox||(ox={}));var nx;(r=>r.defaultData={control1:[.5,0],control2:[.5,1]})(nx||(nx={}));var ix;(i=>(i.linear=[0,0,1,1],i.ease=[.25,.1,.25,1],i.easeIn=[.42,0,1,1],i.easeOut=[0,0,.58,1],i.easeInOut=[.42,0,.58,1]))(ix||(ix={}));function hp(n){return typeof n=="string"&&n.length===36?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n):!1}var Nr;(e=>{e.all=["PerspectiveCamera","OrthographicCamera"];function r(t){return e.all.includes(t)}e.is=r})(Nr||(Nr={}));var dn;(o=>{o.DefaultUp=[0,1,0],o.DefaultTargetOffset=1e3,o.defaultData={far:1e5,type:"OrthographicCamera",perspective:{near:70,fov:45,zoom:1},orthographic:{near:-1e5,zoom:1},up:o.DefaultUp,isUpVectorFlipped:!1,targetOffset:o.DefaultTargetOffset};function t(i){return i.type==="PerspectiveCamera"?i.perspective?.zoom??1:i.orthographic?.zoom??1}o.getZoom=t})(dn||(dn={}));var to;(e=>{function n(t,o=.1){return{disabled:!1,type:"linear",hideBase:!1,count:3,radial:{radius:Math.max(t[0],t[1])*2,start:0,end:360,alignment:!1,axis:"y",scale:[1,1,1],rotation:[0,0,0],position:[0,0,0]},toObject:{object:"",spreadType:"random",scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],axis:"x",seed:0,count:99,align:"normal"},linear:{scale:[1,1,1],rotation:[0,0,0],position:[t[0]+t[0]*o,0,0]},grid:{count:[2,2,2],size:t.map(i=>i*(1+o)),useCenter:!0},randomness:!1,randomnessObject:{strength:100,scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],movement:1,seed:0,freqScale:10,noiseType:"perlin"}}}e.defaultData=n;function r(t,o){let i={...t};if(TT.forEach(a=>{Object.assign(i,{[a]:o[a]??t[a]})}),i.radial={...t.radial},o.radial){let a=t.radial,s=o.radial;IT.forEach(l=>{Object.assign(i.radial,{[l]:s[l]??a[l]})})}if(i.linear={...t.linear},o.linear){let a=t.linear,s=o.linear;MT.forEach(l=>{Object.assign(i.linear,{[l]:s[l]??a[l]})})}if(i.grid={...t.grid},o.grid){let a=t.grid,s=o.grid;ET.forEach(l=>{Object.assign(i.grid,{[l]:s[l]??a[l]})})}if(i.toObject={...t.toObject},o.toObject){let a=t.toObject,s=o.toObject;NT.forEach(l=>{Object.assign(i.toObject,{[l]:s[l]??a[l]})})}if(i.randomnessObject={...t.randomnessObject},o.randomnessObject){let a=t.randomnessObject,s=o.randomnessObject;DT.forEach(l=>{Object.assign(i.randomnessObject,{[l]:s[l]??a[l]})})}return i}e.merge=r})(to||(to={}));var Dc;(t=>{t.defaultData={radial:{},linear:{},grid:{},toObject:{},randomnessObject:{}};let r=["radial","linear","grid","toObject","randomnessObject"];function e(o,i){let a=[];o.count!==void 0&&a.push({type:0,path:i,props:{count:o.count}});for(let s of r){let l=o[s];l&&Object.keys(l).length>0&&a.push({type:0,path:[...i,s],props:l})}return a}t.toOps=e})(Dc||(Dc={}));var TT=["count"],IT=["radius","start","end","position","scale","rotation"],MT=["position","scale","rotation"],ET=["count","size"],NT=["count","position","scale","rotation"],DT=["strength","scale","rotation","position","movement","seed","freqScale"];var _c;(e=>{e.all=["PointLight","SpotLight","DirectionalLight","HemisphereLight"];function r(t){return e.all.includes(t)}e.is=r})(_c||(_c={}));var Bc;(e=>{function n(t){return r(t)}e.defaultData=n;function r(t){if(t==="PointLight")return{type:t,color:Me.white,intensity:1,distance:2e3,decay:1,shadows:!0,shadowResolution:1024,shadowRadius:1,penumbraSize:.5,depth:1e5};if(t==="SpotLight")return{type:t,color:Me.white,intensity:1,distance:2e3,decay:1,shadows:!0,penumbra:0,angle:30/180*Math.PI,depth:1e5,penumbraSize:.5,shadowResolution:1024,shadowRadius:1};if(t==="DirectionalLight")return{type:t,color:Me.white,intensity:1,shadows:!0,size:2e3,depth:1e5,penumbraSize:.5,shadowResolution:1024,shadowRadius:1};throw new Error("not implemented")}})(Bc||(Bc={}));var Qi;(t=>(t.defaultShapeData={type:"PlaneEmitterShape",size:[100,100,100]},t.defaultCollisionData={colliderEntityId:null,collisionBounce:.75},t.defaultData={renderMaterial:{type:"particleMaterial",color:{r:1,g:.2,b:.545,a:1},color2:{r:.945,g:.714,b:.184,a:1},coloring:"gradient",ease:"linearFadeOut",easeSize:"linearFadeOut",transparent:!0,size:[40,40],texture:"pt_default_particle",spriteRotation:[0,0]},birthRatePerSec:50,gravity:1,noiseStrength:0,noiseScale:0,noiseSeed:1,noiseType:"curl",randomRotation:0,randomScale:.2,randomMass:.5,rootObjectType:"instancedMesh",life:1,direction:[0,0,0],directionMode:"axis",speed:10,shape:t.defaultShapeData,autoPlay:!0,emitTimeDelay:0,emitTimeCycle:"infinity",emitTimeDuration:1,...t.defaultCollisionData}))(Qi||(Qi={}));var pn;(r=>r.defaultData={enabled:"visibility",fusedBody:!0,rigidBody:"positioned",density:1,pointMass:0,gravityScale:1,friction:.5,damping:0,restitution:.2,colliderType:"convex",enabledRotation:[!0,!0,!0],enabledTranslation:[!0,!0,!0]})(pn||(pn={}));var mp;(e=>{e.defaultData={castShadow:!0,receiveShadow:!0};function r(t,o){return t.castShadow===o.castShadow&&t.receiveShadow===o.receiveShadow}e.equals=r})(mp||(mp={}));var yp;(e=>{e.defaultData={flatShading:!1,wireframe:!1,side:0};function r(t,o){return t.flatShading===o.flatShading&&t.side===o.side&&t.wireframe===o.wireframe}e.equals=r})(yp||(yp={}));var Rc;(r=>r.defaultData={...yp.defaultData,...mp.defaultData})(Rc||(Rc={}));var sx;(r=>{function n(e,t){let o=[];if("material"in e){let i=typeof e.material=="string"?t.materials[e.material]??t.lib.materials[e.material]?.asset:e.material;i&&o.push(i)}else if("materials"in e)for(let i of e.materials){let a=typeof i=="string"?t.materials[i]??t.lib.materials[i]?.asset:i;a&&o.push(a)}return o}r.getMaterialData=n})(sx||(sx={}));var Zi;(e=>(e.defaultVideo={data:"",thumb:"/_assets/_videos/catThumb.png",type:"video",name:"Cat video"},e.maxSize=3e7))(Zi||(Zi={}));var lx;(r=>{function n(e){return e==="texture"||e==="video"||e==="color"||e==="depth"||e==="normal"||e==="gradient"||e==="noise"||e==="fresnel"||e==="rainbow"||e==="toon"||e==="outline"||e==="particle"||e==="transmission"||e==="matcap"||e==="displace"||e==="pattern"||e==="light"}r.is=n})(lx||(lx={}));function ux(n){return n.type!=="displace"}var cx;(r=>{function n(e){return e==="phong"||e==="toon"||e==="lambert"||e==="physical"}r.is=n})(cx||(cx={}));var dx=["mode","gradientType","noiseType","displacementType","projection","cnormal","crop","axis","side"],px=["wrapping","image","video","name","minFilter","magFilter"],xt;(o=>{function n(i,a){let{texture:s,...l}=a;if(Object.assign(i,l),s){let c=i.texture;c&&Object.assign(c,s)}}o.patch=n;function r(i,a){return i==="light"&&a?e(a):t(i)}o.defaultData=r;function e(i){let a={mode:0,isMask:!1,visible:!0,bumpMap:void 0,bumpMapIntensity:5,roughnessMap:void 0,alphaOverride:1};switch(i){case"phong":return{...a,category:"phong",specular:{r:.2,g:.2,b:.2},shininess:5,type:"light",visible:!0,mode:0,occlusion:!0,alpha:.6};case"toon":return{...a,category:"toon",specular:{r:.2,g:.2,b:.2},shininess:10,type:"light",alpha:1};case"lambert":return{...a,category:"lambert",emissive:{r:0,g:0,b:0},type:"light",alpha:1,visible:!0,mode:0,occlusion:!0};case"physical":return{...a,category:"physical",roughness:.2,metalness:.2,reflectivity:.2,type:"light",alpha:1,visible:!0,mode:0,occlusion:!0}}}function t(i){let a={alpha:1,mode:0,isMask:!1,visible:!0};switch(i){case"texture":return{...a,type:"texture",size:[128,128],blending:0,axis:"x",side:2,projection:0,texture:{image:"image_0",wrapping:1e3,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006},crop:!1};case"video":return{...a,type:"video",size:[128,128],blending:0,axis:"x",side:2,projection:0,texture:{video:Zi.defaultVideo,wrapping:1001,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006},crop:!1};case"color":return{...a,type:"color",color:wt.fromHex(mt)};case"depth":return{...a,type:"depth",gradientType:1,smooth:!1,isVector:!0,isWorldSpace:!1,origin:[0,0,0],direction:[1,0,0],colors:[[1,1,1,1],[0,0,0,1]],steps:[0,1],near:50,far:200};case"normal":return{...a,type:"normal",cnormal:[1,1,1]};case"gradient":return{...a,type:"gradient",gradientType:0,smooth:!1,colors:[[0,0,0,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],steps:[0,1,1,1,1,1,1,1,1,1],num:2,angle:0,offset:[0,0],morph:[0,0]};case"noise":return{...a,type:"noise",size:[100,100,100],noiseType:0,scale:1,move:1,colorA:{...wt.fromHex(6710886),a:1},colorB:{...wt.fromHex(6710886),a:1},colorC:{...wt.fromHex(16777215),a:1},colorD:{...wt.fromHex(16777215),a:1},distortion:[1,1],fA:[1.7,9.2],fB:[8.3,2.8],voronoiStyle:0,highCut:1,lowCut:0,smoothness:.3,seed:0,quality:1};case"fresnel":return{...a,type:"fresnel",color:Me.fromHexAndA(16777215,1),bias:.1,scale:1,intensity:2,factor:1};case"rainbow":return{...a,type:"rainbow",filmThickness:30,movement:0,wavelengths:[0,0,0],noiseStrength:0,noiseScale:1,offset:[0,0,0]};case"toon":return{...a,type:"toon",positioning:2,colors:[[0,0,0,1],[.5,.5,.5,1],[.5,.5,.5,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],steps:[0,.475,.525,1,1,1,1,1,1,1],num:4,source:[0,1e3,0],isWorldSpace:!0,noiseStrength:0,noiseScale:1,shadowColor:Me.fromHexAndA(0,0),offset:[0,0,0]};case"outline":return{...a,type:"outline",outlineColor:Me.fromHexAndA(0,1),contourColor:Me.fromHexAndA(0,1),outlineWidth:2,contourWidth:5,outlineThreshold:.4,contourThreshold:0,outlineSmoothing:0,contourFrequency:10,contourDirection:[0,1,0],positionalLines:!1,compensation:!0};case"matcap":return{...a,type:"matcap",texture:{image:"matcap_0",wrapping:1001,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006}};case"transmission":return{...a,type:"transmission",thickness:10,ior:1.5,roughness:1};case"displace":return{visible:!0,type:"displace",displacementType:"noise",noiseType:0,scale:10,movement:1,offset:[0,0,0],intensity:8,voronoiStyle:0,smoothness:.3,seed:0,highCut:1,lowCut:0,quality:1};case"pattern":return{...a,type:"pattern",style:0,projection:0,axis:"y",blending:0,offset:[0,0],colorA:{...wt.fromHex(0),a:1},colorB:{...wt.fromHex(16777215),a:1},frequency:[10,10],size:.5,variation:0,smoothness:.5,zigzag:0,rotation:0,vertical:[0,1],horizontal:[0,1],sides:6}}}})(xt||(xt={}));var Et;(c=>{function n(u){return!u.layers.some(d=>d.data.type==="texture"&&d.data.projection!==0||d.data.type==="depth"&&!d.data.isWorldSpace||d.data.type==="noise"||d.data.type==="displace")}c.isMergable=n;function r(u){let p="";return u.layers.forEach(d=>{Object.entries(d.data).forEach(([h,f])=>{p+=`${h}${f}`,Array.isArray(f)?f.forEach(m=>p+=`${m}`):typeof f=="object"?Object.values(f).forEach(m=>{typeof m=="number"?p+=`${m.toFixed(4)}`:p+=`${m}`}):p+=`${f}`})}),p}c.getHash=r;function e(){return{layers:new be}}c.defaultEmptyData=e;function t(u="layer1",p="layer2"){return i("phong",u,p)}c.defaultData=t;function o(u,p){return{...u,name:p}}c.withName=o;function i(u,p="layer1",d="layer2"){let h=new be;return h.push({fi:0,data:xt.defaultData("light",u),id:p}),h.push({fi:1,data:xt.defaultData("color"),id:d}),{layers:h}}c.defaultTwoLayerData=i;function a(u){let p=xt.defaultData("texture");u&&Object.assign(p.texture,{image:u});let d=new be;return d.push({fi:0,data:p,id:"layer1"}),d.push({fi:1,data:{...xt.defaultData("transmission"),alpha:1},id:"layer2"}),d.push({fi:2,data:{...xt.defaultData("light","lambert"),alpha:0},id:"layer3"}),{layers:d}}c.defaultUIObjectMaterial=a;function s(u,p="phong",d="layer1",h="layer2"){let f=xt.defaultData("texture");Object.assign(f.texture,{image:u});let m=new be;return m.push({fi:0,data:f,id:d}),m.push({fi:1,data:xt.defaultData("light",p),id:h}),{layers:m}}c.defaultTwoLayerTextureData=s;function l(u,p="phong",d="layer1",h="layer2"){let f=xt.defaultData("video");Object.assign(f.texture,{video:u});let m=new be;return m.push({fi:0,data:f,id:d}),m.push({fi:1,data:xt.defaultData("light",p),id:h}),{layers:m}}c.defaultTwoLayerVideoTextureData=l})(Et||(Et={}));var Ji;(r=>{function n(){return{points:new be,roundness:0,shapeHoles:[],isClosed:!1}}r.defaultData=n})(Ji||(Ji={}));var ea;(r=>{function n(){return{points:new be,lastInsertionPlane:null,subdivisions:12,isClosed:!1}}r.defaultData=n})(ea||(ea={}));var gp={type:"Ellipse",width:50,height:50,spikes:16,angle:360,innerRadius:0};var Lc;(r=>{function n(e,t){let o={...e};return _T.forEach(i=>{Object.assign(o,{[i]:t[i]??e[i]})}),o}r.merge=n})(Lc||(Lc={}));var Vc={shape:gp,depth:1,offset:0,bevel:50,bevelSides:6,angle:0,twist:0,startScale:1,endScale:1,capType:"flat"},_T=["depth","offset","angle","twist","startScale","endScale"];var Ds;(e=>{function n(t){return t==="PolygonGeometry"||t==="RectangleGeometry"||t==="StarGeometry"||t==="TriangleGeometry"||t==="EllipseGeometry"||t==="UIGeometry"}e.is2DParametricMesh=n;function r(t){return t==="PolygonGeometry"||t==="PolygonGeometry"||t==="RectangleGeometry"||t==="StarGeometry"||t==="TriangleGeometry"||t==="EllipseGeometry"||t==="PathGeometry"||t==="VectorGeometry"||t==="ConeGeometry"||t==="CubeGeometry"||t==="CylinderGeometry"||t==="DodecahedronGeometry"||t==="HelixGeometry"||t==="IcosahedronGeometry"||t==="LatheGeometry"||t==="PyramidGeometry"||t==="SphereGeometry"||t==="PlaneGeometry"||t==="BackdropGeometry"||t==="TorusGeometry"||t==="TorusKnotGeometry"||t==="BooleanGeometry"||t==="TextGeometry"||t==="InputGeometry"}e.isParametricMesh=r})(Ds||(Ds={}));var zc;(r=>{function n(e,t){let o={...e};return Object.assign(o,t),o.type==="PathGeometry"&&"extrusion"in t&&t.extrusion&&(o.extrusion={...e.extrusion},Object.assign(o.extrusion,Lc.merge(o.extrusion,t.extrusion))),o}r.merge=n})(zc||(zc={}));var Ao;(r=>{function n(e){if(e==="RectangleGeometry")return{width:320,height:320,type:e,cornerRadius:[0,0,0,0],cornerType:0,depth:0,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="UIGeometry")return{type:e,frame:"",cornerRadius:[0,0,0,0],cornerType:0,width:1,height:1};if(e==="PathGeometry")return{type:e,width:1,height:1,depth:1,path:ea.defaultData(),extrusion:Vc};if(e==="VectorGeometry")return{width:1,height:1,type:e,subdivisions:12,shape:Ji.defaultData(),depth:0,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="BooleanGeometry")return{type:e,operation:2,width:0,height:0,depth:0,phongAngle:35};if(e==="TextGeometry")return{type:e,width:100,height:100,depth:0,horizontalAlign:1,verticalAlign:1,fontSize:16,lineHeight:1.2,letterSpacing:0,text:{textValue:""},textTransform:1,font:"Roboto_regular",editable:!1,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="InputGeometry")return{...r.defaultData("TextGeometry"),type:e,editable:!0};if(e==="SphereGeometry")return{type:"SphereGeometry",width:100,height:100,depth:100,widthSegments:64,heightSegments:64,phiStart:0,phiLength:2*Math.PI,thetaStart:0,thetaLength:180};throw new Error("not implemented")}r.defaultData=n})(Ao||(Ao={}));var Gc;(r=>r.defaultData={enabled:!1,useBackgroundColor:!1,color:wt.white,near:.1,far:2e3})(Gc||(Gc={}));var Fc;(e=>{let n={opacity:1,blendFunction:13,enabled:!1};e.defaultData={enabled:!1,pixelation:{...n,blendFunction:16,granularity:15},bloom:{...n,blendFunction:16,intensity:1,blurScale:1,luminanceThreshold:.25,luminanceSmoothing:.025,kernelSize:3},chromaticAberration:{...n,offset:[2,2]},vignette:{...n,darkness:1,offset:0},hueSaturation:{...n,hue:3,saturation:0},brightnessContrast:{...n,brightness:.25,contrast:0},depthOfField:{...n,focusDistance:100,focalLength:20,bokehScale:5},noise:{...n,blendFunction:16}}})(Fc||(Fc={}));var xp;(r=>r.defaultData={softShadowQuality:"low"})(xp||(xp={}));var bp;(r=>r.defaultData={enabled:!0,color:{r:.8274509803921568,g:.8274509803921568,b:.8274509803921568},intensity:.75})(bp||(bp={}));var vp;(r=>r.defaultData={occlusion:!1,aoFullRes:!1,radius:256,bias:.5,aoColor:{r:.19607843137254902,g:.19607843137254902,b:.19607843137254902}})(vp||(vp={}));var _s;(r=>r.defaultData={usePhysics:!1,gravity:-10})(_s||(_s={}));var Sp;(r=>r.defaultData={playCamera:cn,gameControlObject:null})(Sp||(Sp={}));var jc;(r=>r.defaultData={backgroundColor:Me.fromHexAndA(ax,1),postprocessing:Fc.defaultData,fog:Gc.defaultData,globalPhysics:_s.defaultData,ambient:bp.defaultData,ao:vp.defaultData,shadow:xp.defaultData,publish:Sp.defaultData})(jc||(jc={}));var kc;(r=>r.defaultData={colliderType:"box",size:[100,100,100],colliderHelperVisible:!0,forceType:"collider",forceRange:"global",forceIntensity:.5,forceDambing:.95})(kc||(kc={}));var fx;(e=>{function n(t){return t==="Component"||t==="Instance"}e.isComponentRelated=n;function r(t){return t==="Empty"||t==="Instance"}e.isEmptyOrComponent=r})(fx||(fx={}));var ta;(o=>{o.identity={...Nc.identity,hiddenMatrix:ln.identity};function r(i){return{position:i.position,rotation:i.rotation,scale:i.scale,hiddenMatrix:i.hiddenMatrix}}o.fromObject=r;function e(i,a){return{position:a?.position||i.position,rotation:a?.rotation||i.rotation,scale:a?.scale||i.scale,hiddenMatrix:a?.hiddenMatrix||i.hiddenMatrix}}o.merge=e;function t(i,a){return Gl({position:sn.isEqual(i.position,a.position)?void 0:a.position,rotation:sn.isEqual(i.rotation,a.rotation)?void 0:a.rotation,scale:sn.isEqual(i.scale,a.scale)?null:a.scale,hiddenMatrix:ln.isEqual(i.hiddenMatrix,a.hiddenMatrix)?void 0:a.hiddenMatrix})}o.diff=t})(ta||(ta={}));var bt;(r=>r.defaultData={states:new be,events:new be,visible:!0,raycastLock:!1,physics:pn.defaultData,pathSnapping:{pathId:null,slide:0,offset:0,orientation:"tangential"},...ta.identity,cloner:null})(bt||(bt={}));var Uc;(r=>r.defaultData={type:"Empty",...bt.defaultData})(Uc||(Uc={}));var hx;(r=>r.defaultData={type:"ParticleCollider",...kc.defaultData,...bt.defaultData})(hx||(hx={}));var mx;(r=>r.defaultData={type:"Component",...bt.defaultData})(mx||(mx={}));var yx;(r=>r.defaultData={type:"Particle",...bt.defaultData,...Qi.defaultData})(yx||(yx={}));var fn;(r=>r.defaultData={type:"Mesh",...bt.defaultData,...Rc.defaultData})(fn||(fn={}));var $n;(r=>r.defaultData={...bt.defaultData,...ta.identity,position:[0,0,dn.DefaultTargetOffset],...dn.defaultData})($n||($n={}));var Hc;(e=>{function n(t){return{...bt.defaultData,...Bc.defaultData(t)}}e.defaultData=n,e.defaultDirectionalLightData={...e.defaultData("DirectionalLight"),position:[200,300,300],name:"Directional Light",intensity:.7}})(Hc||(Hc={}));var ra;(e=>{function n(t,o,i=0){for(;i<o.length;){let a=t?t[o[i]]:void 0;if(o.length===i+1)return a;if(a)t=a.descendants,i+=1;else return}}e.resolveWithDes=n;function r(t,o,i=0){let a=n(t,o,i);if(a){let s=Object.keys(a);if(s.length===1&&s[0]==="descendants")return}return a}e.resolve=r})(ra||(ra={}));var ro;(i=>{i.rootOverrideProps=["physics","events"],i.compositeNonOptionalOverrideProps=["geometry"],i.compositeEntireOverrideOverrideProps=["material"];function t(a,s){return{...bt.defaultData,...s,component:a,overrides:new Qe,physics:void 0,events:void 0,type:"Instance"}}i.ofComponent=t;function o(a){let s=ta.fromObject(a.data);return t(a.id,s)}i.fromComponentData=o})(ro||(ro={}));var To;(e=>{e.defaultData={type:"Page",...bt.defaultData,physics:{...pn.defaultData,fusedBody:!1},...jc.defaultData,camera:$n.defaultData};function r(t){return t.uiScene!==void 0}e.isUIPage=r})(To||(To={}));var Wc;(a=>(a.defaultCamera={position:[0,0,1e3],scale:[1,1,1],rotation:[0,0,0],hiddenMatrix:ln.identity,name:"Play Camera",visible:!0,raycastLock:!1,physics:pn.defaultData,states:new be,events:new be,cloner:null,pathSnapping:{pathId:null,orientation:"tangential",slide:0,offset:0},...dn.defaultData},a.KeysByResetCategory={States:["states"],Events:["events"],Material:["material","materials"],Geometry:["geometry"],Position:["position"],Rotation:["rotation"],Scale:["scale"],Transform:["position","scale","rotation","hiddenMatrix"],Name:["name"],Visibility:["visible","raycastLock","flatShading","wireframe","side"],Shadows:["castShadow","receiveShadow"],Cloner:["cloner"],Physics:["physics"]},a.defaultMeshObject={name:"Rectangle",...bt.defaultData,...fn.defaultData,geometry:Ao.defaultData("RectangleGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultBooleanObject={name:"Boolean",...bt.defaultData,...fn.defaultData,geometry:Ao.defaultData("BooleanGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultTextObject={name:"Text",...bt.defaultData,...fn.defaultData,geometry:Ao.defaultData("TextGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultInputObject={name:"Input",...bt.defaultData,...fn.defaultData,geometry:Ao.defaultData("InputGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")}))(Wc||(Wc={}));var Yn;(o=>{function n(i,a){let s={name:a};return i.type==="Mesh"?(s.geometry={},"material"in i&&(s.material={layers:new Qe}),"materials"in i&&(s.materials=i.materials.map(l=>({layers:new Qe})))):Nr.is(i.type)&&(s.perspective={},s.orthographic={}),s}o.newEmpty=n;function r(i,a){if(a===void 0)return i;let s={...i};return"material"in s&&"material"in a&&a.material&&(s.material=rn(s.material,l=>{if(typeof l!="string")for(let[c,u]of Object.entries(a.material.layers)){let p=l.layers.data(c);p&&xt.patch(p,u)}}).data),s.materials&&a.materials&&(s.materials=rn(s.materials,l=>{for(let c=0;c<s.materials.length;c++){let u=a.materials[c];if(typeof u!="string")for(let[p,d]of Object.entries(u.layers)){let h=l[c]?.layers?.data(p);h&&xt.patch(h,d)}}}).data),s}function e(i,a){let s,l=[],c={orthographic:0,perspective:0,geometry:0};function u(p,d){for(let[h,f]of Object.entries(d.layers)){let{texture:m,...y}=f;if(m!==void 0&&Object.keys(m).length>0){let g={path:[...p,"layers",h,"texture"],props:m,type:0};l.push(g)}if(Object.keys(y).length>0){let g={path:[...p,"layers",h],props:y,type:0};l.push(g)}}}for(let[p,d]of Object.entries(a))if(p!=="name")if(p==="cloner")l.push(...Dc.toOps(d,["cloner"]));else if(p==="pathSnapping")l.push({path:[p],props:{slide:d.slide,offset:d.offset},type:0});else if(p==="material")u(["material"],d);else if(p==="materials")for(let[h,f]of Object.entries(d))u(["materials",h],f);else if(c[p]===0){if(p==="geometry"&&d.extrusion!==void 0){let h={path:[p,"extrusion"],props:d.extrusion,type:0};l.push(h),d={...d},delete d.extrusion}if(Object.keys(d).length>0){let h={path:[p],props:d,type:0};l.push(h)}}else s===void 0&&(s={path:[],props:{},type:0},l.push(s)),s.props[p]=d;return l}o.toOps=e;function t(i,a){if(a===void 0)return i;let s={...i};if(Object.assign(s,ta.merge(s,a)),Object.assign(s,{pathSnapping:Object.assign({},s.pathSnapping,{slide:a.pathSnapping?.slide??s.pathSnapping?.slide??0,offset:a.pathSnapping?.offset??s.pathSnapping?.offset??0})}),Nr.is(i.type)){s.orthographic={...s.orthographic},s.perspective={...s.perspective};let l=a;l.orthographic?.zoom!==void 0&&(s.orthographic.zoom=l.orthographic.zoom),l.perspective?.zoom!==void 0&&(s.perspective.zoom=l.perspective.zoom),l.isUpVectorFlipped!==void 0&&(s.isUpVectorFlipped=l.isUpVectorFlipped),l.targetOffset!==void 0&&(s.targetOffset=l.targetOffset)}else if(i.type==="Mesh")"geometry"in a&&Object.assign(s,{geometry:zc.merge(s.geometry,a.geometry)}),(a.material||a.materials)&&(s=r(s,a)),s.cloner&&"cloner"in a&&Object.assign(s,{cloner:to.merge(s.cloner,a.cloner)});else if(i.type==="Empty")s.cloner&&"cloner"in a&&Object.assign(s,{cloner:to.merge(s.cloner,a.cloner)});else if(_c.is(i.type)){let l=a;l.intensity!==void 0&&(s.intensity=l.intensity),l.color!==void 0&&(typeof l.color=="string"?s.color=l.color:s.color=wt.clone(l.color))}return s}o.patch=t})(Yn||(Yn={}));var oa;(r=>r.defaultData={enablePan:!0,enableZoom:!0,enableRotate:!0,enableDamping:!0,rotationLimitsMode:0,rotationVerticalOffset:{min:Math.PI/4,max:Math.PI/4},rotationHorizontalOffset:{min:Math.PI/4,max:Math.PI/4},rotationSoftLimit:2,panLimitsMode:0,panVerticalOffset:{min:250,max:250},panHorizontalOffset:{min:250,max:250},panSoftLimit:2,zoomLimitsEnabled:!1,zoomLimits:{min:.1,max:2},autoRotate:!1,autoRotateSpeed:2,autoRotateClockwise:!0,hoverRotatePanMode:0,hoverRotatePanStrength:20,hoverRotateDamping:.125,isTouchZoom:!0,orbitTouches:2,panTouches:3,resetHoverEffectOnPointerLeave:!0})(oa||(oa={}));var Dr;(r=>r.defaultData={orbitControls:oa.defaultData,playPage:un,withBackground:!0,preventScroll:!1,preventTouchScroll:!1,hideCursor:!1,mouseEventTarget:"canvas",joystickSizeAndXYOffset:Array(12).fill(0).map((e,t)=>{let o=0,i=0;return t<5?i=-30:t<10&&(i=30),t===0||t===10||t===5?o=30:(t===4||t===11||t===9)&&(o=-30),[120,[o,i],"show"]}),settings:{image:{format:"jpg",ratio:1},video:{format:"mp4",imageFormat:"jpg",fps:30,mbps:80,ratio:Math.max(1,typeof window<"u"?Math.floor(window.devicePixelRatio):1),stopMode:"manual",duration:5e3},web:{logo:!0,compress:!0,preset:1,preload:!0,hint:!1,imageQuality:70}},stopRaycast:!0,hdTransmission:!1})(Dr||(Dr={}));var wp;(r=>r.defaultData={id:"basic",label:"Basic",style:"None",prompt:""})(wp||(wp={}));var Pp;(r=>r.defaultData={weather:0,shadows:0,lightOrigin:0,temperature:0,sun:0,camera:0,environment:0,particles:0,nature:0,floor:0})(Pp||(Pp={}));var Io;(e=>(e.defaultData=()=>({mode:"line-art-both",prompt:"",negativePrompt:"",style:{...wp.defaultData},isRandomSeed:!0,seed:e.generateSeed(),guessMode:!1,advanced:!1,steps:20,guidanceScale:7.5,controlNetScale:1,modifiers:Pp.defaultData}),e.generateSeed=()=>Math.round(Math.random()*1e5)))(Io||(Io={}));var gx;(e=>{function n(t){return t.find(o=>o.data.type==="Page"&&o.data.globalPhysics.usePhysics)!==void 0}e.physicsEnabled=n;function r(t,o,i){t.scene.objects.traverseFrom(o,(a,s)=>{if(s.type==="Instance"){let l=na.getComponentData(t,s.component)?.data;l&&i(a,s,l.events)}else i(a,s,s.events)})}e.traverseModuleInstances=r})(gx||(gx={}));var Mo;(c=>{c.TRASH_CAN_ID="830a2708-8ed9-49cf-a68e-085299892222",c.defaultLight={fi:-1,data:Hc.defaultDirectionalLightData,id:"830a2708-8ed9-49cf-a68e-085299899103",children:[]};function e(u=!0,p=[]){let d=[],h=Wc.defaultMeshObject;u&&(d.push({...c.defaultLight}),d.push({fi:1,id:"7ba78968-2a55-48f2-b14c-5191da3e075e",data:h,children:[]})),d.push(...p);let f=new Ke;return f.push({fi:1,id:un,data:{...To.defaultData,name:"Scene 1"},children:d}),f}c.createDefaultObjectTreeWithPage=e,c.defaultData={objects:e(),publish:Dr.defaultData,styles:Io.defaultData()},c.emptyDataWithoutPage=function(){return{objects:new Ke,publish:Dr.defaultData,styles:Io.defaultData()}},c.emptyDataWithPage=function(u=!0){return{objects:e(u),publish:Dr.defaultData,styles:Io.defaultData()}},c.emptyData=function(){return{objects:new Ke,publish:{...Dr.defaultData},styles:Io.defaultData()}};function s(u){return{...c.defaultData,objects:Lt(u,Ke.prototype)}}c.withObjs=s;function l(u,p){return s([{id:u,data:p,children:[],fi:0}])}c.withObj=l})(Mo||(Mo={}));var ia;(r=>r.defaultData={preset:"fullscreen",allowResponsive:!1,size:[512,512],coords:[0,0],sceneScale:1,color:{r:0,g:0,b:0,a:.5}})(ia||(ia={}));var qc;(e=>(e.defaultData=t=>({url:t,name:"New Webhook",parametersSchemas:new be}),e.defaultParameterValueByType=t=>t==="number"?0:t==="boolean"?!1:""))(qc||(qc={}));var xx;(r=>r.defaultData=(e,t="GET")=>({url:e,method:t,name:"New API",headers:new be,queries:new be,autoStart:!0}))(xx||(xx={}));var hn;(i=>{function n(a){return a.textValue!==void 0}i.isTextValue=n;function r(a){return typeof a=="number"}i.isNumber=r;function e(a){return typeof a=="boolean"}i.isBoolean=e;function t(a){return n(a)?"string":e(a)?"boolean":"number"}i.typeOfVariable=t;function o(a){return i.isTextValue(a)?Array.isArray(a.textValue)?a.textValue.map(s=>s.toString().padStart(a.padding??2,"0")).join(a.deliminator??":")+(a.suffix!==void 0?" "+a.suffix:""):a.textValue.toString():i.isBoolean(a)?a?"True":"False":i.isNumber(a)?parseFloat(a.toFixed(3)).toString():a.toString()}i.getDisplayedValue=o})(hn||(hn={}));var Cp;(r=>r.all=["images","videos","colors","audios","particles","fonts","materials","variables"])(Cp||(Cp={}));var bx;(r=>r.all=[...Cp.all,"components"])(bx||(bx={}));var vx;(r=>{function n(){return{images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,materials:new fe,components:new fe,variables:new fe,userAPIs:new fe,userWebhooks:new fe}}r.defaultData=n})(vx||(vx={}));var _r;(r=>{function n(){return{images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,materials:new fe,components:new fe,variables:new fe,userAPIs:new fe,userWebhooks:new fe}}r.defaultData=n})(_r||(_r={}));var xr;(i=>{function n(){let a={};return a["89b10010-844c-11ec-a8a3-0242ac120002"]={r:.5,g:.5,b:.5,a:1,name:"Default Color"},Lt(a,fe.prototype)}i.defaultColors=n;function r(){return Lt({},fe.prototype)}i.defaultImages=r;function e(){return{catelogs:new fe,materials:new fe,images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,variables:new be,userAPIs:new fe,userWebhooks:new fe,lib:_r.defaultData()}}i.emptyData=e;function t(a){switch(a){case"number":return{value:0,name:"Number"};case"boolean":return{value:!1,name:"Boolean"};case"string":return{value:{textValue:"String value"},name:"String"};case"time":let s=[0,0,0];return{name:"Time",value:{textValue:s,deliminator:":",padding:2,suffix:"AM"},dynamicVariableType:"time",format:"HH:mm:ss",format12h24h:"12ampm",timeZone:null,hasEnd:!1,endValue:{textValue:s,deliminator:":",padding:2,suffix:"AM"},autoStart:!0,repeat:!1};case"counter":return{name:"Counter",value:0,dynamicVariableType:"counter",updateInterval:1e3,increment:1,autoStart:!0,hasEnd:!0,endValue:60,repeat:!0,randomStart:!1,range:[0,100],decimals:0};case"random":return{name:"Random",value:0,dynamicVariableType:"random",updateInterval:1e3,increment:1,autoStart:!0,isStatic:!1,hasEnd:!0,endValue:60,repeat:!0,min:0,max:100,decimals:0};default:console.error("Unknown variable type",a)}}i.defaultVariables=t;function o(a,s){if(s.format==="HH:mm:ss"){let l=Math.floor(a/3600),c=Math.floor((a-l*3600)/60),u=Math.round(a-l*3600-c*60);return{textValue:[l,c,u]}}else if(s.format==="mm:ss"){let l=Math.floor(a/60),c=Math.round(a-l*60);return{textValue:[l,c]}}else return s.format==="number"?a=Math.round(a):a=Math.round(a*1e3)/1e3,a}i.getFormattedTimerTime=o})(xr||(xr={}));import{MathUtils as Xc}from"three";var $c;(r=>r.list=["idle","move","jump","run"])($c||($c={}));var Yc;(e=>(e.defaultColliderData={type:"capsule",height:200,radius:50,position:[0,0,0],rotation:[0,0,0]},e.defaultDataThirdPerson={moveMode:"walk",forwardDirection:"+z",speedTranslate:1e3,speedRotate:100,runMultiplier:2,rotationMode:"normal",rotBy:"keys",rotByTouch:"drag",delayPos:[.3,.3],delayRot:[.3,.3],keyAssignments:[["moveNegZ","W"],["moveNegX","A"],["movePosZ","S"],["movePosX","D"],["rotPosX","\u25B2"],["rotPosY","\u25C0"],["rotNegX","\u25BC"],["rotNegY","\u25B6"],["jump","Space"],["run","\u21E7"],["none","Ctrl"]],touchControl:!0,joystickPosLoc:5,joystickRotLoc:11,jumpTouchButtonLoc:9,collider:e.defaultColliderData,colliderHelperVisible:!0,collisionEnabled:!0,jumpPower:100,resetYPosition:3e3,alignToGround:!1,autoOrientMove:!0,orientWith:"camera",orientMode:"radial",delayPosCamera:.3,delayRotCamera:.3,camera:"",cameraXAxis:"Limit",cameraYAxis:"Free",cameraRotXLimits:[0,Math.PI/2],cameraRotYLimits:[-Math.PI/2,Math.PI/2],gameActions:{idle:new be,move:new be,jump:new be,run:new be},navmesh:{enabled:!1,ch:6,cs:6,walkableClimb:5,walkableHeight:1,walkableRadius:0,zones:"all",objects:[],helperVisible:!0,destinationHelperRadius:0,destinationHelperColor:Me.fromHexAndA(3728051,1)}}))(Yc||(Yc={}));function Sx(n){n.layers.forEach(r=>{if(r.type==="depth"&&r.colorA!==void 0){let e=r.colorA,t=r.colorB,o=[[e.r,e.g,e.b,e.a],[t.r,t.g,t.b,t.a]],i=[0,1];for(let s=2;s<10;s++)o.push(o[1]),i.push(1);let a={...Er(it(r),"type","visible","isVector","isWorldSpace","origin","alpha","mode"),near:Math.max(0,r.near),far:Math.max(0,r.far),colors:o,steps:i,num:2,direction:[1,0,0],smooth:!1,gradientType:1};Object.assign(r,a)}else if(r.type==="depth"&&r.gradientType===1&&(r.near<0||r.far<0)){let e={...it(r),near:Math.max(r.near,0),far:Math.max(r.far,0)};Object.assign(r,e)}})}function Eo(n,r){Object.values(n.shared.materials).forEach(e=>r(e))}function No(n,r){n.scene.objects.traverse((e,t)=>{"materials"in t?t.materials.forEach((o,i)=>{o===void 0&&(t.materials[i]=Et.defaultData(),o=t.materials[i]),typeof o!="string"&&r(o)}):"material"in t?typeof t.material!="string"&&(t.material===void 0&&(t.material=Et.defaultData()),r(t.material)):t.type==="Mesh"&&(t.material===void 0&&(t.material=Et.defaultData()),r(t.material)),"overrides"in t&&Object.values(t.overrides).forEach(o=>{o.material&&typeof o.material!="string"&&Object.getPrototypeOf(o.material)!==Qe.prototype&&r(o.material)})})}function BT(n){Object.assign(n.scene.publish,{orbitControls:{...oa.defaultData,...it(n.scene.publish.orbitControls)}})}function RT(n){Object.assign(n.scene.publish.settings,{video:{...Dr.defaultData.settings.video,...it(n.scene.publish.settings.video)}})}function LT(n){function r(e){if(e.layers){for(let t of Object.values(e.layers))if(t){for(let[o,i]of Object.entries(t))if((dx.includes(o)||typeof i=="boolean")&&delete t[o],o==="texture")for(let[a,s]of Object.entries(i))(px.includes(a)||typeof s=="boolean")&&delete i[a]}}}n.scene.objects.traverse((e,t)=>{t.states.forEach(o=>{let i=o;i.material?r(i.material):i.materials&&i.materials.forEach(a=>{r(a)})})})}function VT(n){n.scene.publish.withBackground=!0}function zT(n){n.scene.publish.settings.web={compress:!0,preload:!0,preset:1,logo:!0,hint:!1}}function GT(n){n.scene.objects.traverse((r,e)=>{let t=e.cloner;t&&(t.radial.scale=t.radial.scale.map(o=>o+1),t.linear.scale=t.linear.scale.map(o=>o+1))})}function FT(n){n.scene.objects.traverse((r,e)=>{let t=e.geometry;t&&(t.type==="DodecahedronGeometry"||t.type==="IcosahedronGeometry")&&(t.detail=Math.round(t.detail))})}function jT(n){n.scene.objects.traverse((r,e)=>{let t=n.scene.objects.unproxy().parent(r);if(t){let o=it(n.scene.objects.data(t));o&&o.type==="Mesh"&&o.geometry.type==="BooleanGeometry"&&e.type==="Mesh"&&(e.visible=it(e).booleanExclude!==!0)}})}function kT(n){n.scene.objects.traverse((r,e)=>{if(e.type==="Mesh"){let t=e;e.geometry.type==="NonParametricGeometry"?t.material!==void 0&&delete t.material:t.materials!==void 0&&delete t.materials}})}function UT(n){function r(t){Object.setPrototypeOf(t,Qe.prototype),t.texture&&Object.setPrototypeOf(t.texture,Qe.prototype)}function e(t){Object.setPrototypeOf(t,Qe.prototype);for(let o in t)r(t[o])}n.scene.objects.traverse((t,o)=>{o.states.forEach(i=>{let a=i;if(a.material){let s=it(a.material).layers;e(s),a.material.layers=s}if(a.materials)for(let s=0;s<a.materials.length;s++){let l=a.materials[s],c=it(l).layers;e(c),l.layers=c}})})}function wx(n){n.layers===void 0&&Object.assign(n,Et.defaultTwoLayerData("lambert"))}function Op(n){!n.layers||n.layers.forEach(r=>{if(r.type==="depth"&&r.colors.length===10){let e=[...r.colors];e.push(r.colors[9]);let t=[...r.steps];t.push(r.steps[9]);let o={...it(r),colors:e,steps:t};Object.assign(r,o)}})}function HT(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&(e.geometry.type==="BooleanGeometry"||e.geometry.type==="SubdivGeometry")&&(e.geometry.phongAngle=35)})}function Px(n){n.scene.objects.traverse((r,e)=>{"materials"in e?e.materials.forEach(t=>{typeof t!="string"&&Op(t)}):"material"in e&&typeof e.material!="string"&&Op(e.material)}),Object.values(n.shared.materials).forEach(r=>Op(r))}function WT(n){n.scene.environment.ambientLight.softShadows=!1,n.scene.environment.ambientLight.softShadowQuality="low",n.scene.objects.traverse((r,e)=>{(e.type==="DirectionalLight"||e.type==="SpotLight")&&(e.shadowResolution=1024,e.shadowRadius=1,e.depth=1e5)}),n.shared.penumbraSize=new Array(5).fill(.5)}function qT(n){n.shared.audios=Lt({},fe.prototype)}function $T(n){n.shared.videos=Lt({},fe.prototype)}function YT(n){let r=n.shared.materials;Object.entries(r).forEach(([e,t])=>{if(!t.layers){let o={name:"Untitled Material",layers:[{fi:0,data:{type:"light",category:"phong",alpha:.6,visible:!0,mode:0,specular:{r:.2,g:.2,b:.2},shininess:5},id:"layer1"},{fi:1,data:{type:"color",alpha:1,visible:!0,mode:0,color:{r:.2823529411764706,g:.2823529411764706,b:.30196078431372547}},id:"layer2"}]};Object.assign(r,{[e]:o})}})}function XT(n){Object.entries(it(n.shared.images)).filter(t=>t[1].asset===!1).map(t=>t[0]).forEach(t=>{delete n.shared.images[t]}),Object.entries(it(n.shared.audios)).filter(t=>t[1].asset===!1).map(t=>t[0]).forEach(t=>{delete n.shared.audios[t]})}function KT(n){n.scene.publish.settings.web.preload=!1}function Cx(n){n.layers&&n.layers.forEach(r=>{r.type==="depth"&&r.num!==void 0&&(r.colors=r.colors.slice(0,r.num),r.steps=r.steps.slice(0,r.num),delete r.num)})}function Ox(n){n.layers&&n.layers.forEach(r=>{ux(r)&&r.isMask===void 0&&(r.isMask=!1),(r.type==="texture"||r.type==="video")&&r.blending===void 0&&(r.blending=0),(r.type==="noise"||r.type==="displace"&&r.displacementType==="noise")&&(r.voronoiStyle===void 0&&(r.voronoiStyle=0),r.highCut===void 0&&(r.highCut=1),r.lowCut===void 0&&(r.lowCut=0),r.smoothness===void 0&&(r.smoothness=.3),r.seed===void 0&&(r.seed=0),r.quality===void 0&&(r.quality=1))})}function QT(n){n.shared.fonts=Lt({},fe.prototype)}function ZT(n){return n.replace(".typeface","").replace(/optimer/gi,"open sans").replace("space_mono","space mono").replace(/alma_mono/gi,"varela round").replace(/droid_sans_mono/gi,"noto sans mono").replace(/droid_sans|gentilis|gnomon_(simple|foreground)|helvetiker/gi,"roboto").replace(/droid_serif/gi,"roboto slab").replace("_sans"," sans").replace("crimson_text","crimson text").replace("medium_medium","medium").replace("fatface_fatface","fatface").replace("100hairline","thin").replace("200thin","extralight").replace("300light","light").replace("500medium","medium").replace("600semi","semibold").replace("800heavy","extrabold").replace("900black","black").replace(/bodoni_(11|16|24|36|48|72|96)([^_])/gi,"bodoni_$1_$2").replace(/bodoni_(11|16|24|36|48|72|96)/gi,"bodoni moda").replace(/(thin|hairline)(_regular)?/gi,"100").replace(/(extra|ultra)light(_regular)?/gi,"200").replace(/light(_regular)?/gi,"300").replace(/_book|_normal|_roman/gi,"_regular").replace(/medium(_regular)?/gi,"500").replace(/(semi|demi)bold(_regular)?/gi,"600").replace(/(extra|ultra)bold(_regular)?/gi,"800").replace(/bold(_regular)?/gi,"700").replace(/(black|heavy|fatface)(_regular)?/gi,"900").replace(/([1-9]00)_italic/gi,"$1italic").replace(/regularitalic/gi,"italic").replace(/regularitalic/gi,"italic").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function JT(n){let r=[];n.scene.objects.traverse((e,t)=>{let o=t;if(o.type==="TextFrame"){let i=Et.defaultTwoLayerData("phong"),a=typeof o.color=="string"?n.shared.colors[o.color]:o.color;i.layers[1].data.color={r:a.r,g:a.g,b:a.b},i.layers[1].data.alpha=o.alpha;let s=ZT(o.font);n.shared.fonts[s]===void 0&&(n.shared.fonts[s]={name:s});let l={name:o.name,...bt.defaultData,...fn.defaultData,flatShading:!1,wireframe:!1,geometry:{...Ao.defaultData("TextGeometry"),width:o.width,height:o.height,font:s,depth:0,horizontalAlign:o.horizontalAlign,verticalAlign:o.verticalAlign,fontSize:o.fontSize*1.40625,lineHeight:o.lineHeight/1.40625,letterSpacing:o.letterSpacing-1,text:o.text,textTransform:o.textTransform,extrudeBevelSize:0,extrudeBevelSegments:1},material:i,states:it(o.states),events:it(o.events),visible:o.visible,raycastLock:o.raycastLock,position:o.position,rotation:o.rotation,scale:o.scale,hiddenMatrix:o.hiddenMatrix},c=it(n.scene.objects).parent(e);n.scene.objects.insertAfter(c??null,e,[{id:e+"new",data:l,children:[]}]),r.push(e)}}),r.forEach(e=>{n.scene.objects.delete(e)})}function eI(n){let r={0:"MouseDown",1:"MouseUp",2:"MouseHover",5:"KeyDown",6:"KeyUp",7:"Start",9:"LookAt",10:"Follow",11:"Scroll",12:"Audio",13:"GameControl"};n.scene.objects.traverse((e,t)=>{t.events.forEach(o=>{if(!!r[Number(o.type)])if(Object.assign(o,{type:r[Number(o.type)]}),o.type==="Audio"&&"audioEvent"in o&&(Object.assign(o,{playAudio:o.audioEvent}),delete o.audioEvent),o.type==="GameControl")Object.assign(o,{gameActions:{idle:new be,move:new be,jump:new be}});else{let i=new be;Object.assign(o,{actions:i}),(o.type==="MouseDown"||o.type==="MouseUp"||o.type==="KeyDown"||o.type==="KeyUp")&&"url"in o&&i.push({fi:0,id:Xc.generateUUID(),data:{type:"Link",url:o.url,delay:0}}),"targets"in o&&(o.targets.forEach((a,s,l)=>{let c={state:void 0,repeat:0,delay:0,delayDirection:void 0,direction:"normal",duration:0,easing:4},u={easing:a.easing,duration:a.duration};a.easing===6?Object.assign(u,Er(a,"mass","stiffness","damping","velocity")):a.easing===5&&Object.assign(u,{control1:{...a.control1},control2:{...a.control2}});let p={repeat:a.repeat?-1:0,delay:a.delay,delayDirection:a.delayDirection,direction:a.cycle&&a.rewind?"pingpong-rewind":a.cycle?"pingpong":"normal"},d={state:a.state,...p,...u},h={allowSlerp:!0,type:"Transition",object:a.object,repeat:0,delay:0,delayDirection:void 0,direction:"normal",tweens:new be({fi:0,id:Xc.generateUUID(),data:c},{fi:1,id:Xc.generateUUID(),data:d})};i.push({fi:l,id:s,data:h})}),delete o.targets)}})})}function tI(n){n.scene.objects.traverse((r,e)=>{function t(o,i){let a=new be,s=[];if(e.events.forEach((l,c,u)=>{if(l.type==="Audio"&&l.trigger===i){let p;s.push(c),l.interaction==="play"?p={...Er(l,"interaction","audio","delay","volume","loop"),triggerAfter:"after"in l?l.after:void 0,toggle:"after"in l?l.toggle:void 0,type:"Audio"}:(l.interaction==="pause"||l.interaction==="stop")&&(p={...Er(l,"interaction","delay","object","playAudio"),type:"Audio"}),p&&a.push({fi:u,id:c,data:p})}}),s.forEach(l=>e.events.delete(l)),a.length){let l=e.events.find(c=>c.type===o)?.data;l?"actions"in l&&l.actions.insertBefore(null,a):e.events.insertBefore(null,[{id:Xc.generateUUID(),data:{type:o,actions:a}}])}}t("Start","start"),t("MouseDown","mouseDown"),t("MouseUp","mouseUp"),t("KeyDown","keyDown"),t("KeyUp","keyUp")})}function Ax(n){let r=n.layers.find(e=>e.type==="light")?.data;if(r?.category==="basic"){let e=xt.defaultData("light","phong"),t=r;Object.assign(t,e),t.visible=!1}}function Tx(n){Eo(n,Ax),No(n,Ax)}function rI(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&e.geometry.type==="SubdivGeometry"&&(e.geometry.scaleBaked||(e.geometry.scaleBaked=[1,1,1]))})}function oI(n){n.scene.objects.traverse((r,e)=>{(e.type==="Empty"||e.type==="Mesh")&&e.cloner&&!e.cloner.randomnessObject&&!e.cloner.toObject&&!e.cloner.randomness&&(e.cloner={...e.cloner,toObject:{object:"",spreadType:"random",scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],axis:"x",seed:0,count:99,align:"normal"},randomness:!1,randomnessObject:{strength:100,scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],movement:1,seed:0,freqScale:10,noiseType:"perlin"}})})}function nI(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&e.geometry.type==="NonParametricGeometry"&&!("material"in e)&&!("materials"in e)&&(e.material=Et.defaultTwoLayerData("phong"))})}function iI(n){n.scene.publish.orbitControls.autoZoom===void 0&&(n.scene.publish.orbitControls.autoZoom=!1),n.scene.objects.traverse((r,e)=>{(e.type==="OrthographicCamera"||e.type==="PerspectiveCamera")&&(e.orthographic.autoZoom===void 0&&(e.orthographic.autoZoom=!1),e.orthographic.autoZoomFrustumSize===void 0&&(e.orthographic.autoZoomFrustumSize=790))})}function aI(n){n.scene.objects.traverse((r,e)=>{e.pathSnapping===void 0&&(e.pathSnapping={pathId:null,slide:0,offset:0,orientation:"tangential"}),e.pathSnapping.offset===void 0&&(e.pathSnapping.offset=0)})}function sI(n){n.scene.publish.mouseEventTarget===void 0&&(n.scene.publish.mouseEventTarget="canvas"),n.scene.publish.settings.web.hint===void 0&&(n.scene.publish.settings.web.hint=!1)}function lI(n){let{video:r}=n.scene.publish.settings;r.format==="gif"&&r.fps>48&&(r.fps=15)}function cI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.resetYPosition=Math.abs(t.resetYPosition-e.position[1]))})})}function uI(n){let r=n.scene.environment.usePhysics;n.scene.objects.traverse((e,t)=>{r&&t.physics===null?t.collision=!1:t.collision="visibility"})}function dI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.navmesh=Yc.defaultDataThirdPerson.navmesh)})})}function pI(n){n.scene.styles||(n.scene.styles=Io.defaultData())}function Ix(n){n.layers.forEach(r=>{r.type==="light"&&r.category!=="toon"&&r.occlusion===void 0&&(r.occlusion=!0)})}function fI(n){n.scene.environment.ambientLight.occlusion===void 0&&(n.scene.environment.ambientLight.occlusion=!1),n.scene.environment.ambientLight.aoFullRes===void 0&&(n.scene.environment.ambientLight.aoFullRes=!1),n.scene.environment.ambientLight.radius===void 0&&(n.scene.environment.ambientLight.radius=256),n.scene.environment.ambientLight.bias===void 0&&(n.scene.environment.ambientLight.bias=.5),n.scene.environment.ambientLight.aoColor===void 0&&(n.scene.environment.ambientLight.aoColor={r:.19607843137254902,g:.19607843137254902,b:.19607843137254902}),No(n,Ix),Eo(n,Ix)}function hI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&Object.assign(t.gameActions,{run:new be})})})}function mI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.keyAssignments=[...t.keyAssignments,["run","\u21E7"],["none","Ctrl"]])})})}function Mx(n){n.layers&&n.layers.forEach(r=>{r.type==="light"&&r.bumpMapIntensity===void 0&&(r.bumpMapIntensity=5)})}function Ex(n,r){if(r<1&&(No(n,Sx),Eo(n,Sx),n.schema=1),r<2&&(BT(n),n.schema=2),r<3&&(LT(n),n.schema=3),r<4&&(VT(n),n.schema=4),r<5&&(zT(n),n.schema=5),r<6&&(GT(n),n.schema=6),r<7&&(FT(n),n.schema=7),r<8&&(n.schema=8),r<9&&(Px(n),n.schema=9),r<10&&(HT(n),n.schema=10),r<11&&(WT(n),n.schema=11),r<12&&(Px(n),n.schema=12),r<13&&(qT(n),n.schema=13),r<14&&(YT(n),n.schema=14),r<15&&(XT(n),n.schema=15),r<16&&(KT(n),n.schema=16),r<17&&(No(n,Cx),Eo(n,Cx),n.schema=17),r<18&&(No(n,wx),Eo(n,wx),n.schema=18),r<19&&(RT(n),n.schema=19),r<20&&(QT(n),JT(n),n.schema=20),r<21&&(eI(n),tI(n),n.schema=21),r<22&&(Tx(n),n.schema=22),r<23&&(rI(n),n.schema=23),r<24&&(oI(n),n.schema=24),(r<25||n.shared.videos===void 0)&&($T(n),r<25&&(n.schema=25)),r<26&&(jT(n),n.schema=26),r<27&&(kT(n),n.schema=27),r<28&&(Tx(n),n.schema=28),r<29&&(UT(n),n.schema=29),r<30&&(nI(n),n.schema=30),r<31&&(iI(n),n.schema=31),r<33&&(aI(n),n.schema=33),r<34&&(sI(n),n.schema=34),r<35&&(lI(n),n.schema=35),r<36&&(cI(n),n.schema=36),r<37&&(uI(n),n.schema=37),r<38&&(No(n,Ox),Eo(n,Ox),n.schema=38),r<39&&(dI(n),n.schema=39),r<40&&(pI(n),n.schema=40),r<41&&(fI(n),n.schema=41),r<42&&(hI(n),n.schema=42),r<43&&(mI(n),n.schema=43),r<99){No(n,Mx),Eo(n,Mx),n.scene.publish.playCamera===null&&(n.scene.publish.playCamera=cn);let e=it(n.scene.objects),t=n.scene.objects;n.scene.publish.playPage=un,t.insertBefore(null,null,[{id:un,data:{...To.defaultData,backgroundColor:n.scene.backgroundColor,fog:n.scene.fog,postprocessing:n.scene.postprocessing,ao:Er(n.scene.environment.ambientLight,"occlusion","aoFullRes","radius","bias","aoColor"),publish:{playCamera:n.scene.publish.playCamera,gameControlObject:n.scene.publish.gameControlObject},shadow:Er(n.scene.environment.ambientLight,"softShadowQuality"),globalPhysics:{..._s.defaultData,...Er(n.scene.environment,"usePhysics","gravity")},camera:it(n.scene.ownerCamera)??To.defaultData.camera,name:"Scene"},children:[]}]);for(let a of e)a.id!==Mo.TRASH_CAN_ID&&t.move(un,a.fi,a.id);let o=0,i=0;n.shared.penumbraSize&&n.scene.objects.traverse((a,s)=>{s.type==="DirectionalLight"?(s.penumbraSize=n.shared.penumbraSize[Math.min(o,2)],o+=1):s.type==="SpotLight"&&(s.penumbraSize=n.shared.penumbraSize[3+Math.min(i,1)],i+=1),(s.physics===void 0||s.physics===null)&&s.type!=="Instance"&&(s.physics={},Object.assign(s.physics,pn.defaultData)),s.physics!==void 0&&s.physics!==null&&(s.physics.enabled=s.collision??"visibility",delete s.collision)}),n.schema=99}}function Nx(n){n.layers&&n.layers.forEach(r=>{r.type==="light"&&r.alphaOverride===void 0&&(r.alphaOverride=1)})}function yI(n){n.scene.objects.traverse((r,e)=>{let t=e.geometry;t&&t.type==="PathGeometry"&&(t.extrusion.capType="flat",t.extrusion.bevel=50,t.extrusion.bevelSides=6,t.extrusion.shape.type==="Custom"&&(t.extrusion.shape.shapeQuality="low"))})}function gI(n){Array.isArray(it(n.events))&&n.events?.forEach(r=>{"disabled"in r||(r.disabled=!1),(r.type==="MouseDown"||r.type==="MouseUp"||r.type==="MousePress")&&(r.mode=r.mode||"Object")})}var aa=180/Math.PI;function Dx(n){n.rotation=n.rotation.slice(0,3).map(r=>r*aa)}function _x(n){Dx(n),n.type==="Page"&&Dx(n.camera),n.states?.forEach(e=>{e.rotation===void 0||e.rotation===null||(e.rotation=e.rotation.slice(0,3).map(t=>t*aa))});let r=n.geometry;r&&r.type==="SphereGeometry"&&(r.thetaLength=(r.thetaLength??180)*aa),r&&r.type==="TorusGeometry"&&(r.arc=r.arc*aa),r&&r.type==="PathGeometry"&&(r.extrusion.angle*=aa,r.extrusion.twist*=aa),n.type==="Mesh"&&n.geometry.type==="TextGeometry"&&(n.geometry.text={textValue:n.geometry.text}),Array.isArray(it(n.events))&&n.events?.forEach(e=>{(e.type==="MouseDown"||e.type==="MouseUp"||e.type==="MousePress"||e.type==="KeyDown"||e.type==="KeyUp"||e.type==="KeyPress"||e.type==="Collision"||e.type==="Trigger")&&(e.runMode=e.toggle?"Toggle":"Repeat")})}function xI(n){n.shared.variables=Lt({},fe.prototype)}function bI(n){let r=it(n.shared.variables);n.shared.variables=Lt(Object.entries(r??{}).map(([e,t],o)=>({fi:o,id:e,data:t})),be.prototype)}var oo=115;function Bx(n,r){r(n.data);for(let e of n.children)Bx(e,r)}function vI(n){let r=n.schema??104;r!==oo&&r<105&&(Bx(n.asset,_x),n.schema=105)}function SI(n){n.shared.particles=Lt({},fe.prototype),n.shared.lib&&(n.shared.lib.particles=_r.defaultData().particles)}function wI(n){n.scene.objects.traverse((r,e)=>{e.type==="Particle"&&typeof e.renderMaterial.size=="number"&&Object.assign(e.renderMaterial,{size:[e.renderMaterial.size,e.renderMaterial.size]})})}function PI(n){n.scene.objects.traverse((r,e)=>{e.type==="Page"&&(e.postprocessing.depthOfField.focusDistance=100,e.postprocessing.depthOfField.focalLength=20,e.postprocessing.depthOfField.bokehScale=5)})}function CI(n){n.scene.objects.traverse((r,e)=>{Array.isArray(it(e.events))!==!1&&e.events?.forEach(t=>{let o=t.runMode;t.type==="MouseDown"||t.type==="MouseUp"||t.type==="KeyDown"||t.type==="KeyUp"||t.type==="Collision"||t.type==="Trigger"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode=o??"Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode=o==="Toggle"?"Toggle":"Normal")}):t.type==="MouseHover"||t.type==="MousePress"||t.type==="KeyPress"?t.actions?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")}):t.type==="GameControl"?(delete t.actions,Object.keys(t.gameActions).forEach(a=>{t.gameActions[a]?.forEach(s=>{s.type==="Transition"&&(s.runMode="Repeat"),s.type==="Animation"&&(s.runMode="Normal")})})):t.type==="DragDrop"?(delete t.actions,t.dragDropActions?.drag?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")}),t.dragDropActions?.drop?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")})):t.type==="Resize"?(delete t.actions,t.breakpoints?.forEach(i=>{i.actions?.forEach(a=>{(a.type==="Transition"||a.type==="Animation"||a.type==="SwitchCamera")&&(a.runMode="Toggle")})})):t.type==="Start"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Once"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}):t.type==="VariableChange"||t.type==="Scroll"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}):t.type==="Conditional"&&(delete t.actions,t.inActions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}),t.outActions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}))})})}function OI(n){n.shared.userAPIs=Lt({},fe.prototype),n.shared.userWebhooks=Lt({},fe.prototype),n.shared.lib&&(n.shared.lib.userAPIs=_r.defaultData().userAPIs,n.shared.lib.userWebhooks=_r.defaultData().userWebhooks)}function Kc(n){let r=n.schema??0;if(r!==oo){console.warn("updating from ",r,"to ",oo),Ex(n,r),r<100&&(n.scene.publish.joystickSizeAndXYOffset===void 0&&(n.scene.publish.joystickSizeAndXYOffset=Dr.defaultData.joystickSizeAndXYOffset),n.schema=100),r<101&&(No(n,Nx),Eo(n,Nx),n.schema=101),r<102&&(yI(n),n.schema=102),r<104&&(n.shared.catelogs=new fe,n.shared.lib=_r.defaultData(),n.schema=104),r<105&&(xI(n),n.scene.objects.traverse((e,t)=>{_x(t)}),n.schema=105);for(let e of Object.values(n.shared.lib.components))vI(e);r<106&&(bI(n),n.schema=106),r<107&&(n.shared.lib.variables=_r.defaultData().variables,n.schema=107),r<109&&(SI(n),n.schema=109),r<110&&(wI(n),n.schema=110),r<111&&(n.scene.objects.traverse((e,t)=>{gI(t)}),n.schema=111),r<112&&(PI(n),n.schema=112),r<113&&(CI(n),n.schema=113),r<114&&(n.scene.publish.settings.web.imageQuality===void 0&&(n.scene.publish.settings.web.imageQuality=70),n.schema=114),r<115&&(OI(n),n.schema=115)}}var na;(c=>{c.defaultData={schema:oo,scene:Mo.defaultData,frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",ia.defaultData),shared:{...xr.emptyData(),colors:xr.defaultColors()}},c.emptyDataForImports=function(){let u=Mo.emptyDataWithPage();return{schema:oo,scene:u,frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",ia.defaultData),shared:{...xr.emptyData(),colors:xr.defaultColors(),images:xr.defaultImages()}}},c.emptyData=function(){return{schema:oo,scene:Mo.emptyDataWithPage(),frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",ia.defaultData),shared:xr.emptyData()}},c.clipboard2dData=function(){return{schema:oo,scene:Mo.emptyData(),frames:new fe,shared:xr.emptyData()}},c.collabHelper={...Ts,updateSchema(u){return(u.schema??0)<oo?rn(u,Kc):(u.schema??0)-oo}};function i(u){let p=c.collabHelper.updateSchema(u);return typeof p=="number"?p===0?u:null:p.data}c.updateSchemaDirectly=i;function a(u){return{...u,shared:{...u.shared,lib:_r.defaultData()}}}c.withoutLib=a;function s(u,p){let d=u.scene.objects.get(p);if(d&&d.data.type==="Component")return d;{let h=u.shared.lib.components[p];if(h)return h.asset}}c.getComponentData=s;function l(u){let p=Object.values(u.shared.userAPIs);for(let d of p){let h=d.headers;for(let f of h)if(f.data.key.toLowerCase()==="authorization"&&f.data.value!=="")return!0}return!1}c.hasSensitiveData=l})(na||(na={}));var Qc;(r=>r.emptyImage={data:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=",name:"empty"})(Qc||(Qc={}));var Rx;(r=>{function n(e){return!0}r.is=n})(Rx||(Rx={}));var Zc;(t=>{t.defaultData={position:[0,0],scale:[1,1],rotation:0,shear:[0,0]};function r(o,i){return{position:i?.position??o.position,rotation:i?.rotation??o.rotation,scale:i?.scale??o.scale,shear:i?.shear??o.shear}}t.merge=r;function e(o,i){return Gl({position:Ki.isEqual(o.position,i.position)?void 0:i.position,rotation:o.rotation===i.rotation?void 0:i.rotation,scale:Ki.isEqual(o.scale,i.scale)?void 0:i.scale,shear:o.shear&&i.shear&&Ki.isEqual(o.shear,i.shear)?void 0:i.shear})}t.diff=e})(Zc||(Zc={}));var Ap;(r=>r.defaultData={horizontalConstraint:0,verticalConstraint:0})(Ap||(Ap={}));var Lx;(r=>r.defaultData={direction:"row",wrap:"unwrap",align:"top-left",gap:10,rowGap:10,autoGap:!1,autoRowGap:!1,leftPadding:8,rightPadding:8,topPadding:8,bottomPadding:8})(Lx||(Lx={}));var Jc;(r=>r.defaultData={opacity:1,fill:{color:Me.fromHexAndA(mt,1),enabled:!0},stroke:{color:Me.from0to1([0,0,0,1]),thickness:1,enabled:!1,mode:"inside"},layerBlur:{radius:2,enabled:!1},backgroundBlur:{radius:2,enabled:!1},dropShadow:{offset:[10,10],blurRadius:10,color:Me.from0to1([0,0,0,1]),enabled:!1,spread:0},innerShadow:{offset:[10,10],blurRadius:10,color:Me.from0to1([0,0,0,1]),enabled:!1,spread:0}})(Jc||(Jc={}));var Xn;(i=>{function n(a,s){return{name:s}}i.newEmpty=n;function r(a,s){if(s===void 0)return a;let l={...a},c=["width","height","cornerRadius"];for(let u of c)u in l&&u in s&&s[u]!==void 0&&Object.assign(l,{[u]:s[u]});return l}function e(a,s){if(s===void 0)return a;let l={...a};return"fill"in l&&"fill"in s&&s.fill!==void 0&&Object.assign(l,{fill:{...l.fill,...s.fill}}),"stroke"in l&&"stroke"in s&&s.stroke!==void 0&&Object.assign(l,{stroke:{...l.stroke,...s.stroke}}),"layerBlur"in l&&"layerBlur"in s&&s.layerBlur!==void 0&&Object.assign(l,{layerBlur:{...l.layerBlur,...s.layerBlur}}),"backgroundBlur"in l&&"backgroundBlur"in s&&s.backgroundBlur!==void 0&&Object.assign(l,{backgroundBlur:{...l.backgroundBlur,...s.backgroundBlur}}),"dropShadow"in l&&"dropShadow"in s&&s.dropShadow!==void 0&&Object.assign(l,{dropShadow:{...l.dropShadow,...s.dropShadow}}),"innerShadow"in l&&"innerShadow"in s&&s.innerShadow!==void 0&&Object.assign(l,{innerShadow:{...l.innerShadow,...s.innerShadow}}),l}function t(a,s){if(s===void 0)return a;let l={...a};return Object.assign(l,Zc.merge(l,s)),l=r(l,s),l=e(l,s),l}i.patch=t;function o(a,s){let l,c=[];for(let[u,p]of Object.entries(s))u!=="name"&&(l===void 0&&(l={path:[],props:{},type:0},c.push(l)),l.props[u]=p);return c}i.toOps=o})(Xn||(Xn={}));var Bs;(r=>r.defaultData={...Zc.defaultData,...Ap.defaultData,states:new be,events:new be,visible:!0,raycastLock:!1})(Bs||(Bs={}));var sa;(r=>r.defaultData={...Bs.defaultData,...Jc.defaultData})(sa||(sa={}));var eu;(r=>r.defaultData={cornerRadius:[0,0,0,0]})(eu||(eu={}));var Tp;(r=>r.defaultData={...sa.defaultData,type:"ellipse2d",width:100,height:100,name:"Ellipse"})(Tp||(Tp={}));var la;(r=>r.defaultData={...sa.defaultData,...eu.defaultData,type:"rectangle2d",width:100,height:100,name:"Rectangle"})(la||(la={}));var Ip;(r=>r.defaultData={...sa.defaultData,type:"text2d",width:100,height:100,fontSize:12,lineHeight:1.2,letterSpacing:0,text:{textValue:"Hello world"},horizontalAlign:1,verticalAlign:1,textTransform:1,font:"Roboto_regular",name:"Text"})(Ip||(Ip={}));var Mp;(r=>r.defaultData={...sa.defaultData,type:"path2d",path:"",name:"Path"})(Mp||(Mp={}));var Vx;(r=>{function n(e){return e.type==="ellipse2d"||e.type==="rectangle2d"||e.type==="text2d"||e.type==="vector2d"||e.type==="path2d"}r.is=n})(Vx||(Vx={}));var Rs;(r=>r.defaultData={...Bs.defaultData,name:"Group",type:"group2d"})(Rs||(Rs={}));var Ep;(r=>r.defaultData=()=>({...Bs.defaultData,...eu.defaultData,...Jc.defaultData,name:"Frame",type:"frame2d",clipped:!0,width:200,height:200,fill:{color:Me.fromHexAndA(4737101,1),enabled:!0},stroke:{color:Me.fromHexAndA(0,1),thickness:1,enabled:!1,mode:"inside"},backgroundBlur:{radius:2,enabled:!1},layerBlur:{radius:2,enabled:!1}}))(Ep||(Ep={}));var Do;(i=>{function n(a){switch(a){case"rectangle2d":return{...la.defaultData};case"ellipse2d":return{...Tp.defaultData};case"text2d":return{...Ip.defaultData};case"vector2d":return{...la.defaultData};case"path2d":return{...Mp.defaultData};case"frame2d":return{...Ep.defaultData()};case"group2d":return{...Rs.defaultData}}}i.defaultData=n;function r(a){return"width"in a&&"height"in a?[typeof a.width=="number"?a.width*.5:0,typeof a.height=="number"?a.height*.5:0]:[0,0]}i.getPivot=r;function e(a){return a.type==="rectangle2d"||a.type==="ellipse2d"||a.type==="text2d"||a.type==="frame2d"}i.isResizeable=e;function t(a){return a.type==="frame2d"&&a.autoLayout!==void 0}i.isAutoLayoutable=t;function o(a){return a.type==="rectangle2d"||a.type==="frame2d"}i.hasCorners=o})(Do||(Do={}));var tu;(e=>(e.defaultData={name:"UI",type:"scene2d",objects:new Ke},e.emptyData=function(){return{type:"scene2d",objects:new Ke}}))(tu||(tu={}));var ns=vs(Gx());import{Object3D as $D,Vector3 as pr,Euler as uh,MathUtils as Av,Matrix4 as fi}from"three";var AI=.5*(Math.sqrt(3)-1),Ls=(3-Math.sqrt(3))/6,TI=1/3,no=1/6,KW=(Math.sqrt(5)-1)/4,QW=(5-Math.sqrt(5))/20,Vs=n=>Math.floor(n)|0,Fx=new Float64Array([1,1,-1,1,1,-1,-1,-1,1,0,-1,0,1,0,-1,0,0,1,0,-1,0,1,0,-1]),Dp=new Float64Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]);function ru(n=Math.random){let r=kx(n),e=new Float64Array(r).map(o=>Fx[o%12*2]),t=new Float64Array(r).map(o=>Fx[o%12*2+1]);return function(i,a){let s=0,l=0,c=0,u=(i+a)*AI,p=Vs(i+u),d=Vs(a+u),h=(p+d)*Ls,f=p-h,m=d-h,y=i-f,g=a-m,v,w;y>g?(v=1,w=0):(v=0,w=1);let O=y-v+Ls,S=g-w+Ls,C=y-1+2*Ls,T=g-1+2*Ls,x=p&255,N=d&255,E=.5-y*y-g*g;if(E>=0){let _=x+r[N],B=e[_],V=t[_];E*=E,s=E*E*(B*y+V*g)}let M=.5-O*O-S*S;if(M>=0){let _=x+v+r[N+w],B=e[_],V=t[_];M*=M,l=M*M*(B*O+V*S)}let D=.5-C*C-T*T;if(D>=0){let _=x+1+r[N+1],B=e[_],V=t[_];D*=D,c=D*D*(B*C+V*T)}return 70*(s+l+c)}}function jx(n=Math.random){let r=kx(n),e=new Float64Array(r).map(i=>Dp[i%12*3]),t=new Float64Array(r).map(i=>Dp[i%12*3+1]),o=new Float64Array(r).map(i=>Dp[i%12*3+2]);return function(a,s,l){let c,u,p,d,h=(a+s+l)*TI,f=Vs(a+h),m=Vs(s+h),y=Vs(l+h),g=(f+m+y)*no,v=f-g,w=m-g,O=y-g,S=a-v,C=s-w,T=l-O,x,N,E,M,D,_;S>=C?C>=T?(x=1,N=0,E=0,M=1,D=1,_=0):S>=T?(x=1,N=0,E=0,M=1,D=0,_=1):(x=0,N=0,E=1,M=1,D=0,_=1):C<T?(x=0,N=0,E=1,M=0,D=1,_=1):S<T?(x=0,N=1,E=0,M=0,D=1,_=1):(x=0,N=1,E=0,M=1,D=1,_=0);let B=S-x+no,V=C-N+no,k=T-E+no,L=S-M+2*no,W=C-D+2*no,F=T-_+2*no,j=S-1+3*no,H=C-1+3*no,q=T-1+3*no,re=f&255,ee=m&255,X=y&255,te=.6-S*S-C*C-T*T;if(te<0)c=0;else{let $=re+r[ee+r[X]];te*=te,c=te*te*(e[$]*S+t[$]*C+o[$]*T)}let K=.6-B*B-V*V-k*k;if(K<0)u=0;else{let $=re+x+r[ee+N+r[X+E]];K*=K,u=K*K*(e[$]*B+t[$]*V+o[$]*k)}let Z=.6-L*L-W*W-F*F;if(Z<0)p=0;else{let $=re+M+r[ee+D+r[X+_]];Z*=Z,p=Z*Z*(e[$]*L+t[$]*W+o[$]*F)}let Q=.6-j*j-H*H-q*q;if(Q<0)d=0;else{let $=re+1+r[ee+1+r[X+1]];Q*=Q,d=Q*Q*(e[$]*j+t[$]*H+o[$]*q)}return 32*(c+u+p+d)}}function kx(n){let e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){let o=t+~~(n()*(256-t)),i=e[t];e[t]=e[o],e[o]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}import{Triangle as II}from"three";var Br=new II,ou=class{constructor(r){this.weightAttribute=null;let e=r.geometry;if(!e.isBufferGeometry||e.attributes.position.itemSize!==3)throw new Error("THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.");e.index&&(e=e.toNonIndexed()),this.geometry=e,this.randomFunction=Math.random,this.positionAttribute=this.geometry.getAttribute("position"),this.distribution=null}build(){let r=this.positionAttribute,e=new Float32Array(r.count/3);for(let o=0;o<r.count;o+=3){let i=1;Br.a.fromBufferAttribute(r,o),Br.b.fromBufferAttribute(r,o+1),Br.c.fromBufferAttribute(r,o+2),i*=Br.getArea(),e[o/3]=i}this.distribution=new Float32Array(r.count/3);let t=0;for(let o=0;o<e.length;o++)t+=e[o],this.distribution[o]=t;return this}setRandomGenerator(r){return this.randomFunction=r,this}sample(r,e){if(this.distribution){let t=this.distribution[this.distribution.length-1],o=this.binarySearch(this.randomFunction()*t);return this.sampleFace(o,r,e)}}binarySearch(r){if(!this.distribution)return 0;let e=this.distribution,t=0,o=e.length-1,i=-1;for(;t<=o;){let a=Math.ceil((t+o)/2);if(a===0||e[a-1]<=r&&e[a]>r){i=a;break}else r<e[a]?o=a-1:t=a+1}return i}sampleFace(r,e,t){let o=this.randomFunction(),i=this.randomFunction();return o+i>1&&(o=1-o,i=1-i),Br.a.fromBufferAttribute(this.positionAttribute,r*3),Br.b.fromBufferAttribute(this.positionAttribute,r*3+1),Br.c.fromBufferAttribute(this.positionAttribute,r*3+2),e.set(0,0,0).addScaledVector(Br.a,o).addScaledVector(Br.b,i).addScaledVector(Br.c,1-(o+i)),Br.getNormal(t),this}};import{Object3D as _I}from"three";var Wx=vs(Hx());import{Object3D as MI,Matrix4 as io}from"three";var EI=new io,NI=new io,DI=new io,ca;(r=>{function n(e){return e&&e.__isSPEObject}r.is=n})(ca||(ca={}));var ua=n=>class extends n{constructor(){super(...arguments);this.previousModelViewMatrix=new io;this.copyPreviousMatrix=!0;this.hiddenMatrix=new io;this.matrixWorldRigid=new io;this.shearScale=new io;this.shearScaleInv=new io}get __isSPEObject(){return!0}isDescendantOf(t){t instanceof MI&&(t=t.uuid);let o=this;for(;o.parent;){if(o.parent.uuid===t)return!0;o=o.parent}return!1}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.parent===null?this.matrixWorld.multiplyMatrices(this.hiddenMatrix,this.matrix):(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.hiddenMatrix),this.matrixWorld.multiplyMatrices(this.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);for(let o of this.children)o.updateMatrixWorld(t)}updateWorldMatrix(t,o){let i=this.parent;if(t&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.parent===null?this.matrixWorld.multiplyMatrices(this.hiddenMatrix,this.matrix):(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.hiddenMatrix),this.matrixWorld.multiplyMatrices(this.matrixWorld,this.matrix)),o)for(let a of this.children)a.updateWorldMatrix(!1,!0)}traverseChildren(t,o=0){for(let i of this.children)ca.is(i)&&i.traverseObject(t,o+1)}traverseObject(t,o=0){if(t(this,o)!==!0)for(let a of this.children)ca.is(a)&&a.traverseObject(t,o+1)}updateMatrixWorldSVD(){let t=this.matrixWorld.elements,o=[[t[0],t[4],t[8]],[t[1],t[5],t[9]],[t[2],t[6],t[10]]],{u:i,v:a,q:s}=(0,Wx.SVD)(o),l=EI.set(i[0][0],i[0][1],i[0][2],0,i[1][0],i[1][1],i[1][2],0,i[2][0],i[2][1],i[2][2],0,0,0,0,1),c=NI.set(a[0][0],a[0][1],a[0][2],0,a[1][0],a[1][1],a[1][2],0,a[2][0],a[2][1],a[2][2],0,0,0,0,1),u=DI.copy(c).transpose();this.shearScale.makeScale(s[0],s[1],s[2]).multiply(u).premultiply(c),this.shearScaleInv.copy(this.shearScale).invert(),this.matrixWorldRigid.multiplyMatrices(l,u).copyPosition(this.matrixWorld),s.every(p=>Math.abs(s[0]-p)<.01)?this.hasNonUniformScale=!1:this.hasNonUniformScale=!0}attach(t,o){this.updateWorldMatrix(!0,!1);let i=new io().copy(this.matrixWorld).invert();return t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),i.multiply(t.parent.matrixWorld)),"hiddenMatrix"in t&&t.hiddenMatrix instanceof io?t.hiddenMatrix.premultiply(i):t.applyMatrix4(i),t.updateWorldMatrix(!1,!1),this.add(t),o!==void 0&&(this.children.pop(),this.children.splice(o,0,t)),this}copy(t,o=!1){return super.copy(t,o),this.hasNonUniformScale=t.hasNonUniformScale,this}onAfterRender(t,o,i,a,s,l){this.copyPreviousMatrix&&this.previousModelViewMatrix.copy(this.modelViewMatrix)}};var _p=class extends ua(_I){},BI=n=>n.type==="Mesh",_o=class extends _p{constructor(e){super();this.object=e;this.matrixAutoUpdate=!1,this.hasNonUniformScale=e.hasNonUniformScale}raycast(e,t){}expand(){let e=0,t=this.object.entityChildren(e);for(;t;){let o=this.children[e];o?.object!==t&&(o&&this.remove(o),o=new _o(t),this.add(o),this.children.splice(e,0,this.children.pop()),o.matrixWorldNeedsUpdate=!0,o.matrixAutoUpdate=!1,o.matrix=t.matrix,o.hiddenMatrix=t.hiddenMatrix),o.expand(),e+=1,t=this.object.entityChildren(e)}for(;this.children.length>e;)this.remove(this.children[e])}get visible(){return this.playModeVisible!==void 0?this.playModeVisible:this.object.visible||this.object.dataPatched.visible&&this.object.dataPatched.cloner?.hideBase===!0}set visible(e){}get castShadow(){return this.object.castShadow}set castShadow(e){}get receiveShadow(){return this.object.receiveShadow}set receiveShadow(e){}get isMesh(){return BI(this.object)}get isLight(){return this.object.isLight}get layers(){return this.object.layers}set layers(e){}get isCamera(){return!1}get geometry(){if(this.object.geometry)return this.object.geometry}get material(){if(this.object.material)return this.object.material}};import{Box3 as rN,BufferGeometry as oN,MeshBasicMaterial as nN}from"three";import{Matrix4 as eN,Mesh as tN}from"three";import{Matrix4 as au,Vector3 as Yx,Euler as FI,MathUtils as Gs}from"three";import{Box3 as RI,Line3 as LI,Matrix4 as Bp,Vector3 as cr}from"three";var Kn=new cr,Qn=new cr,da=new Bp,$x=[new cr(-1,1,1),new cr(-1,-1,1),new cr(1,-1,1),new cr(1,1,1),new cr(-1,1,-1),new cr(-1,-1,-1),new cr(1,-1,-1),new cr(1,1,-1)],VI=[[0,3],[1,2],[5,6],[4,7],[0,1],[3,2],[7,6],[4,5],[0,4],[1,5],[2,6],[3,7]],zI=[[0,2],[7,5],[4,1],[3,6],[4,3],[1,6]],qx=(n,r,e)=>{n.updateEntityBoxSize(Kn,Qn),da.copy(r).multiply(n.matrixWorld),Qn.x===0&&Qn.y===0&&Qn.z===0?e.push(new cr(Kn.x,Kn.y,Kn.z).applyMatrix4(da)):$x.forEach(t=>{e.push(t.clone().multiply(Qn).add(Kn).applyMatrix4(da))})},zs=class extends RI{constructor(){super(...arguments);this.matrix=new Bp;this.vertices=[];this.faces=[];this.edges=[];this.centerEdges=[]}copy(e){return super.copy(e),this.matrix.copy(e.matrix),this.vertices=e.vertices.map(t=>t.clone()),this.faces=e.faces.map(t=>t.clone()),this.edges=e.edges.map(t=>t.clone()),this.centerEdges=e.centerEdges.map(t=>t.clone()),this}setFromObjectSize(e,t=!1){e.updateWorldMatrix(!1,t),this.makeEmpty(),this.matrix.copy(e.matrixWorld);let o=new Bp().copy(e.matrixWorld).invert();return this.expandByObjectSize(e,o,t)}expandByObjectSize(e,t,o=!1){let i=[];return o===!0?e.traverseEntity(a=>{if(a.visible||a.cloner&&a.data.visible){if(!("geometry"in a)){i.push(new cr);return}qx(a,t,i)}}):qx(e,t,i),this.setFromPoints(i)}getCenter(e){return e=super.getCenter(e),e.applyMatrix4(this.matrix),e}getPositionToCenter(e){return e=super.getCenter(e),e.applyMatrix4(da.copy(this.matrix).setPosition(0,0,0)),e}computeVertices(){this.getSize(Qn).multiplyScalar(.5),this.getCenter(Kn),da.copy(this.matrix).setPosition(Kn),this.vertices=$x.map(e=>e.clone().multiply(Qn).applyMatrix4(da))}computeEdges(){this.vertices.length>0&&this.computeVertices(),this.edges=VI.map(([e,t])=>new LI(this.vertices[e],this.vertices[t])),this.centerEdges=this.edges.map(e=>e.getCenter(new cr))}computeFaces(){this.vertices.length>0&&this.computeVertices(),this.faces=zI.map(([e,t])=>this.vertices[e].clone().add(this.vertices[t]).multiplyScalar(.5))}};var Rr={Cloner:()=>{},changeEntityProptotype:()=>{},createEntity:()=>{}};import{CurvePath as GI,CubicBezierCurve3 as Rp,Vector3 as Lr}from"three";var Vp=class extends GI{constructor(){super()}getPoints(r=12){let e=[],t,o=this.getCurveLengths(),a=o[o.length-1]/o.length;for(let s=0,l=this.curves;s<l.length;s++){let c=l[s],u=s===0?o[s]:o[s]-o[s-1],p=Math.ceil(r*u/a),d=c.getPoints(p);for(let h=0;h<d.length;h++){let f=d[h];t&&t.equals(f)||(e.push(f),t=f)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}};var zp=.001;function Gp(n,r,e){return r.clone().sub(n).cross(r.clone().sub(e)).length()<=zp}function Lp(n,r){let e=new Lr(...n.position),t=new Lr(...n.controlNext.position),o=new Lr(...r.controlPrevious.position),i=new Lr(...r.position);return Gp(e,t,i)&&Gp(e,o,i)}function iu(n){let r=n.points.map(u=>new Lr(...u.data.position)),e=[n.points[0]],t=new Lr(...e[0].data.position);for(let u=0;u<n.points.length-1;u++)Gp(t,r[u],r[u+1])||(e.push(n.points[u]),t=r[u]);e.push(n.points[n.points.length-1]);let o=n.isClosed,i=e.length-(o?0:1),a=e.length,s=[];for(let u=0;u<a;u++){let p=e[u].data,d=new Lr(...p.position),h=new Lr(...p.controlPrevious.position),f=new Lr(...p.controlNext.position),m={position:d,baseRoundness:p.roundness,controlPrevious:h,controlNext:f};if(p.roundness===0||!n.isClosed&&(u===0||u===a-1)){s[u]={...m,removedLength:0};continue}let y=o&&u==0?a-1:u-1,g=o&&u==a-1?0:u+1,v=e[y].data,w=e[g].data,O=new Lr(...v.position),S=new Lr(...w.position),C=O.clone().sub(d).normalize(),T=S.clone().sub(d).normalize();Object.assign(m,{prevDir:C,nextDir:T});let x=Lp(v,p),N=Lp(p,w);if(!x||!N)s[u]={...m,removedLength:0};else{let E=C.clone().add(T).normalize(),M=E.clone().cross(C).length()/C.dot(E);s[u]={...m,tan:M,removedLength:p.roundness/M}}}for(let u=0;u<i;u++){let p=u,d=o&&u===a-1?0:u+1,h=s[p],f=s[d];if(h.removedLength!==0||f.removedLength!==0){let m=h.position.distanceTo(f.position);h.removedLength=Math.min(h.removedLength,m/2),f.removedLength=Math.min(f.removedLength,m/2)}}let l=[];for(let u=0;u<i;u++){let p=u,d=o&&u===a-1?0:u+1,h=s[p],f=s[d],m=null;if(!Lp(e[p].data,e[d].data))h.position.distanceTo(f.position)>zp&&(m=new Rp(h.position,h.controlNext,f.controlPrevious,f.position));else{let y=h.position.clone(),g=f.position.clone();(h.removedLength!==0||f.removedLength!==0)&&(h.nextDir&&y.add(h.nextDir.clone().setLength(h.removedLength)),f.prevDir&&g.add(f.prevDir.clone().setLength(f.removedLength))),y.distanceTo(g)>zp&&(m=new Rp(y,y.clone().lerp(g,.3),g.clone().lerp(y,.3),g))}l[2*u+1]=m}for(let u=0;u<a;u++){let p=s[u];if(p.removedLength===0){l[2*u]=null;continue}let d=p.position,h=p.prevDir.clone().multiplyScalar(p.removedLength).add(d),f=p.nextDir.clone().multiplyScalar(p.removedLength).add(d),m=p.tan*p.removedLength,y=p.prevDir.clone().add(p.nextDir).normalize(),g=h.clone().lerp(f,.5),v=h.distanceTo(f)/2,w=y.clone().multiplyScalar(Math.sqrt(Math.pow(m,2)-Math.pow(v,2))).add(g),O=y.clone().multiplyScalar(-m).add(w),S=d.distanceTo(O)/d.distanceTo(g),C=p.prevDir.clone().multiplyScalar(S*d.distanceTo(h)).add(d),T=C.clone().lerp(O,2),x=h.clone().lerp(C,4/3),N=f.clone().lerp(T,4/3);l[2*u]=new Rp(h,x,N,f)}let c=new Vp;return l.forEach(u=>{u&&c.add(u)}),c}var Le;(r=>{function n(e){return e&&e.__isEntity}r.is=n})(Le||(Le={}));var pa=n=>Le.is(n),jI={type:"completeState",isfromEntity:!0},kI=["x","y","z"],Fp=new Yx,UI=new Yx().set(0,1,0),fa=n=>class extends ua(n){constructor(){super(...arguments);this.raycastLock=!1;this.scaleLock=!1;this.disposed=!1;this.stateSelection=null;this.destroyedInAction=!1;this.instances=[];this.prevState=null;this.currentState=null;this.reversibleToState=null;this.currentTransitionEvent=null;this.previousAction=null;this._singleBBox=new zs;this._recursiveBBox=new zs;this.singleBBoxNeedsUpdate=!0;this.recursiveBBoxNeedsUpdate=!0;this._needApplyPathSnapping=!0;this.attachedPaths=new Set}get __isEntity(){return!0}entityChildren(t){let o=this.children[t];if(Le.is(o))return o}entityChildrenCount(){let t=this.children.length;for(;t--;)if(Le.is(this.children[t]))return t+1;return 0}get isConcreteEntity(){return typeof this.identity=="string"}get isVirtualEntity(){return typeof this.identity!="string"}get isInstanceRoot(){return this.isConcreteEntity&&this.data.type==="Instance"}nearestInstanceSelfOrParent(){let t=this;for(;t.data.type!=="Instance";){let o=t.parent;if(Le.is(o))t=o;else return}return t}forInstancesRec(t){this.instances.forEach(o=>{o.disposed||t(o),o.forInstancesRec(t)})}super_Entity(t,o){typeof t=="string"&&(this.uuid=t),this.identity=t,this.data=o,this.matrixAutoUpdate=!1,this.dataPatched=this.data}changeSelectedState(t,o,i=!1){if(!(this.data.states.length===0&&!i)){for(let a of this.data.states)Yn.toOps(this.data,a.data).forEach(l=>{let c=qi.replaceProps(l,this.data);this.dataPatched=this.data,this.updateByPatchedOp(c,this.data,o)});if(t!==null){let a=this.data.states.data(t);a&&(this.dataPatched=Yn.patch(this.data,a),Yn.toOps(this.data,a).forEach(l=>{this.updateByPatchedOp(l,this.dataPatched,o)}))}i&&this.updateTransformState(this.dataPatched,o),this.stateSelection=t,this.updatePathSnapping(this.dataPatched.pathSnapping)}}get singleBBox(){return this.singleBBoxNeedsUpdate&&(this.singleBBoxNeedsUpdate=!1,this._singleBBox.setFromObjectSize(this,!1),this._singleBBox.computeVertices(),this._singleBBox.computeEdges(),this._singleBBox.computeFaces()),this._singleBBox}get recursiveBBox(){return this.recursiveBBoxNeedsUpdate&&(this.recursiveBBoxNeedsUpdate=!1,this._recursiveBBox.setFromObjectSize(this,!0),this._recursiveBBox.computeVertices(),this._recursiveBBox.computeEdges(),this._recursiveBBox.computeFaces()),this._recursiveBBox}updateEntityBoxSize(t,o){t.setScalar(0),o.setScalar(0)}resetBBoxNeedsUpdateSelf(){this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}resetBBoxNeedsUpdate(){this.resetBBoxNeedsUpdateSelf(),this.traverseAncestors(t=>{pa(t)&&t.resetBBoxNeedsUpdateSelf()}),this.traverseEntity(t=>{t.resetBBoxNeedsUpdateSelf()})}find(t){let o;return this.traverseEntity(i=>{i.uuid===t&&(o=i)}),o}traverseSortNextHelper(){let t=this.parent;if(t){let o=t.children,i=o.indexOf(this)+1;if(Le.is(o[i]))return o[i];if(Le.is(t))return t.traverseSortNextHelper()}}sortNext(){let t=this.children;return this.children.length>0&&Le.is(this.children[0])?t[0]:this.traverseSortNextHelper()}goUp(t){let o=this;for(;t>0&&o!==null;)o=o.parent,t-=1;return o}hasAnccestorOrSelf(t){return this===t||this.hasAnccestor(t)}hasAnccestor(t){let o=this.parent;for(;o;){if(t===o)return!0;o=o.parent}return!1}countToAccestor(t){let o=0,i=this;for(;i!==t;){if(i===null)return-1;i=i.parent,o+=1}return o}forEachEntity(t){for(let o of this.children)pa(o)&&t(o)}traverseEntityAncestors(t){this.traverseAncestors(o=>{Le.is(o)&&t(o)})}traverseConcreteEntity(t,o=0){if(t(this,o)!==!0)for(let a of this.children)pa(a)&&a.isConcreteEntity&&a.traverseEntity(t,o+1)}traverseEntity(t,o=0){if(t(this,o)!==!0)for(let a of this.children)pa(a)&&a.traverseEntity(t,o+1)}traverseVisibleEntity(t){t(this);for(let o of this.children)pa(o)&&o.visible&&o.traverseVisibleEntity(t)}updateMatrix(){super.updateMatrix(),this.cloner&&this.cloner.onObjUpdateMatrix(),this.dispatchEvent({type:"updateMatrix"})}updateMatrixWorld(t){super.updateMatrixWorld(t),this.dispatchEvent({type:"updateMatrixWorld"})}copy(t,o=!1){return super.copy(t,o),this.dataPatched=t.dataPatched,this.raycastLock=t.raycastLock,this.scaleLock=t.scaleLock,this.hiddenMatrix.copy(t.hiddenMatrix),this}hasEntityChild(){return this.children.some(t=>pa(t))}isAncestorOf(t){if(this.uuid===t)return!1;let o=!1;return this.traverseEntity(i=>{i.uuid===t&&(o=!0)}),o}toObjectTransformState(t=[]){this.updateWorldMatrix(!0,!1);let o={position:this.position.toArray(),rotation:[this.rotation.x*Gs.RAD2DEG,this.rotation.y*Gs.RAD2DEG,this.rotation.z*Gs.RAD2DEG],scale:this.scale.toArray(),hiddenMatrix:this.hiddenMatrix.toArray()};return ji(o,t)}getTransformValues(t,o,i){return o[t].map((a,s)=>i?.shared.getVariable(a,[this.uuid,t,kI[s]])??a)}updateTransformState(t,o){let i=!1;return t.position&&(this.position.fromArray(this.getTransformValues("position",t,o)),i=!0),t.rotation&&(Fp.fromArray(this.getTransformValues("rotation",t,o)).multiplyScalar(Gs.DEG2RAD),this.rotation.setFromVector3(Fp),i=!0),t.scale&&(this.scale.fromArray(this.getTransformValues("scale",t,o)),i=!0),t.hiddenMatrix!==void 0&&(i=!0,this.hiddenMatrix.fromArray(t.hiddenMatrix??ln.identity)),i&&(this.updateMatrix(),this.resetBBoxNeedsUpdate(),this.invalidateClonerTransform(this),this.traverseEntityAncestors(a=>{a.invalidateClonerTransform(this)})),t.position&&t.rotation&&t.scale&&t.hiddenMatrix!==void 0&&this.updateWorldMatrix(!1,!0),i}onVariableUpdate(t=!1){if(t){this.resetBBoxNeedsUpdate();return}this.updateMatrix(),this.resetBBoxNeedsUpdate(),this.invalidateClonerTransform(this),this.traverseEntityAncestors(o=>{o.invalidateClonerTransform(this)})}dispose(){this.disposed=!0,this.cloner&&(this.cloner.removeFromParent(),this.cloner=void 0)}disposeChildrenRecursively(){for(let t of this.children)Le.is(t)&&t.disposeRecursively()}disposeRecursively(){this.dispose(),this.children.forEach(t=>{Le.is(t)&&t.disposeRecursively()})}toState(t=[]){let o={name:this.name,visible:this.visible,raycastLock:this.raycastLock,...this.toObjectTransformState(t)};return ji(o,t)}updateByObjUpdateOp(t,o){t!==void 0&&this.updateByOp({type:0,props:t,path:[]},{...this.data,...t},o,!1)}updateByOp(t,o,i,a){let s=this.data;this.data=o;let l=t,c=Re(t.path,["states","*"]);if(c!==null){if(t.type===0){let[u]=c;if(this?.stateSelection===u){let p={...t.props};if(delete p.name,Object.values(t.props).some(d=>d===void 0)){let d=this.data;if(d!==void 0){let h=Ze.zoom(d,t.path.slice(2));if(h)for(let f in t.props)t.props[f]===void 0&&f in h&&(p[f]=h[f])}}l={...t,props:p,path:t.path.slice(2)}}}}else if(t.type===0){let u=this.stateSelection?this.data.states.data(this.stateSelection):void 0;if(u!==void 0){if(t.props.name!==void 0&&u.name){let{name:d,...h}=u;u=h}if(t.props.material!==void 0&&"material"in u){let{material:d,...h}=u;u=h}let p=Ze.removeOverridden(t.path,t.props,u);l={...t,props:p}}}if(this.updateByPatchedOpBase(l,Yn.patch(this.data,this.stateSelection?this.data.states.data(this.stateSelection):void 0),i),Re(t.path,["overrides"])){let u=[],p=[...t.path];for(u.push(p[1]),p.splice(0,2);p.length>0&&p[0]==="descendants";)u.push(p[1]),p.splice(0,2);if(u[u.length-1]===void 0){if(t.type===0)for(let d of Object.keys(t.props)){u[u.length-1]=d;let h=i.scene.findInstance([this.uuid,...u]);h&&(h.overrideData=t.props[d],h.updateState(Kr.apply(h.component.data,h.overrideData),i))}}else{let d=i.scene.findInstance([this.uuid,...u]);if(d){let h=Ze.zoom(d.component.data,p);if(t={...t,path:p},t.type===0){let f=t.props;if(h)for(let[m,y]of Object.entries(t.props))y===void 0&&(f===t.props&&(f={...t.props}),f[m]=h[m]);t={...t,props:f}}d.overrideData=ra.resolve(o.overrides,u),d.updateByOp(t,nt.applySimple(d.data,t),i,!1)}}}else if(this.instances.length>0){let u;if(t.path.length===0&&t.type===0){let p;for(let d of ro.rootOverrideProps)d in t.props&&(p===void 0&&(p={}),p[d]=t.props[d]);p&&(u={...t,props:p})}else for(let p of ro.rootOverrideProps)if(Re(t.path,[p])){u=t;break}u!==void 0&&this.instances.forEach(p=>{if(p.isInstanceRoot){let d=Kr.filterOp(p.overrideData,u);d&&p.updateByOp(d,nt.applySimple(p.data,d),i,!0)}}),this.instances.forEach(p=>{if(!p.isInstanceRoot){let d=Kr.filterOp(p.overrideData,t);if(d){let h;s===p.data&&t===d?h=o:h=nt.applySimple(p.data,d),p.updateByOp(d,h,i,!0)}}})}}updateByPatchedOpBase(t,o,i){if(this.dataPatched=o,t.path.length===0&&t.type===0)t.props.type!==void 0&&!Nr.is(t.props.type)&&Rr.changeEntityProptotype(this,o,i);else if(t.path.length===1&&t.path[0]==="geometry"&&t.type===0&&"type"in t.props){Rr.changeEntityProptotype(this,o,i);for(let a of this.children)Le.is(a)&&a.updateVisible(i.scene)}this.updateByPatchedOp(t,o,i)}updateByPatchedOp(t,o,i){if(t.path.length===0&&t.type===0&&this.updateState(t.props,i),t.path[0]==="morphTargetInfluences"&&t.type===0){let s=o.morphTargetInfluences.get(t.path[1])?.data.name;s&&this.updateMorphInfluences(s,i.shared.getVariable(t.props.value,[this.uuid,"morphTargetInfluences",s]))}if(Re(t.path,["pathSnapping"])!==null&&this.updatePathSnapping(o.pathSnapping),Re(t.path,["cloner"])!==null){let a=nt.drop(t,1);a.path.length===0&&a.type===0&&a.props.disabled===!0?this.setFromClonerState(null,i):this.cloner?this.cloner.updateState(o.cloner,i.scene):(this.setFromClonerState(o.cloner,i),this.expandCloner(i.scene)),this.updateVisible(i.scene)}}updatePathSnapping(t=this.dataPatched.pathSnapping){this._updatedPathSnapping=t,this._needApplyPathSnapping=!0}get updatedPathSnapping(){return this._updatedPathSnapping}applyPathSnapping(t){let o=this._updatedPathSnapping?.pathId??this.dataPatched.pathSnapping.pathId,i=this._updatedPathSnapping?.slide??this.dataPatched.pathSnapping.slide??0,a=this._updatedPathSnapping?.offset??this.dataPatched.pathSnapping.offset??0,s=this._updatedPathSnapping?.orientation??this.dataPatched.pathSnapping.orientation;if(o===null)return;let l=t.find(o);if(!l||this._needApplyPathSnapping===!1)return;this._needApplyPathSnapping=!1;let c=l.data;if(c.geometry.path.points.length<=1)return;let u=iu(c.geometry.path),p=(i+a)%1;i+a===1&&p===0&&(p=1);let d=null;try{d=u.curves.length?u.getPointAt(p):null}catch(y){!1&&(console.warn(`The aligned path on ${this.name} is invalid. (${l.name})`),console.error(y))}if(d===null)return;let h=this.parent?this.parent?.matrixWorld:new au;l.updateMatrixWorld();let f=new au().multiplyMatrices(h.clone().invert(),l.matrixWorld);d.applyMatrix4(f);let m={position:d.toArray(),rotation:c.rotation};if(s==="tangential"){let y=new au().extractRotation(l.matrixWorld),g=u.getTangentAt(p).applyMatrix4(y).add(d),v=new au().lookAt(d,g,UI),w=Fp.setFromEuler(new FI().setFromRotationMatrix(v)).multiplyScalar(Gs.RAD2DEG);m={...m,rotation:w.toArray()}}this.updateTransformState(m),this.traverseEntity(y=>{y._cameraType&&y.dispatchEvent(jI)})}updateVisible(t){if(this.visible=this.dataPatched.visible&&(!this.dataPatched.cloner||(this.dataPatched.cloner.disabled??!1)||this.dataPatched.cloner?.hideBase!==!0),!t)return;let o=!1;this.traverseEntity(i=>{if(i.data.type==="Splat")return o=!0,!0}),o&&t.reloadSplats()}updateState_Entity(t,o){t.name!==void 0&&(this.name=t.name),t.raycastLock!==void 0&&(this.raycastLock=t.raycastLock),t.visible!==void 0&&(this.updateVisible(o?.scene),this.resetBBoxNeedsUpdate()),o&&"cloner"in t&&t.cloner!==void 0&&(this.setFromClonerState(t.cloner,o),this.updateVisible(o.scene)),this.updateTransformState(t,o)}get attachedSurfaceCloners(){return this.children.filter(t=>t instanceof Rr.Cloner&&t.parameters.type==="toObject")}setFromClonerState(t,o){this.disposed||(t===null||t.disabled?(this.cloner&&this.cloner.removeFromParent(),this.cloner=void 0):this.cloner===void 0?(this.cloner=new Rr.Cloner(this,t),o.scene.addPendingExpandCloner(this)):this.cloner.updateState(t,o.scene))}expandCloner(t){!this.disposed&&this.cloner&&this.cloner.expandClones(t)}invalidateClonerTransform(t){this.cloner&&this.cloner.invalidateTransform(t)}requestRender(){this.dispatchEvent({type:"requestRender"})}};import{BufferGeometry as qI,ConeGeometry as $I,Float32BufferAttribute as YI,MathUtils as XI}from"three";import{BufferGeometry as Kx,CylinderGeometry as HI,Float32BufferAttribute as lu,MathUtils as WI,Vector2 as Vr,Vector3 as su}from"three";var Qx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:64,heightSegments:1,openEnded:!1,thetaStart:0,thetaLength:360,cornerRadius:8,cornerSegments:8,hollow:0},n.parameters);e.thetaLength=WI.clamp(e.thetaLength,0,360);let t=e.width/2,o=e.radiusTop??t,i=e.radiusBottom??t;return o===i?(o=t,i=t):o>i?(o=t,i=i*t/o):(o=o*t/i,i=t),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width),radiusTop:o,radiusBottom:i})}}static build(n){let{width:r,depth:e,height:t,radialSegments:o,heightSegments:i,openEnded:a,thetaStart:s,thetaLength:l,radiusTop:c,radiusBottom:u,cornerRadius:p,cornerSegments:d,hollow:h}=n.parameters,f;return l===0?(f=new Kx,f.setAttribute("position",new lu([],3))):p||h?f=new Fs(c,u,t,o,i,a,s,l*Math.PI/180,p,p,d,h):f=new HI(c,u,t,o,i,a,s,l*Math.PI/180),f.scale(1,1,e/r),Object.assign(f,{userData:{...n,type:"CylinderGeometry"}})}};function mn(n,r,e){e.x=n.x*r.x,e.y=n.y,e.z=n.x*r.y}function Xx(n){return new Vr(n.y,-n.x)}var Fs=class extends Kx{constructor(r,e,t,o,i,a,s,l,c,u,p,d,h=!1){super(),this.type="RoundedCylinderBufferGeometry",r=r!==void 0?r:1,e=e!==void 0?e:1,t=t||1,o=Math.floor(o)||8,i=Math.floor(i)||1,a=a!==void 0?a:!1,s=s!==void 0?s:0,l=l!==void 0?l:Math.PI*2,a&&(c=0,u=0);let f=[],m=[],y=[],g=[],v=0,w=t/2,O=new su,S=new su;h&&r==0&&(r=c),h&&e==0&&(e=u);let C=new Vr(r,w),T=new Vr(e,-w),x=null,N=null,E=null,M=null,D=C.clone().sub(T),_=0,B=0,V=0;d>0&&(_=Math.min(r,e)*(1-d),B=r-_,V=e-_);let k=C.clone();k.x-=_;let L=Math.PI-D.angle(),W=D.angle(),F=Math.tan(W/2),j=Math.tan(L/2),H=F+j,q=d?H:j,re=d?H:F;if(c=Math.min(c,(r-B)/q,D.length()/H),u=Math.min(u,(e-V)/re,D.length()/H),c>0){let Q=c/F;x=C.clone().sub(new Vr(Q,c)),d&&(E=x.clone(),E.x-=_-H*c),C.sub(D.clone().setLength(Q))}if(u>0){let Q=u/j;N=T.clone().sub(new Vr(Q,-u)),T.add(D.clone().setLength(Q)),d&&(M=N.clone(),M.x-=_-H*u,k.sub(D.clone().setLength(Q)))}D=C.clone().sub(T);let ee=D.length()<.5,X=[];for(let Q=0;Q<=o;Q++){let $=[],ue=Q/o,le=ue*l+s,ne=new Vr(Math.sin(le),Math.cos(le));M&&N?(te($,ue,ne,L,u,M,-1,!0),te($,ue,ne,W,u,N,-1,!1)):N?(K($,ne,N.x,0,-1),te($,ue,ne,W,u,N,-1,!1)):a||K($,ne,e,V,-1);let ce=Xx(D).normalize();if(mn(ce,ne,O),!ee)for(let ae=0;ae<=i;ae++){let me=ae/i,pe=D.clone().multiplyScalar(me).add(T);mn(pe,ne,S),m.push(S.x,S.y,S.z),y.push(O.x,O.y,O.z),g.push(ue,.5+S.y/t),$.push(v++)}if(E&&x?(te($,ue,ne,L,c,x,1,!1),te($,ue,ne,W,c,E,1,!0)):x?(te($,ue,ne,L,c,x,1,!1),K($,ne,x.x,0,1)):a||K($,ne,r,B,1),d&&!ee){let ae=Xx(D).multiplyScalar(-1).normalize();mn(ae,ne,O);for(let me=0;me<=i;me++){let pe=me/i,he=D.clone().multiplyScalar(-pe).add(k);mn(he,ne,S),m.push(S.x,S.y,S.z),y.push(O.x,O.y,O.z),g.push(ue,.5+S.y/t),$.push(v++)}}d&&!a&&$.push($[0]),X.push($)}for(let Q=0;Q<X.length-1;Q++)for(let $=0;$<X[0].length-1;$++){if(a&&d&&$==i)continue;let ue=X[Q][$],le=X[Q+1][$],ne=X[Q+1][$+1],ce=X[Q][$+1],ae=m[ne*3+0],me=m[ne*3+2];f.push(ue,le,ce),(ae!=0||me!=0)&&f.push(le,ne,ce)}l<Math.PI*2&&(Z(-1,X[0],s),Z(1,X[X.length-1],s+l)),this.setIndex(f),this.setAttribute("position",new lu(m,3)),this.setAttribute("normal",new lu(y,3)),this.setAttribute("uv",new lu(g,2));function te(Q,$,ue,le,ne,ce,ae,me){for(let pe=0;pe<p+1;pe++){let he=pe/p,xe=ae<0?he:1-he;me&&(xe-=1),xe*=le;let ye=new Vr(Math.sin(xe),Math.cos(xe)*ae),A=ye.clone().multiplyScalar(ne).add(ce);mn(A,ue,S),m.push(S.x,S.y,S.z),mn(ye,ue,O),y.push(O.x,O.y,O.z),g.push($,.5+S.y/t),Q.push(v++)}}function K(Q,$,ue,le,ne){let ce=new su,ae=new Vr,me=[ue,le];ne<0&&me.reverse();for(let pe of me)ae.set(pe,w*ne),mn(ae,$,ce),m.push(ce.x,ce.y,ce.z),y.push(0,ne,0),g.push(.5,.5),Q.push(v++)}function Z(Q,$,ue){let le=new Vr(Math.sin(ue),Math.cos(ue)),ne=new Vr(-Math.cos(ue),Math.sin(ue)),ce=new su,ae=Q<0?(he,xe,ye)=>f.push(he,xe,ye):(he,xe,ye)=>f.push(he,ye,xe),me=new Vr((r+e+B+V)/4,0);mn(me,le,ce),m.push(ce.x,ce.y,ce.z),y.push(ne.x,0,ne.y),g.push(.5,.5);let pe=v++;for(let he of $){let xe=m.slice(he*3,he*3+3);m.push(...xe),y.push(ne.x,0,ne.y);let ye=g.slice(he*2,he*2+2);g.push(...ye),v++}for(let he=pe+1;he<v-1;he++)ae(pe,he,he+1);ae(pe,v-1,pe+1)}}};var Zx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:32,heightSegments:8,openEnded:!1,thetaStart:0,thetaLength:360,cornerRadiusTop:8,cornerRadiusBottom:8,cornerSegments:8},n.parameters);return e.thetaLength=XI.clamp(e.thetaLength,0,360),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,depth:e,height:t,radialSegments:o,heightSegments:i,openEnded:a,thetaStart:s,thetaLength:l,cornerRadiusTop:c,cornerRadiusBottom:u,cornerSegments:p}=n.parameters,d;return l===0?(d=new qI,d.setAttribute("position",new YI([],3))):c>0||u>0||l<360?d=new Fs(0,r/2,t,o,i,a,s,l*Math.PI/180,c,u,p,0,!0):d=new $I(r/2,t,o,i,a),d.scale(1,1,e/r),Object.assign(d,{userData:{...n,type:"ConeGeometry"}})}};import{BoxGeometry as KI,BufferGeometry as QI,Float32BufferAttribute as jp,Vector3 as js}from"three";var Jx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,widthSegments:1,heightSegments:1,depthSegments:1,cornerRadius:8,cornerSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,widthSegments:o,heightSegments:i,depthSegments:a,cornerRadius:s,cornerSegments:l}=n.parameters,c;return s===0?c=new KI(r,e,t,o,i,a):c=new Up(r,e,t,o,i,a,s,l),Object.assign(c,{userData:{...n,type:"CubeGeometry"}})}},kp=Math.PI/2,Up=class extends QI{constructor(r=1,e=1,t=1,o=1,i=1,a=1,s=0,l=4){super(),this.type="BoxGeometry",o=Math.floor(o),i=Math.floor(i),a=Math.floor(a),l=Math.floor(l),s=Math.min(s,r/2,e/2,t/2);let c=[],u=[],p=[],d=[],h=0;f("z","y","x",-1,-1,t,e,r,a,i),f("z","y","x",1,-1,t,e,-r,a,i),f("x","z","y",1,1,r,t,e,o,a),f("x","z","y",1,-1,r,t,-e,o,a),f("x","y","z",1,-1,r,e,t,o,i),f("x","y","z",-1,-1,r,e,-t,o,i),s>0&&(m("z","y","x",-1,-1,1,t,e,r,a),m("z","y","x",1,-1,-1,t,e,r,a),m("z","y","x",-1,1,-1,t,e,r,a),m("z","y","x",1,1,1,t,e,r,a),m("x","y","z",-1,-1,-1,r,e,t,o),m("x","y","z",1,-1,1,r,e,t,o),m("x","y","z",-1,1,1,r,e,t,o),m("x","y","z",1,1,-1,r,e,t,o),m("y","x","z",-1,-1,1,e,r,t,i),m("y","x","z",1,-1,-1,e,r,t,i),m("y","x","z",1,1,1,e,r,t,i),m("y","x","z",-1,1,-1,e,r,t,i),y(1,1,1),y(-1,1,1),y(1,-1,1),y(-1,-1,1),y(1,1,-1),y(-1,1,-1),y(1,-1,-1),y(-1,-1,-1)),this.setIndex(c),this.setAttribute("position",new jp(u,3)),this.setAttribute("normal",new jp(p,3)),this.setAttribute("uv",new jp(d,2));function f(g,v,w,O,S,C,T,x,N,E){let M=(C-2*s)/N,D=(T-2*s)/E,_=C/2-s,B=T/2-s,V=x/2,k=N+1,L=E+1,W=0,F=new js;for(let j=0;j<L;j++){let H=j*D-B;for(let q=0;q<k;q++){let re=q*M-_;F[g]=re*O,F[v]=H*S,F[w]=V,u.push(F.x,F.y,F.z),F[g]=0,F[v]=0,F[w]=x>0?1:-1,p.push(F.x,F.y,F.z),d.push(q/N),d.push(1-j/E),W+=1}}for(let j=0;j<E;j++)for(let H=0;H<N;H++){let q=h+H+k*j,re=h+H+k*(j+1),ee=h+(H+1)+k*(j+1),X=h+(H+1)+k*j;c.push(q,re,X),c.push(re,ee,X)}h+=W}function m(g,v,w,O,S,C,T,x,N,E){let M=(T-2*s)/E,D=T/2-s,_=x/2-s,B=N/2,V=E+1,k=0,L=new js,W=new js;for(let F=0;F<l+1;F++){let j=F/l*kp,H=Math.sin(j)*s,q=(1-Math.cos(j))*s,re=Math.sin(j),ee=Math.cos(j);L[v]=(_+H)*S,L[w]=(B-q)*C,W[g]=0,W[v]=re*Math.sign(L[v]),W[w]=ee*Math.sign(L[w]);for(let X=0;X<V;X++){let te=X*M-D;L[g]=te*O,u.push(L.x,L.y,L.z),p.push(W.x,W.y,W.z),d.push(X/E),d.push(0),k+=1}}for(let F=0;F<l;F++)for(let j=0;j<E;j++){let H=h+j+V*F,q=h+j+V*(F+1),re=h+(j+1)+V*(F+1),ee=h+(j+1)+V*F;c.push(H,q,ee),c.push(q,re,ee)}h+=k}function y(g,v,w){let O=new js,S=new js(r/2,e/2,t/2);S.subScalar(s);let C=[],T=g*v*w>0?(N,E,M)=>c.push(N,E,M):(N,E,M)=>c.push(N,M,E);for(let N=0;N<=l;N++){let E=[],M=kp*(1-N/l),D=Math.cos(M),_=Math.sin(M),B=0;for(let V=0;V<=N;V++){let k=Math.cos(B),L=Math.sin(B);O.x=D*k,O.y=_,O.z=D*L;let W=S.clone().addScaledVector(O,s);u.push(g*W.x,v*W.y,w*W.z),p.push(g*O.x,v*O.y,w*O.z),d.push(0,0),E.push(h++),B+=kp/N}C.push(E)}let x=C.length-1;for(let N=0;N<x;N++){let E=C[N],M=C[N+1],D=E.length-1;T(E[0],M[1],M[0]);for(let _=1;_<=D;_++)T(E[_-1],E[_],M[_]),T(E[_],M[_+1],M[_])}}}};import{BufferGeometry as ZI,Float32BufferAttribute as Hp,Triangle as JI,Vector3 as Bo,Vector2 as Wp}from"three";var yn=class extends ZI{constructor(r=[],e=[],t="",o=1,i=.2,a=4){super(),this.type="PolyhedronGeometryRound";let s=[],l=[],c=[];u(),p(),this.setAttribute("position",new Hp(s,3)),this.setAttribute("normal",new Hp(c,3)),this.setAttribute("uv",new Hp(l,2));return;function u(){i=Math.min(1-1e-5,i),i==0&&(a=0);let h={IcosahedronGeometry:5,DodecahedronGeometry:3,HexahedronGeometry:3,OctahedronGeometry:4,TetrahedronGeometry:3}[t],f=new Bo,m=f.clone(),y=new JI,g=i*o,v=o-g,w=a+1,O=new Bo,S=(F,j)=>O.subVectors(F,j).normalize(),C=(F,j)=>Array(F).fill(void 0).map(j),T=C(r.length/3,(F,j)=>new Bo().fromArray(r,j*3).setLength(o)),x=[],N=1e6;for(let F=0;F<T.length;F++){let j=T[F],H=[],q,re,ee,X=1e10,te=-1;for(;(te=e.indexOf(F,te+1))!=-1;){let $=te-te%3;q=e[$+(te+1)%3],re=e[$+(te+2)%3],ee=j.distanceToSquared(T[q]),X=Math.min(X,ee),H.push([q,re,ee])}X+=1e-6;let K=[],Z=0,Q=H.length;for(let $=0;$<Q;$++){[q,re,ee]=H[Z];let ue=x[q]?.includes(F)==!0;ee<=X&&K.push(q+ +ue*N),Z=H.findIndex(le=>le[0]==re)}x.push(K)}let E=[];{let F=0,j=0,H,q,re=h==3;for(let ee=0;ee<=a;ee++){H=ee*(ee+1)/2,q=(ee+1)*(ee+2)/2;for(let X=0;X<a-ee;X++)[F,j]=[H+X+ee+2,q+X+ee+3],E.push(H,q,...re?[j,H]:[F,q],j,F),[H,q]=[F,j];E.push(H,q,H+a+2)}}let M=f.clone(),D=f.clone(),_=f.clone(),B=f.clone(),V=f.clone(),k=[],L=C(T.length,()=>C(h,()=>f.clone()));for(let F=0;F<T.length;F++){f.copy(T[F]).normalize(),M.copy(f).multiplyScalar(v);let j=x[F];for(let K=0;K<j.length;K++){let Z=j[K],Q=j[(K+1)%h];y.setFromPointsAndIndices(T,F,Z%N,Q%N),y.b.sub(y.a).setLength(1e10).add(y.a),y.c.sub(y.a).setLength(1e10).add(y.a),y.closestPointToPoint(M,L[F][K])}let H=[],q=[],re=[],ee=new Bo;a==0&&[...L[F]].reduce((K,Z)=>K.add(Z),ee).multiplyScalar(1/h);for(let K=0;K<h;K++){let Z=[],Q=(K-1+h)%h,$=L[F][Q],ue=L[F][K];f.copy($).sub(M),m.copy(ue).sub(M);let le=M.angleTo(f),ne=f.angleTo(m),ce=Math.cos(le)*g;a==0?D.copy(ee):D.copy(M).setLength(v+ce),q.push(ce);let ae=[D,$,ue];for(let me=0;me<2;me++){let pe=ae[me],he=ae[me+1];B.subVectors(pe,M),V.subVectors(he,M),_.crossVectors(B,V).normalize();for(let xe=0;xe<w;xe++){let ye=[le,ne][me]*xe/w;f.copy(B).applyAxisAngle(_,ye).add(M),H.push(f.clone()),me&&(S(f,M),Z.push([xe==0?pe:f.clone(),O.clone()]))}me&&(S(he,M),Z.push([he,O.clone()]))}re.push(Z)}k.push(re);let X=2*w,te=2;for(let K=0;K<h;K++){let Z=X*K,Q=X*((K+1)%h),$=[H[Z]];for(let le=1;le<w;le++){B=H[Z+le],V=H[Q+le],$.push(B);for(let ne=1,ce=le-te+1;ne<=ce;ne++)f.lerpVectors(B,V,ne/(ce+1)),f.sub(M).setLength(q[K]).add(M),$.push(f.clone());$.push(V)}for(let le=0;le<w;le++)$.push(H[le+w+Z]);$.push(H[Q+w]);let ue=E.map(le=>$[le]);s.push(...ue.map(le=>[le.x,le.y,le.z]).flat()),c.push(...ue.map(le=>(S(le,M),[O.x,O.y,O.z])).flat())}}let W=[];for(let F=0;F<x.length;F++)for(let j=0;j<h;j++){let H=x[F][j];if(H<N){let q=x[H].findIndex(X=>X%N==F),re=k[F][j],ee=k[H][q];for(let X=0;X<w;X++){let te=re[X],K=ee[w-X],Z=re[X+1],Q=ee[w-(X+1)];[te,K,Z,Z,K,Q].forEach($=>{s.push($[0].x,$[0].y,$[0].z),c.push($[1].x,$[1].y,$[1].z)})}W.push(re[0][0],ee[w][0],re[w][0],ee[0][0])}}for(;W.length;){let F,j,H,q;[F,j]=W.splice(0,2);let re=[F];for(;F!=j;)re.push(j),H=W.indexOf(j),q=H%2,j=W.splice(H-q,2)[1-q];O.subVectors(re[0],re[1]).cross(f.subVectors(re[0],re[2])).normalize();let ee=O.dot(re[0])<0;ee&&O.negate();for(let X=1;X<=re.length-2;X++)[re[X+ +ee],re[X+1-+ee],re[0]].forEach(te=>{s.push(te.x,te.y,te.z),c.push(O.x,O.y,O.z)})}}function p(){let d=new Bo;for(let T=0;T<s.length;T+=3){d.x=s[T+0],d.y=s[T+1],d.z=s[T+2];let x=S(d)/2/Math.PI+.5,N=C(d)/Math.PI+.5;l.push(x,1-N)}let h=new Bo,f=new Bo,m=new Bo,y=new Bo,g=new Wp,v=new Wp,w=new Wp,O=(T,x,N,E)=>{E<0&&T.x===1&&(l[x]=T.x-1),N.x===0&&N.z===0&&(l[x]=E/2/Math.PI+.5)};for(let T=0,x=0;T<s.length;T+=9,x+=6){h.set(s[T+0],s[T+1],s[T+2]),f.set(s[T+3],s[T+4],s[T+5]),m.set(s[T+6],s[T+7],s[T+8]),g.set(l[x+0],l[x+1]),v.set(l[x+2],l[x+3]),w.set(l[x+4],l[x+5]),y.copy(h).add(f).add(m).divideScalar(3);let N=S(y);O(g,x+0,h,N),O(v,x+2,f,N),O(w,x+4,m,N)}for(let T=0;T<l.length;T+=6){let x=l[T+0],N=l[T+2],E=l[T+4],M=Math.max(x,N,E),D=Math.min(x,N,E);M>.9&&D<.1&&(x<.2&&(l[T+0]+=1),N<.2&&(l[T+2]+=1),E<.2&&(l[T+4]+=1))}function S(T){return Math.atan2(T.z,-T.x)}function C(T){return Math.atan2(-T.y,Math.sqrt(T.x*T.x+T.z*T.z))}}}static fromJSON(r){return new yn(r.vertices,r.indices,r.radius,r.corner,r.cornerSides)}};import{DodecahedronGeometry as eM}from"three";var e0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,detail:0,corner:0,cornerSides:4},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,detail:o,corner:i,cornerSides:a}=n.parameters,s=o===0&&i!==0?new ks(r*.5,i,a):new eM(r*.5,o);return s.scale(1,e/r,t/r),Object.assign(s,{userData:{...n,type:"DodecahedronGeometry"}})}},ks=class extends yn{constructor(r=1,e=.2,t=4){let o=(1+Math.sqrt(5))/2,i=1/o,a=[-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-o,0,-i,o,0,i,-o,0,i,o,-i,-o,0,-i,o,0,i,-o,0,i,o,0,-o,0,-i,o,0,-i,-o,0,i,o,0,i],s=[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],l="DodecahedronGeometry";super(a,s,l,r,e,t),this.type=l}static fromJSON(r){return new ks(r.radius,r.corner,r.cornerSides)}};import{Plane as dM,Shape as m0,Vector2 as Ro,Vector3 as pM,MathUtils as Zp,LineCurve as Jp,QuadraticBezierCurve as y0,CubicBezierCurve as pu}from"three";import{CubicBezierCurve as cu,EllipseCurve as tM,LineCurve as uu,LineCurve3 as rM,MathUtils as oM,QuadraticBezierCurve as $p,SplineCurve as nM,Vector2 as Ht,Vector3 as o0}from"three";var Us=1e-12,ha=class{constructor(r){this.position=new Ht;this.startPosition=new Ht;this.uuid=oM.generateUUID();this.position=r.clone()}start(){this.reset()}reset(){this.startPosition.copy(this.position)}applyOffset(r){this.position.copy(this.startPosition).add(r)}copy(r){return this.position.copy(r.position),this.startPosition.copy(r.startPosition),this}clone(){return new ha(this.position).copy(this)}toJSON(){return[this.position.x,this.position.y]}},ma=class extends ha{constructor(e){super(e.position);this.parent=e}copy(e){return super.copy(e),this}clone(){return new ma(this.parent).copy(this)}},zr=class extends ha{constructor(e,t){super(t);this.controls=[];this.roundness=0;this.areControlsDirectionsMirrored=!0;this.uuid=e,this.controls.push(new ma(this),new ma(this))}static create(e,t){let o=new zr(e,new Ht(...t.position));return o.controls[0].position.set(...t.controlPrevious.position),o.controls[1].position.set(...t.controlNext.position),o.roundness=t.roundness,o.areControlsDirectionsMirrored=t.areControlsDirectionsMirrored,o}getOppositeControl(e){let t=this.controls.indexOf(e);return t===0?this.controls[1]:t===1?this.controls[0]:null}applyOffsetToControls(e,t=1){for(let o=0,i=this.controls.length;o<i;o++){let a=this.controls[o];this.position.distanceTo(a.position)<=t?a.position.copy(this.position):a.applyOffset(e)}}controlsMoved(){return!(this.position.equals(this.controls[0].position)&&this.position.equals(this.controls[1].position))}copy(e){return super.copy(e),this.controls[0].copy(e.controls[0]),this.controls[1].copy(e.controls[1]),this.roundness=e.roundness,this.uuid=e.uuid,this}clone(){return new zr(this.uuid,this.position).copy(this)}toJSON(){return super.toJSON().concat(this.controls[0].toJSON(),this.controls[1].toJSON(),[this.roundness])}computeTangents(){let e=this.curveBefore?.getTangentAt(1),t=this.curveAfter?.getTangentAt(0);return[e,t]}computeNormals(e=new Ht,t=new Ht){let[o,i]=this.computeTangents();return o&&i&&(t0(o,e),t0(i,t)),[e,t]}computeTangent(e=new Ht){let[t,o]=this.computeTangents();return t&&o&&e.copy(t).add(o).normalize(),e}computeNormal(e=new Ht){let[t,o]=this.computeNormals();return e.copy(t).add(o).normalize(),e}};function t0(n,r=new Ht){let e=n.length();return r.set(-n.y/e,n.x/e)}var Yp=n=>n,ya=new Ht,du=new Ht,iM=new Ht,aM=new Ht,sM=new Ht,lM=new Ht,n0=new o0,i0=new o0;function a0(n){let r=new Ht;r.addVectors(n.v0,ya.subVectors(n.v1,n.v0).multiplyScalar(2/3));let e=new Ht;return e.addVectors(n.v2,du.subVectors(n.v1,n.v2).multiplyScalar(2/3)),new cu(n.v0,r,e,n.v2)}function Hs(n,r,e=Number.EPSILON){return Math.abs(n-r)<e}function cM(n,r,e=Number.EPSILON){return n.distanceTo(r)<e}function uM(n,r,e=Number.EPSILON){return n.distanceTo(r)<e}function Xp(n,r,e){let t=Math.sqrt(Math.pow(r.x-n.x,2)+Math.pow(r.y-n.y,2)),o=Math.sqrt(Math.pow(r.x-e.x,2)+Math.pow(r.y-e.y,2)),i=Math.sqrt(Math.pow(e.x-n.x,2)+Math.pow(e.y-n.y,2));return Math.acos((o*o+t*t-i*i)/(2*o*t))}function s0(n,r,e){return r0(n,r)&&r0(r,e)&&qp(n.position,r.position,e.position)}function qp(n,r,e){return ya.copy(r).sub(n).cross(du.copy(e).sub(n))===0}function l0(n,r,e,t,o){let i=Math.sqrt(Math.pow(r.x-n.x,2)+Math.pow(r.y-n.y,2)),a=(n.y+r.y)/2,s=(n.x+r.x)/2,l=Math.sqrt(Math.pow(e,2)-Math.pow(i/2,2))*(n.y-r.y)/i,c=Math.sqrt(Math.pow(e,2)-Math.pow(i/2,2))*(r.x-n.x)/i;return t.set(s+l,a+c),o.set(s-l,a-c),[t,o]}function c0(n,r,e){let t=n.distanceTo(e),o=r.distanceTo(e);return t<o?r:n}function u0(n,r,e,t,o,i){let a=r.x-n.x,s=r.y-n.y,l=e.x-n.x,c=e.y-n.y,u=Math.sqrt((a+l)*(a+l)+(s+c)*(s+c)),p;return Xp(r,n,e)>Math.PI&&(u*=-1),Hs(c,s)?p=(s+c)*(t/u-.5)*8/3/(a-l):p=(a+l)*(t/u-.5)*8/3/(c-s),o.set(r.x-p*s,r.y+p*a),i.set(e.x+p*c,e.y-p*l),[o,i]}function Kp(n,r){return n.position.equals(n.controls[1].position)&&r.position.equals(r.controls[0].position)}function r0(n,r){return qp(n.position,n.controls[1].position,r.position)&&qp(n.position,r.controls[0].position,r.position)}function d0(n,r,e,t,o=.5){let i=ya.subVectors(r,n).multiplyScalar(o).add(n),a=du.subVectors(e,r).multiplyScalar(o).add(r),s=iM.subVectors(t,e).multiplyScalar(o).add(e),l=i,c=aM.subVectors(a,i).multiplyScalar(o).add(i),u=sM.subVectors(s,a).multiplyScalar(o).add(a),p=s,d=lM.subVectors(u,c).multiplyScalar(o).add(c);return[n.x,n.y,l.x,l.y,c.x,c.y,d.x,d.y,u.x,u.y,p.x,p.y,t.x,t.y]}function p0(n,r,e=12,t=!0){let o=i0.set(0,0,0),i,a=0,s=[];for(let l=0;l<r.length;l++){let c=Yp(r[l]),u=ya,p=gn(c,e);s.push(p);for(let d=0;d<=p;d++)if(c instanceof cu||c instanceof $p||c instanceof uu){if(c.getPoint(d/p,u),o.set(u.x,u.y,0),i!==void 0&&uM(i,o))continue;i===void 0&&(i=n0),i.copy(o),n.setXYZ(a,o.x,o.y,o.z),a++}}return t&&a>1&&!(n.getX(a-1)===n.getX(0)&&n.getY(a-1)===n.getY(0)&&n.getZ(a-1)===n.getZ(0))&&(n.setXYZ(a,n.getX(0),n.getY(0),n.getZ(0)),a++),n}function f0(n,r,e,t=12,o=!0){let i=i0.set(0,0,0),a=0,s=[];for(let l=0;l<r.length;l++){if(e[l]===!1)continue;let c,u=Yp(r[l]),p=ya,d=gn(u,t);s.push(d);for(let h=0;h<=d;h++)if(u instanceof cu||u instanceof $p||u instanceof uu){if(u.getPoint(h/d,p),i.set(p.x,p.y,0),c?.equals(i))continue;c===void 0?c=n0:(n.setXYZ(a,c.x,c.y,c.z),a++,n.setXYZ(a,i.x,i.y,i.z),a++),c.copy(i)}}return o&&a>1&&!(n.getX(a-1)===n.getX(0)&&n.getY(a-1)===n.getY(0)&&n.getZ(a-1)===n.getZ(0))&&(n.setXYZ(a,n.getX(0),n.getY(0),n.getZ(0)),a++),s}function Qp(n,r=12,e=!1){let t=[];for(let o=0,i=n.length;o<i;o++){let a=n[o],s=0;if(e&&a.roundedCurveCorner!==void 0){let l=gn(a.roundedCurveCorner,r)*.5;o>0&&(t[o-1]+=l),s+=l}a.curveAfter!==void 0&&(s+=gn(a.curveAfter,r)),t.push(s)}return n.length>0&&e&&n[0].roundedCurveCorner!==void 0&&(t[n.length-1]+=gn(n[0].roundedCurveCorner,r)*.5),t}function gn(n,r=12){return n&&n instanceof tM?r*2:n&&(n instanceof uu||n instanceof rM)?1:n&&n instanceof nM?r*n.points.length:r}function h0(n,r,e=12,t=!0){let o,i=0;for(let a=0;a<r.length;a++){let s=Yp(r[a]),l=gn(s,e),c=ya;for(let u=0;u<=l;u++)if(s instanceof cu||s instanceof $p||s instanceof uu){if(s.getPoint(u/l,c),o!==void 0&&cM(o,c,Us))continue;o===void 0&&(o=du),o.copy(c),n.push(c.x,c.y),i++}}return Hs(n[0],n[n.length-2],Us)&&Hs(n[1],n[n.length-1],Us)&&(n.pop(),n.pop()),t&&i>1&&!(Hs(n[i-1],n[1],Us)&&Hs(n[i-2],n[0],Us))&&(n.push(n[0],n[1]),i++),n}var ef=new Ro,fM=new Ro,hM=new Ro,mM=new Ro,yM=new Ro,gM=new Ro,je=class extends m0{constructor(e=100,t=100){super();this.points=[];this.shapeHoles=[];this.plane=new dM(new pM(0,0,-1));this.subdivision=0;this.controlSnapDistance=4;this.pointIDs=0;this.isMesh2D=!1;this.isText=!1;this._roundness=0;this.isClosed=!1;this.useCubicForRoundedCorners=!0;this.uuid=Zp.generateUUID();this.needsUpdate=!1;this.roundedCurves=[];this._width=e,this._height=t}static createFromState(e,t,o){let i=new je;return i.isClosed=e.isClosed,i.points=e.points.map(a=>zr.create(a.id,a.data)),typeof e.roundness=="number"&&(i.roundness=e.roundness),i.shapeHoles=e.shapeHoles.map(a=>je.createFromState(a)),t!==void 0&&o!==void 0&&i.applySize(t,o),i.update(),i}get width(){return this._width}get height(){return this._height}get roundness(){return this._roundness}set roundness(e){if(this._roundness!==e){this._roundness=e;for(let t=0,o=this.points.length;t<o;t++)this.points[t].roundness=e;this.needsUpdate=!0}}getPointsIndexesByIds(e){return e.map(t=>this.getPointIndexById(t)).filter(t=>t>=0)}getPointIndexById(e){let t=this.points.length,o=this.points.findIndex(i=>i.uuid===e);if(o<0){let i=t;for(let a=0,s=this.shapeHoles.length;a<s;a++){let l=this.shapeHoles[a],c=l.points.length,u=l.getPointIndexById(e);if(u<0)i+=c;else return u+i}}return o}getLineIndexById(e){return this.getPointIndexById(e)}getBezierPoint(e){if(e<=this.points.length-1)return this.points[e];if(this.shapeHoles.length>0){let t=this.points.length;for(let o=0,i=this.shapeHoles.length;o<i;o++){let a=this.shapeHoles[o],s=e-t;if(s<=a.points.length-1)return a.points[s];t+=a.points.length}}throw new Error("This shape does not have a point for this index: "+e)}getBezierPointIndex(e){let t=this.points.indexOf(e);if(t>=0)return t;if(t=this.points.length,this.shapeHoles.length>0)for(let o=0,i=this.shapeHoles.length;o<i;o++){let a=this.shapeHoles[o],s=a.points.indexOf(e);if(s>=0)return t+s;t+=a.points.length}return-1}getAllPoints(){let e=[].concat(...this.shapeHoles.map(t=>t.points));return[...this.points,...e]}applySize(e,t){e===0&&(e=.001),t===0&&(t=.001),this._width=e,this._height=t}applyScale(e,t){let o=ef.set(e,t);for(let i=0,a=this.points.length;i<a;i++){let s=this.points[i];s.position.multiply(o),s.controls[0].position.multiply(o),s.controls[1].position.multiply(o)}for(let i=0,a=this.shapeHoles.length;i<a;i++)this.shapeHoles[i].applyScale(e,t);this._update()}createPoint(e,t=0,o=Zp.generateUUID()){let i;e instanceof Ro?i=e:i=new Ro(e,t);let a=new zr(o,i);return a.roundness=this.roundness,a}addPoint(e){this.points.push(e),this.needsUpdate=!0}addPointAt(e,t){this.points.splice(t,0,e),this.needsUpdate=!0}getPointByUuid(e){for(let t=0,o=this.points.length;t<o;t++){let i=this.points[t];if(i.uuid===e)return i}for(let t=0,o=this.shapeHoles.length;t<o;t++){let a=this.shapeHoles[t].getPointByUuid(e);if(a)return a}}getFirstPoint(){return this.points[0]}getLastPoint(){return this.points[this.points.length-1]}removePoint(e){let t=this.points.indexOf(e);t>=0&&this.points.splice(t,1),this.needsUpdate=!0}removePointById(e){let t=this.points.find(o=>o.uuid===e);t&&this.removePoint(t)}update(){for(let e=0,t=this.shapeHoles.length;e<t;e++)this.shapeHoles[e].update();this._update()}extractShapePointsToBuffer(e,t=12,o=!1){this.subdivision=t,this.curveDivisions===void 0&&this.computeCurveDivisions(t);let i=o?this.roundedCurveDivisions:this.curveDivisions;return p0(e,o?this.roundedCurves:this.curves,t,this.autoClose),i.reduce((a,s)=>a+s,0)+1}computeCurveDivisions(e=12){return this.curveDivisions=Qp(this.points,e,!1),this.roundedCurveDivisions=Qp(this.points,e,!0),this.curveDivisions}extractFilteredShapePointsToBuffer(e,t,o=12){return f0(e,this.curves,t,o,this.autoClose).reduce((a,s)=>a+s,0)*2}extractShapePointsToFlatArray(e,t=12){return this.subdivision=t,this.curveDivisions===void 0&&this.computeCurveDivisions(t),h0(e,this.roundedCurves,t,this.autoClose)}getCurveIndexFromVertexId(e,t=!1){let o=0;this.curveDivisions===void 0&&this.computeCurveDivisions(this.subdivision);let i=t?this.roundedCurveDivisions:this.curveDivisions,a=0;t&&this.points[0].roundedCurveCorner!==void 0&&(a=gn(this.points[0].roundedCurveCorner,this.subdivision)*.5);let s=e-a;s<0&&(s+=i.reduce((l,c)=>l+c,0));for(let l=0,c=i.length;l<c;l++){let u=i[l];if(s<o+u)return[l,(s-o+1)/u];o+=u}return[0,1]}getCurveT(e,t,o){let i=this.points[e],a=this.points[e>=this.points.length-1?0:e+1],s=this.curveDivisions,l=s[e];if(Kp(i,a)){let p=i.position.distanceTo(a.position);return i.position.distanceTo(ef.set(o.x,o.y))/p}let c=0;for(let p=0;p<e;p++)c+=s[p];return(t-c)/l}dispose(){}_applyCurveForPoint(e,t){Kp(t,e)?this.lineTo(e.position.x,e.position.y):this.bezierCurveTo(t.controls[1].position.x,t.controls[1].position.y,e.controls[0].position.x,e.controls[0].position.y,e.position.x,e.position.y);let o=this.curves[this.curves.length-1];e.curveBefore=o,t.curveAfter=o;let i=o.clone();e.roundedCurveBefore=i,t.roundedCurveAfter=i,e.roundedCurveCorner=void 0,this.roundedCurves.push(i)}_update(){if(this.curves=[],this.roundedCurves=[],!this.points.length)return;for(let t=0,o=this.points.length;t<o;t++){let i=this.points[t];if(t===0)this.moveTo(i.position.x,i.position.y);else{let a=this.points[t-1];this._applyCurveForPoint(i,a)}}let e=this.getLastPoint();if(e?.curveAfter&&(e.curveAfter=void 0),this.isClosed){let t=this.points[0],o=this.points[this.points.length-1];this._applyCurveForPoint(t,o)}if(this.points.length>2){let t=0;for(let o=0,i=this.points.length;o<i;o++){let a=this.points[o],s=this.points[o-1]??this.points[this.points.length-1],l=this.points[o+1]??this.points[0],c=a.roundness,u=s&&l&&s0(s,a,l);if(!a.controlsMoved()&&c>0&&!u){let p=a.curveBefore,d=a.curveAfter;if(p===void 0||d===void 0)continue;let h=a.roundedCurveBefore,f=a.roundedCurveAfter,m=p.getLength(),y=d.getLength(),g=Math.min(c,m*.499),v=Math.min(c,y*.499),w=Math.min(g,v),O=1-w/m,S=w/y,C=p.getPointAt(O,ef),T=d.getPointAt(S,fM);this._subSplitCurve(p,h,O,C,void 0),this._subSplitCurve(d,f,S,void 0,T);let x;if(this.useCubicForRoundedCorners){let N=Xp(C,a.position,T)/2,E=Math.tan(N)*C.distanceTo(a.position),[M,D]=l0(C,T,E,hM,mM),_=c0(M,D,a.position),[B,V]=u0(_,C,T,E,yM,gM);x=new pu(C.clone(),B.clone(),V.clone(),T.clone())}else x=new y0(C.clone(),a.position.clone(),T.clone());a.roundedCurveCorner=x,this.roundedCurves.splice(o+t,0,x),t++}}}}_subSplitCurve(e,t,o,i,a){if(e instanceof Jp)i!==void 0&&t.v2.copy(i),a!==void 0&&t.v1.copy(a);else{let s=e,l=t,c=s.getUtoTmapping(o,0),u=d0(s.v0,s.v1,s.v2,s.v3,c);return i!==void 0&&(l.v0.set(u[0],u[1]),l.v1.set(u[2],u[3]),l.v2.set(u[4],u[5]),l.v3.set(u[6],u[7])),a!==void 0&&(l.v0.set(u[6],u[7]),l.v1.set(u[8],u[9]),l.v2.set(u[10],u[11]),l.v3.set(u[12],u[13])),l}return t}clone(){let e=new je(this._width,this._height);return e.points=this.points.map(t=>t.clone()),e.isClosed=this.isClosed,e.roundness=this.roundness,e.isMesh2D=this.isMesh2D,e.shapeHoles=this.shapeHoles.map(t=>t.clone()),e}toJSON(){return{points:this.points.reduce((e,t)=>e.concat(t.toJSON()),[]),shapeHoles:this.shapeHoles.map(e=>e.toJSON()),isClosed:this.isClosed,roundness:this.roundness}}fromJSON(e){this.points=[],this.pointIDs=0;let t=e.points.length/7;for(let o=0;o<t;o++){let i=o*7,a=e.points[i+0],s=e.points[i+1],l=e.points[i+2],c=e.points[i+3],u=e.points[i+4],p=e.points[i+5],d=e.points[i+6],h=new zr(Zp.generateUUID(),new Ro(a,s));h.controls[0].position.set(l,c),h.controls[1].position.set(u,p),h.roundness=d,this.points.push(h)}return this.shapeHoles=e.shapeHoles?.length?e.shapeHoles.map(o=>{let i=new je;return i.fromJSON(o),i}):[],this.isClosed=e.isClosed,this._roundness=e.roundness,this._update(),this}fromShape(e,t=!1){this.isText=t;let o=(a,s)=>{s instanceof pu&&s.v3.equals(a.position)&&a.controls[0].position.copy(s.v2)},i=a=>{let s=[],l,c;for(l=0,c=a.length;l<c;l++)a[l]instanceof y0&&(a[l]=a0(a[l]));for(l=0,c=a.length;l<c;l++){let d=a[l],h=l>0?a[l-1]:null,f;d instanceof pu?(f=this.createPoint(d.v0),f.controls[1].position.copy(d.v1)):d instanceof Jp&&(f=this.createPoint(d.v1)),f!==void 0&&(h!==null&&o(f,h),s.push(f))}let u=a[a.length-1],p=!1;return u instanceof pu?u.v3.equals(s[0].position)&&(s[0].controls[0].position.copy(u.v2),p=!0):u instanceof Jp&&u.v2.equals(s[0].position)&&(p=!0),this.isClosed=p,s};return this.points=i(e.curves),e instanceof m0&&(this.shapeHoles=e.holes.map(a=>{let s=new je;return s.fromShape(a),s})),this.update(),this}updatePoint(e,t){let o=this.getPointByUuid(e);o&&(t.position!==void 0&&o.position.fromArray(t.position),t.roundness!==void 0&&(o.roundness=t.roundness),t.areControlsDirectionsMirrored!==void 0&&(o.areControlsDirectionsMirrored=t.areControlsDirectionsMirrored),this.needsUpdate=!0)}updatePreviousControl(e,t){let i=this.getPointByUuid(e)?.controls[0];i&&(t.position&&i.position.fromArray(t.position),this.needsUpdate=!0)}updateNextControl(e,t){let i=this.getPointByUuid(e)?.controls[1];i&&(t.position&&i.position.fromArray(t.position),this.needsUpdate=!0)}};var rf=Math.PI*2;function tf({x:n,y:r},e,t,o,i){return{x:n*e+o,y:r*t+i}}function xM(n,r){let e=r===1.5707963267948966?.551915024494:r===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(r/4),t=Math.cos(n),o=Math.sin(n),i=Math.cos(n+r),a=Math.sin(n+r);return[{x:t-o*e,y:o+t*e},{x:i+a*e,y:a-i*e},{x:i,y:a}]}function g0(n,r,e,t){let o=n*t-r*e<0?-1:1,i=Math.min(1,Math.max(-1,n*e+r*t));return o*Math.acos(i)}function bM(n,r,e,t,o,i,a,s,l,c){let u=Math.pow(o,2),p=Math.pow(i,2),d=Math.pow(a,2),h=Math.pow(s,2),f=u*p-u*h-p*d;f<0&&(f=0),f/=u*h+p*d,f=Math.sqrt(f)*(l===c?-1:1);let m=f*o/i*s,y=f*-i/o*a,g=m+(n+e)/2,v=y+(r+t)/2,w=(a-m)/o,O=(s-y)/i,S=(-a-m)/o,C=(-s-y)/i,T=g0(1,0,w,O),x=g0(w,O,S,C);return!c&&x>0&&(x-=rf),c&&x<0&&(x+=rf),{centerx:g,centery:v,ang1:T,ang2:x}}function x0({px:n,py:r,cx:e,cy:t,rx:o,ry:i,largeArcFlag:a,sweepFlag:s}){let l=[];if(o===0||i===0)return[];let c=(n-e)/2,u=(r-t)/2;if(c===0&&u===0)return[];o=Math.abs(o),i=Math.abs(i);let p=Math.pow(c,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(i,2);p>1&&(o*=Math.sqrt(p),i*=Math.sqrt(p));let d=bM(n,r,e,t,o,i,c,u,a,s),{ang1:h,ang2:f}=d,{centerx:m,centery:y}=d,g=Math.abs(f)/(rf/4);Math.abs(1-g)<1e-7&&(g=1);let v=Math.max(Math.ceil(g),1);f/=v;for(let w=0;w<v;w++)l.push(xM(h,f)),h+=f;return l.map(w=>{let{x:O,y:S}=tf(w[0],o,i,m,y),{x:C,y:T}=tf(w[1],o,i,m,y),{x,y:N}=tf(w[2],o,i,m,y);return{x1:O,y1:S,x2:C,y2:T,x,y:N}})}import{BufferAttribute as gu,BufferGeometry as EM}from"three";var Ge;(function(n){n[n.ODD=0]="ODD",n[n.NONZERO=1]="NONZERO",n[n.POSITIVE=2]="POSITIVE",n[n.NEGATIVE=3]="NEGATIVE",n[n.ABS_GEQ_TWO=4]="ABS_GEQ_TWO"})(Ge||(Ge={}));var at;(function(n){n[n.POLYGONS=0]="POLYGONS",n[n.CONNECTED_POLYGONS=1]="CONNECTED_POLYGONS",n[n.BOUNDARY_CONTOURS=2]="BOUNDARY_CONTOURS"})(at||(at={}));function we(n,r){if(!n)throw r||"Assertion Failed!"}var ve=function(){function n(){}return n.vertEq=function(r,e){return r.s===e.s&&r.t===e.t},n.vertLeq=function(r,e){return r.s<e.s||r.s===e.s&&r.t<=e.t},n.transLeq=function(r,e){return r.t<e.t||r.t===e.t&&r.s<=e.s},n.edgeGoesLeft=function(r){return n.vertLeq(r.Dst,r.Org)},n.edgeGoesRight=function(r){return n.vertLeq(r.Org,r.Dst)},n.vertL1dist=function(r,e){return Math.abs(r.s-e.s)+Math.abs(r.t-e.t)},n.edgeEval=function(r,e,t){we(n.vertLeq(r,e)&&n.vertLeq(e,t));var o=e.s-r.s,i=t.s-e.s;return o+i>0?o<i?e.t-r.t+(r.t-t.t)*(o/(o+i)):e.t-t.t+(t.t-r.t)*(i/(o+i)):0},n.edgeSign=function(r,e,t){we(n.vertLeq(r,e)&&n.vertLeq(e,t));var o=e.s-r.s,i=t.s-e.s;return o+i>0?(e.t-t.t)*o+(e.t-r.t)*i:0},n.transEval=function(r,e,t){we(n.transLeq(r,e)&&n.transLeq(e,t));var o=e.t-r.t,i=t.t-e.t;return o+i>0?o<i?e.s-r.s+(r.s-t.s)*(o/(o+i)):e.s-t.s+(t.s-r.s)*(i/(o+i)):0},n.transSign=function(r,e,t){we(n.transLeq(r,e)&&n.transLeq(e,t));var o=e.t-r.t,i=t.t-e.t;return o+i>0?(e.s-t.s)*o+(e.s-r.s)*i:0},n.vertCCW=function(r,e,t){return r.s*(e.t-t.t)+e.s*(t.t-r.t)+t.s*(r.t-e.t)>=0},n.interpolate=function(r,e,t,o){return r=r<0?0:r,t=t<0?0:t,r<=t?t===0?(e+o)/2:e+(o-e)*(r/(r+t)):o+(e-o)*(t/(r+t))},n.intersect=function(r,e,t,o,i){var a,s,l;n.vertLeq(r,e)||(l=r,r=e,e=l),n.vertLeq(t,o)||(l=t,t=o,o=l),n.vertLeq(r,t)||(l=r,r=t,t=l,l=e,e=o,o=l),n.vertLeq(t,e)?n.vertLeq(e,o)?(a=n.edgeEval(r,t,e),s=n.edgeEval(t,e,o),a+s<0&&(a=-a,s=-s),i.s=n.interpolate(a,t.s,s,e.s)):(a=n.edgeSign(r,t,e),s=-n.edgeSign(r,o,e),a+s<0&&(a=-a,s=-s),i.s=n.interpolate(a,t.s,s,o.s)):i.s=(t.s+e.s)/2,n.transLeq(r,e)||(l=r,r=e,e=l),n.transLeq(t,o)||(l=t,t=o,o=l),n.transLeq(r,t)||(l=r,r=t,t=l,l=e,e=o,o=l),n.transLeq(t,e)?n.transLeq(e,o)?(a=n.transEval(r,t,e),s=n.transEval(t,e,o),a+s<0&&(a=-a,s=-s),i.t=n.interpolate(a,t.t,s,e.t)):(a=n.transSign(r,t,e),s=-n.transSign(r,o,e),a+s<0&&(a=-a,s=-s),i.t=n.interpolate(a,t.t,s,o.t)):i.t=(t.t+e.t)/2},n}(),Ws=function(){function n(){this.next=null,this.prev=null,this.anEdge=null,this.trail=null,this.n=0,this.marked=!1,this.inside=!1}return n}(),fu=function(){function n(r){this.side=r,this.next=null,this.Org=null,this.Sym=null,this.Onext=null,this.Lnext=null,this.Lface=null,this.activeRegion=null,this.winding=0}return Object.defineProperty(n.prototype,"Rface",{get:function(){return this.Sym.Lface},set:function(r){this.Sym.Lface=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dst",{get:function(){return this.Sym.Org},set:function(r){this.Sym.Org=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Oprev",{get:function(){return this.Sym.Lnext},set:function(r){this.Sym.Lnext=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Lprev",{get:function(){return this.Onext.Sym},set:function(r){this.Onext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dprev",{get:function(){return this.Lnext.Sym},set:function(r){this.Lnext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Rprev",{get:function(){return this.Sym.Onext},set:function(r){this.Sym.Onext=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dnext",{get:function(){return this.Sym.Onext.Sym},set:function(r){this.Sym.Onext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Rnext",{get:function(){return this.Sym.Lnext.Sym},set:function(r){this.Sym.Lnext.Sym=r},enumerable:!0,configurable:!0}),n}(),ga=function(){function n(){this.next=null,this.prev=null,this.anEdge=null,this.coords=[0,0,0],this.s=0,this.t=0,this.pqHandle=0,this.n=0,this.idx=0}return n}(),b0=function(){function n(){var r=new ga,e=new Ws,t=new fu(0),o=new fu(1);r.next=r.prev=r,r.anEdge=null,e.next=e.prev=e,t.next=t,t.Sym=o,o.next=o,o.Sym=t,this.vHead=r,this.fHead=e,this.eHead=t,this.eHeadSym=o}return n.prototype.makeEdge_=function(r){var e=new fu(0),t=new fu(1);r.Sym.side<r.side&&(r=r.Sym);var o=r.Sym.next;return t.next=o,o.Sym.next=e,e.next=r,r.Sym.next=t,e.Sym=t,e.Onext=e,e.Lnext=t,e.Org=null,e.Lface=null,e.winding=0,e.activeRegion=null,t.Sym=e,t.Onext=t,t.Lnext=e,t.Org=null,t.Lface=null,t.winding=0,t.activeRegion=null,e},n.prototype.splice_=function(r,e){var t=r.Onext,o=e.Onext;t.Sym.Lnext=e,o.Sym.Lnext=r,r.Onext=o,e.Onext=t},n.prototype.makeVertex_=function(r,e,t){var o=r;we(o,"Vertex can't be null!");var i=t.prev;o.prev=i,i.next=o,o.next=t,t.prev=o,o.anEdge=e;var a=e;do a.Org=o,a=a.Onext;while(a!==e)},n.prototype.makeFace_=function(r,e,t){var o=r;we(o,"Face can't be null");var i=t.prev;o.prev=i,i.next=o,o.next=t,t.prev=o,o.anEdge=e,o.trail=null,o.marked=!1,o.inside=t.inside;var a=e;do a.Lface=o,a=a.Lnext;while(a!==e)},n.prototype.killEdge_=function(r){r.Sym.side<r.side&&(r=r.Sym);var e=r.next,t=r.Sym.next;e.Sym.next=t,t.Sym.next=e},n.prototype.killVertex_=function(r,e){var t=r.anEdge,o=t;do o.Org=e,o=o.Onext;while(o!==t);var i=r.prev,a=r.next;a.prev=i,i.next=a},n.prototype.killFace_=function(r,e){var t=r.anEdge,o=t;do o.Lface=e,o=o.Lnext;while(o!==t);var i=r.prev,a=r.next;a.prev=i,i.next=a},n.prototype.makeEdge=function(){var r=new ga,e=new ga,t=new Ws,o=this.makeEdge_(this.eHead);return this.makeVertex_(r,o,this.vHead),this.makeVertex_(e,o.Sym,this.vHead),this.makeFace_(t,o,this.fHead),o},n.prototype.splice=function(r,e){var t=!1,o=!1;if(r!==e){if(e.Org!==r.Org&&(o=!0,this.killVertex_(e.Org,r.Org)),e.Lface!==r.Lface&&(t=!0,this.killFace_(e.Lface,r.Lface)),this.splice_(e,r),!o){var i=new ga;this.makeVertex_(i,e,r.Org),r.Org.anEdge=r}if(!t){var a=new Ws;this.makeFace_(a,e,r.Lface),r.Lface.anEdge=r}}},n.prototype.delete=function(r){var e=r.Sym,t=!1;if(r.Lface!==r.Rface&&(t=!0,this.killFace_(r.Lface,r.Rface)),r.Onext===r)this.killVertex_(r.Org,null);else if(r.Rface.anEdge=r.Oprev,r.Org.anEdge=r.Onext,this.splice_(r,r.Oprev),!t){var o=new Ws;this.makeFace_(o,r,r.Lface)}e.Onext===e?(this.killVertex_(e.Org,null),this.killFace_(e.Lface,null)):(r.Lface.anEdge=e.Oprev,e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev)),this.killEdge_(r)},n.prototype.addEdgeVertex=function(r){var e=this.makeEdge_(r),t=e.Sym;this.splice_(e,r.Lnext),e.Org=r.Dst;var o=new ga;return this.makeVertex_(o,t,e.Org),e.Lface=t.Lface=r.Lface,e},n.prototype.splitEdge=function(r){var e=this.addEdgeVertex(r),t=e.Sym;return this.splice_(r.Sym,r.Sym.Oprev),this.splice_(r.Sym,t),r.Dst=t.Org,t.Dst.anEdge=t.Sym,t.Rface=r.Rface,t.winding=r.winding,t.Sym.winding=r.Sym.winding,t.idx=r.idx,t.Sym.idx=r.Sym.idx,t},n.prototype.connect=function(r,e){var t=!1,o=this.makeEdge_(r),i=o.Sym;if(e.Lface!==r.Lface&&(t=!0,this.killFace_(e.Lface,r.Lface)),this.splice_(o,r.Lnext),this.splice_(i,e),o.Org=r.Dst,i.Org=e.Org,o.Lface=i.Lface=r.Lface,r.Lface.anEdge=i,!t){var a=new Ws;this.makeFace_(a,o,r.Lface)}return o},n.prototype.zapFace=function(r){var e=r.anEdge,t,o,i,a,s;o=e.Lnext;do t=o,o=t.Lnext,t.Lface=null,t.Rface===null&&(t.Onext===t?this.killVertex_(t.Org,null):(t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),i=t.Sym,i.Onext===i?this.killVertex_(i.Org,null):(i.Org.anEdge=i.Onext,this.splice_(i,i.Oprev)),this.killEdge_(t));while(t!=e);a=r.prev,s=r.next,s.prev=a,a.next=s},n.prototype.countFaceVerts_=function(r){var e=r.anEdge,t=0;do t++,e=e.Lnext;while(e!==r.anEdge);return t},n.prototype.mergeConvexFaces=function(r){var e,t,o,i,a,s,l;for(e=this.fHead.next;e!==this.fHead;e=e.next)if(!!e.inside)for(t=e.anEdge,a=t.Org;o=t.Lnext,i=t.Sym,i&&i.Lface&&i.Lface.inside&&(s=this.countFaceVerts_(e),l=this.countFaceVerts_(i.Lface),s+l-2<=r&&ve.vertCCW(t.Lprev.Org,t.Org,i.Lnext.Lnext.Org)&&ve.vertCCW(i.Lprev.Org,i.Org,t.Lnext.Lnext.Org)&&(o=i.Lnext,this.delete(i),t=null,i=null)),!(t&&t.Lnext.Org===a);)t=o;return!0},n.prototype.check=function(){var r=this.fHead,e=this.vHead,t=this.eHead,o,i,a,s,l,c;for(i=r,i=r;(o=i.next)!==r;i=o){we(o.prev===i),l=o.anEdge;do we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l),we(l.Lface===o),l=l.Lnext;while(l!==o.anEdge)}for(we(o.prev===i&&o.anEdge===null),s=e,s=e;(a=s.next)!==e;s=a){we(a.prev===s),l=a.anEdge;do we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l),we(l.Org===a),l=l.Onext;while(l!==a.anEdge)}for(we(a.prev===s&&a.anEdge===null),c=t,c=t;(l=c.next)!==t;c=l)we(l.Sym.next===c.Sym),we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Org!==null),we(l.Dst!==null),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l);we(l.Sym.next===c.Sym&&l.Sym===this.eHeadSym&&l.Sym.Sym===l&&l.Org===null&&l.Dst===null&&l.Lface===null&&l.Rface===null)},n}(),v0=function(){function n(){this.handle=null}return n}(),S0=function(){function n(){this.key=null,this.node=0}return n}(),vM=function(){function n(r,e){this.leq=e,this.max=0,this.nodes=[],this.handles=[],this.initialized=!1,this.freeList=0,this.size=0,this.max=r,this.nodes=[],this.handles=[];for(var t=0;t<r+1;t++)this.nodes[t]=new v0,this.handles[t]=new S0;this.initialized=!1,this.nodes[1].handle=1,this.handles[1].key=null}return n.prototype.floatDown_=function(r){var e=this.nodes,t=this.handles,o,i,a;for(o=e[r].handle;;){if(a=r<<1,a<this.size&&this.leq(t[e[a+1].handle].key,t[e[a].handle].key)&&++a,we(a<=this.max),i=e[a].handle,a>this.size||this.leq(t[o].key,t[i].key)){e[r].handle=o,t[o].node=r;break}e[r].handle=i,t[i].node=r,r=a}},n.prototype.floatUp_=function(r){var e=this.nodes,t=this.handles,o,i,a;for(o=e[r].handle;;){if(a=r>>1,i=e[a].handle,a===0||this.leq(t[i].key,t[o].key)){e[r].handle=o,t[o].node=r;break}e[r].handle=i,t[i].node=r,r=a}},n.prototype.init=function(){for(var r=this.size;r>=1;--r)this.floatDown_(r);this.initialized=!0},n.prototype.min=function(){return this.handles[this.nodes[1].handle].key},n.prototype.insert=function(r){var e,t;if(e=++this.size,e*2>this.max){this.max*=2;var o,i;for(i=this.nodes.length,this.nodes.length=this.max+1,o=i;o<this.nodes.length;o++)this.nodes[o]=new v0;for(i=this.handles.length,this.handles.length=this.max+1,o=i;o<this.handles.length;o++)this.handles[o]=new S0}return this.freeList===0?t=e:(t=this.freeList,this.freeList=this.handles[t].node),this.nodes[e].handle=t,this.handles[t].node=e,this.handles[t].key=r,this.initialized&&this.floatUp_(e),t},n.prototype.extractMin=function(){var r=this.nodes,e=this.handles,t=r[1].handle,o=e[t].key;return this.size>0&&(r[1].handle=r[this.size].handle,e[r[1].handle].node=1,e[t].key=null,e[t].node=this.freeList,this.freeList=t,--this.size,this.size>0&&this.floatDown_(1)),o},n.prototype.delete=function(r){var e=this.nodes,t=this.handles,o;we(r>=1&&r<=this.max&&t[r].key!==null),o=t[r].node,e[o].handle=e[this.size].handle,t[e[o].handle].node=o,--this.size,o<=this.size&&(o<=1||this.leq(t[e[o>>1].handle].key,t[e[o].handle].key)?this.floatDown_(o):this.floatUp_(o)),t[r].key=null,t[r].node=this.freeList,this.freeList=r},n}(),of=function(){function n(){this.eUp=null,this.nodeUp=null,this.windingNumber=0,this.inside=!1,this.sentinel=!1,this.dirty=!1,this.fixUpperEdge=!1}return n}(),w0=function(){function n(){this.key=null,this.next=null,this.prev=null}return n}(),SM=function(){function n(r,e){this.frame=r,this.leq=e,this.head=new w0,this.head.next=this.head,this.head.prev=this.head}return n.prototype.min=function(){return this.head.next},n.prototype.max=function(){return this.head.prev},n.prototype.insert=function(r){return this.insertBefore(this.head,r)},n.prototype.search=function(r){var e=this.head;do e=e.next;while(e.key!==null&&!this.leq(this.frame,r,e.key));return e},n.prototype.insertBefore=function(r,e){do r=r.prev;while(r.key!==null&&!this.leq(this.frame,r.key,e));var t=new w0;return t.key=e,t.next=r.next,r.next.prev=t,t.prev=r,r.next=t,t},n.prototype.delete=function(r){r.next.prev=r.prev,r.prev.next=r.next},n}(),wM=function(){function n(){}return n.regionBelow=function(r){return r.nodeUp.prev.key},n.regionAbove=function(r){return r.nodeUp.next.key},n.debugEvent=function(r){},n.addWinding=function(r,e){r.winding+=e.winding,r.Sym.winding+=e.Sym.winding},n.edgeLeq=function(r,e,t){var o=r.event,i=e.eUp,a=t.eUp;if(i.Dst===o)return a.Dst===o?ve.vertLeq(i.Org,a.Org)?ve.edgeSign(a.Dst,i.Org,a.Org)<=0:ve.edgeSign(i.Dst,a.Org,i.Org)>=0:ve.edgeSign(a.Dst,o,a.Org)<=0;if(a.Dst===o)return ve.edgeSign(i.Dst,o,i.Org)>=0;var s=ve.edgeEval(i.Dst,o,i.Org),l=ve.edgeEval(a.Dst,o,a.Org);return s>=l},n.deleteRegion=function(r,e){e.fixUpperEdge&&we(e.eUp.winding===0),e.eUp.activeRegion=null,r.dict.delete(e.nodeUp)},n.fixUpperEdge=function(r,e,t){we(e.fixUpperEdge),r.mesh.delete(e.eUp),e.fixUpperEdge=!1,e.eUp=t,t.activeRegion=e},n.topLeftRegion=function(r,e){var t=e.eUp.Org,o;do e=n.regionAbove(e);while(e.eUp.Org===t);if(e.fixUpperEdge){if(o=r.mesh.connect(n.regionBelow(e).eUp.Sym,e.eUp.Lnext),o===null)return null;n.fixUpperEdge(r,e,o),e=n.regionAbove(e)}return e},n.topRightRegion=function(r){var e=r.eUp.Dst;do r=n.regionAbove(r);while(r.eUp.Dst===e);return r},n.addRegionBelow=function(r,e,t){var o=new of;return o.eUp=t,o.nodeUp=r.dict.insertBefore(e.nodeUp,o),o.fixUpperEdge=!1,o.sentinel=!1,o.dirty=!1,t.activeRegion=o,o},n.isWindingInside=function(r,e){switch(r.windingRule){case Ge.ODD:return(e&1)!==0;case Ge.NONZERO:return e!==0;case Ge.POSITIVE:return e>0;case Ge.NEGATIVE:return e<0;case Ge.ABS_GEQ_TWO:return e>=2||e<=-2}throw new Error("Invalid winding rulle")},n.computeWinding=function(r,e){e.windingNumber=n.regionAbove(e).windingNumber+e.eUp.winding,e.inside=n.isWindingInside(r,e.windingNumber)},n.finishRegion=function(r,e){var t=e.eUp,o=t.Lface;o.inside=e.inside,o.anEdge=t,n.deleteRegion(r,e)},n.finishLeftRegions=function(r,e,t){for(var o,i=null,a=e,s=e.eUp;a!==t;){if(a.fixUpperEdge=!1,i=n.regionBelow(a),o=i.eUp,o.Org!=s.Org){if(!i.fixUpperEdge){n.finishRegion(r,a);break}o=r.mesh.connect(s.Lprev,o.Sym),n.fixUpperEdge(r,i,o)}s.Onext!==o&&(r.mesh.splice(o.Oprev,o),r.mesh.splice(s,o)),n.finishRegion(r,a),s=i.eUp,a=i}return s},n.addRightEdges=function(r,e,t,o,i,a){var s,l,c,u,p=!0;c=t;do we(ve.vertLeq(c.Org,c.Dst)),n.addRegionBelow(r,e,c.Sym),c=c.Onext;while(c!==o);for(i===null&&(i=n.regionBelow(e).eUp.Rprev),l=e,u=i;s=n.regionBelow(l),c=s.eUp.Sym,c.Org===u.Org;)c.Onext!==u&&(r.mesh.splice(c.Oprev,c),r.mesh.splice(u.Oprev,c)),s.windingNumber=l.windingNumber-c.winding,s.inside=n.isWindingInside(r,s.windingNumber),l.dirty=!0,!p&&n.checkForRightSplice(r,l)&&(n.addWinding(c,u),n.deleteRegion(r,l),r.mesh.delete(u)),p=!1,l=s,u=c;l.dirty=!0,we(l.windingNumber-c.winding===s.windingNumber),a&&n.walkDirtyRegions(r,l)},n.spliceMergeVertices=function(r,e,t){r.mesh.splice(e,t)},n.vertexWeights=function(r,e,t){var o=ve.vertL1dist(e,r),i=ve.vertL1dist(t,r),a=.5*i/(o+i),s=.5*o/(o+i);r.coords[0]+=a*e.coords[0]+s*t.coords[0],r.coords[1]+=a*e.coords[1]+s*t.coords[1],r.coords[2]+=a*e.coords[2]+s*t.coords[2]},n.getIntersectData=function(r,e,t,o,i,a){e.coords[0]=e.coords[1]=e.coords[2]=0,e.idx=-1,n.vertexWeights(e,t,o),n.vertexWeights(e,i,a)},n.checkForRightSplice=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp;if(ve.vertLeq(o.Org,i.Org)){if(ve.edgeSign(i.Dst,o.Org,i.Org)>0)return!1;ve.vertEq(o.Org,i.Org)?o.Org!==i.Org&&(r.pq.delete(o.Org.pqHandle),n.spliceMergeVertices(r,i.Oprev,o)):(r.mesh.splitEdge(i.Sym),r.mesh.splice(o,i.Oprev),e.dirty=t.dirty=!0)}else{if(ve.edgeSign(o.Dst,i.Org,o.Org)<0)return!1;n.regionAbove(e).dirty=e.dirty=!0,r.mesh.splitEdge(o.Sym),r.mesh.splice(i.Oprev,o)}return!0},n.checkForLeftSplice=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp,a;if(we(!ve.vertEq(o.Dst,i.Dst)),ve.vertLeq(o.Dst,i.Dst)){if(ve.edgeSign(o.Dst,i.Dst,o.Org)<0)return!1;n.regionAbove(e).dirty=e.dirty=!0,a=r.mesh.splitEdge(o),r.mesh.splice(i.Sym,a),a.Lface.inside=e.inside}else{if(ve.edgeSign(i.Dst,o.Dst,i.Org)>0)return!1;e.dirty=t.dirty=!0,a=r.mesh.splitEdge(i),r.mesh.splice(o.Lnext,i.Sym),a.Rface.inside=e.inside}return!0},n.checkForIntersect=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp,a=o.Org,s=i.Org,l=o.Dst,c=i.Dst,u,p,d=new ga,h,f;if(we(!ve.vertEq(c,l)),we(ve.edgeSign(l,r.event,a)<=0),we(ve.edgeSign(c,r.event,s)>=0),we(a!==r.event&&s!==r.event),we(!e.fixUpperEdge&&!t.fixUpperEdge),a===s||(u=Math.min(a.t,l.t),p=Math.max(s.t,c.t),u>p))return!1;if(ve.vertLeq(a,s)){if(ve.edgeSign(c,a,s)>0)return!1}else if(ve.edgeSign(l,s,a)<0)return!1;return n.debugEvent(r),ve.intersect(l,a,c,s,d),we(Math.min(a.t,l.t)<=d.t),we(d.t<=Math.max(s.t,c.t)),we(Math.min(c.s,l.s)<=d.s),we(d.s<=Math.max(s.s,a.s)),ve.vertLeq(d,r.event)&&(d.s=r.event.s,d.t=r.event.t),h=ve.vertLeq(a,s)?a:s,ve.vertLeq(h,d)&&(d.s=h.s,d.t=h.t),ve.vertEq(d,a)||ve.vertEq(d,s)?(n.checkForRightSplice(r,e),!1):!ve.vertEq(l,r.event)&&ve.edgeSign(l,r.event,d)>=0||!ve.vertEq(c,r.event)&&ve.edgeSign(c,r.event,d)<=0?c===r.event?(r.mesh.splitEdge(o.Sym),r.mesh.splice(i.Sym,o),e=n.topLeftRegion(r,e),o=n.regionBelow(e).eUp,n.finishLeftRegions(r,n.regionBelow(e),t),n.addRightEdges(r,e,o.Oprev,o,o,!0),!0):l===r.event?(r.mesh.splitEdge(i.Sym),r.mesh.splice(o.Lnext,i.Oprev),t=e,e=n.topRightRegion(e),f=n.regionBelow(e).eUp.Rprev,t.eUp=i.Oprev,i=n.finishLeftRegions(r,t,null),n.addRightEdges(r,e,i.Onext,o.Rprev,f,!0),!0):(ve.edgeSign(l,r.event,d)>=0&&(n.regionAbove(e).dirty=e.dirty=!0,r.mesh.splitEdge(o.Sym),o.Org.s=r.event.s,o.Org.t=r.event.t),ve.edgeSign(c,r.event,d)<=0&&(e.dirty=t.dirty=!0,r.mesh.splitEdge(i.Sym),i.Org.s=r.event.s,i.Org.t=r.event.t),!1):(r.mesh.splitEdge(o.Sym),r.mesh.splitEdge(i.Sym),r.mesh.splice(i.Oprev,o),o.Org.s=d.s,o.Org.t=d.t,o.Org.pqHandle=r.pq.insert(o.Org),n.getIntersectData(r,o.Org,a,l,s,c),n.regionAbove(e).dirty=e.dirty=t.dirty=!0,!1)},n.walkDirtyRegions=function(r,e){for(var t=n.regionBelow(e),o,i;;){for(;t.dirty;)e=t,t=n.regionBelow(t);if(!e.dirty&&(t=e,e=n.regionAbove(e),e===null||!e.dirty))return;if(e.dirty=!1,o=e.eUp,i=t.eUp,o.Dst!==i.Dst&&n.checkForLeftSplice(r,e)&&(t.fixUpperEdge?(n.deleteRegion(r,t),r.mesh.delete(i),t=n.regionBelow(e),i=t.eUp):e.fixUpperEdge&&(n.deleteRegion(r,e),r.mesh.delete(o),e=n.regionAbove(t),o=e.eUp)),o.Org!==i.Org)if(o.Dst!==i.Dst&&!e.fixUpperEdge&&!t.fixUpperEdge&&(o.Dst===r.event||i.Dst===r.event)){if(n.checkForIntersect(r,e))return}else n.checkForRightSplice(r,e);o.Org===i.Org&&o.Dst===i.Dst&&(n.addWinding(i,o),n.deleteRegion(r,e),r.mesh.delete(o),e=n.regionAbove(t))}},n.connectRightVertex=function(r,e,t){var o,i=t.Onext,a=n.regionBelow(e),s=e.eUp,l=a.eUp,c=!1;if(s.Dst!==l.Dst&&n.checkForIntersect(r,e),ve.vertEq(s.Org,r.event)&&(r.mesh.splice(i.Oprev,s),e=n.topLeftRegion(r,e),i=n.regionBelow(e).eUp,n.finishLeftRegions(r,n.regionBelow(e),a),c=!0),ve.vertEq(l.Org,r.event)&&(r.mesh.splice(t,l.Oprev),t=n.finishLeftRegions(r,a,null),c=!0),c){n.addRightEdges(r,e,t.Onext,i,i,!0);return}ve.vertLeq(l.Org,s.Org)?o=l.Oprev:o=s,o=r.mesh.connect(t.Lprev,o),n.addRightEdges(r,e,o,o.Onext,o.Onext,!1),o.Sym.activeRegion.fixUpperEdge=!0,n.walkDirtyRegions(r,e)},n.connectLeftDegenerate=function(r,e,t){var o,i,a,s,l;if(o=e.eUp,ve.vertEq(o.Org,t)){we(!1),n.spliceMergeVertices(r,o,t.anEdge);return}if(!ve.vertEq(o.Dst,t)){r.mesh.splitEdge(o.Sym),e.fixUpperEdge&&(r.mesh.delete(o.Onext),e.fixUpperEdge=!1),r.mesh.splice(t.anEdge,o),n.sweepEvent(r,t);return}we(!1),e=n.topRightRegion(e),l=n.regionBelow(e),a=l.eUp.Sym,i=s=a.Onext,l.fixUpperEdge&&(we(i!==a),n.deleteRegion(r,l),r.mesh.delete(a),a=i.Oprev),r.mesh.splice(t.anEdge,a),ve.edgeGoesLeft(i)||(i=null),n.addRightEdges(r,e,a.Onext,s,i,!0)},n.connectLeftVertex=function(r,e){var t,o,i,a,s,l,c=new of;if(c.eUp=e.anEdge.Sym,t=r.dict.search(c).key,o=n.regionBelow(t),!!o){if(a=t.eUp,s=o.eUp,ve.edgeSign(a.Dst,e,a.Org)===0){n.connectLeftDegenerate(r,t,e);return}if(i=ve.vertLeq(s.Dst,a.Dst)?t:o,t.inside||i.fixUpperEdge){if(i===t)l=r.mesh.connect(e.anEdge.Sym,a.Lnext);else{var u=r.mesh.connect(s.Dnext,e.anEdge);l=u.Sym}i.fixUpperEdge?n.fixUpperEdge(r,i,l):n.computeWinding(r,n.addRegionBelow(r,t,l)),n.sweepEvent(r,e)}else n.addRightEdges(r,t,e.anEdge,e.anEdge,null,!0)}},n.sweepEvent=function(r,e){r.event=e,n.debugEvent(r);for(var t=e.anEdge;t.activeRegion===null;)if(t=t.Onext,t===e.anEdge){n.connectLeftVertex(r,e);return}var o=n.topLeftRegion(r,t.activeRegion);we(o!==null);var i=n.regionBelow(o),a=i.eUp,s=n.finishLeftRegions(r,i,null);s.Onext===a?n.connectRightVertex(r,o,s):n.addRightEdges(r,o,s.Onext,a,a,!0)},n.addSentinel=function(r,e,t,o){var i=new of,a=r.mesh.makeEdge();a.Org.s=t,a.Org.t=o,a.Dst.s=e,a.Dst.t=o,r.event=a.Dst,i.eUp=a,i.windingNumber=0,i.inside=!1,i.fixUpperEdge=!1,i.sentinel=!0,i.dirty=!1,i.nodeUp=r.dict.insert(i)},n.initEdgeDict=function(r){r.dict=new SM(r,n.edgeLeq);var e=r.bmax[0]-r.bmin[0],t=r.bmax[1]-r.bmin[1],o=r.bmin[0]-e,i=r.bmax[0]+e,a=r.bmin[1]-t,s=r.bmax[1]+t;n.addSentinel(r,o,i,a),n.addSentinel(r,o,i,s)},n.doneEdgeDict=function(r){for(var e,t=0;(e=r.dict.min().key)!==null;)e.sentinel||(we(e.fixUpperEdge),we(++t===1)),we(e.windingNumber===0),n.deleteRegion(r,e)},n.removeDegenerateEdges=function(r){var e,t,o,i=r.mesh.eHead;for(e=i.next;e!==i;e=t)t=e.next,o=e.Lnext,ve.vertEq(e.Org,e.Dst)&&e.Lnext.Lnext!==e&&(n.spliceMergeVertices(r,o,e),r.mesh.delete(e),e=o,o=e.Lnext),o.Lnext===e&&(o!==e&&((o===t||o===t.Sym)&&(t=t.next),r.mesh.delete(o)),(e===t||e===t.Sym)&&(t=t.next),r.mesh.delete(e))},n.initPriorityQ=function(r){var e,t,o,i=0;for(o=r.mesh.vHead,t=o.next;t!==o;t=t.next)i++;for(i+=8,e=r.pq=new vM(i,ve.vertLeq),o=r.mesh.vHead,t=o.next;t!==o;t=t.next)t.pqHandle=e.insert(t);return t!==o?!1:(e.init(),!0)},n.donePriorityQ=function(r){r.pq=null},n.removeDegenerateFaces=function(r,e){var t,o,i;for(t=e.fHead.next;t!==e.fHead;t=o)o=t.next,i=t.anEdge,we(i.Lnext!==i),i.Lnext.Lnext===i&&(n.addWinding(i.Onext,i),r.mesh.delete(i));return!0},n.computeInterior=function(r,e){e===void 0&&(e=!0);var t,o;if(n.removeDegenerateEdges(r),!n.initPriorityQ(r))return!1;for(n.initEdgeDict(r);(t=r.pq.extractMin())!==null;){for(;o=r.pq.min(),!(o===null||!ve.vertEq(o,t));)o=r.pq.extractMin(),n.spliceMergeVertices(r,t.anEdge,o.anEdge);n.sweepEvent(r,t)}return r.event=r.dict.min().key.eUp.Org,n.debugEvent(r),n.doneEdgeDict(r),n.donePriorityQ(r),n.removeDegenerateFaces(r,r.mesh)?(e&&r.mesh.check(),!0):!1},n}(),PM=function(){function n(){this.mesh=new b0,this.normal=[0,0,0],this.sUnit=[0,0,0],this.tUnit=[0,0,0],this.bmin=[0,0],this.bmax=[0,0],this.windingRule=Ge.ODD,this.dict=null,this.pq=null,this.event=null,this.vertexIndexCounter=0,this.vertices=[],this.vertexIndices=[],this.vertexCount=0,this.elements=[],this.elementCount=0}return n.prototype.dot_=function(r,e){return r[0]*e[0]+r[1]*e[1]+r[2]*e[2]},n.prototype.normalize_=function(r){var e=r[0]*r[0]+r[1]*r[1]+r[2]*r[2];if(!e)throw"Zero-size vector!";e=Math.sqrt(e),r[0]/=e,r[1]/=e,r[2]/=e},n.prototype.longAxis_=function(r){var e=0;return Math.abs(r[1])>Math.abs(r[0])&&(e=1),Math.abs(r[2])>Math.abs(r[e])&&(e=2),e},n.prototype.computeNormal_=function(r){var e,t,o,i,a,s,l=[0,0,0],c=[0,0,0],u=[0,0,0],p=[0,0,0],d=[0,0,0],h=[null,null,null],f=[null,null,null],m=this.mesh.vHead;e=m.next;for(var y=0;y<3;++y)i=e.coords[y],c[y]=i,f[y]=e,l[y]=i,h[y]=e;for(e=m.next;e!==m;e=e.next)for(var g=0;g<3;++g)i=e.coords[g],i<c[g]&&(c[g]=i,f[g]=e),i>l[g]&&(l[g]=i,h[g]=e);var v=0;if(l[1]-c[1]>l[0]-c[0]&&(v=1),l[2]-c[2]>l[v]-c[v]&&(v=2),c[v]>=l[v]){r[0]=0,r[1]=0,r[2]=1;return}for(s=0,t=f[v],o=h[v],u[0]=t.coords[0]-o.coords[0],u[1]=t.coords[1]-o.coords[1],u[2]=t.coords[2]-o.coords[2],e=m.next;e!==m;e=e.next)p[0]=e.coords[0]-o.coords[0],p[1]=e.coords[1]-o.coords[1],p[2]=e.coords[2]-o.coords[2],d[0]=u[1]*p[2]-u[2]*p[1],d[1]=u[2]*p[0]-u[0]*p[2],d[2]=u[0]*p[1]-u[1]*p[0],a=d[0]*d[0]+d[1]*d[1]+d[2]*d[2],a>s&&(s=a,r[0]=d[0],r[1]=d[1],r[2]=d[2]);s<=0&&(r[0]=r[1]=r[2]=0,r[this.longAxis_(u)]=1)},n.prototype.checkOrientation_=function(){for(var r=this.mesh.fHead,e,t=this.mesh.vHead,o,i=0,a=r.next;a!==r;a=a.next)if(o=a.anEdge,!(o.winding<=0))do i+=(o.Org.s-o.Dst.s)*(o.Org.t+o.Dst.t),o=o.Lnext;while(o!==a.anEdge);if(i<0){for(e=t.next;e!==t;e=e.next)e.t=-e.t;this.tUnit[0]=-this.tUnit[0],this.tUnit[1]=-this.tUnit[1],this.tUnit[2]=-this.tUnit[2]}},n.prototype.projectPolygon_=function(){var r=this.mesh.vHead,e=[0,0,0],t,o,i=!1;e[0]=this.normal[0],e[1]=this.normal[1],e[2]=this.normal[2],!e[0]&&!e[1]&&!e[2]&&(this.computeNormal_(e),i=!0),t=this.sUnit,o=this.tUnit;var a=this.longAxis_(e);t[a]=0,t[(a+1)%3]=1,t[(a+2)%3]=0,o[a]=0,o[(a+1)%3]=0,o[(a+2)%3]=e[a]>0?1:-1;for(var s=r.next;s!==r;s=s.next)s.s=this.dot_(s.coords,t),s.t=this.dot_(s.coords,o);i&&this.checkOrientation_();for(var l=!0,c=r.next;c!==r;c=c.next)l?(this.bmin[0]=this.bmax[0]=c.s,this.bmin[1]=this.bmax[1]=c.t,l=!1):(c.s<this.bmin[0]&&(this.bmin[0]=c.s),c.s>this.bmax[0]&&(this.bmax[0]=c.s),c.t<this.bmin[1]&&(this.bmin[1]=c.t),c.t>this.bmax[1]&&(this.bmax[1]=c.t))},n.prototype.addWinding_=function(r,e){r.winding+=e.winding,r.Sym.winding+=e.Sym.winding},n.prototype.tessellateMonoRegion_=function(r,e){var t,o;if(t=e.anEdge,!(t.Lnext!==t&&t.Lnext.Lnext!==t))throw"Mono region invalid";for(;ve.vertLeq(t.Dst,t.Org);t=t.Lprev);for(;ve.vertLeq(t.Org,t.Dst);t=t.Lnext);o=t.Lprev;for(var i=void 0;t.Lnext!==o;)if(ve.vertLeq(t.Dst,o.Org)){for(;o.Lnext!==t&&(ve.edgeGoesLeft(o.Lnext)||ve.edgeSign(o.Org,o.Dst,o.Lnext.Dst)<=0);)i=r.connect(o.Lnext,o),o=i.Sym;o=o.Lprev}else{for(;o.Lnext!==t&&(ve.edgeGoesRight(t.Lprev)||ve.edgeSign(t.Dst,t.Org,t.Lprev.Org)>=0);)i=r.connect(t,t.Lprev),t=i.Sym;t=t.Lnext}if(o.Lnext===t)throw"Mono region invalid";for(;o.Lnext.Lnext!==t;)i=r.connect(o.Lnext,o),o=i.Sym;return!0},n.prototype.tessellateInterior_=function(r){for(var e,t=r.fHead.next;t!==r.fHead;t=e)if(e=t.next,t.inside&&!this.tessellateMonoRegion_(r,t))return!1;return!0},n.prototype.discardExterior_=function(r){for(var e,t=r.fHead.next;t!==r.fHead;t=e)e=t.next,t.inside||r.zapFace(t)},n.prototype.setWindingNumber_=function(r,e,t){for(var o,i=r.eHead.next;i!==r.eHead;i=o)o=i.next,i.Rface.inside!==i.Lface.inside?i.winding=i.Lface.inside?e:-e:t?r.delete(i):i.winding=0},n.prototype.getNeighbourFace_=function(r){return!r.Rface||!r.Rface.inside?-1:r.Rface.n},n.prototype.outputPolymesh_=function(r,e,t,o){var i,a=0,s=0,l;t>3&&r.mergeConvexFaces(t);for(var c=r.vHead.next;c!==r.vHead;c=c.next)c.n=-1;for(var u=r.fHead.next;u!==r.fHead;u=u.next)if(u.n=-1,!!u.inside){i=u.anEdge,l=0;do{var c=i.Org;c.n===-1&&(c.n=s,s++),l++,i=i.Lnext}while(i!==u.anEdge);if(l>t)throw"Face vertex greater that support polygon";u.n=a,++a}this.elementCount=a,e===at.CONNECTED_POLYGONS&&(a*=2),this.elements=[],this.elements.length=a*t,this.vertexCount=s,this.vertices=[],this.vertices.length=s*o,this.vertexIndices=[],this.vertexIndices.length=s;for(var c=r.vHead.next;c!==r.vHead;c=c.next)if(c.n!==-1){var p=c.n*o;this.vertices[p+0]=c.coords[0],this.vertices[p+1]=c.coords[1],o>2&&(this.vertices[p+2]=c.coords[2]),this.vertexIndices[c.n]=c.idx}for(var d=0,u=r.fHead.next;u!==r.fHead;u=u.next)if(!!u.inside){i=u.anEdge,l=0;do{var c=i.Org;this.elements[d++]=c.n,l++,i=i.Lnext}while(i!==u.anEdge);for(var h=l;h<t;++h)this.elements[d++]=-1;if(e===at.CONNECTED_POLYGONS){i=u.anEdge;do this.elements[d++]=this.getNeighbourFace_(i),i=i.Lnext;while(i!==u.anEdge);for(var f=l;f<t;++f)this.elements[d++]=-1}}},n.prototype.outputContours_=function(r,e){var t,o,i=0,a=0;this.vertexCount=0,this.elementCount=0;for(var s=r.fHead.next;s!==r.fHead;s=s.next)if(!!s.inside){o=t=s.anEdge;do this.vertexCount++,t=t.Lnext;while(t!==o);this.elementCount++}this.elements=[],this.elements.length=this.elementCount*2,this.vertices=[],this.vertices.length=this.vertexCount*e,this.vertexIndices=[],this.vertexIndices.length=this.vertexCount;var l=0,c=0,u=0;i=0;for(var s=r.fHead.next;s!==r.fHead;s=s.next)if(!!s.inside){a=0,o=t=s.anEdge;do this.vertices[l++]=t.Org.coords[0],this.vertices[l++]=t.Org.coords[1],e>2&&(this.vertices[l++]=t.Org.coords[2]),this.vertexIndices[c++]=this.vertexIdCallback?this.vertexIdCallback(t):t.Org.idx,a++,t=t.Lnext;while(t!==o);this.elements[u++]=i,this.elements[u++]=a,i+=a}},n.prototype.addContour=function(r,e){this.mesh===null&&(this.mesh=new b0),r<2&&(r=2),r>3&&(r=3);for(var t=null,o=0;o<e.length;o+=r)t===null?(t=this.mesh.makeEdge(),this.mesh.splice(t,t.Sym)):(this.mesh.splitEdge(t),t=t.Lnext),t.Org.coords[0]=e[o+0],t.Org.coords[1]=e[o+1],r>2?t.Org.coords[2]=e[o+2]:t.Org.coords[2]=0,t.Org.idx=this.vertexIndexCounter++,this.edgeCreateCallback&&this.edgeCreateCallback(t),t.winding=1,t.Sym.winding=-1},n.prototype.tesselate=function(r,e,t,o,i,a){if(r===void 0&&(r=Ge.ODD),e===void 0&&(e=at.POLYGONS),a===void 0&&(a=!0),this.vertices=[],this.elements=[],this.vertexIndices=[],this.vertexIndexCounter=0,i&&(this.normal[0]=i[0],this.normal[1]=i[1],this.normal[2]=i[2]),this.windingRule=r,o<2&&(o=2),o>3&&(o=3),!this.mesh)return!1;this.projectPolygon_(),wM.computeInterior(this,a);var s=this.mesh;return e===at.BOUNDARY_CONTOURS?this.setWindingNumber_(s,1,!0):this.tessellateInterior_(s),a&&s.check(),e===at.BOUNDARY_CONTOURS?this.outputContours_(s,o):this.outputPolymesh_(s,e,t,o),!0},n}();function Gr(n){var r=n.windingRule,e=r===void 0?Ge.ODD:r,t=n.elementType,o=t===void 0?at.POLYGONS:t,i=n.polySize,a=i===void 0?3:i,s=n.vertexSize,l=s===void 0?2:s,c=n.normal,u=c===void 0?[0,0,1]:c,p=n.contours,d=p===void 0?[]:p,h=n.strict,f=h===void 0?!0:h,m=n.debug,y=m===void 0?!1:m;if(!d&&f)throw new Error("Contours can't be empty");if(!!d){var g=new PM;n.edgeCreateCallback&&(g.edgeCreateCallback=n.edgeCreateCallback),n.vertexIdCallback&&(g.vertexIdCallback=n.vertexIdCallback);for(var v=0;v<d.length;v++)g.addContour(l||2,d[v]);return g.tesselate(e,o,a,l,u,f),{vertices:g.vertices,vertexIndices:g.vertexIndices,vertexCount:g.vertexCount,elements:g.elements,elementCount:g.elementCount,mesh:y?g.mesh:void 0}}}var A6=Ge.ODD,T6=Ge.NONZERO,I6=Ge.POSITIVE,M6=Ge.NEGATIVE,E6=Ge.ABS_GEQ_TWO,N6=at.POLYGONS,D6=at.CONNECTED_POLYGONS,_6=at.BOUNDARY_CONTOURS;import{Box2 as TM,BufferAttribute as yu,BufferGeometry as IM,Vector2 as MM}from"three";var hu=class{constructor(r=256,e=!1){this.capacity=r,this.size=0,this.debug=e,this.debug&&console.log(`allocating with cap ${r}`);let t=r*hu.eSize;this.buffer=new ArrayBuffer(t);let o=Float32Array.BYTES_PER_ELEMENT,i=0;this.positions=new Float32Array(this.buffer,i*o,3*r),i+=3*r,this.normals=new Float32Array(this.buffer,i*o,3*r),i+=3*r,this.uvs=new Float32Array(this.buffer,i*o,2*r)}realloc(r,e=!1){if(r<this.size)throw Error("cannot shrink buffer");if(r<=this.capacity&&!e)return;this.debug&&console.log(`resizing from ${this.capacity} \u2192 ${r}`);let t=r*hu.eSize,o=new ArrayBuffer(t),i=Float32Array.BYTES_PER_ELEMENT,a=0,s=new Float32Array(o,a*i,3*r);a+=3*r;let l=new Float32Array(o,a*i,3*r);a+=3*r;let c=new Float32Array(o,a*i,2*r);e?(s.set(this.positions.subarray(0,this.size*3)),l.set(this.normals.subarray(0,this.size*3)),c.set(this.uvs.subarray(0,this.size*2))):(s.set(this.positions),l.set(this.normals),c.set(this.uvs)),this.buffer=o,this.positions=s,this.normals=l,this.uvs=c,this.capacity=r}get(r=1){let e=this.size+r;if(e>this.capacity){let o=this.capacity;for(;e>o;)o*=2;this.realloc(o)}let t=this.size;return this.size=e,t}reserve(r){let e=this.size+r;e>this.capacity&&this.realloc(e)}shrink(){this.debug&&console.log(`shrinking ${this.capacity} \u2192 ${this.size}`),this.realloc(this.size,!0)}},qs=hu;qs.eSize=(3+3+2)*Float32Array.BYTES_PER_ELEMENT;var $s=class{constructor(r=[],e=(t,o)=>t<o?-1:t>o?1:0){if(this.data=r,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(r){this.data.push(r),this._up(this.length++)}pop(){if(this.length===0)return;let r=this.data[0],e=this.data.pop();return--this.length>0&&(this.data[0]=e,this._down(0)),r}peek(){return this.data[0]}_up(r){let{data:e,compare:t}=this,o=e[r];for(;r>0;){let i=r-1>>1,a=e[i];if(t(o,a)>=0)break;e[r]=a,r=i}e[r]=o}_down(r){let{data:e,compare:t}=this,o=this.length>>1,i=e[r];for(;r<o;){let a=(r<<1)+1,s=a+1;if(s<this.length&&t(e[s],e[a])<0&&(a=s),t(e[a],i)>=0)break;e[r]=e[a],r=a}e[r]=i}};function nf(n,r,e=1,t=!1){let o=1/0,i=1/0,a=-1/0,s=-1/0;for(let[v,w]of n[0])v<o&&(o=v),w<i&&(i=w),v>a&&(a=v),w>s&&(s=w);let l=a-o,c=s-i,u=Math.max(e,Math.min(l,c));if(u===e){let v=[o,i];return v.distance=0,v.distance}let p=new $s([],(v,w)=>w.max-v.max),d=OM(n),h=new mu(o+l/2,i+c/2,0,n);h.d>d.d&&(d=h);let f=2;function m(v,w,O){let S=new mu(v,w,O,n);if(f++,S.max>d.d+e&&p.push(S),S.d>d.d&&(d=S,t&&console.log(`found best ${Math.round(1e4*S.d)/1e4} after ${f} probes`),d.d>r))return r}let y=u/2;for(let v=o;v<a;v+=u)for(let w=i;w<s;w+=u)m(v+y,w+y,y);for(;p.length;){let{max:v,x:w,y:O,h:S}=p.pop();if(v-d.d<=e)break;y=S/2,m(w-y,O-y,y),m(w+y,O-y,y),m(w-y,O+y,y),m(w+y,O+y,y)}t&&console.log(`num probes: ${f}
3
- best distance: ${d.d}`);let g=[d.x,d.y];return g.distance=d.d,g.distance}function mu(n,r,e,t){this.x=n,this.y=r,this.h=e,this.d=CM(n,r,t),this.max=this.d+this.h*Math.SQRT2}function CM(n,r,e){let t=!1,o=1/0;for(let i of e)for(let a=0,s=i.length,l=s-1;a<s;l=a++){let c=i[a],u=i[l];c[1]>r!=u[1]>r&&n<(u[0]-c[0])*(r-c[1])/(u[1]-c[1])+c[0]&&(t=!t),o=Math.min(o,AM(n,r,c,u))}return o===0?0:(t?1:-1)*Math.sqrt(o)}function OM(n){let r=0,e=0,t=0,o=n[0];for(let a=0,s=o.length,l=s-1;a<s;l=a++){let c=o[a],u=o[l],p=c[0]*u[1]-u[0]*c[1];e+=(c[0]+u[0])*p,t+=(c[1]+u[1])*p,r+=p*3}let i=new mu(e/r,t/r,0,n);return r===0||i.d<0?new mu(o[0][0],o[0][1],0,n):i}function AM(n,r,e,t){let o=e[0],i=e[1],a=t[0]-o,s=t[1]-i;if(a!==0||s!==0){let l=((n-o)*a+(r-i)*s)/(a*a+s*s);l>1?(o=t[0],i=t[1]):l>0&&(o+=a*l,i+=s*l)}return a=n-o,s=r-i,a*a+s*s}var Ys={vertices:[160,160,-160,160,-160,-160,160,-160],vertexIndices:[1,0,3,2],vertexCount:4,elements:[0,4],elementCount:1,mesh:void 0},sf={vertices:[],vertexIndices:[],vertexCount:0,elements:[],elementCount:0,mesh:void 0},lf={vertices:[-160,160,160,-160,160,160,-160,-160],vertexIndices:[1,3,0,2],vertexCount:4,elements:[0,1,2,1,0,3],elementCount:2,mesh:void 0},af=(n,r)=>([e,t])=>(t<e&&(t+=r),(n>=e?n:n+r)<=t),xn=class extends IM{constructor(e,t,o=0,i=12,a=3,s=Ge.ODD,l=!1){super();this.forPathBevel=l;this.type="ShapeGeometry";this.vertexCache={};this._shape=e,this._depth=t,this._curveSegments=i,this._bevelSegmentsInput=a;let c=this._shape.extractShapePointsToFlatArray([],i),u=this._shape.shapeHoles.map(M=>{let D=M.extractShapePointsToFlatArray([],i),_=[];for(let B=D.length-1;B>=1;B-=2){let V=D[B-1],k=D[B-0];_.push(V,k)}return _}),p=[],d=[];for(let M=0;M<c.length;M+=2)d.push([c[M],c[M+1]]);p.push(d);for(let M=0;M<u.length;M++){let D=u[M],_=[];for(let B=0;B<D.length;B+=2)_.push([D[B],D[B+1]]);p.push(_)}let h;e.isText?h=new TM().setFromPoints(e.points.map(D=>D.position)).getSize(new MM).length()*.1:p[0].length===0?h=o:o>0?h=nf(p,o):h=1e-5,o<=0?(this._bevel=0,this._bevelSegments=0):(this._bevel=Math.min(o,h,t/2),this._bevelSegments=Math.floor(a));let f;try{f=Gr({windingRule:s,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[c]})}catch{f=Ys}let m;try{m=Gr({windingRule:Ge.ODD,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...u]})}catch{m=sf}if(!f)throw new Error("error generating geometry");let y=f.elementCount;if(m){f.elementCount+=m.elementCount;for(let M=0;M<m.elements.length;M++){let D=m.elements[M],_=M%2===0?f.vertexCount:0;f.elements.push(D+_)}for(let M=0;M<m.vertexIndices.length;M++){let D=m.vertexIndices[M],_=f.vertexCount;f.vertexIndices.push(D+_)}for(let M=0;M<m.vertices.length;M++){let D=m.vertices[M];f.vertices.push(D)}}let g=1/0,v=-1/0,w=1/0,O=-1/0;for(let M=0,D=f.vertexCount;M<D;M++){let _=M*2,B=f.vertices[_+0],V=f.vertices[_+1];B<g&&(g=B),B>v&&(v=B),V<w&&(w=V),V>O&&(O=V)}this._minX=g,this._minY=w,this._width=v-g,this._height=O-w,this._buffer=new qs(this._computeBufferEstimatedSize(f));let S=[],C=[];for(let M=f.elementCount-1;M>=0;M--){let D=M>=y,_=M*2,B=f.elements[_+0],V=f.elements[_+1],k=B+V,L={start:B,count:V,normals:[],continuous:[],concave:[]},W=B,F=k-1,j=B+1,H=this._shape.roundedCurves.length;do{let te=W-B,K=f.vertices[F*2+0],Z=f.vertices[F*2+1],Q=f.vertices[W*2+0],$=f.vertices[W*2+1],ue=f.vertices[j*2+0],le=f.vertices[j*2+1],ne=Q-K,ce=$-Z,ae=Math.sqrt(ne*ne+ce*ce);ne/=ae,ce/=ae;let me=Q-ue,pe=$-le,he=Math.sqrt(me*me+pe*pe);me/=he,pe/=he,L.normals[te*2+0]=-pe,L.normals[te*2+1]=me,L.concave[te]=ne*pe-ce*me>0;let xe=f.vertexIndices[W];if(Array.isArray(xe))L.continuous[te]=!1;else{let[ye,A]=this._shape.getCurveIndexFromVertexId(xe-1,!0);if(A>0&&A<1)L.continuous[te]=!0;else{let ie=A===1?ye+1:ye-1;ie=(ie+H)%H;let De=A===1?0:1,Ve=this._shape.roundedCurves[ye].getTangent(A),_e=this._shape.roundedCurves[ie].getTangent(De);L.continuous[te]=Ve.dot(_e)>.95}}D&&(L.normals[te*2+0]*=-1,L.normals[te*2+1]*=-1),[F,W,j]=[W,j,j+1],j>=k&&(j-=V)}while(j!==B+1);let q=[];q.push({bevelI:0,angle:0,size:0,boundary:{vertices:f.vertices.slice(B*2,k*2),vertexCount:V,vertexIndices:new Array(V).fill(!0).map((te,K)=>[K,K]),elements:[0,V],elementCount:1,mesh:null},reverseMap:[],insetPoints:f.vertices.slice(B*2,k*2)});let re=0;for(let te=1;te<=this._bevelSegments;te++){let K=te/this._bevelSegments*Math.PI/2,Z=(1-Math.cos(K))*this._bevel,Q=[],$=[],ue=[],le=[],ne=0;for(let ae=0;ae<V;ae++){let me=ae*2,pe=(ae-1+V)%V*2,he=f.vertices[L.start*2+me+0],xe=f.vertices[L.start*2+me+1],ye=-L.normals[pe+0]*Z,A=-L.normals[pe+1]*Z,ie=-L.normals[me+0]*Z,De=-L.normals[me+1]*Z;if(L.concave[ae]||!L.concave[ae]&&D){let Ve=Math.atan2(A,ye),_e=Math.atan2(De,ie);_e>Ve&&(_e-=Math.PI*2);let Pe=_e-Ve;if(L.continuous[ae]||D){let vt=Ve+Pe/2,Ie=Math.cos(vt)*Z,gt=Math.sin(vt)*Z;Q[2*ne+0]=he+Ie*(D?-1:1),Q[2*ne+1]=xe+gt*(D?-1:1),le[ne]=ae,ne++}else{let vt=Math.max(1,Math.floor(i/4*Math.abs(Pe)/Math.PI));for(let Ie=0;Ie<=vt;Ie++){let gt=Ve+Pe*(Ie/vt),St=Math.cos(gt)*Z,Vn=Math.sin(gt)*Z;Q[2*ne+0]=he+St,Q[2*ne+1]=xe+Vn,le[ne]=ae,ne++}}}else Q[2*ne+0]=he+ye,Q[2*ne+1]=xe+A,le[ne]=ae,$[ae]=ne,ne++,Q[2*ne+0]=he,Q[2*ne+1]=xe,le[ne]=ae,ne++,Q[2*ne+0]=he+ie,Q[2*ne+1]=xe+De,le[ne]=ae,ue[ae]=ne,ne++}let ce=Gr({windingRule:Ge.POSITIVE,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[Q],edgeCreateCallback:ae=>{let pe=ae.Org.idx,he=le[pe],xe=le[(pe+1)%le.length];ae.idx=[he,xe],ae.Sym.idx=[xe,he]},vertexIdCallback:ae=>{let me=ae.Lprev.idx;return[me?me[1]:0,ae.idx?ae.idx[0]:0]}});if(!ce)throw console.log("Error"),new Error(`error generating bevel geometry for ${te}'th loop`);if(!ce.vertexCount){let ae=(te-1)/this._bevelSegments*Math.PI/2;re=(1-Math.sin(ae))*this._bevel;break}for(let ae=0;ae<ce.vertexIndices.length;ae++){let[me,pe]=ce.vertexIndices[ae];if(me===pe)continue;let he=pe;pe<me&&(he+=V);for(let xe=me;xe<he;xe++){let ye=xe%V,A=(xe+1)%V;if(!L.continuous[ye]||!L.continuous[A]){ce.vertexIndices[ae]=[me,ye],ce.vertexIndices.splice(ae+1,0,[A,pe]),ce.vertices.splice((ae+1)*2,0,ce.vertices[ae*2],ce.vertices[ae*2+1]);break}}}q.push({bevelI:te,angle:K,size:Z,boundary:ce,reverseMap:le,insetPoints:Q})}let ee=(te,K,Z)=>{let Q=0,$=te.boundary.vertexIndices.length;for(;Q<$&&Z(te.boundary.vertexIndices[K]);)K=(K+1)%$,Q++;return Q},X=S.length;for(let te=1;te<q.length;te++){let K=q[te-1],Z=q[te],Q=K.boundary.vertexIndices.length,$=Z.boundary.vertexIndices.length;if(!Q||!$)break;let ue=L.concave.length,le=0,ne=af(le,V);for(;!K.boundary.vertexIndices.filter(ne).length||!Z.boundary.vertexIndices.filter(ne).length;)le++,ne=af(le,V);let ce=K.boundary.vertexIndices.findIndex(ne),ae=Z.boundary.vertexIndices.findIndex(ne);do ce=(ce+1)%Q;while(ne(K.boundary.vertexIndices[ce]));do ae=(ae+1)%$;while(ne(Z.boundary.vertexIndices[ae]));le=(le+1)%V;let me=le,pe=0,he=this._buildBevelVert(L,K,(ce-1+Q)%Q,void 0,pe),xe=this._buildBevelVert(L,Z,(ae-1+$)%$,void 0,pe),ye=he,A=xe,ie,De,Ve=!1;do{pe=(le||ue)/ue,ne=af(le,V);let _e=ee(K,ce,ne),Pe=ee(Z,ae,ne),vt=Ve;if(Ve=!1,_e&&!Pe){for(let Ie=0;Ie<_e;Ie++)ie=this._buildBevelVert(L,K,(ce+Ie)%Q,Ie/(_e-1),pe),S.push(ye.topN,ie.topP,A.topN),l===!1&&S.push(ie.bottomP,ye.bottomN,A.bottomN),ye=ie;Ve=!0}else if(!_e&&Pe)for(let Ie=0;Ie<Pe;Ie++)De=this._buildBevelVert(L,Z,(ae+Ie)%$,Ie/(Pe-1),pe),S.push(A.topN,ye.topP,De.topP),l===!1&&S.push(ye.bottomP,A.bottomN,De.bottomP),A=De;else if(_e&&Pe)if(ie=this._buildBevelVert(L,K,ce,0,pe),De=this._buildBevelVert(L,Z,ae,0,pe),vt?(S.push(ye.topN,De.topP,A.topN),S.push(ye.topN,ie.topP,De.topP),l===!1&&(S.push(De.bottomP,ye.bottomN,A.bottomN),S.push(De.bottomP,ie.bottomP,ye.bottomN))):(S.push(A.topN,ye.topN,ie.topP),S.push(A.topN,ie.topP,De.topP),l===!1&&(S.push(ie.bottomP,ye.bottomN,A.bottomN),S.push(ie.bottomP,A.bottomN,De.bottomP))),ye=ie,A=De,_e===Pe)for(let Ie=1;Ie<_e;Ie++)ie=this._buildBevelVert(L,K,(ce+Ie)%Q,Ie/(_e-1),pe),De=this._buildBevelVert(L,Z,(ae+Ie)%$,Ie/(Pe-1),pe),S.push(ye.topN,ie.topP,A.topN),S.push(A.topN,ie.topP,De.topP),l===!1&&(S.push(ie.bottomP,ye.bottomN,A.bottomN),S.push(ie.bottomP,A.bottomN,De.bottomP)),ye=ie,A=De;else if(_e>Pe){let Ie=_e/Pe,gt=0;for(let St=1;St<_e;St++)ie=this._buildBevelVert(L,K,(ce+St)%Q,St/(_e-1),pe),S.push(ye.topN,ie.topP,A.topN),l===!1&&S.push(ie.bottomP,ye.bottomN,A.bottomN),ye=ie,St>(gt+1)*Ie&&(gt++,De=this._buildBevelVert(L,Z,(ae+gt)%$,gt/(Pe-1),pe),S.push(A.topN,ie.topP,De.topP),l===!1&&S.push(ie.bottomP,A.bottomN,De.bottomP),A=De)}else{let Ie=Pe/_e,gt=0;for(let St=1;St<Pe;St++)De=this._buildBevelVert(L,Z,(ae+St)%$,St/(Pe-1),pe),S.push(A.topN,ie.topP,De.topP),l===!1&&S.push(ie.bottomP,A.bottomN,De.bottomP),A=De,St>(gt+1)*Ie&&(gt++,ie=this._buildBevelVert(L,K,(ce+gt)%Q,gt/(_e-1),pe),S.push(ye.topN,ie.topP,A.topN),l===!1&&S.push(ie.bottomP,ye.bottomN,A.bottomN),ye=ie)}ce=(ce+_e)%Q,ae=(ae+Pe)%$,le=(le+1)%ue}while(le!==me)}if(l===!1&&this._depth>this._bevel*2&&this._buildWall(q,L,S),D){let te=[];for(let K=S.length-1;K>=X+2;K-=3){let Z=S[K-2],Q=S[K-1],$=S[K-0];te.push($,Q,Z)}S.splice(X,S.length-X,...te)}if(D){let te=[];for(let K=q[q.length-1].boundary.vertices.length-1;K>=1;K-=2){let Z=q[q.length-1].boundary.vertices[K-1],Q=q[q.length-1].boundary.vertices[K-0];te.push(Z,Q)}C.push(te)}if(!D){let te=q[q.length-1],K;try{K=Gr({windingRule:q.length>1?Ge.POSITIVE:Ge.ODD,elementType:at.POLYGONS,vertexSize:2,strict:!0,contours:[te.insetPoints,...C]})}catch{K=lf}if(!K)throw new Error("Error generating geometry for surface");u.length===0&&this._bevel<h&&Object.assign(this,{useNgonForTopBottomFaceDuringBake:!0});for(let Z=0;Z<K.elementCount*3;Z+=3){let Q=this._buildSurfaceVert(K,K.elements[Z+0],re),$=this._buildSurfaceVert(K,K.elements[Z+1],re),ue=this._buildSurfaceVert(K,K.elements[Z+2],re);S.push(Q.top,$.top,ue.top),l===!1&&S.push(ue.bottom,$.bottom,Q.bottom)}}this.vertexCache={}}this._buffer.shrink();let T=new yu(Uint32Array.from(S),1),x=new yu(this._buffer.positions,3),N=new yu(this._buffer.normals,3),E=new yu(this._buffer.uvs,2);x.needsUpdate=!0,N.needsUpdate=!0,E.needsUpdate=!0,T.needsUpdate=!0,this.setAttribute("position",x),this.setAttribute("normal",N),this.setAttribute("uv",E),this.setIndex(T)}_computeBufferEstimatedSize(e){return e.vertexCount*2*(2+this._bevelSegments)}_buildWall(e,t,o){let i=e[0];for(let a=0,s=i.boundary.vertexCount;a<s;a++){let l=this._buildBevelVert(t,i,a),c=this._buildBevelVert(t,i,(a+1)%s);o.push(c.topP,l.topN,l.bottomN),o.push(c.topP,l.bottomN,c.bottomP)}}_buildSurfaceVert(e,t,o){let i=t.toString();if(i in this.vertexCache)return this.vertexCache[i];let a=e.vertices[t*2+0],s=e.vertices[t*2+1],l=(a-this._minX)/this._width,c=(s-this._minY)/this._height;this.forPathBevel&&(c=1);let u=this._buffer.get(this.forPathBevel?1:2),p=u*3,d=u*2,h={top:u+0,bottom:u+1};return this._buffer.positions[p+0]=a,this._buffer.positions[p+1]=s,this._buffer.positions[p+2]=this.forPathBevel?this._bevel:this._depth-o,this._buffer.normals[p+0]=0,this._buffer.normals[p+1]=0,this._buffer.normals[p+2]=1,this._buffer.uvs[d+0]=l,this._buffer.uvs[d+1]=c,this.forPathBevel===!1&&(this._buffer.positions[p+3]=a,this._buffer.positions[p+4]=s,this._buffer.positions[p+5]=o,this._buffer.normals[p+3]=0,this._buffer.normals[p+4]=0,this._buffer.normals[p+5]=-1,this._buffer.uvs[d+2]=l,this._buffer.uvs[d+3]=c),this.vertexCache[i]=h,h}_buildBevelVert(e,t,o,i=1,a){let s=`${t.bevelI}:${o}`;if(s in this.vertexCache&&a!==0&&a!==1&&(!a||a===this.vertexCache[s].pathBevelUCoord))return this.vertexCache[s];let[l,c]=t.boundary.vertexIndices[o],u,p,d,h;l!==c?(p=l,u=c,h=!1,d=e.continuous[p]&&e.continuous[u]):(u=l,p=(u-1+e.count)%e.count,h=e.concave[u]&&t.bevelI>0,d=e.continuous[u]||h);let f=Math.cos(t.angle),m=Math.sin(t.angle),y=o*2,g=u*2,v=p*2,w=t.boundary.vertices[y+0],O=t.boundary.vertices[y+1],S=(1-m)*this._bevel,C=(w-this._minX)/this._width,T=(O-this._minY)/this._height;this.forPathBevel&&(a!==void 0&&(C=a),T=1);let x=e.normals[g+0],N=e.normals[g+1],E=e.normals[v+0],M=e.normals[v+1];if(h){let k=E-x,L=M-N;x=x+k*(1-i),N=N+L*(1-i);let W=Math.sqrt(x*x+N*N);x/=W,N/=W}let D=this.forPathBevel?this._buffer.get(d?1:2):this._buffer.get(d?2:4),_=D*3,B=D*2,V={i:o,fi:u,topP:D+0,topN:D+0,bottomP:D+1,bottomN:D+1,pathBevelUCoord:a};return this._buffer.positions[_+0]=w,this._buffer.positions[_+1]=O,this._buffer.positions[_+2]=(this.forPathBevel?this._bevel:this._depth)-S,this._buffer.normals[_+0]=x*f,this._buffer.normals[_+1]=N*f,this._buffer.normals[_+2]=m,this._buffer.uvs[B+0]=C,this._buffer.uvs[B+1]=T,this.forPathBevel===!1&&(this._buffer.positions[_+3]=w,this._buffer.positions[_+4]=O,this._buffer.positions[_+5]=S,this._buffer.normals[_+3]=x*f,this._buffer.normals[_+4]=N*f,this._buffer.normals[_+5]=-m,this._buffer.uvs[B+2]=T,this._buffer.uvs[B+3]=C),d||(this.forPathBevel?(D+=1,_+=3,B+=2):(D+=2,_+=6,B+=4),V.topP=D+0,V.bottomP=D+1,this._buffer.positions[_+0]=w,this._buffer.positions[_+1]=O,this._buffer.positions[_+2]=(this.forPathBevel?this._bevel:this._depth)-S,this._buffer.normals[_+0]=E*f,this._buffer.normals[_+1]=M*f,this._buffer.normals[_+2]=m,this._buffer.uvs[B+0]=C,this._buffer.uvs[B+1]=T,this.forPathBevel===!1&&(this._buffer.positions[_+3]=w,this._buffer.positions[_+4]=O,this._buffer.positions[_+5]=S,this._buffer.normals[_+3]=E*f,this._buffer.normals[_+4]=M*f,this._buffer.normals[_+5]=-m,this._buffer.uvs[B+2]=T,this._buffer.uvs[B+3]=C)),this.vertexCache[s]=V,V}clone(){let e=new xn(this._shape,this._depth,this._bevel,this._curveSegments,this._bevelSegmentsInput);return e.userData=Co(this.userData),e}};var xa=class extends EM{constructor(e,t=12,o={}){super();this.type="ShapeGeometry";this.windingRule=Ge.ODD;this.elementType=at.POLYGONS;this.polySize=3;this.vertexSize=2;this.strict=!0;this._shape=e,this._curveSegments=t,this._triangulationOptions=Object.assign({windingRule:Ge.ODD,elementType:at.POLYGONS,polySize:3,vertexSize:2,strict:!0},o);let i=this._shape.extractShapePointsToFlatArray([],this._curveSegments),a=this._shape.shapeHoles.map(f=>f.extractShapePointsToFlatArray([],this._curveSegments)),s,l=!0,c=!0,u,p;for(let f=0,m=i.length/2;f<m;f++){let y=f*2,g=i[y+0],v=i[y+1];if(u!==void 0&&g!==u&&(l=!1),p!==void 0&&v!==p&&(c=!1),u=g,p=v,!l&&!c)break}if(!l&&!c)try{s=Gr({contours:[i,...a],windingRule:this._triangulationOptions.windingRule,elementType:this._triangulationOptions.elementType,polySize:this._triangulationOptions.polySize,vertexSize:this._triangulationOptions.vertexSize,strict:this._triangulationOptions.strict})}catch{s=Ys}let d=s?.vertexCount??1,h=s?.elementCount??1;if(this._positionAttribute=new gu(new Float32Array(d*3),3),this._normalAttribute=new gu(new Float32Array(d*3),3),this._uvAttribute=new gu(new Float32Array(d*2),2),this._indexAttribute=new gu(new Uint32Array(h*3),1),s){let f=1/0,m=-1/0,y=1/0,g=-1/0;for(let O=0,S=d;O<S;O++){let C=O*2,T=s.vertices[C+0],x=s.vertices[C+1];T<f&&(f=T),T>m&&(m=T),x<y&&(y=x),x>g&&(g=x)}let v=m-f,w=g-y;for(let O=0,S=d;O<S;O++){let C=O*2,T=s.vertices[C+0],x=s.vertices[C+1],N=(T-f)/v,E=(x-y)/w;this._positionAttribute.setXYZ(O,T,x,0),this._normalAttribute.setXYZ(O,0,0,1),this._uvAttribute.setXY(O,N,E)}for(let O=0,S=h;O<S;O++){let C=O*3,T=s.elements[C+0],x=s.elements[C+1],N=s.elements[C+2];this._indexAttribute.setX(C+0,T),this._indexAttribute.setX(C+1,x),this._indexAttribute.setX(C+2,N)}}this.setAttribute("position",this._positionAttribute),this.setAttribute("normal",this._normalAttribute),this.setAttribute("uv",this._uvAttribute),this.setIndex(this._indexAttribute),this.setDrawRange(0,(s?.elementCount??1)*3)}clone(){let e=new xa(this._shape,this._curveSegments);return e.userData=Co(this.userData),e}};var ba=class extends xn{constructor(e,t,o=0,i=12,a=3,s=Ge.ODD){super(e,t,o,i,a,s);this.type="ShapeGeometry"}_computeBufferEstimatedSize(e){return e.vertexCount*2*(2+this._bevelSegments)}_buildWall(e,t,o){let i=e[0];for(let a=0,s=i.boundary.vertexCount;a<s;a++){let l=this._buildBevelVert(t,i,a),c=this._buildBevelVert(t,i,(a+1)%s);o.push(c.topP,l.topN,l.bottomN),o.push(c.topP,l.bottomN,c.bottomP)}}clone(){let e=new ba(this._shape,this._depth,this._bevel,this._curveSegments,this._bevelSegmentsInput);return e.userData=Co(this.userData),e}};var Jt=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,subdivisions:40,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3,windingRule:Ge.ODD},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.abs(e.depth??0),a=n.shape??r?.shape,s=a?.roundness??e.roundness;a!==void 0&&(a instanceof je?(a.width!==t||a.height!==o)&&a.applySize(t,o):a=new je(t,o).fromJSON(a),n.parameters?.roundness!==void 0&&n.parameters?.roundness>0&&a.update());let l=a??new je(t,o);return{parameters:Object.assign(e,{width:t,height:o,depth:i,roundness:s}),shape:l}}static build(n){let{depth:r,extrudeBevelSize:e,extrudeBevelSegments:t,subdivisions:o,roundness:i,windingRule:a}=n.parameters;n.shape.roundness=i;let s;return r<=0?s=new xa(n.shape,o,{windingRule:a}):s=new ba(n.shape,r,e,o,t,a),Object.assign(s,{userData:{...n,type:"VectorGeometry"}})}};import{BufferGeometry as NM,Float32BufferAttribute as DM,MathUtils as cf,Vector2 as C0}from"three";var O0=Math.PI*2,Sa=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:64,angle:360,innerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters);return e.angle=cf.clamp(e.angle,0,360),{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,spikes:t,angle:o,innerRadius:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}=n.parameters,c=n.shape,u=r*.5,p=e*.5,d=_M(c,u,p,o*Math.PI/180,t,i);c.isClosed=!0,c.update();let h;return o===0?(h=new NM,h.setAttribute("position",new DM([],3))):h=Jt.create({shape:c,parameters:{subdivisions:d,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}}),Object.assign(h,{userData:{...n,type:"EllipseGeometry"}})}};function _M(n,r,e,t,o,i){if(t>=O0)return o>30||o%4===0?(RM(n,r,e,i),Math.round(o/4)):P0(n,t,o,r,e,i);t=Math.max(t,.001);let a={x:0,y:e},s=t+Math.PI*.5,l={x:Math.cos(s)*r,y:Math.sin(s)*e},c=x0({px:a.x,py:a.y,cx:l.x,cy:l.y,rx:r,ry:e,largeArcFlag:t>Math.PI,sweepFlag:!0});return o>30||o%c.length===0?BM(n,a.x,a.y,c,o,r,e,i):P0(n,t,o,r,e,i)}function BM(n,r,e,t,o,i,a,s){let l=Math.round(o/t.length);n.addPoint(va(r,e));for(let c=0,u=t.length;c<u;c++){let p=t[c],d=n.points[c],h=va(p.x,p.y);d.controls[1].position.set(p.x1,p.y1),h.controls[0].position.set(p.x2,p.y2),n.addPoint(h)}return s>0?A0(n,i,a,s):n.addPoint(va(0,0)),l}function P0(n,r,e,t,o,i){let a=-r/e;for(let s=0;s<=e;s++){let l=a*s,c=Math.sin(l)*t,u=Math.cos(l)*o;n.addPoint(va(c,u))}return r<O0?i>0?A0(n,t,o,i):n.addPoint(va(0,0)):(n.removePoint(n.points[n.points.length-1]),i>0&&T0(n,t,o,i)),1}function RM(n,r,e,t=0,o=0,i=0){let a=.5522847498,s=r*a,l=e*a;n.addPoint(xu(o-r,i,o-r,i-l,o-r,i+l)),n.addPoint(xu(o,i+e,o-s,i+e,o+s,i+e)),n.addPoint(xu(o+r,i,o+r,i+l,o+r,i-l)),n.addPoint(xu(o,i-e,o+s,i-e,o-s,i-e)),t>0&&T0(n,r,e,t)}function va(n,r){return new zr(cf.generateUUID(),new C0(n,r))}function xu(n,r,e,t,o,i){let a=va(n,r);return a.controls[0].position.set(e,t),a.controls[1].position.set(o,i),a}function A0(n,r,e,t){I0(n,r,e,t).forEach(i=>n.addPoint(i))}function T0(n,r,e,t){let o=I0(n,r,e,t),i=new je;o.forEach(a=>i.addPoint(a)),i.isClosed=!0,n.shapeHoles.push(i)}function I0(n,r,e,t){let o=t*r/100,i=o*(Math.abs(e)/Math.abs(r)),a=new C0(o/r,i/e),s=n.points.map(l=>{let c=l.clone();return c.uuid=cf.generateUUID(),c}).reverse();return s.forEach(l=>{l.position.multiply(a);let c=l.controls[0].position.clone().multiply(a),u=l.controls[1].position.clone().multiply(a);l.controls[0].position.copy(u),l.controls[1].position.copy(c)}),s}import{BufferGeometry as LM,Float32BufferAttribute as uf,Uint32BufferAttribute as VM,Vector3 as M0}from"three";var E0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,revolutions:2,segments:40,pathRadius:10,pathType:0,pathSegments:30,cornerRadius:30,cornerSegments:4},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??t),i=Math.abs(e.depth??t),a=Math.abs(Math.min(t,i))/2;return{parameters:Object.assign(e,{width:t,height:o,depth:i,radius:a,segments:Math.round(e.segments),pathSegments:Math.round(e.pathSegments),cornerSegments:Math.round(e.cornerSegments)})}}static build(n){let{width:r,height:e,depth:t,radius:o,revolutions:i,segments:a,pathRadius:s,pathType:l,pathSegments:c,cornerRadius:u,cornerSegments:p}=n.parameters,d=new Xs(!1,r,e,t,o,i,a,s,l,c,u,p);return Object.assign(d,{userData:{...n,type:"HelixGeometry"}})}},df=new VM([0,0,0],1),Xs=class extends LM{constructor(r=!0,e=1,t=1,o=1,i=1,a=1,s=1,l=1,c=1,u=1,p=1,d=1){if(super(),a===0)return;let h=r&&a===1;h&&(d=0),p>100&&(p=100),p===0&&(d=0);let f=()=>new M0,m=new M0,y=f(),g=f(),v=f(),w,O,S,C,T,x,N,E,M=f(),D=f(),_=f(),B=f(),V=f(),k=f(),L=f(),W=f(),F=t-2*l+.001,j=F/a,H=Math.ceil(s*a),q=H+1,re=F/H,ee=-F/2,X=u+1,te=2*Math.PI/u,K=Math.PI/2/d,Z=.01,Q=Math.min((1-p/100)*l,l-Z),$=l-Q,ue=0,le=2,ne=d*le+le,ce=X*ne/le,ae=ce+X*q,me=Math.max(0,X*(q+ne)),[pe,he,xe]=[3,3,2].map(ot=>Array(me*ot).fill(0)),ye=[],A=i-l;function ie(ot,Xe){let Mr=Math.PI/2;x=Xe*re,E=2*Math.PI*(x%j)/j+Mr,x+=ee,N=Math.sin(E)*A,T=Math.cos(E)*A,r?ot.set(T,N,x):ot.set(T,x,N)}ie(m,-1e-10),ie(y,0),M.copy(m),ie(m,1);let De=m.distanceTo(y),Ve=h?0:$+Q,_e=De*H+2*Ve,Pe=Q,vt=_e-Ve;for(let ot=0;ot<=H;ot++){ie(g,ot),W.subVectors(g,M).normalize(),M.copy(g),k.copy(g).setComponent(+r+1,0).normalize(),L.crossVectors(W,k).normalize();let Xe=ot===0,Mr=ot===H,Dd=Xe?3*Math.PI/2:K,_d=Xe?Pe:vt,_l=Xe?X:ae,zn=Xe?0:me-X,ct=W.clone().multiplyScalar(Xe?-$:$).add(g),Bd=W.clone().multiplyScalar(Xe?-1:1).normalize();for(let hr=0;hr<X;hr++){let xs=hr*te;if(D.addVectors(m.copy(k).multiplyScalar(l*Math.cos(xs)),y.copy(L).multiplyScalar(l*Math.sin(xs))),_.copy(D).normalize(),Xe||Mr){h||(ue=zn+hr,[0,1,2].forEach(Ut=>{pe[ue*3+Ut]=ct.getComponent(Ut),he[ue*3+Ut]=Bd.getComponent(Ut)}),xe[ue*2]=+Mr,xe[ue*2+1]=hr/u),y.copy(_).multiplyScalar(Q),v.addVectors(g,y);for(let Ut=0;Ut<d;Ut++){let Gn=Ut*K+Dd;B.addVectors(m.copy(W).multiplyScalar($*Math.sin(Gn)),y.copy(_).multiplyScalar($*Math.cos(Gn))),V.copy(B).normalize(),y.addVectors(v,B),B.normalize(),ue=_l+Ut*X+hr,[0,1,2].forEach(gi=>{pe[ue*3+gi]=y.getComponent(gi),he[ue*3+gi]=V.getComponent(gi)});let Bl=+Xe+Math.sin(Gn);xe[ue*2]=(_d+$*Bl)/_e,xe[ue*2+1]=hr/u}}y.addVectors(g,D),ue=ce+ot*X+hr,[0,1,2].forEach(Ut=>{pe[ue*3+Ut]=y.getComponent(Ut),he[ue*3+Ut]=_.getComponent(Ut)}),xe[ue*2]=(Ve+ot*De)/_e,xe[ue*2+1]=hr/u}}let Ie=q+2*d+le,gt=1,[St,Vn]=[+h,Ie-1];for(let ot=St;ot<=Vn-1;ot++){let Xe=h&&ot===Vn-1;for(let Mr=0;Mr<X-1;Mr++)w=ot*X+Mr,O=w+1,S=(Xe?Mr:w)+X,C=(Xe?Mr+1:O)+X,ot===0?ye.push(O,C,S):ot===Ie-2?ye.push(w,O,S):ye.push(w,O,S,O,C,S)}this.setIndex(ye),this.setAttribute("position",new uf(pe,3)),this.setAttribute("normal",new uf(he,3)),this.setAttribute("uv",new uf(xe,2))}getClosedTorusIndicesForBooleanOrSubdiv(){let r=this.userData.parameters,e=Math.ceil(r.tubularSegments),t=r.radialSegments+1,o=Array.from(this.getIndex().array),i,a,s,l,c=6*(e-1)*r.radialSegments,u=e,p=u===e;for(let d=0;d<r.radialSegments;d++)i=u*t+d,a=i+1,s=(p?d:i)+t,l=(p?d+1:a)+t,o[c++]=i,o[c++]=a,o[c++]=s,o[c++]=a,o[c++]=l,o[c++]=s;return o.length=c,df.array=o,df.count=o.length,df}};import{IcosahedronGeometry as zM}from"three";var N0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,detail:0,corner:0,cornerSides:4},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,detail:o,corner:i,cornerSides:a}=n.parameters,s=o===0&&i!==0?new Ks(r*.5,i,a):new zM(r*.5,o);return s.scale(1,e/r,t/r),Object.assign(s,{userData:{...n,type:"IcosahedronGeometry"}})}},Ks=class extends yn{constructor(r=1,e=.2,t=4){let o=(1+Math.sqrt(5))/2,i=[-1,o,0,1,o,0,-1,-o,0,1,-o,0,0,-1,o,0,1,o,0,-1,-o,0,1,-o,o,0,-1,o,0,1,-o,0,-1,-o,0,1],a=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],s="IcosahedronGeometry";super(i,a,s,r,e,t),this.type=s}static fromJSON(r){return new Ks(r.radius,r.corner,r.cornerSides)}};import{LatheGeometry as GM,Shape as FM}from"three";var D0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){(n.parameters?.points??[]).forEach(t=>{Array.isArray(t)&&(t.x=t[0],t.y=t[1])});let e=Object.assign({},r?.parameters??{width:100,segments:64,verticalSegments:64,points:[{x:0,y:-50,id:0},{x:50,y:-50,id:1},{x:50,y:50,id:2},{x:0,y:50,id:3}]},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{points:r,segments:e,verticalSegments:t}=n.parameters,o=new FM;o.moveTo(r[0].x,r[0].y),o.bezierCurveTo(r[1].x,r[1].y,r[2].x,r[2].y,r[3].x,r[3].y);let i=new GM(o.extractPoints(t).shape,e);return i.rotateZ(Math.PI),Object.assign(i,{userData:{...n,type:"LatheGeometry"}})}};import{BufferGeometry as F0,BufferGeometryLoader as ZM,Vector3 as JM,BoxGeometry as j0}from"three";import{BufferGeometry as YM,Vector2 as mf,Vector3 as G0}from"three";import{Box3 as jM,BufferAttribute as Qs,BufferGeometry as _0,Color as hf,EventDispatcher as kM,Float32BufferAttribute as wa,Matrix3 as B0,Matrix4 as z0,MathUtils as UM,Object3D as HM,Sphere as WM,Vector2 as ur,Vector3 as zt,Vector4 as qM}from"three";var ao=new z0,pf=new HM,bu=new zt,bn=class extends kM{constructor(){super(),this.uuid=UM.generateUUID(),this.name="",this.type="Geometry",this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.elementsNeedUpdate=!1,this.verticesNeedUpdate=!1,this.uvsNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.lineDistancesNeedUpdate=!1,this.groupsNeedUpdate=!1}applyMatrix4(r){let e=new B0().getNormalMatrix(r);for(let t=0,o=this.vertices.length;t<o;t++)this.vertices[t].applyMatrix4(r);for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t];i.normal.applyMatrix3(e).normalize();for(let a=0,s=i.vertexNormals.length;a<s;a++)i.vertexNormals[a].applyMatrix3(e).normalize()}return this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this.verticesNeedUpdate=!0,this.normalsNeedUpdate=!0,this}rotateX(r){return ao.makeRotationX(r),this.applyMatrix4(ao),this}rotateY(r){return ao.makeRotationY(r),this.applyMatrix4(ao),this}rotateZ(r){return ao.makeRotationZ(r),this.applyMatrix4(ao),this}translate(r,e,t){return ao.makeTranslation(r,e,t),this.applyMatrix4(ao),this}scale(r,e,t){return ao.makeScale(r,e,t),this.applyMatrix4(ao),this}lookAt(r){return pf.lookAt(r),pf.updateMatrix(),this.applyMatrix4(pf.matrix),this}fromBufferGeometry(r){let e=this,t=r.index!==null?r.index:void 0,o=r.attributes;if(o.position===void 0)return console.error("THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion."),this;let i=o.position,a=o.normal,s=o.color,l=o.uv,c=o.uv2;c!==void 0&&(this.faceVertexUvs[1]=[]);for(let d=0;d<i.count;d++)e.vertices.push(new zt().fromBufferAttribute(i,d)),s!==void 0&&e.colors.push(new hf().fromBufferAttribute(s,d));function u(d,h,f,m){let y=s===void 0?[]:[e.colors[d].clone(),e.colors[h].clone(),e.colors[f].clone()],g=a===void 0?[]:[new zt().fromBufferAttribute(a,d),new zt().fromBufferAttribute(a,h),new zt().fromBufferAttribute(a,f)],v=new Pa(d,h,f,g,y,m);e.faces.push(v),l!==void 0&&e.faceVertexUvs[0].push([new ur().fromBufferAttribute(l,d),new ur().fromBufferAttribute(l,h),new ur().fromBufferAttribute(l,f)]),c!==void 0&&e.faceVertexUvs[1].push([new ur().fromBufferAttribute(c,d),new ur().fromBufferAttribute(c,h),new ur().fromBufferAttribute(c,f)])}let p=r.groups;if(p.length>0)for(let d=0;d<p.length;d++){let h=p[d],f=h.start,m=h.count;for(let y=f,g=f+m;y<g;y+=3)t!==void 0?u(t.getX(y),t.getX(y+1),t.getX(y+2),h.materialIndex):u(y,y+1,y+2,h.materialIndex)}else if(t!==void 0)for(let d=0;d<t.count;d+=3)u(t.getX(d),t.getX(d+1),t.getX(d+2));else for(let d=0;d<i.count;d+=3)u(d,d+1,d+2);return this.computeFaceNormals(),r.boundingBox!==null&&(this.boundingBox=r.boundingBox.clone()),r.boundingSphere!==null&&(this.boundingSphere=r.boundingSphere.clone()),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(bu).negate(),this.translate(bu.x,bu.y,bu.z),this}normalize(){this.computeBoundingSphere();let r=this.boundingSphere.center,e=this.boundingSphere.radius,t=e===0?1:1/e,o=new z0;return o.set(t,0,0,-t*r.x,0,t,0,-t*r.y,0,0,t,-t*r.z,0,0,0,1),this.applyMatrix4(o),this}computeFaceNormals(){let r=new zt,e=new zt;for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t],a=this.vertices[i.a],s=this.vertices[i.b],l=this.vertices[i.c];r.subVectors(l,s),e.subVectors(a,s),r.cross(e),r.normalize(),i.normal.copy(r)}}computeVertexNormals(r=!0){let e=new Array(this.vertices.length);for(let t=0,o=this.vertices.length;t<o;t++)e[t]=new zt;if(r){let t=new zt,o=new zt;for(let i=0,a=this.faces.length;i<a;i++){let s=this.faces[i],l=this.vertices[s.a],c=this.vertices[s.b],u=this.vertices[s.c];t.subVectors(u,c),o.subVectors(l,c),t.cross(o),e[s.a].add(t),e[s.b].add(t),e[s.c].add(t)}}else{this.computeFaceNormals();for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t];e[i.a].add(i.normal),e[i.b].add(i.normal),e[i.c].add(i.normal)}}for(let t=0,o=this.vertices.length;t<o;t++)e[t].normalize();for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t],a=i.vertexNormals;a.length===3?(a[0].copy(e[i.a]),a[1].copy(e[i.b]),a[2].copy(e[i.c])):(a[0]=e[i.a].clone(),a[1]=e[i.b].clone(),a[2]=e[i.c].clone())}this.faces.length>0&&(this.normalsNeedUpdate=!0)}computeFlatVertexNormals(){this.computeFaceNormals();for(let r=0,e=this.faces.length;r<e;r++){let t=this.faces[r],o=t.vertexNormals;o.length===3?(o[0].copy(t.normal),o[1].copy(t.normal),o[2].copy(t.normal)):(o[0]=t.normal.clone(),o[1]=t.normal.clone(),o[2]=t.normal.clone())}this.faces.length>0&&(this.normalsNeedUpdate=!0)}computeMorphNormals(){for(let e=0,t=this.faces.length;e<t;e++){let o=this.faces[e];o.__originalFaceNormal?o.__originalFaceNormal.copy(o.normal):o.__originalFaceNormal=o.normal.clone(),o.__originalVertexNormals||(o.__originalVertexNormals=[]);for(let i=0,a=o.vertexNormals.length;i<a;i++)o.__originalVertexNormals[i]?o.__originalVertexNormals[i].copy(o.vertexNormals[i]):o.__originalVertexNormals[i]=o.vertexNormals[i].clone()}let r=new bn;r.faces=this.faces;for(let e=0,t=this.morphTargets.length;e<t;e++){if(!this.morphNormals[e]){this.morphNormals[e]={},this.morphNormals[e].faceNormals=[],this.morphNormals[e].vertexNormals=[];let i=this.morphNormals[e].faceNormals,a=this.morphNormals[e].vertexNormals;for(let s=0,l=this.faces.length;s<l;s++){let c=new zt,u={a:new zt,b:new zt,c:new zt};i.push(c),a.push(u)}}let o=this.morphNormals[e];r.vertices=this.morphTargets[e].vertices,r.computeFaceNormals(),r.computeVertexNormals();for(let i=0,a=this.faces.length;i<a;i++){let s=this.faces[i],l=o.faceNormals[i],c=o.vertexNormals[i];l.copy(s.normal),c.a.copy(s.vertexNormals[0]),c.b.copy(s.vertexNormals[1]),c.c.copy(s.vertexNormals[2])}}for(let e=0,t=this.faces.length;e<t;e++){let o=this.faces[e];o.normal=o.__originalFaceNormal,o.vertexNormals=o.__originalVertexNormals}}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new jM),this.boundingBox.setFromPoints(this.vertices)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new WM),this.boundingSphere.setFromPoints(this.vertices)}merge(r,e,t=0){if(!(r&&r.isGeometry)){console.error("THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.",r);return}let o,i=this.vertices.length,a=this.vertices,s=r.vertices,l=this.faces,c=r.faces,u=this.colors,p=r.colors;e!==void 0&&(o=new B0().getNormalMatrix(e));for(let d=0,h=s.length;d<h;d++){let m=s[d].clone();e!==void 0&&m.applyMatrix4(e),a.push(m)}for(let d=0,h=p.length;d<h;d++)u.push(p[d].clone());for(let d=0,h=c.length;d<h;d++){let f=c[d],m,y,g=f.vertexNormals,v=f.vertexColors,w=new Pa(f.a+i,f.b+i,f.c+i);w.normal.copy(f.normal),o!==void 0&&w.normal.applyMatrix3(o).normalize();for(let O=0,S=g.length;O<S;O++)m=g[O].clone(),o!==void 0&&m.applyMatrix3(o).normalize(),w.vertexNormals.push(m);w.color.copy(f.color);for(let O=0,S=v.length;O<S;O++)y=v[O],w.vertexColors.push(y.clone());w.materialIndex=f.materialIndex+t,l.push(w)}for(let d=0,h=r.faceVertexUvs.length;d<h;d++){let f=r.faceVertexUvs[d];this.faceVertexUvs[d]===void 0&&(this.faceVertexUvs[d]=[]);for(let m=0,y=f.length;m<y;m++){let g=f[m],v=[];for(let w=0,O=g.length;w<O;w++)v.push(g[w].clone());this.faceVertexUvs[d].push(v)}}}mergeMesh(r){if(!(r&&r.isMesh)){console.error("THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.",r);return}r.matrixAutoUpdate&&r.updateMatrix(),this.merge(r.geometry,r.matrix)}mergeVertices(r=4){let e={},t=[],o=[],i=Math.pow(10,r);for(let l=0,c=this.vertices.length;l<c;l++){let u=this.vertices[l],p=Math.round(u.x*i)+"_"+Math.round(u.y*i)+"_"+Math.round(u.z*i);e[p]===void 0?(e[p]=l,t.push(this.vertices[l]),o[l]=t.length-1):o[l]=o[e[p]]}let a=[];for(let l=0,c=this.faces.length;l<c;l++){let u=this.faces[l];u.a=o[u.a],u.b=o[u.b],u.c=o[u.c];let p=[u.a,u.b,u.c];for(let d=0;d<3;d++)if(p[d]===p[(d+1)%3]){a.push(l);break}}for(let l=a.length-1;l>=0;l--){let c=a[l];this.faces.splice(c,1);for(let u=0,p=this.faceVertexUvs.length;u<p;u++)this.faceVertexUvs[u].splice(c,1)}let s=this.vertices.length-t.length;return this.vertices=t,s}setFromPoints(r){this.vertices=[];for(let e=0,t=r.length;e<t;e++){let o=r[e];this.vertices.push(new zt(o.x,o.y,o.z||0))}return this}sortFacesByMaterialIndex(){let r=this.faces,e=r.length;for(let l=0;l<e;l++)r[l]._id=l;function t(l,c){return l.materialIndex-c.materialIndex}r.sort(t);let o=this.faceVertexUvs[0],i=this.faceVertexUvs[1],a,s;o&&o.length===e&&(a=[]),i&&i.length===e&&(s=[]);for(let l=0;l<e;l++){let c=r[l]._id;a&&a.push(o[c]),s&&s.push(i[c])}a&&(this.faceVertexUvs[0]=a),s&&(this.faceVertexUvs[1]=s)}toJSON(){let r={metadata:{version:4.5,type:"Geometry",generator:"Geometry.toJSON"}};if(r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.parameters!==void 0){let f=this.parameters;for(let m in f)f[m]!==void 0&&(r[m]=f[m]);return r}let e=[];for(let f=0;f<this.vertices.length;f++){let m=this.vertices[f];e.push(m.x,m.y,m.z)}let t=[],o=[],i={},a=[],s={},l=[],c={};for(let f=0;f<this.faces.length;f++){let m=this.faces[f],y=!0,g=!1,v=this.faceVertexUvs[0][f]!==void 0,w=m.normal.length()>0,O=m.vertexNormals.length>0,S=m.color.r!==1||m.color.g!==1||m.color.b!==1,C=m.vertexColors.length>0,T=0;if(T=u(T,0,0),T=u(T,1,y),T=u(T,2,g),T=u(T,3,v),T=u(T,4,w),T=u(T,5,O),T=u(T,6,S),T=u(T,7,C),t.push(T),t.push(m.a,m.b,m.c),t.push(m.materialIndex),v){let x=this.faceVertexUvs[0][f];t.push(h(x[0]),h(x[1]),h(x[2]))}if(w&&t.push(p(m.normal)),O){let x=m.vertexNormals;t.push(p(x[0]),p(x[1]),p(x[2]))}if(S&&t.push(d(m.color)),C){let x=m.vertexColors;t.push(d(x[0]),d(x[1]),d(x[2]))}}function u(f,m,y){return y?f|1<<m:f&~(1<<m)}function p(f){let m=f.x.toString()+f.y.toString()+f.z.toString();return i[m]!==void 0||(i[m]=o.length/3,o.push(f.x,f.y,f.z)),i[m]}function d(f){let m=f.r.toString()+f.g.toString()+f.b.toString();return s[m]!==void 0||(s[m]=a.length,a.push(f.getHex())),s[m]}function h(f){let m=f.x.toString()+f.y.toString();return c[m]!==void 0||(c[m]=l.length/2,l.push(f.x,f.y)),c[m]}return r.data={},r.data.vertices=e,r.data.normals=o,a.length>0&&(r.data.colors=a),l.length>0&&(r.data.uvs=[l]),r.data.faces=t,r}clone(){return new bn().copy(this)}copy(r){this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=r.name;let e=r.vertices;for(let d=0,h=e.length;d<h;d++)this.vertices.push(e[d].clone());let t=r.colors;for(let d=0,h=t.length;d<h;d++)this.colors.push(t[d].clone());let o=r.faces;for(let d=0,h=o.length;d<h;d++)this.faces.push(o[d].clone());for(let d=0,h=r.faceVertexUvs.length;d<h;d++){let f=r.faceVertexUvs[d];this.faceVertexUvs[d]===void 0&&(this.faceVertexUvs[d]=[]);for(let m=0,y=f.length;m<y;m++){let g=f[m],v=[];for(let w=0,O=g.length;w<O;w++){let S=g[w];v.push(S.clone())}this.faceVertexUvs[d].push(v)}}let i=r.morphTargets;for(let d=0,h=i.length;d<h;d++){let f={};if(f.name=i[d].name,i[d].vertices!==void 0){f.vertices=[];for(let m=0,y=i[d].vertices.length;m<y;m++)f.vertices.push(i[d].vertices[m].clone())}if(i[d].normals!==void 0){f.normals=[];for(let m=0,y=i[d].normals.length;m<y;m++)f.normals.push(i[d].normals[m].clone())}this.morphTargets.push(f)}let a=r.morphNormals;for(let d=0,h=a.length;d<h;d++){let f={};if(a[d].vertexNormals!==void 0){f.vertexNormals=[];for(let m=0,y=a[d].vertexNormals.length;m<y;m++){let g=a[d].vertexNormals[m],v={};v.a=g.a.clone(),v.b=g.b.clone(),v.c=g.c.clone(),f.vertexNormals.push(v)}}if(a[d].faceNormals!==void 0){f.faceNormals=[];for(let m=0,y=a[d].faceNormals.length;m<y;m++)f.faceNormals.push(a[d].faceNormals[m].clone())}this.morphNormals.push(f)}let s=r.skinWeights;for(let d=0,h=s.length;d<h;d++)this.skinWeights.push(s[d].clone());let l=r.skinIndices;for(let d=0,h=l.length;d<h;d++)this.skinIndices.push(l[d].clone());let c=r.lineDistances;for(let d=0,h=c.length;d<h;d++)this.lineDistances.push(c[d]);let u=r.boundingBox;u!==null&&(this.boundingBox=u.clone());let p=r.boundingSphere;return p!==null&&(this.boundingSphere=p.clone()),this.elementsNeedUpdate=r.elementsNeedUpdate,this.verticesNeedUpdate=r.verticesNeedUpdate,this.uvsNeedUpdate=r.uvsNeedUpdate,this.normalsNeedUpdate=r.normalsNeedUpdate,this.colorsNeedUpdate=r.colorsNeedUpdate,this.lineDistancesNeedUpdate=r.lineDistancesNeedUpdate,this.groupsNeedUpdate=r.groupsNeedUpdate,this}toBufferGeometry(){let r=new ff().fromGeometry(this),e=new _0,t=new Float32Array(r.vertices.length*3);if(e.setAttribute("position",vu.call(new Qs(t,3),r.vertices)),r.normals.length>0){let o=new Float32Array(r.normals.length*3);e.setAttribute("normal",vu.call(new Qs(o,3),r.normals))}if(r.colors.length>0){let o=new Float32Array(r.colors.length*3);e.setAttribute("color",R0.call(new Qs(o,3),r.colors))}if(r.uvs.length>0){let o=new Float32Array(r.uvs.length*2);e.setAttribute("uv",L0.call(new Qs(o,2),r.uvs))}if(r.uvs2.length>0){let o=new Float32Array(r.uvs2.length*2);e.setAttribute("uv2",L0.call(new Qs(o,2),r.uvs2))}e.groups=r.groups;for(let o in r.morphTargets){let i=[],a=r.morphTargets[o];for(let s=0,l=a.length;s<l;s++){let c=a[s],u=new wa(c.data.length*3,3);u.name=c.name,i.push(vu.call(u,c.data))}e.morphAttributes[o]=i}if(r.skinIndices.length>0){let o=new wa(r.skinIndices.length*4,4);e.setAttribute("skinIndex",V0.call(o,r.skinIndices))}if(r.skinWeights.length>0){let o=new wa(r.skinWeights.length*4,4);e.setAttribute("skinWeight",V0.call(o,r.skinWeights))}return r.boundingSphere!==null&&(e.boundingSphere=r.boundingSphere.clone()),r.boundingBox!==null&&(e.boundingBox=r.boundingBox.clone()),e}computeTangents(){console.error("THREE.Geometry: .computeTangents() has been removed.")}computeLineDistances(){console.error("THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.")}applyMatrix(r){return console.warn("THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4()."),this.applyMatrix4(r)}dispose(){this.dispatchEvent({type:"dispose"})}static createBufferGeometryFromObject(r){let e=new _0,t=r.geometry;if(r.isPoints||r.isLine){let o=new wa(t.vertices.length*3,3),i=new wa(t.colors.length*3,3);if(e.setAttribute("position",vu.call(o,t.vertices)),e.setAttribute("color",R0.call(i,t.colors)),t.lineDistances&&t.lineDistances.length===t.vertices.length){let a=new wa(t.lineDistances.length,1);e.setAttribute("lineDistance",$M.call(a,t.lineDistances))}t.boundingSphere!==null&&(e.boundingSphere=t.boundingSphere.clone()),t.boundingBox!==null&&(e.boundingBox=t.boundingBox.clone())}else r.isMesh&&(e=t.toBufferGeometry());return e}};bn.prototype.isGeometry=!0;var ff=class{constructor(){this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.uvs2=[],this.groups=[],this.morphTargets={},this.skinWeights=[],this.skinIndices=[],this.boundingBox=null,this.boundingSphere=null,this.verticesNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.groupsNeedUpdate=!1}computeGroups(r){let e=[],t,o,i,a=r.faces;for(o=0;o<a.length;o++){let s=a[o];s.materialIndex!==i&&(i=s.materialIndex,t!==void 0&&(t.count=o*3-t.start,e.push(t)),t={start:o*3,materialIndex:i})}t!==void 0&&(t.count=o*3-t.start,e.push(t)),this.groups=e}fromGeometry(r){let e=r.faces,t=r.vertices,o=r.faceVertexUvs,i=o[0]&&o[0].length>0,a=o[1]&&o[1].length>0,s=r.morphTargets,l=s.length,c;if(l>0){c=[];for(let g=0;g<l;g++)c[g]={name:s[g].name,data:[]};this.morphTargets.position=c}let u=r.morphNormals,p=u.length,d;if(p>0){d=[];for(let g=0;g<p;g++)d[g]={name:u[g].name,data:[]};this.morphTargets.normal=d}let h=r.skinIndices,f=r.skinWeights,m=h.length===t.length,y=f.length===t.length;t.length>0&&e.length===0&&console.error("THREE.DirectGeometry: Faceless geometries are not supported.");for(let g=0;g<e.length;g++){let v=e[g];this.vertices.push(t[v.a],t[v.b],t[v.c]);let w=v.vertexNormals;if(w.length===3)this.normals.push(w[0],w[1],w[2]);else{let S=v.normal;this.normals.push(S,S,S)}let O=v.vertexColors;if(O.length===3)this.colors.push(O[0],O[1],O[2]);else{let S=v.color;this.colors.push(S,S,S)}if(i===!0){let S=o[0][g];S!==void 0?this.uvs.push(S[0],S[1],S[2]):(console.warn("THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ",g),this.uvs.push(new ur,new ur,new ur))}if(a===!0){let S=o[1][g];S!==void 0?this.uvs2.push(S[0],S[1],S[2]):(console.warn("THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ",g),this.uvs2.push(new ur,new ur,new ur))}for(let S=0;S<l;S++){let C=s[S].vertices;c[S].data.push(C[v.a],C[v.b],C[v.c])}for(let S=0;S<p;S++){let C=u[S].vertexNormals[g];d[S].data.push(C.a,C.b,C.c)}m&&this.skinIndices.push(h[v.a],h[v.b],h[v.c]),y&&this.skinWeights.push(f[v.a],f[v.b],f[v.c])}return this.computeGroups(r),this.verticesNeedUpdate=r.verticesNeedUpdate,this.normalsNeedUpdate=r.normalsNeedUpdate,this.colorsNeedUpdate=r.colorsNeedUpdate,this.uvsNeedUpdate=r.uvsNeedUpdate,this.groupsNeedUpdate=r.groupsNeedUpdate,r.boundingSphere!==null&&(this.boundingSphere=r.boundingSphere.clone()),r.boundingBox!==null&&(this.boundingBox=r.boundingBox.clone()),this}},Pa=class{constructor(r,e,t,o,i,a=0){this.a=r,this.b=e,this.c=t,this.normal=o&&o.isVector3?o:new zt,this.vertexNormals=Array.isArray(o)?o:[],this.color=i&&i.isColor?i:new hf,this.vertexColors=Array.isArray(i)?i:[],this.materialIndex=a}clone(){return new this.constructor().copy(this)}copy(r){this.a=r.a,this.b=r.b,this.c=r.c,this.normal.copy(r.normal),this.color.copy(r.color),this.materialIndex=r.materialIndex;for(let e=0,t=r.vertexNormals.length;e<t;e++)this.vertexNormals[e]=r.vertexNormals[e].clone();for(let e=0,t=r.vertexColors.length;e<t;e++)this.vertexColors[e]=r.vertexColors[e].clone();return this}};function $M(n){return this.array.set(n),this}function R0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyColorsArray(): color is undefined",t),i=new hf),r[e++]=i.r,r[e++]=i.g,r[e++]=i.b}return this}function L0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector2sArray(): vector is undefined",t),i=new ur),r[e++]=i.x,r[e++]=i.y}return this}function vu(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector3sArray(): vector is undefined",t),i=new zt),r[e++]=i.x,r[e++]=i.y,r[e++]=i.z}return this}function V0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector4sArray(): vector is undefined",t),i=new qM),r[e++]=i.x,r[e++]=i.y,r[e++]=i.z,r[e++]=i.w}return this}var XM=["a","b","c"];function KM(n,r){switch(r){case"c":return n.c;case"b":return n.b;case"a":default:return n.a}}function yf(n,r,e){let t=Math.min(n,r),o=Math.max(n,r),i=t+"_"+o;return e.get(i)}function gf(n,r,e,t,o,i){let a=Math.min(n,r),s=Math.max(n,r),l=a+"_"+s,c;if(t.has(l))c=t.get(l);else{let u=e[a],p=e[s];c={a:u,b:p,newEdge:null,faces:[]},t.set(l,c)}c.faces.push(o),i[n].edges.push(c),i[r].edges.push(c)}function QM(n,r,e,t){let o,i,a;for(o=0,i=n.length;o<i;o++)e[o]={edges:[]};for(o=0,i=r.length;o<i;o++)a=r[o],gf(a.a,a.b,n,t,a,e),gf(a.b,a.c,n,t,a,e),gf(a.c,a.a,n,t,a,e)}function Su(n,r,e,t,o){n.push(new Pa(r,e,t,void 0,void 0,o))}function Ca(n,r){return Math.abs(r-n)/2+Math.min(n,r)}function wu(n,r,e,t){n.push([r.clone(),e.clone(),t.clone()])}var Pu=class{constructor(r=1){this.subdivisions=r}modify(r){r instanceof YM?r=new bn().fromBufferGeometry(r):r=r.clone(),r.mergeVertices();let e=this.subdivisions;for(;e-- >0;)this._smooth(r);return r.computeFaceNormals(),r.computeVertexNormals(),r}_smooth(r){let e=new G0,t,o,i,a,s,l=r.vertices,c=r.faces,u=r.faceVertexUvs[0],p=u!==void 0&&u.length>0,d=[],h=new Map;QM(l,c,d,h);let f=[],m,y,g,v,w,O,S;for(let Z of Array.from(h.keys())){for(y=h.get(Z),g=new G0,w=3/8,O=1/8,S=y.faces.length,S!=2&&(w=.5,O=0,S!=1),g.addVectors(y.a,y.b).multiplyScalar(w),e.set(0,0,0),a=0;a<S;a++){for(v=y.faces[a],s=0;s<3&&(m=l[KM(v,XM[s])],!(m!==y.a&&m!==y.b));s++);m&&e.add(m)}e.multiplyScalar(O),g.add(e),y.newEdge=f.length,f.push(g)}let C,T,x,N,E,M,D,_=[];for(o=0,i=l.length;o<i;o++){for(M=l[o],E=d[o].edges,t=E.length,t==3?C=3/16:t>3&&(C=3/(8*t)),T=1-t*Number(C),x=C,t<=2&&(t==2?(T=3/4,x=1/8):t==1||t==0),D=M.clone().multiplyScalar(T),e.set(0,0,0),a=0;a<t;a++)N=E[a],m=N.a!==M?N.a:N.b,e.add(m);e.multiplyScalar(Number(x)),D.add(e),_.push(D)}let B=_.concat(f),V=_.length,k,L,W,F=[],j=[],H,q,re,ee,X=new mf,te=new mf,K=new mf;for(o=0,i=c.length;o<i;o++)v=c[o],k=Number(yf(v.a,v.b,h).newEdge)+V,L=Number(yf(v.b,v.c,h).newEdge)+V,W=Number(yf(v.c,v.a,h).newEdge)+V,Su(F,k,L,W,v.materialIndex),Su(F,v.a,k,W,v.materialIndex),Su(F,v.b,L,k,v.materialIndex),Su(F,v.c,W,L,v.materialIndex),p&&(H=u[o],q=H[0],re=H[1],ee=H[2],X.set(Ca(q.x,re.x),Ca(q.y,re.y)),te.set(Ca(re.x,ee.x),Ca(re.y,ee.y)),K.set(Ca(q.x,ee.x),Ca(q.y,ee.y)),wu(j,X,te,K),wu(j,q,X,K),wu(j,re,te,X),wu(j,ee,K,te));r.vertices=B,r.faces=F,p&&(r.faceVertexUvs[0]=j)}};var Pt=new JM,k0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=n.geometry??r?.geometry??new F0().copy(new j0(100,100,100)),t;r===void 0?(e.computeBoundingBox(),e.boundingBox.getSize(Pt),t={width:Pt.x,height:Pt.y,depth:Pt.z,subdivisions:0}):t=r.parameters;let o={...t,...n.parameters};return{parameters:{width:Math.abs(o.width),height:Math.abs(o.height),depth:Math.abs(o.depth),subdivisions:Math.abs(o.subdivisions)},geometry:e}}static build(n){let{width:r,height:e,depth:t,subdivisions:o}=n.parameters,i=n.geometry??new F0().copy(new j0(100,100,100)),a=i.userData.parameters;a===void 0?(i.computeBoundingBox(),i.boundingBox.getSize(Pt)):Pt.set(a.width,a.height,a.depth),(r!==Pt.x||e!==Pt.y||t!==Pt.z)&&i.scale(Pt.x===0?1:r/Pt.x,Pt.y===0?1:e/Pt.y,Pt.z===0?1:t/Pt.z);let s=i.originalGeometry;try{o>0?(s===void 0||a?.subdivisions!==o)&&(s===void 0&&(s=i),i=new Pu(o).modify(s).toBufferGeometry()):(s!==void 0&&(i=s),s=void 0,i.getAttribute("normal")===void 0&&i.computeVertexNormals())}catch{s!==void 0&&(i=s),s=void 0,i.getAttribute("normal")===void 0&&i.computeVertexNormals()}return s!==void 0&&Object.assign(i,{originalGeometry:s}),delete n.geometry,Object.assign(i,{userData:{...n,type:"NonParametricGeometry"}})}static loadFromUrl(n,r,e){new ZM(e).load(n,o=>{let i=this.normalizeInputs({geometry:o});o.boundingBox.getSize(Pt);let a=100/Pt.x;Object.assign(i.parameters,{width:100,height:Pt.y*a,depth:Pt.z*a}),r(this.build(i))})}};var Cu=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:5,cornerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:3},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,spikes:t,cornerRadius:o,depth:i,extrudeBevelSize:a,extrudeBevelSegments:s}=n.parameters,l=n.shape,c=r*.5,u=e*.5,p=0,d=0,h=2*Math.PI/t;for(let m=0;m<t;m++){let y=h*m,g=p+Math.sin(y)*c,v=d+Math.cos(y)*u;l.addPoint(l.createPoint(g,v))}l.isClosed=!0;for(let m=0,y=l.points.length;m<y;m++)l.points[m].roundness=o;l.roundness=o,l.update();let f=Jt.create({shape:l,parameters:{roundness:o,depth:i,extrudeBevelSize:a,extrudeBevelSegments:s}});return Object.assign(f,{userData:{...n,type:"PolygonGeometry"}})}};import{BufferGeometry as eE,Float32BufferAttribute as xf,Vector2 as so,Vector3 as Nt}from"three";var U0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:4,heightSegments:1,cornerRadius:0,cornerSegments:8,openEnded:!1},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,radialSegments:o,heightSegments:i,openEnded:a,cornerRadius:s,cornerSegments:l}=n.parameters,c=new vf(r*.5,e,o,i,a,s,l);return c.scale(1,1,t/r),Object.assign(c,{userData:{...n,type:"PyramidGeometry"}})}};function Zs(n,r,e){e.x=n.x*r.x,e.y=n.y,e.z=n.x*r.y}function bf(n,r,e,t,o,i){let a=r.clone().sub(n),s=e.clone().sub(n),l=a.angleTo(s);if(a.normalize(),s.normalize(),t===o){let c=a.add(s).normalize();i.copy(n).addScaledVector(c,t/Math.sin(l/2))}else{let c=a.angleTo(s);i.copy(n),i.addScaledVector(a,o/Math.sin(c)),i.addScaledVector(s,t/Math.sin(c))}}function tE(n,r,e){let t=n.clone().sub(r),o=e.clone().sub(r);return t.projectOnVector(o),t.add(r)}var vf=class extends eE{constructor(r=.5,e=1,t=4,o=1,i=!1,a=0,s=4){super(),t=Math.floor(Math.max(3,t)),o=Math.floor(o),s=Math.floor(s);let l=[],c=[],u=[],p=[],d=0,h=e/2,f=Math.PI/t,m=r*Math.cos(Math.PI/t),y=2*Math.PI/t,g=(t-2)*Math.PI/t,v=Math.PI-g,w=new Nt(0,-h,0),O=new Nt(0,h,0),S=new so(r,-h),C=new so(m,-h),T=new so(0,O.y).sub(C),x=new so(0,O.y).sub(S),N=new so(T.y,-T.x).normalize(),E=new so(x.y,-x.x).normalize(),D=r*Math.cos(Math.PI/t)*Math.tan((Math.PI-T.angle())/2)-1e-8;a=Math.min(a,D);let _;{let j=new Nt(N.x,N.y,0),H=new Nt(Math.cos(y)*j.x,j.y,Math.sin(y)*j.x);_=j.angleTo(H)}let B=a/Math.tan((Math.PI-T.angle())/2),V=a/Math.tan((Math.PI-_)/2),k=new Nt;if(!i){c.push(w.x,w.y,w.z),u.push(0,-1,0),p.push(0,0);let j=d++,H=[],q=S.clone(),re=B/Math.cos(Math.PI/t);q.x-=re;for(let ee=0;ee<t;ee++){let X=ee/t*Math.PI*2+f,te=new so(Math.sin(X),Math.cos(X));Zs(q,te,k),c.push(k.x,k.y,k.z),u.push(0,-1,0),p.push(0,0),H.push(d++)}for(let ee=0;ee<H.length;ee++)l.push(H[ee],j,H[(ee+1)%H.length])}let L=[];{let j=new Nt,H=new Nt,q=new Nt,re=new Nt,ee=new Nt,X=new Nt;for(let te=0;te<t;te++){let K=te/t*Math.PI*2+f,Z=(te+.5)/t*Math.PI*2+f,Q=(te+1)/t*Math.PI*2+f,$=new so(Math.sin(K),Math.cos(K)),ue=new so(Math.sin(Z),Math.cos(Z)),le=new so(Math.sin(Q),Math.cos(Q));Zs(S,$,H),Zs(S,le,q),Zs(N,ue,j),bf(O,H,q,V,V,re),c.push(re.x,re.y,re.z),bf(H,O,q,V,B,ee),c.push(ee.x,ee.y,ee.z),bf(q,H,O,B,V,X),c.push(X.x,X.y,X.z),u.push(j.x,j.y,j.z),u.push(j.x,j.y,j.z),u.push(j.x,j.y,j.z),p.push(0,0),p.push(0,0),p.push(0,0);let ne=d++,ce=d++,ae=d++;if(l.push(ne,ce,ae),a>0){{let he=H.clone().add(q).multiplyScalar(.5),xe=O.clone().sub(he).normalize(),A=w.clone().sub(he).normalize().add(xe).normalize().multiplyScalar(-1),ie=X.clone().sub(ee);W(he,ie,A,T.angle())}let me,pe;{let he=new Nt;Zs(E,le,he);let xe=X.clone().add(re).multiplyScalar(.5);xe=tE(xe,q,O);let ye=X.clone().sub(re);[me,pe]=W(xe,ye,he,_,re.y)}{let he=me,xe=he.clone().setY(0).normalize(),ye=new Nt(0,-1,0),A=xe.clone().cross(ye);F(he,xe,ye,A)}L.concat(pe);{let he=T.angle(),xe=Math.PI-he,ye=O.clone();ye.y-=a/Math.sin(he-Math.PI/2);let A=new Nt,ie=[];for(let Ve=0;Ve<s;Ve++){let _e=[],Pe=Math.PI/2-xe*Ve/s,vt=Math.cos(Pe),Ie=Math.sin(Pe),gt=Z;for(let St=0;St<=Ve;St++){let Vn=Math.cos(gt),ot=Math.sin(gt);j.x=vt*ot,j.y=Ie,j.z=vt*Vn,A.copy(ye).addScaledVector(j,a),c.push(A.x,A.y,A.z),u.push(j.x,j.y,j.z),p.push(0,0),_e.push(d++),gt+=Math.PI*2/Ve/t}ie.push(_e)}pe.reverse(),ie.push(pe);let De=ie.length-1;for(let Ve=0;Ve<De;Ve++){let _e=ie[Ve],Pe=ie[Ve+1],vt=_e.length-1;l.push(Pe[1],_e[0],Pe[0]);for(let Ie=1;Ie<=vt;Ie++)l.push(_e[Ie],_e[Ie-1],Pe[Ie]),l.push(Pe[Ie+1],_e[Ie],Pe[Ie])}}}}}this.setIndex(l),this.setAttribute("position",new xf(c,3)),this.setAttribute("normal",new xf(u,3)),this.setAttribute("uv",new xf(p,2));function W(j,H,q,re,ee){let X=-re/2,te=(Math.PI-re)/2,K=H.clone().normalize().cross(q);j.addScaledVector(q,-a/Math.sin(te));let Z=new Nt,Q=new Nt,$=1,ue=d,le=[];for(let ne=0;ne<=s;ne++){let ce=X+ne/s*re;Q.set(0,0,0),Q.addScaledVector(K,Math.sin(ce)),Q.addScaledVector(q,Math.cos(ce));for(let ae=0;ae<=$;ae++){let me=ae/$-.5;if(Z.copy(j),Z.addScaledVector(H,me),Z.addScaledVector(Q,a),ee!=null){let pe=Math.max(0,Z.y-ee);Z.addScaledVector(H,-pe/H.y)}c.push(Z.x,Z.y,Z.z),u.push(Q.x,Q.y,Q.z),p.push(0,0),ae===0&&le.push(d),d++}}for(let ne=0;ne<s;ne++)for(let ce=0;ce<$;ce++){let ae=ue+ce+($+1)*ne,me=ae+($+1),pe=me+1,he=ae+1;l.push(ae,me,he),l.push(me,pe,he)}return[j.clone().addScaledVector(H,.5),le]}function F(j,H,q,re){let ee=Math.PI/2,X=x.angle()-ee,te=[],K=new Nt,Z=new Nt;for(let $=0;$<=s;$++){let ue=[],le=$/s;for(let ne=0;ne<=$;ne++){let ae=(($?ne/$:0)-.5)*v,me=Math.cos(ae),pe=Math.sin(ae),he=Math.atan(Math.tan(X)*me),xe=(ee+he)*le,ye=Math.cos(xe),A=Math.sin(xe);K.set(0,0,0),K.addScaledVector(H,A*me),K.addScaledVector(q,ye),K.addScaledVector(re,A*pe),Z.copy(j).addScaledVector(K,a),c.push(Z.x,Z.y,Z.z),u.push(K.x,K.y,K.z),p.push(0,0),ue.push(d++)}te.push(ue)}let Q=te.length-1;for(let $=0;$<Q;$++){let ue=te[$],le=te[$+1],ne=ue.length-1;l.push(ue[0],le[1],le[0]);for(let ce=1;ce<=ne;ce++)l.push(ue[ce-1],ue[ce],le[ce]),l.push(ue[ce],le[ce+1],le[ce])}}}};var Oa=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,cornerRadius:[0,0,0,0],cornerType:1,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters),t=Object.assign(r?.ui??{enabledIndieCorners:!1},n.ui);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)}),ui:t}}static build(n){let r=n.shape,{width:e,height:t,cornerRadius:o,cornerType:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}=n.parameters,c={x:e*.5,y:t*.5},u={x:-c.x,y:-c.y},p={x:c.x,y:c.y};function d(O,S,C){return S>e&&C>t?Math.min(O*e/S,O*t/C):S>e?O*e/S:C>t?O*t/C:O}let h=[];h[0]=o[0]===0?0:d(o[0],o[0]+o[3],o[0]+o[1]),h[1]=o[1]===0?0:d(o[1],o[1]+o[2],o[1]+o[0]),h[2]=o[2]===0?0:d(o[2],o[2]+o[1],o[2]+o[3]),h[3]=o[3]===0?0:d(o[3],o[3]+o[0],o[3]+o[2]);let f=u.x,m=p.x,y=p.y,g=u.y;r.addPoint(r.createPoint(f,y)),r.addPoint(r.createPoint(m,y)),r.addPoint(r.createPoint(m,g)),r.addPoint(r.createPoint(f,g)),r.isClosed=!0;let v=!0;for(let O=0,S=r.points.length;O<S;O++)r.points[O].roundness=h[O],O>0&&h[O]!==h[O-1]&&(v=!1);v&&(r.roundness=h[0]),r.useCubicForRoundedCorners=i!==1,r.update();let w=Jt.create({shape:r,parameters:{depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}});return Object.assign(w,{userData:{...n,type:"RectangleGeometry"}})}};import{BufferGeometry as rE,Float32BufferAttribute as oE,MathUtils as H0,SphereGeometry as nE}from"three";var W0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,widthSegments:64,heightSegments:64,phiStart:0,phiLength:2*Math.PI,thetaStart:0,thetaLength:180},n.parameters);return e.thetaLength=H0.clamp(e.thetaLength,0,180),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r=100,height:e=r,depth:t=r,widthSegments:o=64,heightSegments:i=64,phiStart:a,phiLength:s,thetaStart:l,thetaLength:c}=n.parameters,u;return c===0?(u=new rE,u.setAttribute("position",new oE([],3))):u=new nE(.5*r,o,i,a,s,l,c*H0.DEG2RAD),u.scale(1,e/r,t/r),Object.assign(u,{userData:{...n,type:"SphereGeometry"}})}};import{PlaneGeometry as iE}from"three";var q0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,widthSegments:8,heightSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:0})}}static build(n){let{width:r=100,height:e=r,widthSegments:t=8,heightSegments:o=8}=n.parameters,i=new iE(r,e,t,o);return i.scale(1,1,1),Object.assign(i,{userData:{...n,type:"PlaneGeometry"}})}};import{BufferGeometry as aE,Float32BufferAttribute as Sf,Vector3 as sE}from"three";var $0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,angle:90,cornerRadius:24,cornerSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,angle:o,cornerRadius:i,cornerSegments:a}=n.parameters,s=new wf(r,e,t,o,i,a);return Object.assign(s,{userData:{...n,type:"BackdropGeometry"}})}},wf=class extends aE{constructor(r=1,e=1,t=1,o=90,i=10,a=24){super(),this.type="BackdropGeometry";let s=[],l=[],c=[],u=.001;i==0&&(a=1),a=Math.max(1,Math.floor(a)),i=Math.min(i,100),o=Math.min(180-u,o),o*=Math.PI/180;let p=[],d=Math.PI/2,h=(Z=0,Q=0,$=0)=>new sE(Z,Q,$),f=h(),m=h(),[y,g,v]=[e/2,r/2,t/2],w=-g,O=+g,[S,C,T]=[h(w,-y,+v),h(w,-y,-v),h(w,+y,-v)],x=(Z,Q=!1)=>Math.sin(Z-Math.PI/(1+ +Q)),N=(Z,Q=!1)=>Math.cos(Z-Math.PI/(1+ +Q));T.y=Math.sin(o)*e-y;let E=Math.cos(o)*e-v,M=S.z-u;o<=d?(T.z=Math.min(E,M),T.z==M&&(T.y-=(E-M)/Math.tan(d-o))):C.z=Math.min(C.z-E-v,S.z-u),f.subVectors(S,C),m.subVectors(T,C);let D=Math.min(f.length(),m.length())*i/100,_=D*Math.tan(o/2),B=D/Math.cos(o/2),V=f.clone().normalize().add(m.normalize()).setLength(B).add(C);f.set(0,x(o,!0),N(o,!0)),p.push([T,f.clone()]);let k=(Math.PI-o)/a;for(let Z=0;Z<=a;Z++){let Q=d+o+Z*k;f.set(0,Math.sin(Q)*_,Math.cos(Q)*_),f.add(V),m.set(0,x(Q),N(Q)),p.push([f.clone(),m.clone()])}p.push([S,h(0,1,0)]);let L=Math.sin(k/2)*_*2,W=p.length-1,F=p[0][0].distanceTo(p[1][0]),j=p[W-1][0].distanceTo(p[W][0]),H=F+L*a+j;p[0].push(1);for(let Z=0;Z<=a;Z++)p[Z+1].push(1-(F+Z*L)/H);p[W].push(0);let[q,re,ee]=p[0],X,te,K;for(let Z=1;Z<p.length;Z++)[X,te,K]=p[Z],s.push(w,q.y,q.z,w,X.y,X.z,O,q.y,q.z,O,q.y,q.z,w,X.y,X.z,O,X.y,X.z),l.push(0,re.y,re.z,0,te.y,te.z,0,re.y,re.z,0,re.y,re.z,0,te.y,te.z,0,te.y,te.z),c.push(0,ee,0,K,1,ee,1,ee,0,K,1,K),[q,re,ee]=[X,te,K];this.setAttribute("position",new Sf(s,3)),this.setAttribute("normal",new Sf(l,3)),this.setAttribute("uv",new Sf(c,2))}};var Ou=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,innerRadiusPercent:38.19,spikes:5,cornerRadius:0,angle:360,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,innerRadiusPercent:t,spikes:o,cornerRadius:i,angle:a,depth:s,extrudeBevelSize:l,extrudeBevelSegments:c}=n.parameters,u=n.shape,p=r*.5,d=e*.5,h=0,f=0,m=a*Math.PI/360/o,y=Math.PI/2*3*-1,g=p*t/100,v=d*t/100;if(o===3&&t===50){m=2*Math.PI/o;for(let O=0;O<o;O++){let S=m*O,C=h+Math.sin(S)*p,T=f+Math.cos(S)*d;u.addPoint(u.createPoint(C,T))}}else for(let O=0;O<o;O++){let S=h+Math.cos(y)*p,C=f+Math.sin(y)*d;u.addPoint(u.createPoint(S,C)),y+=m,S=h+Math.cos(y)*g,C=f+Math.sin(y)*v,O<=o,u.addPoint(u.createPoint(S,C)),y+=m}u.isClosed=!0;for(let O=0,S=u.points.length;O<S;O++)u.points[O].roundness=i;u.roundness=i,u.update();let w=Jt.create({shape:u,parameters:{roundness:i,depth:s,extrudeBevelSize:l,extrudeBevelSegments:c}});return Object.assign(w,{userData:{...n,type:"StarGeometry"}})}};import{PlaneGeometry as lE}from"three";var Y0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e}=n.parameters,t=new lE(r,e);return Object.assign(t,{userData:{...n,type:"TextFrameGeometry"}})}};import{BufferGeometry as cE,Float32BufferAttribute as uE,MathUtils as dE}from"three";var X0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:32,tubularSegments:64,arc:360,cornerRadius:30,cornerSegments:8},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.round(Math.abs(e.depth??e.width*.25));return{parameters:Object.assign(e,{width:t,height:o,depth:i})}}static build(n){let{width:r,height:e,depth:t,radialSegments:o,tubularSegments:i,arc:a,cornerRadius:s,cornerSegments:l}=n.parameters,c=pE(r,e,t,r*.5,a,i,0,0,o,s,l);return c.scale(1,e/r,1),Object.assign(c,{userData:{...n,type:"TorusGeometry"}})}};function pE(n,r,e,t,o,i,a,s,l,c,u){[r,e]=[e,r],a=r/2;let p=dE.clamp(o/360,0,1);if(p===0){let d=new cE;return d.setAttribute("position",new uE([],3)),d}return p===1&&(c=0),new Xs(!0,n,r,e,t,p,i,a,s,l,c,u)}import{TorusKnotGeometry as fE}from"three";var K0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,tubularSegments:64,radialSegments:32,p:2,q:3},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width),tube:e.tube??e.width*.125})}}static build(n){let{width:r,tube:e,tubularSegments:t,radialSegments:o,p:i,q:a}=n.parameters,s=r*.5;s!==e&&(s-=e);let l=new fE(s,e,t,o,i,a);return Object.assign(l,{userData:{...n,type:"TorusKnotGeometry"}})}};var Q0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:5,cornerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:1,isRect:!1},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width*(e.isRect?1:Math.sqrt(3)/2)),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r=100,height:e,cornerRadius:t,depth:o,extrudeBevelSize:i,extrudeBevelSegments:a,isRect:s}=n.parameters,l=n.shape,c=r*.5,u=e*.5;s?(l.addPoint(l.createPoint(-c,u)),l.addPoint(l.createPoint(c,-u)),l.addPoint(l.createPoint(-c,-u))):(l.addPoint(l.createPoint(0,u)),l.addPoint(l.createPoint(c,-u)),l.addPoint(l.createPoint(-c,-u))),l.isClosed=!0;for(let d=0,h=l.points.length;d<h;d++)l.points[d].roundness=t;l.roundness=t,l.update();let p=Jt.create({shape:l,parameters:{roundness:t,depth:o,extrudeBevelSize:i,extrudeBevelSegments:a}});return Object.assign(p,{userData:{...n,type:"TriangleGeometry"}})}};import{Vector2 as tb,Vector3 as Dt,Matrix3 as AE,Matrix4 as Zn,BufferGeometry as rb,BufferAttribute as Aa,MathUtils as Tu}from"three";function Z0(n,r){let e=2*Math.PI;return(n%e+e)%e===(r%e+e)%e}function hE(n){return/^(rgba)?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(n.toLowerCase())}function mE(n,r,e){let t,o,i,a=Math.floor(n*6),s=n*6-a,l=e*(1-r),c=e*(1-s*r),u=e*(1-(1-s)*r);switch(a%6){case 0:t=e,o=u,i=l;break;case 1:t=c,o=e,i=l;break;case 2:t=l,o=e,i=u;break;case 3:t=l,o=c,i=e;break;case 4:t=u,o=l,i=e;break;case 5:default:t=e,o=l,i=c;break}return{r:t*255,g:o*255,b:i*255}}function yE(n,r,e){n/=255,r/=255,e/=255;let t=Math.max(n,r,e),o=Math.min(n,r,e),i=t,a=t-o,s=t==0?0:a/t,l;if(t==o)l=0;else{switch(t){case n:l=(r-e)/a+(r<e?6:0);break;case r:l=(e-n)/a+2;break;case e:default:l=(n-r)/a+4;break}l/=6}return{h:l,s,v:i}}function gE(n){return n=Math.floor(n),{r:n>>16&255,g:n>>8&255,b:n&255}}function xE(n,r,e){return(n<<16)+(r<<8)+e}function bE(n,r,e){return n=Math.round(n),r=Math.round(r),e=Math.round(e),"#"+[n,r,e].map(t=>t.toString(16).padStart(2,"0")).join("").toUpperCase()}function vE(n){let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;n=n.replace(r,(t,o,i,a)=>String(o+o+i+i+a+a));let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}var J0={parseRgba:hE,hsvToRgb:mE,rgbToHsv:yE,hexToRgb:gE,rgbToHex:xE,rgbToHexString:bE,hexStringToRgb:vE};function Lo(n){return{all:n=n||new Map,on:function(r,e){var t=n.get(r);t?t.push(e):n.set(r,[e])},off:function(r,e){var t=n.get(r);t&&(e?t.splice(t.indexOf(e)>>>0,1):n.set(r,[]))},emit:function(r,e){var t=n.get(r);t&&t.slice().map(function(o){o(e)}),(t=n.get("*"))&&t.slice().map(function(o){o(r,e)})}}}var Au=class{constructor(r,e,t){this.id=r;this.userAPI=e;this.result=void 0;this.error="null";this.isPrefetched=!1;this.isLoading=!1;this.isLoaded=!1;this.prefetchPromise=new Promise(r=>r());this.emitter=Lo();this._innerCallUserAPI=async r=>{this.emitter.emit("start",{userAPIId:this.id}),this.isLoading=!0,this.isLoading=!1;try{this.result=await OE(this.userAPI,r),this.error="null",this.emitter.emit("success",{userAPIId:this.id})}catch(e){let t=e.message?.split("_:_")?.[0]?.replace("status:","")??"null";this.error=t,this.result=null,this.emitter.emit("error",{userAPIId:this.id})}this.isLoading=!1,this.isPrefetched=!0,this.isLoaded=!0};e?.integration?.type==="OpenAI"?this.result={content:""}:e.method==="GET"&&e.url!==""&&(this.prefetchPromise=this.prefetch(t)),this._debouncedCallUserAPI=this._innerCallUserAPI,this._updateDebouncedCallUserAPI(),this._debouncedPrefetch=fc(this.prefetch,1e3,{trailing:!0})}_updateDebouncedCallUserAPI(){this._debouncedCallUserAPI=this.userAPI.debounce!==void 0&&this.userAPI.debounce>0?fc(this._innerCallUserAPI,this.userAPI.debounce,{leading:!0,trailing:!0}):this._innerCallUserAPI}async prefetch(r){await this.callUserAPI(r)}async callUserAPI(r){await this._debouncedCallUserAPI(r)}update(r,e,t=!0){this.userAPI=r,this._updateDebouncedCallUserAPI(),this.userAPI.url!==""&&this.userAPI.method==="GET"&&t&&this._debouncedPrefetch(e)}retrieveValue(r){if(this.result)try{return Ze.zoom(this.result,r)}catch(e){console.error(e)}}retrieveZoomedKeyValues(r){if(this.result){let e=r&&r.length?Ze.zoom(this.result,r):this.result;if(CE(e))return Object.entries(e);if(PE(e))return e.map((t,o)=>[o.toString(),t]);throw wE(e)?new Error("This path points to a value, use retrieveValue() instead. "+r?.join(".")):new Error("Path error"+r?.join("."))}}dispose(){}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}get autostart(){return this.userAPI.autoStart}};function SE(n){let r=new Headers;return n.headers.forEach(e=>{e.data.key!==""&&r.append(e.data.key,e.data.value)}),r}function wE(n){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null}function PE(n){return Array.isArray(n)}function CE(n){return typeof n=="object"&&n!==null}async function OE(n,r,e=new AbortController){let t,o=n.url,i=n.proxy?.enabled??!1,a;if(n.integration?.type==="OpenAI"){let l=Js(n.integration.prompt===""?[]:JSON.parse(n.integration.prompt),r),c=n.integration.behavior===""?[]:Js(JSON.parse(n.integration.behavior),r);a=`{
1
+ var L1=Object.create;var Rl=Object.defineProperty;var V1=Object.getOwnPropertyDescriptor;var z1=Object.getOwnPropertyNames;var G1=Object.getPrototypeOf,F1=Object.prototype.hasOwnProperty;var j1=(n,r,e)=>r in n?Rl(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var gs=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),k1=(n,r)=>{for(var e in r)Rl(n,e,{get:r[e],enumerable:!0})},U1=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of z1(r))!F1.call(n,o)&&o!==e&&Rl(n,o,{get:()=>r[o],enumerable:!(t=V1(r,o))||t.enumerable});return n};var xs=(n,r,e)=>(e=n!=null?L1(G1(n)):{},U1(r||!n||!n.__esModule?Rl(e,"default",{value:n,enumerable:!0}):e,n));var $r=(n,r,e)=>(j1(n,typeof r!="symbol"?r+"":r,e),e);var Vx=gs((Ip,Lx)=>{(function(n,r){typeof Ip=="object"?Lx.exports=r():typeof define=="function"&&define.amd?define(r):n.Alea=r()})(Ip,function(){"use strict";return n.importState=function(e){var t=new n;return t.importState(e),t},n;function n(){return function(e){var t=0,o=0,i=0,a=1;e.length==0&&(e=[+new Date]);var s=r();t=s(" "),o=s(" "),i=s(" ");for(var l=0;l<e.length;l++)t-=s(e[l]),t<0&&(t+=1),o-=s(e[l]),o<0&&(o+=1),i-=s(e[l]),i<0&&(i+=1);s=null;var c=function(){var u=2091639*t+a*23283064365386963e-26;return t=o,o=i,i=u-(a=u|0)};return c.next=c,c.uint32=function(){return c()*4294967296},c.fract53=function(){return c()+(c()*2097152|0)*11102230246251565e-32},c.version="Alea 0.9",c.args=e,c.exportState=function(){return[t,o,i,a]},c.importState=function(u){t=+u[0]||0,o=+u[1]||0,i=+u[2]||0,a=+u[3]||0},c}(Array.prototype.slice.call(arguments))}function r(){var e=4022871197,t=function(o){o=o.toString();for(var i=0;i<o.length;i++){e+=o.charCodeAt(i);var a=.02519603282416938*e;e=a>>>0,a-=e,a*=e,e=a>>>0,a-=e,e+=a*4294967296}return(e>>>0)*23283064365386963e-26};return t.version="Mash 0.9",t}})});var Ux=gs((eu,kx)=>{(function(n,r){typeof eu=="object"&&typeof kx<"u"?r(eu):typeof define=="function"&&define.amd?define(["exports"],r):r((n=typeof globalThis<"u"?globalThis:n||self).SVDJS={})})(eu,function(n){"use strict";n.SVD=function(r,e,t,o,i){if(e=e===void 0||e,t=t===void 0||t,i=1e-64/(o=o||Math.pow(2,-52)),!r)throw new TypeError("Matrix a is not defined");var a,s,l,c,u,p,d,f,h,m,y,b,S=r[0].length,P=r.length;if(P<S)throw new TypeError("Invalid matrix: m < n");for(var C=[],v=[],A=[],T=e==="f"?P:S,g=m=d=0;g<P;g++)v[g]=new Array(T).fill(0);for(g=0;g<S;g++)A[g]=new Array(S).fill(0);var D,E=new Array(S).fill(0);for(g=0;g<P;g++)for(a=0;a<S;a++)v[g][a]=r[g][a];for(g=0;g<S;g++){for(C[g]=d,h=0,l=g+1,a=g;a<P;a++)h+=Math.pow(v[a][g],2);if(h<i)d=0;else for(f=(p=v[g][g])*(d=p<0?Math.sqrt(h):-Math.sqrt(h))-h,v[g][g]=p-d,a=l;a<S;a++){for(h=0,s=g;s<P;s++)h+=v[s][g]*v[s][a];for(p=h/f,s=g;s<P;s++)v[s][a]=v[s][a]+p*v[s][g]}for(E[g]=d,h=0,a=l;a<S;a++)h+=Math.pow(v[g][a],2);if(h<i)d=0;else{for(f=(p=v[g][g+1])*(d=p<0?Math.sqrt(h):-Math.sqrt(h))-h,v[g][g+1]=p-d,a=l;a<S;a++)C[a]=v[g][a]/f;for(a=l;a<P;a++){for(h=0,s=l;s<S;s++)h+=v[a][s]*v[g][s];for(s=l;s<S;s++)v[a][s]=v[a][s]+h*C[s]}}m<(y=Math.abs(E[g])+Math.abs(C[g]))&&(m=y)}if(t)for(g=S-1;0<=g;g--){if(d!==0){for(f=v[g][g+1]*d,a=l;a<S;a++)A[a][g]=v[g][a]/f;for(a=l;a<S;a++){for(h=0,s=l;s<S;s++)h+=v[g][s]*A[s][a];for(s=l;s<S;s++)A[s][a]=A[s][a]+h*A[s][g]}}for(a=l;a<S;a++)A[g][a]=0,A[a][g]=0;A[g][g]=1,d=C[g],l=g}if(e){if(e==="f")for(g=S;g<P;g++){for(a=S;a<P;a++)v[g][a]=0;v[g][g]=1}for(g=S-1;0<=g;g--){for(l=g+1,d=E[g],a=l;a<T;a++)v[g][a]=0;if(d!==0){for(f=v[g][g]*d,a=l;a<T;a++){for(h=0,s=l;s<P;s++)h+=v[s][g]*v[s][a];for(p=h/f,s=g;s<P;s++)v[s][a]=v[s][a]+p*v[s][g]}for(a=g;a<P;a++)v[a][g]=v[a][g]/d}else for(a=g;a<P;a++)v[a][g]=0;v[g][g]=v[g][g]+1}}for(o*=m,s=S-1;0<=s;s--)for(var M=0;M<50;M++){for(D=!1,l=s;0<=l;l--){if(Math.abs(C[l])<=o){D=!0;break}if(Math.abs(E[l-1])<=o)break}if(!D){for(u=0,c=l-(h=1),g=l;g<s+1&&(p=h*C[g],C[g]=u*C[g],!(Math.abs(p)<=o));g++)if(d=E[g],E[g]=Math.sqrt(p*p+d*d),u=d/(f=E[g]),h=-p/f,e)for(a=0;a<P;a++)y=v[a][c],b=v[a][g],v[a][c]=y*u+b*h,v[a][g]=-y*h+b*u}if(b=E[s],l===s){if(b<0&&(E[s]=-b,t))for(a=0;a<S;a++)A[a][s]=-A[a][s];break}for(m=E[l],p=(((y=E[s-1])-b)*(y+b)+((d=C[s-1])-(f=C[s]))*(d+f))/(2*f*y),d=Math.sqrt(p*p+1),p=((m-b)*(m+b)+f*(y/(p<0?p-d:p+d)-f))/m,g=l+(h=u=1);g<s+1;g++){if(d=C[g],y=E[g],f=h*d,d*=u,b=Math.sqrt(p*p+f*f),p=m*(u=p/(C[g-1]=b))+d*(h=f/b),d=-m*h+d*u,f=y*h,y*=u,t)for(a=0;a<S;a++)m=A[a][g-1],b=A[a][g],A[a][g-1]=m*u+b*h,A[a][g]=-m*h+b*u;if(b=Math.sqrt(p*p+f*f),p=(u=p/(E[g-1]=b))*d+(h=f/b)*y,m=-h*d+u*y,e)for(a=0;a<P;a++)y=v[a][g-1],b=v[a][g],v[a][g-1]=y*u+b*h,v[a][g]=-y*h+b*u}C[l]=0,C[s]=p,E[s]=m}for(g=0;g<S;g++)E[g]<o&&(E[g]=0);return{u:v,q:E,v:A}},n.VERSION="1.1.1",Object.defineProperty(n,"__esModule",{value:!0})})});var lS=gs((Rle,sS)=>{"use strict";function FD(n,r){function e(){this.constructor=n}e.prototype=r.prototype,n.prototype=new e}function fi(n,r,e,t){this.message=n,this.expected=r,this.found=e,this.location=t,this.name="SyntaxError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,fi)}FD(fi,Error);fi.buildMessage=function(n,r){var e={literal:function(c){return'"'+o(c.text)+'"'},class:function(c){var u="",p;for(p=0;p<c.parts.length;p++)u+=c.parts[p]instanceof Array?i(c.parts[p][0])+"-"+i(c.parts[p][1]):i(c.parts[p]);return"["+(c.inverted?"^":"")+u+"]"},any:function(c){return"any character"},end:function(c){return"end of input"},other:function(c){return c.description}};function t(c){return c.charCodeAt(0).toString(16).toUpperCase()}function o(c){return c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+t(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+t(u)})}function i(c){return c.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+t(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+t(u)})}function a(c){return e[c.type](c)}function s(c){var u=new Array(c.length),p,d;for(p=0;p<c.length;p++)u[p]=a(c[p]);if(u.sort(),u.length>0){for(p=1,d=1;p<u.length;p++)u[p-1]!==u[p]&&(u[d]=u[p],d++);u.length=d}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}function l(c){return c?'"'+o(c)+'"':"end of input"}return"Expected "+s(n)+" but "+l(r)+" found."};function jD(n,r){r=r!==void 0?r:{};var e={},t={svg_path:ys},o=ys,i=function(x){if(!x)return[];for(var w=[],R=0;R<x.length;R++)w=w.concat.apply(w,x[R]);var I=w[0];return I&&I.code=="m"&&(delete I.relative,I.code="M"),w},a=function(x,w){return R1(x,w)},s=/^[Mm]/,l=Xe(["M","m"],!1,!1),c=function(x,w,R){var I=xi(x,[w]);return R&&(I=I.concat(xi(x=="M"?"L":"l",R[1]))),I},u=/^[Zz]/,p=Xe(["Z","z"],!1,!1),d=function(){return xi("Z")},f=/^[Ll]/,h=Xe(["L","l"],!1,!1),m=function(x,w){return xi(x,w)},y=/^[Hh]/,b=Xe(["H","h"],!1,!1),S=function(x,w){return xi(x,w.map(function(R){return{x:R}}))},P=/^[Vv]/,C=Xe(["V","v"],!1,!1),v=function(x,w){return xi(x,w.map(function(R){return{y:R}}))},A=/^[Cc]/,T=Xe(["C","c"],!1,!1),g=function(x,w,R){return{x1:x.x,y1:x.y,x2:w.x,y2:w.y,x:R.x,y:R.y}},D=/^[Ss]/,E=Xe(["S","s"],!1,!1),M=function(x,w){return{x2:x.x,y2:x.y,x:w.x,y:w.y}},N=/^[Qq]/,_=Xe(["Q","q"],!1,!1),B=function(x,w){return{x1:x.x,y1:x.y,x:w.x,y:w.y}},V=/^[Tt]/,k=Xe(["T","t"],!1,!1),L=/^[Aa]/,W=Xe(["A","a"],!1,!1),F=function(x,w,R,I,z,oe){return{rx:x,ry:w,xAxisRotation:R,largeArc:I,sweep:z,x:oe.x,y:oe.y}},j=function(x,w){return{x,y:w}},H=function(x){return x*1},q=function(x){return x.join("")*1},re=/^[01]/,ee=Xe(["0","1"],!1,!1),X=function(x){return x=="1"},te=function(){return""},K=",",Z=ot(",",!1),Q=function(x){return x.join("")},$=".",ue=ot(".",!1),le=/^[eE]/,ne=Xe(["e","E"],!1,!1),ce=/^[+\-]/,ae=Xe(["+","-"],!1,!1),me=/^[0-9]/,pe=Xe([["0","9"]],!1,!1),he=function(x){return x.join("")},xe=/^[ \t\n\r]/,ye=Xe([" "," ",`
2
+ `,"\r"],!1,!1),O=0,ie=0,De=[{line:1,column:1}],Ve=0,_e=[],Pe=0,vt;if("startRule"in r){if(!(r.startRule in t))throw new Error(`Can't start parsing from rule "`+r.startRule+'".');o=t[r.startRule]}function Ie(){return n.substring(ie,O)}function gt(){return Vn(ie,O)}function St(x,w){throw w=w!==void 0?w:Vn(ie,O),hr([Ed(x)],n.substring(ie,O),w)}function Ln(x,w){throw w=w!==void 0?w:Vn(ie,O),Nd(x,w)}function ot(x,w){return{type:"literal",text:x,ignoreCase:w}}function Xe(x,w,R){return{type:"class",parts:x,inverted:w,ignoreCase:R}}function Mr(){return{type:"any"}}function Md(){return{type:"end"}}function Ed(x){return{type:"other",description:x}}function El(x){var w=De[x],R;if(w)return w;for(R=x-1;!De[R];)R--;for(w=De[R],w={line:w.line,column:w.column};R<x;)n.charCodeAt(R)===10?(w.line++,w.column=1):w.column++,R++;return De[x]=w,w}function Vn(x,w){var R=El(x),I=El(w);return{start:{offset:x,line:R.line,column:R.column},end:{offset:w,line:I.line,column:I.column}}}function ct(x){O<Ve||(O>Ve&&(Ve=O,_e=[]),_e.push(x))}function Nd(x,w){return new fi(x,null,null,w)}function hr(x,w,R){return new fi(fi.buildMessage(x,w),x,w,R)}function ys(){var x,w,R,I,z;for(x=O,w=[],R=ze();R!==e;)w.push(R),R=ze();if(w!==e)if(R=Ut(),R===e&&(R=null),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(ie=x,w=i(R),x=w):(O=x,x=e)}else O=x,x=e;else O=x,x=e;return x}function Ut(){var x,w,R,I,z,oe;if(x=O,w=zn(),w!==e){for(R=[],I=O,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();for(z!==e?(oe=zn(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;){for(R.push(I),I=O,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();z!==e?(oe=zn(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e)}R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function zn(){var x,w,R,I,z,oe;if(x=O,w=yi(),w!==e){for(R=[],I=O,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();for(z!==e?(oe=Nl(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;){for(R.push(I),I=O,z=[],oe=ze();oe!==e;)z.push(oe),oe=ze();z!==e?(oe=Nl(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e)}R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function Nl(){var x;return x=v1(),x===e&&(x=S1(),x===e&&(x=w1(),x===e&&(x=P1(),x===e&&(x=C1(),x===e&&(x=A1(),x===e&&(x=I1(),x===e&&(x=E1(),x===e&&(x=D1())))))))),x}function yi(){var x,w,R,I,z,oe,bi;if(x=O,s.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(l)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Wt(),I!==e?(z=O,oe=et(),oe===e&&(oe=null),oe!==e?(bi=Uh(),bi!==e?(oe=[oe,bi],z=oe):(O=z,z=e)):(O=z,z=e),z===e&&(z=null),z!==e?(ie=x,w=c(w,I,z),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function v1(){var x,w;return x=O,u.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(p)),w!==e&&(ie=x,w=d()),x=w,x}function S1(){var x,w,R,I;if(x=O,f.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(h)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Uh(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function Uh(){var x,w,R,I,z,oe;if(x=O,w=Wt(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function w1(){var x,w,R,I;if(x=O,y.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(b)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Hh(),I!==e?(ie=x,w=S(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function Hh(){var x,w,R,I,z,oe;if(x=O,w=gi(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=gi(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=gi(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function P1(){var x,w,R,I;if(x=O,P.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(C)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=Hh(),I!==e?(ie=x,w=v(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function C1(){var x,w,R,I;if(x=O,A.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(T)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=O1(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function O1(){var x,w,R,I,z,oe;if(x=O,w=Dd(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=Dd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=Dd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function Dd(){var x,w,R,I,z,oe;return x=O,w=Wt(),w!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(ie=x,w=g(w,I,oe),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e),x}function A1(){var x,w,R,I;if(x=O,D.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(E)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=T1(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function T1(){var x,w,R,I,z,oe;if(x=O,w=_d(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=_d(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=_d(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function _d(){var x,w,R,I;return x=O,w=Wt(),w!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(ie=x,w=M(w,I),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e),x}function I1(){var x,w,R,I;if(x=O,N.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(_)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=M1(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function M1(){var x,w,R,I,z,oe;if(x=O,w=Bd(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=Bd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=Bd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function Bd(){var x,w,R,I;return x=O,w=Wt(),w!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wt(),I!==e?(ie=x,w=B(w,I),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e),x}function E1(){var x,w,R,I;if(x=O,V.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(k)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=N1(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function N1(){var x,w,R,I,z,oe;if(x=O,w=Wt(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=Wt(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function D1(){var x,w,R,I;if(x=O,L.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(W)),w!==e){for(R=[],I=ze();I!==e;)R.push(I),I=ze();R!==e?(I=_1(),I!==e?(ie=x,w=m(w,I),x=w):(O=x,x=e)):(O=x,x=e)}else O=x,x=e;return x}function _1(){var x,w,R,I,z,oe;if(x=O,w=Rd(),w!==e){for(R=[],I=O,z=et(),z===e&&(z=null),z!==e?(oe=Rd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);I!==e;)R.push(I),I=O,z=et(),z===e&&(z=null),z!==e?(oe=Rd(),oe!==e?(z=[z,oe],I=z):(O=I,I=e)):(O=I,I=e);R!==e?(ie=x,w=a(w,R),x=w):(O=x,x=e)}else O=x,x=e;return x}function Rd(){var x,w,R,I,z,oe,bi,Vd,_l,zd,Bl,Gd;return x=O,w=Wh(),w!==e?(R=et(),R===e&&(R=null),R!==e?(I=Wh(),I!==e?(z=et(),z===e&&(z=null),z!==e?(oe=gi(),oe!==e?(bi=et(),bi!==e?(Vd=qh(),Vd!==e?(_l=et(),_l===e&&(_l=null),_l!==e?(zd=qh(),zd!==e?(Bl=et(),Bl===e&&(Bl=null),Bl!==e?(Gd=Wt(),Gd!==e?(ie=x,w=F(w,I,oe,Vd,zd,Gd),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e)):(O=x,x=e),x}function Wt(){var x,w,R,I;return x=O,w=gi(),w!==e?(R=et(),R===e&&(R=null),R!==e?(I=gi(),I!==e?(ie=x,w=j(w,I),x=w):(O=x,x=e)):(O=x,x=e)):(O=x,x=e),x}function Wh(){var x,w;return x=O,w=Yh(),w===e&&(w=Gn()),w!==e&&(ie=x,w=H(w)),x=w,x}function gi(){var x,w,R,I;return x=O,w=O,R=Ld(),R===e&&(R=null),R!==e?(I=Yh(),I!==e?(R=[R,I],w=R):(O=w,w=e)):(O=w,w=e),w===e&&(w=O,R=Ld(),R===e&&(R=null),R!==e?(I=Gn(),I!==e?(R=[R,I],w=R):(O=w,w=e)):(O=w,w=e)),w!==e&&(ie=x,w=q(w)),x=w,x}function qh(){var x,w;return x=O,re.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(ee)),w!==e&&(ie=x,w=X(w)),x=w,x}function et(){var x,w,R,I,z;if(x=O,w=[],R=ze(),R!==e)for(;R!==e;)w.push(R),R=ze();else w=e;if(w!==e)if(R=$h(),R===e&&(R=null),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(w=[w,R,I],x=w):(O=x,x=e)}else O=x,x=e;else O=x,x=e;if(x===e){if(x=O,w=O,R=$h(),R!==e){for(I=[],z=ze();z!==e;)I.push(z),z=ze();I!==e?(R=[R,I],w=R):(O=w,w=e)}else O=w,w=e;w!==e&&(ie=x,w=te()),x=w}return x}function $h(){var x;return n.charCodeAt(O)===44?(x=K,O++):(x=e,Pe===0&&ct(Z)),x}function Yh(){var x,w,R,I;return x=O,w=O,R=B1(),R!==e?(I=Xh(),I===e&&(I=null),I!==e?(R=[R,I],w=R):(O=w,w=e)):(O=w,w=e),w===e&&(w=O,R=Gn(),R!==e?(I=Xh(),I!==e?(R=[R,I],w=R):(O=w,w=e)):(O=w,w=e)),w!==e&&(ie=x,w=Q(w)),x=w,x}function B1(){var x,w,R,I,z;return x=O,w=O,R=Gn(),R===e&&(R=null),R!==e?(n.charCodeAt(O)===46?(I=$,O++):(I=e,Pe===0&&ct(ue)),I!==e?(z=Gn(),z!==e?(R=[R,I,z],w=R):(O=w,w=e)):(O=w,w=e)):(O=w,w=e),w===e&&(w=O,R=Gn(),R!==e?(n.charCodeAt(O)===46?(I=$,O++):(I=e,Pe===0&&ct(ue)),I!==e?(R=[R,I],w=R):(O=w,w=e)):(O=w,w=e)),w!==e&&(ie=x,w=Q(w)),x=w,x}function Xh(){var x,w,R,I,z;return x=O,w=O,le.test(n.charAt(O))?(R=n.charAt(O),O++):(R=e,Pe===0&&ct(ne)),R!==e?(I=Ld(),I===e&&(I=null),I!==e?(z=Gn(),z!==e?(R=[R,I,z],w=R):(O=w,w=e)):(O=w,w=e)):(O=w,w=e),w!==e&&(ie=x,w=Q(w)),x=w,x}function Ld(){var x;return ce.test(n.charAt(O))?(x=n.charAt(O),O++):(x=e,Pe===0&&ct(ae)),x}function Gn(){var x,w,R;if(x=O,w=[],me.test(n.charAt(O))?(R=n.charAt(O),O++):(R=e,Pe===0&&ct(pe)),R!==e)for(;R!==e;)w.push(R),me.test(n.charAt(O))?(R=n.charAt(O),O++):(R=e,Pe===0&&ct(pe));else w=e;return w!==e&&(ie=x,w=he(w)),x=w,x}function ze(){var x,w;return x=O,xe.test(n.charAt(O))?(w=n.charAt(O),O++):(w=e,Pe===0&&ct(ye)),w!==e&&(ie=x,w=te()),x=w,x}function R1(x,w){if(!w)return[x];for(var R=[x],I=0,z=w.length;I<z;I++)R[I+1]=w[I][1];return R}var Dl={m:"moveto",l:"lineto",h:"horizontal lineto",v:"vertical lineto",c:"curveto",s:"smooth curveto",q:"quadratic curveto",t:"smooth quadratic curveto",a:"elliptical arc",z:"closepath"};for(var Kh in Dl)Dl[Kh.toUpperCase()]=Dl[Kh];function xi(x,w){w||(w=[{}]);for(var R=w.length;R--;){var I={code:x,command:Dl[x]};x==x.toLowerCase()&&(I.relative=!0);for(var z in w[R])I[z]=w[R][z];w[R]=I}return w}if(vt=o(),vt!==e&&O===n.length)return vt;throw vt!==e&&O<n.length&&ct(Md()),hr(_e,Ve<n.length?n.charAt(Ve):null,Ve<n.length?Vn(Ve,Ve+1):Vn(Ve,Ve))}sS.exports={SyntaxError:fi,parse:jD}});var wh=gs((Lle,cS)=>{var dd=lS().parse;dd.parseSVG=dd;dd.makeAbsolute=kD;cS.exports=dd;function kD(n){var r,e={x:0,y:0},t={x:"x0",y:"y0",x1:"x0",y1:"y0",x2:"x0",y2:"y0"};return n.forEach(function(o){o.command==="moveto"&&(r=o),o.x0=e.x,o.y0=e.y;for(var i in t)i in o&&(o[i]+=o.relative?o[t[i]]:0);"x"in o||(o.x=e.x),"y"in o||(o.y=e.y),o.relative=!1,o.code=o.code.toUpperCase(),o.command=="closepath"&&(o.x=r.x,o.y=r.y),e=o}),n}});var g1=gs((Rme,y1)=>{y1.exports=function(r,e){for(var t=r.split("."),o=e.split("."),i=0;i<3;i++){var a=Number(t[i]),s=Number(o[i]);if(a>s)return 1;if(s>a)return-1;if(!isNaN(a)&&isNaN(s))return 1;if(isNaN(a)&&!isNaN(s))return-1}return 0}});import{FileLoader as IB,Loader as MB}from"three";function Ll(n){for(let r of Object.keys(n))n[r]===void 0&&delete n[r];return n}function Lt(n,r){return Object.setPrototypeOf(n,r),n}function Vl(n){return Array.isArray(n)?n:[n]}function zl(n,r){let e=0;for(;e<n.length&&e<r.length;){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1;e+=1}return e!==r.length?-1:e!==n.length?1:0}var H1=typeof global=="object"&&global&&global.Object===Object&&global,Gl=H1;var W1=typeof self=="object"&&self&&self.Object===Object&&self,q1=Gl||W1||Function("return this")(),ut=q1;var $1=ut.Symbol,Tt=$1;var Qh=Object.prototype,Y1=Qh.hasOwnProperty,X1=Qh.toString,bs=Tt?Tt.toStringTag:void 0;function K1(n){var r=Y1.call(n,bs),e=n[bs];try{n[bs]=void 0;var t=!0}catch{}var o=X1.call(n);return t&&(r?n[bs]=e:delete n[bs]),o}var Zh=K1;var Q1=Object.prototype,Z1=Q1.toString;function J1(n){return Z1.call(n)}var Jh=J1;var ew="[object Null]",tw="[object Undefined]",em=Tt?Tt.toStringTag:void 0;function rw(n){return n==null?n===void 0?tw:ew:em&&em in Object(n)?Zh(n):Jh(n)}var sr=rw;function ow(n){return n!=null&&typeof n=="object"}var Vt=ow;var nw="[object Symbol]";function iw(n){return typeof n=="symbol"||Vt(n)&&sr(n)==nw}var Xo=iw;function aw(n,r){for(var e=-1,t=n==null?0:n.length,o=Array(t);++e<t;)o[e]=r(n[e],e,n);return o}var Fl=aw;var sw=Array.isArray,dt=sw;var lw=1/0,tm=Tt?Tt.prototype:void 0,rm=tm?tm.toString:void 0;function om(n){if(typeof n=="string")return n;if(dt(n))return Fl(n,om)+"";if(Xo(n))return rm?rm.call(n):"";var r=n+"";return r=="0"&&1/n==-lw?"-0":r}var nm=om;var cw=/\s/;function uw(n){for(var r=n.length;r--&&cw.test(n.charAt(r)););return r}var im=uw;var dw=/^\s+/;function pw(n){return n&&n.slice(0,im(n)+1).replace(dw,"")}var am=pw;function fw(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}var It=fw;var sm=0/0,hw=/^[-+]0x[0-9a-f]+$/i,mw=/^0b[01]+$/i,yw=/^0o[0-7]+$/i,gw=parseInt;function xw(n){if(typeof n=="number")return n;if(Xo(n))return sm;if(It(n)){var r=typeof n.valueOf=="function"?n.valueOf():n;n=It(r)?r+"":r}if(typeof n!="string")return n===0?n:+n;n=am(n);var e=mw.test(n);return e||yw.test(n)?gw(n.slice(2),e?2:8):hw.test(n)?sm:+n}var Fd=xw;function bw(n){return n}var lm=bw;var vw="[object AsyncFunction]",Sw="[object Function]",ww="[object GeneratorFunction]",Pw="[object Proxy]";function Cw(n){if(!It(n))return!1;var r=sr(n);return r==Sw||r==ww||r==vw||r==Pw}var jl=Cw;var Ow=ut["__core-js_shared__"],kl=Ow;var cm=function(){var n=/[^.]+$/.exec(kl&&kl.keys&&kl.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""}();function Aw(n){return!!cm&&cm in n}var um=Aw;var Tw=Function.prototype,Iw=Tw.toString;function Mw(n){if(n!=null){try{return Iw.call(n)}catch{}try{return n+""}catch{}}return""}var vo=Mw;var Ew=/[\\^$.*+?()[\]{}|]/g,Nw=/^\[object .+?Constructor\]$/,Dw=Function.prototype,_w=Object.prototype,Bw=Dw.toString,Rw=_w.hasOwnProperty,Lw=RegExp("^"+Bw.call(Rw).replace(Ew,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Vw(n){if(!It(n)||um(n))return!1;var r=jl(n)?Lw:Nw;return r.test(vo(n))}var dm=Vw;function zw(n,r){return n?.[r]}var pm=zw;function Gw(n,r){var e=pm(n,r);return dm(e)?e:void 0}var Qt=Gw;var Fw=Qt(ut,"WeakMap"),Ul=Fw;var fm=Object.create,jw=function(){function n(){}return function(r){if(!It(r))return{};if(fm)return fm(r);n.prototype=r;var e=new n;return n.prototype=void 0,e}}(),hm=jw;function kw(n,r,e){switch(e.length){case 0:return n.call(r);case 1:return n.call(r,e[0]);case 2:return n.call(r,e[0],e[1]);case 3:return n.call(r,e[0],e[1],e[2])}return n.apply(r,e)}var mm=kw;function Uw(n,r){var e=-1,t=n.length;for(r||(r=Array(t));++e<t;)r[e]=n[e];return r}var ym=Uw;var Hw=800,Ww=16,qw=Date.now;function $w(n){var r=0,e=0;return function(){var t=qw(),o=Ww-(t-e);if(e=t,o>0){if(++r>=Hw)return arguments[0]}else r=0;return n.apply(void 0,arguments)}}var gm=$w;function Yw(n){return function(){return n}}var xm=Yw;var Xw=function(){try{var n=Qt(Object,"defineProperty");return n({},"",{}),n}catch{}}(),vi=Xw;var Kw=vi?function(n,r){return vi(n,"toString",{configurable:!0,enumerable:!1,value:xm(r),writable:!0})}:lm,bm=Kw;var Qw=gm(bm),vm=Qw;function Zw(n,r){for(var e=-1,t=n==null?0:n.length;++e<t&&r(n[e],e,n)!==!1;);return n}var Sm=Zw;var Jw=9007199254740991,e2=/^(?:0|[1-9]\d*)$/;function t2(n,r){var e=typeof n;return r=r??Jw,!!r&&(e=="number"||e!="symbol"&&e2.test(n))&&n>-1&&n%1==0&&n<r}var Si=t2;function r2(n,r,e){r=="__proto__"&&vi?vi(n,r,{configurable:!0,enumerable:!0,value:e,writable:!0}):n[r]=e}var Hl=r2;function o2(n,r){return n===r||n!==n&&r!==r}var wi=o2;var n2=Object.prototype,i2=n2.hasOwnProperty;function a2(n,r,e){var t=n[r];(!(i2.call(n,r)&&wi(t,e))||e===void 0&&!(r in n))&&Hl(n,r,e)}var Pi=a2;function s2(n,r,e,t){var o=!e;e||(e={});for(var i=-1,a=r.length;++i<a;){var s=r[i],l=t?t(e[s],n[s],s,e,n):void 0;l===void 0&&(l=n[s]),o?Hl(e,s,l):Pi(e,s,l)}return e}var Yr=s2;var wm=Math.max;function l2(n,r,e){return r=wm(r===void 0?n.length-1:r,0),function(){for(var t=arguments,o=-1,i=wm(t.length-r,0),a=Array(i);++o<i;)a[o]=t[r+o];o=-1;for(var s=Array(r+1);++o<r;)s[o]=t[o];return s[r]=e(a),mm(n,this,s)}}var Pm=l2;var c2=9007199254740991;function u2(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=c2}var Ci=u2;function d2(n){return n!=null&&Ci(n.length)&&!jl(n)}var Wl=d2;var p2=Object.prototype;function f2(n){var r=n&&n.constructor,e=typeof r=="function"&&r.prototype||p2;return n===e}var Oi=f2;function h2(n,r){for(var e=-1,t=Array(n);++e<n;)t[e]=r(e);return t}var Cm=h2;var m2="[object Arguments]";function y2(n){return Vt(n)&&sr(n)==m2}var jd=y2;var Om=Object.prototype,g2=Om.hasOwnProperty,x2=Om.propertyIsEnumerable,b2=jd(function(){return arguments}())?jd:function(n){return Vt(n)&&g2.call(n,"callee")&&!x2.call(n,"callee")},Ai=b2;function v2(){return!1}var Am=v2;var Mm=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Tm=Mm&&typeof module=="object"&&module&&!module.nodeType&&module,S2=Tm&&Tm.exports===Mm,Im=S2?ut.Buffer:void 0,w2=Im?Im.isBuffer:void 0,P2=w2||Am,Fn=P2;var C2="[object Arguments]",O2="[object Array]",A2="[object Boolean]",T2="[object Date]",I2="[object Error]",M2="[object Function]",E2="[object Map]",N2="[object Number]",D2="[object Object]",_2="[object RegExp]",B2="[object Set]",R2="[object String]",L2="[object WeakMap]",V2="[object ArrayBuffer]",z2="[object DataView]",G2="[object Float32Array]",F2="[object Float64Array]",j2="[object Int8Array]",k2="[object Int16Array]",U2="[object Int32Array]",H2="[object Uint8Array]",W2="[object Uint8ClampedArray]",q2="[object Uint16Array]",$2="[object Uint32Array]",tt={};tt[G2]=tt[F2]=tt[j2]=tt[k2]=tt[U2]=tt[H2]=tt[W2]=tt[q2]=tt[$2]=!0;tt[C2]=tt[O2]=tt[V2]=tt[A2]=tt[z2]=tt[T2]=tt[I2]=tt[M2]=tt[E2]=tt[N2]=tt[D2]=tt[_2]=tt[B2]=tt[R2]=tt[L2]=!1;function Y2(n){return Vt(n)&&Ci(n.length)&&!!tt[sr(n)]}var Em=Y2;function X2(n){return function(r){return n(r)}}var Ti=X2;var Nm=typeof exports=="object"&&exports&&!exports.nodeType&&exports,vs=Nm&&typeof module=="object"&&module&&!module.nodeType&&module,K2=vs&&vs.exports===Nm,kd=K2&&Gl.process,Q2=function(){try{var n=vs&&vs.require&&vs.require("util").types;return n||kd&&kd.binding&&kd.binding("util")}catch{}}(),So=Q2;var Dm=So&&So.isTypedArray,Z2=Dm?Ti(Dm):Em,ql=Z2;var J2=Object.prototype,eP=J2.hasOwnProperty;function tP(n,r){var e=dt(n),t=!e&&Ai(n),o=!e&&!t&&Fn(n),i=!e&&!t&&!o&&ql(n),a=e||t||o||i,s=a?Cm(n.length,String):[],l=s.length;for(var c in n)(r||eP.call(n,c))&&!(a&&(c=="length"||o&&(c=="offset"||c=="parent")||i&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Si(c,l)))&&s.push(c);return s}var $l=tP;function rP(n,r){return function(e){return n(r(e))}}var Yl=rP;var oP=Yl(Object.keys,Object),_m=oP;var nP=Object.prototype,iP=nP.hasOwnProperty;function aP(n){if(!Oi(n))return _m(n);var r=[];for(var e in Object(n))iP.call(n,e)&&e!="constructor"&&r.push(e);return r}var Bm=aP;function sP(n){return Wl(n)?$l(n):Bm(n)}var Ii=sP;function lP(n){var r=[];if(n!=null)for(var e in Object(n))r.push(e);return r}var Rm=lP;var cP=Object.prototype,uP=cP.hasOwnProperty;function dP(n){if(!It(n))return Rm(n);var r=Oi(n),e=[];for(var t in n)t=="constructor"&&(r||!uP.call(n,t))||e.push(t);return e}var Lm=dP;function pP(n){return Wl(n)?$l(n,!0):Lm(n)}var Mi=pP;var fP=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,hP=/^\w*$/;function mP(n,r){if(dt(n))return!1;var e=typeof n;return e=="number"||e=="symbol"||e=="boolean"||n==null||Xo(n)?!0:hP.test(n)||!fP.test(n)||r!=null&&n in Object(r)}var Vm=mP;var yP=Qt(Object,"create"),wo=yP;function gP(){this.__data__=wo?wo(null):{},this.size=0}var zm=gP;function xP(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}var Gm=xP;var bP="__lodash_hash_undefined__",vP=Object.prototype,SP=vP.hasOwnProperty;function wP(n){var r=this.__data__;if(wo){var e=r[n];return e===bP?void 0:e}return SP.call(r,n)?r[n]:void 0}var Fm=wP;var PP=Object.prototype,CP=PP.hasOwnProperty;function OP(n){var r=this.__data__;return wo?r[n]!==void 0:CP.call(r,n)}var jm=OP;var AP="__lodash_hash_undefined__";function TP(n,r){var e=this.__data__;return this.size+=this.has(n)?0:1,e[n]=wo&&r===void 0?AP:r,this}var km=TP;function Ei(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}Ei.prototype.clear=zm;Ei.prototype.delete=Gm;Ei.prototype.get=Fm;Ei.prototype.has=jm;Ei.prototype.set=km;var Ud=Ei;function IP(){this.__data__=[],this.size=0}var Um=IP;function MP(n,r){for(var e=n.length;e--;)if(wi(n[e][0],r))return e;return-1}var Ko=MP;var EP=Array.prototype,NP=EP.splice;function DP(n){var r=this.__data__,e=Ko(r,n);if(e<0)return!1;var t=r.length-1;return e==t?r.pop():NP.call(r,e,1),--this.size,!0}var Hm=DP;function _P(n){var r=this.__data__,e=Ko(r,n);return e<0?void 0:r[e][1]}var Wm=_P;function BP(n){return Ko(this.__data__,n)>-1}var qm=BP;function RP(n,r){var e=this.__data__,t=Ko(e,n);return t<0?(++this.size,e.push([n,r])):e[t][1]=r,this}var $m=RP;function Ni(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}Ni.prototype.clear=Um;Ni.prototype.delete=Hm;Ni.prototype.get=Wm;Ni.prototype.has=qm;Ni.prototype.set=$m;var Qo=Ni;var LP=Qt(ut,"Map"),Zo=LP;function VP(){this.size=0,this.__data__={hash:new Ud,map:new(Zo||Qo),string:new Ud}}var Ym=VP;function zP(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}var Xm=zP;function GP(n,r){var e=n.__data__;return Xm(r)?e[typeof r=="string"?"string":"hash"]:e.map}var Jo=GP;function FP(n){var r=Jo(this,n).delete(n);return this.size-=r?1:0,r}var Km=FP;function jP(n){return Jo(this,n).get(n)}var Qm=jP;function kP(n){return Jo(this,n).has(n)}var Zm=kP;function UP(n,r){var e=Jo(this,n),t=e.size;return e.set(n,r),this.size+=e.size==t?0:1,this}var Jm=UP;function Di(n){var r=-1,e=n==null?0:n.length;for(this.clear();++r<e;){var t=n[r];this.set(t[0],t[1])}}Di.prototype.clear=Ym;Di.prototype.delete=Km;Di.prototype.get=Qm;Di.prototype.has=Zm;Di.prototype.set=Jm;var jn=Di;var HP="Expected a function";function Hd(n,r){if(typeof n!="function"||r!=null&&typeof r!="function")throw new TypeError(HP);var e=function(){var t=arguments,o=r?r.apply(this,t):t[0],i=e.cache;if(i.has(o))return i.get(o);var a=n.apply(this,t);return e.cache=i.set(o,a)||i,a};return e.cache=new(Hd.Cache||jn),e}Hd.Cache=jn;var ey=Hd;var WP=500;function qP(n){var r=ey(n,function(t){return e.size===WP&&e.clear(),t}),e=r.cache;return r}var ty=qP;var $P=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,YP=/\\(\\)?/g,XP=ty(function(n){var r=[];return n.charCodeAt(0)===46&&r.push(""),n.replace($P,function(e,t,o,i){r.push(o?i.replace(YP,"$1"):t||e)}),r}),ry=XP;function KP(n){return n==null?"":nm(n)}var oy=KP;function QP(n,r){return dt(n)?n:Vm(n,r)?[n]:ry(oy(n))}var mr=QP;var ZP=1/0;function JP(n){if(typeof n=="string"||Xo(n))return n;var r=n+"";return r=="0"&&1/n==-ZP?"-0":r}var en=JP;function eC(n,r){r=mr(r,n);for(var e=0,t=r.length;n!=null&&e<t;)n=n[en(r[e++])];return e&&e==t?n:void 0}var Xl=eC;function tC(n,r){for(var e=-1,t=r.length,o=n.length;++e<t;)n[o+e]=r[e];return n}var _i=tC;var ny=Tt?Tt.isConcatSpreadable:void 0;function rC(n){return dt(n)||Ai(n)||!!(ny&&n&&n[ny])}var iy=rC;function ay(n,r,e,t,o){var i=-1,a=n.length;for(e||(e=iy),o||(o=[]);++i<a;){var s=n[i];r>0&&e(s)?r>1?ay(s,r-1,e,t,o):_i(o,s):t||(o[o.length]=s)}return o}var sy=ay;function oC(n){var r=n==null?0:n.length;return r?sy(n,1):[]}var ly=oC;function nC(n){return vm(Pm(n,void 0,ly),n+"")}var Kl=nC;var iC=Yl(Object.getPrototypeOf,Object),Bi=iC;var aC="[object Object]",sC=Function.prototype,lC=Object.prototype,cy=sC.toString,cC=lC.hasOwnProperty,uC=cy.call(Object);function dC(n){if(!Vt(n)||sr(n)!=aC)return!1;var r=Bi(n);if(r===null)return!0;var e=cC.call(r,"constructor")&&r.constructor;return typeof e=="function"&&e instanceof e&&cy.call(e)==uC}var uy=dC;function pC(n,r,e){var t=-1,o=n.length;r<0&&(r=-r>o?0:o+r),e=e>o?o:e,e<0&&(e+=o),o=r>e?0:e-r>>>0,r>>>=0;for(var i=Array(o);++t<o;)i[t]=n[t+r];return i}var dy=pC;function fC(){this.__data__=new Qo,this.size=0}var py=fC;function hC(n){var r=this.__data__,e=r.delete(n);return this.size=r.size,e}var fy=hC;function mC(n){return this.__data__.get(n)}var hy=mC;function yC(n){return this.__data__.has(n)}var my=yC;var gC=200;function xC(n,r){var e=this.__data__;if(e instanceof Qo){var t=e.__data__;if(!Zo||t.length<gC-1)return t.push([n,r]),this.size=++e.size,this;e=this.__data__=new jn(t)}return e.set(n,r),this.size=e.size,this}var yy=xC;function Ri(n){var r=this.__data__=new Qo(n);this.size=r.size}Ri.prototype.clear=py;Ri.prototype.delete=fy;Ri.prototype.get=hy;Ri.prototype.has=my;Ri.prototype.set=yy;var Li=Ri;function bC(n,r){return n&&Yr(r,Ii(r),n)}var gy=bC;function vC(n,r){return n&&Yr(r,Mi(r),n)}var xy=vC;var wy=typeof exports=="object"&&exports&&!exports.nodeType&&exports,by=wy&&typeof module=="object"&&module&&!module.nodeType&&module,SC=by&&by.exports===wy,vy=SC?ut.Buffer:void 0,Sy=vy?vy.allocUnsafe:void 0;function wC(n,r){if(r)return n.slice();var e=n.length,t=Sy?Sy(e):new n.constructor(e);return n.copy(t),t}var Py=wC;function PC(n,r){for(var e=-1,t=n==null?0:n.length,o=0,i=[];++e<t;){var a=n[e];r(a,e,n)&&(i[o++]=a)}return i}var Cy=PC;function CC(){return[]}var Ql=CC;var OC=Object.prototype,AC=OC.propertyIsEnumerable,Oy=Object.getOwnPropertySymbols,TC=Oy?function(n){return n==null?[]:(n=Object(n),Cy(Oy(n),function(r){return AC.call(n,r)}))}:Ql,Vi=TC;function IC(n,r){return Yr(n,Vi(n),r)}var Ay=IC;var MC=Object.getOwnPropertySymbols,EC=MC?function(n){for(var r=[];n;)_i(r,Vi(n)),n=Bi(n);return r}:Ql,Zl=EC;function NC(n,r){return Yr(n,Zl(n),r)}var Ty=NC;function DC(n,r,e){var t=r(n);return dt(n)?t:_i(t,e(n))}var Jl=DC;function _C(n){return Jl(n,Ii,Vi)}var Ss=_C;function BC(n){return Jl(n,Mi,Zl)}var ec=BC;var RC=Qt(ut,"DataView"),tc=RC;var LC=Qt(ut,"Promise"),rc=LC;var VC=Qt(ut,"Set"),oc=VC;var Iy="[object Map]",zC="[object Object]",My="[object Promise]",Ey="[object Set]",Ny="[object WeakMap]",Dy="[object DataView]",GC=vo(tc),FC=vo(Zo),jC=vo(rc),kC=vo(oc),UC=vo(Ul),kn=sr;(tc&&kn(new tc(new ArrayBuffer(1)))!=Dy||Zo&&kn(new Zo)!=Iy||rc&&kn(rc.resolve())!=My||oc&&kn(new oc)!=Ey||Ul&&kn(new Ul)!=Ny)&&(kn=function(n){var r=sr(n),e=r==zC?n.constructor:void 0,t=e?vo(e):"";if(t)switch(t){case GC:return Dy;case FC:return Iy;case jC:return My;case kC:return Ey;case UC:return Ny}return r});var Po=kn;var HC=Object.prototype,WC=HC.hasOwnProperty;function qC(n){var r=n.length,e=new n.constructor(r);return r&&typeof n[0]=="string"&&WC.call(n,"index")&&(e.index=n.index,e.input=n.input),e}var _y=qC;var $C=ut.Uint8Array,zi=$C;function YC(n){var r=new n.constructor(n.byteLength);return new zi(r).set(new zi(n)),r}var Gi=YC;function XC(n,r){var e=r?Gi(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.byteLength)}var By=XC;var KC=/\w*$/;function QC(n){var r=new n.constructor(n.source,KC.exec(n));return r.lastIndex=n.lastIndex,r}var Ry=QC;var Ly=Tt?Tt.prototype:void 0,Vy=Ly?Ly.valueOf:void 0;function ZC(n){return Vy?Object(Vy.call(n)):{}}var zy=ZC;function JC(n,r){var e=r?Gi(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.length)}var Gy=JC;var eO="[object Boolean]",tO="[object Date]",rO="[object Map]",oO="[object Number]",nO="[object RegExp]",iO="[object Set]",aO="[object String]",sO="[object Symbol]",lO="[object ArrayBuffer]",cO="[object DataView]",uO="[object Float32Array]",dO="[object Float64Array]",pO="[object Int8Array]",fO="[object Int16Array]",hO="[object Int32Array]",mO="[object Uint8Array]",yO="[object Uint8ClampedArray]",gO="[object Uint16Array]",xO="[object Uint32Array]";function bO(n,r,e){var t=n.constructor;switch(r){case lO:return Gi(n);case eO:case tO:return new t(+n);case cO:return By(n,e);case uO:case dO:case pO:case fO:case hO:case mO:case yO:case gO:case xO:return Gy(n,e);case rO:return new t;case oO:case aO:return new t(n);case nO:return Ry(n);case iO:return new t;case sO:return zy(n)}}var Fy=bO;function vO(n){return typeof n.constructor=="function"&&!Oi(n)?hm(Bi(n)):{}}var jy=vO;var SO="[object Map]";function wO(n){return Vt(n)&&Po(n)==SO}var ky=wO;var Uy=So&&So.isMap,PO=Uy?Ti(Uy):ky,Hy=PO;var CO="[object Set]";function OO(n){return Vt(n)&&Po(n)==CO}var Wy=OO;var qy=So&&So.isSet,AO=qy?Ti(qy):Wy,$y=AO;var TO=1,IO=2,MO=4,Yy="[object Arguments]",EO="[object Array]",NO="[object Boolean]",DO="[object Date]",_O="[object Error]",Xy="[object Function]",BO="[object GeneratorFunction]",RO="[object Map]",LO="[object Number]",Ky="[object Object]",VO="[object RegExp]",zO="[object Set]",GO="[object String]",FO="[object Symbol]",jO="[object WeakMap]",kO="[object ArrayBuffer]",UO="[object DataView]",HO="[object Float32Array]",WO="[object Float64Array]",qO="[object Int8Array]",$O="[object Int16Array]",YO="[object Int32Array]",XO="[object Uint8Array]",KO="[object Uint8ClampedArray]",QO="[object Uint16Array]",ZO="[object Uint32Array]",Je={};Je[Yy]=Je[EO]=Je[kO]=Je[UO]=Je[NO]=Je[DO]=Je[HO]=Je[WO]=Je[qO]=Je[$O]=Je[YO]=Je[RO]=Je[LO]=Je[Ky]=Je[VO]=Je[zO]=Je[GO]=Je[FO]=Je[XO]=Je[KO]=Je[QO]=Je[ZO]=!0;Je[_O]=Je[Xy]=Je[jO]=!1;function nc(n,r,e,t,o,i){var a,s=r&TO,l=r&IO,c=r&MO;if(e&&(a=o?e(n,t,o,i):e(n)),a!==void 0)return a;if(!It(n))return n;var u=dt(n);if(u){if(a=_y(n),!s)return ym(n,a)}else{var p=Po(n),d=p==Xy||p==BO;if(Fn(n))return Py(n,s);if(p==Ky||p==Yy||d&&!o){if(a=l||d?{}:jy(n),!s)return l?Ty(n,xy(a,n)):Ay(n,gy(a,n))}else{if(!Je[p])return o?n:{};a=Fy(n,p,s)}}i||(i=new Li);var f=i.get(n);if(f)return f;i.set(n,a),$y(n)?n.forEach(function(y){a.add(nc(y,r,e,y,n,i))}):Hy(n)&&n.forEach(function(y,b){a.set(b,nc(y,r,e,b,n,i))});var h=c?l?ec:Ss:l?Mi:Ii,m=u?void 0:h(n);return Sm(m||n,function(y,b){m&&(b=y,y=n[b]),Pi(a,b,nc(y,r,e,b,n,i))}),a}var ic=nc;var JO=1,eA=4;function tA(n){return ic(n,JO|eA)}var Co=tA;var rA="__lodash_hash_undefined__";function oA(n){return this.__data__.set(n,rA),this}var Qy=oA;function nA(n){return this.__data__.has(n)}var Zy=nA;function ac(n){var r=-1,e=n==null?0:n.length;for(this.__data__=new jn;++r<e;)this.add(n[r])}ac.prototype.add=ac.prototype.push=Qy;ac.prototype.has=Zy;var Jy=ac;function iA(n,r){for(var e=-1,t=n==null?0:n.length;++e<t;)if(r(n[e],e,n))return!0;return!1}var eg=iA;function aA(n,r){return n.has(r)}var tg=aA;var sA=1,lA=2;function cA(n,r,e,t,o,i){var a=e&sA,s=n.length,l=r.length;if(s!=l&&!(a&&l>s))return!1;var c=i.get(n),u=i.get(r);if(c&&u)return c==r&&u==n;var p=-1,d=!0,f=e&lA?new Jy:void 0;for(i.set(n,r),i.set(r,n);++p<s;){var h=n[p],m=r[p];if(t)var y=a?t(m,h,p,r,n,i):t(h,m,p,n,r,i);if(y!==void 0){if(y)continue;d=!1;break}if(f){if(!eg(r,function(b,S){if(!tg(f,S)&&(h===b||o(h,b,e,t,i)))return f.push(S)})){d=!1;break}}else if(!(h===m||o(h,m,e,t,i))){d=!1;break}}return i.delete(n),i.delete(r),d}var sc=cA;function uA(n){var r=-1,e=Array(n.size);return n.forEach(function(t,o){e[++r]=[o,t]}),e}var rg=uA;function dA(n){var r=-1,e=Array(n.size);return n.forEach(function(t){e[++r]=t}),e}var og=dA;var pA=1,fA=2,hA="[object Boolean]",mA="[object Date]",yA="[object Error]",gA="[object Map]",xA="[object Number]",bA="[object RegExp]",vA="[object Set]",SA="[object String]",wA="[object Symbol]",PA="[object ArrayBuffer]",CA="[object DataView]",ng=Tt?Tt.prototype:void 0,Wd=ng?ng.valueOf:void 0;function OA(n,r,e,t,o,i,a){switch(e){case CA:if(n.byteLength!=r.byteLength||n.byteOffset!=r.byteOffset)return!1;n=n.buffer,r=r.buffer;case PA:return!(n.byteLength!=r.byteLength||!i(new zi(n),new zi(r)));case hA:case mA:case xA:return wi(+n,+r);case yA:return n.name==r.name&&n.message==r.message;case bA:case SA:return n==r+"";case gA:var s=rg;case vA:var l=t&pA;if(s||(s=og),n.size!=r.size&&!l)return!1;var c=a.get(n);if(c)return c==r;t|=fA,a.set(n,r);var u=sc(s(n),s(r),t,o,i,a);return a.delete(n),u;case wA:if(Wd)return Wd.call(n)==Wd.call(r)}return!1}var ig=OA;var AA=1,TA=Object.prototype,IA=TA.hasOwnProperty;function MA(n,r,e,t,o,i){var a=e&AA,s=Ss(n),l=s.length,c=Ss(r),u=c.length;if(l!=u&&!a)return!1;for(var p=l;p--;){var d=s[p];if(!(a?d in r:IA.call(r,d)))return!1}var f=i.get(n),h=i.get(r);if(f&&h)return f==r&&h==n;var m=!0;i.set(n,r),i.set(r,n);for(var y=a;++p<l;){d=s[p];var b=n[d],S=r[d];if(t)var P=a?t(S,b,d,r,n,i):t(b,S,d,n,r,i);if(!(P===void 0?b===S||o(b,S,e,t,i):P)){m=!1;break}y||(y=d=="constructor")}if(m&&!y){var C=n.constructor,v=r.constructor;C!=v&&"constructor"in n&&"constructor"in r&&!(typeof C=="function"&&C instanceof C&&typeof v=="function"&&v instanceof v)&&(m=!1)}return i.delete(n),i.delete(r),m}var ag=MA;var EA=1,sg="[object Arguments]",lg="[object Array]",lc="[object Object]",NA=Object.prototype,cg=NA.hasOwnProperty;function DA(n,r,e,t,o,i){var a=dt(n),s=dt(r),l=a?lg:Po(n),c=s?lg:Po(r);l=l==sg?lc:l,c=c==sg?lc:c;var u=l==lc,p=c==lc,d=l==c;if(d&&Fn(n)){if(!Fn(r))return!1;a=!0,u=!1}if(d&&!u)return i||(i=new Li),a||ql(n)?sc(n,r,e,t,o,i):ig(n,r,l,e,t,o,i);if(!(e&EA)){var f=u&&cg.call(n,"__wrapped__"),h=p&&cg.call(r,"__wrapped__");if(f||h){var m=f?n.value():n,y=h?r.value():r;return i||(i=new Li),o(m,y,e,t,i)}}return d?(i||(i=new Li),ag(n,r,e,t,o,i)):!1}var ug=DA;function dg(n,r,e,t,o){return n===r?!0:n==null||r==null||!Vt(n)&&!Vt(r)?n!==n&&r!==r:ug(n,r,e,t,dg,o)}var pg=dg;function _A(n,r){return n!=null&&r in Object(n)}var fg=_A;function BA(n,r,e){r=mr(r,n);for(var t=-1,o=r.length,i=!1;++t<o;){var a=en(r[t]);if(!(i=n!=null&&e(n,a)))break;n=n[a]}return i||++t!=o?i:(o=n==null?0:n.length,!!o&&Ci(o)&&Si(a,o)&&(dt(n)||Ai(n)))}var hg=BA;function RA(n,r){return n!=null&&hg(n,r,fg)}var mg=RA;var LA=function(){return ut.Date.now()},cc=LA;var VA="Expected a function",zA=Math.max,GA=Math.min;function FA(n,r,e){var t,o,i,a,s,l,c=0,u=!1,p=!1,d=!0;if(typeof n!="function")throw new TypeError(VA);r=Fd(r)||0,It(e)&&(u=!!e.leading,p="maxWait"in e,i=p?zA(Fd(e.maxWait)||0,r):i,d="trailing"in e?!!e.trailing:d);function f(A){var T=t,g=o;return t=o=void 0,c=A,a=n.apply(g,T),a}function h(A){return c=A,s=setTimeout(b,r),u?f(A):a}function m(A){var T=A-l,g=A-c,D=r-T;return p?GA(D,i-g):D}function y(A){var T=A-l,g=A-c;return l===void 0||T>=r||T<0||p&&g>=i}function b(){var A=cc();if(y(A))return S(A);s=setTimeout(b,m(A))}function S(A){return s=void 0,d&&t?f(A):(t=o=void 0,a)}function P(){s!==void 0&&clearTimeout(s),c=0,t=l=o=s=void 0}function C(){return s===void 0?a:S(cc())}function v(){var A=cc(),T=y(A);if(t=arguments,o=this,l=A,T){if(s===void 0)return h(l);if(p)return clearTimeout(s),s=setTimeout(b,r),f(l)}return s===void 0&&(s=setTimeout(b,r)),a}return v.cancel=P,v.flush=C,v}var uc=FA;function jA(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}var yg=jA;function kA(n,r){return r.length<2?n:Xl(n,dy(r,0,-1))}var gg=kA;function UA(n,r){return pg(n,r)}var qd=UA;function HA(n,r){return r=mr(r,n),n=gg(n,r),n==null||delete n[en(yg(r))]}var xg=HA;function WA(n){return uy(n)?void 0:n}var bg=WA;var qA=1,$A=2,YA=4,XA=Kl(function(n,r){var e={};if(n==null)return e;var t=!1;r=Fl(r,function(i){return i=mr(i,n),t||(t=i.length>1),i}),Yr(n,ec(n),e),t&&(e=ic(e,qA|$A|YA,bg));for(var o=r.length;o--;)xg(e,r[o]);return e}),Fi=XA;function KA(n,r,e,t){if(!It(n))return n;r=mr(r,n);for(var o=-1,i=r.length,a=i-1,s=n;s!=null&&++o<i;){var l=en(r[o]),c=e;if(l==="__proto__"||l==="constructor"||l==="prototype")return n;if(o!=a){var u=s[l];c=t?t(u,l,s):void 0,c===void 0&&(c=It(u)?u:Si(r[o+1])?[]:{})}Pi(s,l,c),s=s[l]}return n}var vg=KA;function QA(n,r,e){for(var t=-1,o=r.length,i={};++t<o;){var a=r[t],s=Xl(n,a);e(s,a)&&vg(i,mr(a,n),s)}return i}var Sg=QA;function ZA(n,r){return Sg(n,r,function(e,t){return mg(n,t)})}var wg=ZA;var JA=Kl(function(n,r){return n==null?{}:wg(n,r)}),Er=JA;var fe=class{modifyById(r,e){let t=this;if(t[r]===void 0)throw new Error("not expected");{let i={...t,[r]:e};return Object.setPrototypeOf(i,fe.prototype),i}}add(r,e){return this.runOp({type:1,id:r,data:e})?.data??this}runOp(r){let e=this;if(r.type===1){let t=e[r.id],o;t===void 0?o={type:2,id:r.id}:o={type:1,id:r.id,data:t};let{id:i,data:a}=r,s={...e,[i]:a};return Object.setPrototypeOf(s,fe.prototype),{data:s,actual:r,reverse:o}}else if(r.type===2){let{id:t}=r,o=e[t];if(o===void 0)return null;{let i={...e};return Object.setPrototypeOf(i,fe.prototype),delete i[t],{data:i,actual:r,reverse:{type:1,id:t,data:o}}}}return null}};function ws(n){if(n.deepFreeze!==void 0){n.deepFreeze(n);return}let r=Object.getOwnPropertyNames(n);for(let e of r){let t=n[e];t&&typeof t=="object"&&ws(t)}return Object.freeze(n)}function Pg(n,r){let e=0;for(;e<n.length&&e<r.length;){if(n[e]<r[e])return-1;if(n[e]>r[e])return 1;e+=1}return e!==r.length?-1:e!==n.length?1:0}var ji=class extends Error{};function dc(n){let r={...n};return Object.setPrototypeOf(r,Object.getPrototypeOf(n)),r}function Xr(n,r,e){if(n===void 0?r===void 0?(n=0,r=10):n=r-10:r===void 0&&(r=n+10),n>r){let i=n;n=r,r=i}let t=[],o=1/(e+1);for(let i=0;i<e;i++){let a=n+(r-n)*(i+.75+Math.random()*.5)*o;t.push(a)}return t}function ki(n){return n instanceof Uint8Array||n instanceof Uint16Array||n instanceof Uint32Array||n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array||n instanceof Float32Array||n instanceof Float64Array}function Cg(){return typeof process<"u"}function Og(n,r){for(let e of n)r(e.id,e.data)!==!0&&Og(e.children,r)}function Ag(n,r){if(r(n.id,n.data)!==!0)for(let e of n.children)Ag(e,r)}var Ke=class extends Array{constructor(...e){super(...e);Object.setPrototypeOf(this,Ke.prototype)}deepFreeze(){let e=0;for(;e<this.length;)ws(this[e]),e++}fillCaches0(e,t){this.objCaches.set(e.id,e),this.parentCaches.set(e.id,t);for(let o of e.children)this.fillCaches0(o,e.id)}fillCaches(){if(this.objCaches===void 0){this.objCaches=new Map,this.parentCaches=new Map;for(let e of this)this.fillCaches0(e,null)}}randomId(){this.fillCaches();let e=Array.from(this.objCaches.keys());if(e.length!==0)return e[Math.max(0,Math.floor(Math.random()*e.length)-1)]}nonExistOrDescendantOf(e,t){if(!this.has(e))return!0;for(;e;){let o=this.parent(e);if(o===t)return!0;e=o}return!1}rootAcestor(e){for(;e;){let t=this.parent(e);if(t)e=t;else return e}return e}isDescendantOf(e,t){for(;e;){let o=this.parent(e);if(o===t)return!0;e=o}return!1}data(e){return this.get(e)?.data}has(e){return this.childrenOf(e)!==void 0}get(e){return this.fillCaches(),this.objCaches.get(e)}childrenOf(e){return e===null?this:this.get(e)?.children}traverseFrom(e,t){if(e===null)this.traverse(t);else{let o=this.get(e);o&&Ag(o,t)}}traverse(e){Og(this,e)}totalSize(){return this.fillCaches(),this.objCaches.size}parent(e){return this.fillCaches(),this.parentCaches.get(e)}childrenArray(e){return e===null?this:this.get(e).children}modifyById(e,t){if(this.get(e)===void 0)throw new Error("not expected");{let i=this.parent(e),a=this.childrenArray(i),s=a.findIndex(u=>u.id===e);if(s<0)throw new Error("not expected");let l=a[s];return a=[...a],a[s]={...l,data:t},this.modifyArrayBy(i,a)}}modifyArrayBy(e,t){let o=e,i=t;for(;o!==null;){let s=i,l=o;if(o=this.parent(o),o===void 0)throw new Error;i=this.childrenArray(o);let c=i.findIndex(u=>u.id===l);if(c<0)throw new Error;i=[...i],i[c]={...i[c],children:s}}Object.setPrototypeOf(i,Ke.prototype);let a=i;return a.fillCaches(),a}runOp(e){switch(e.type){case 7:return this.addOp(e);case 8:return this.deleteOp(e);case 9:return this.moveOp(e)}return null}checkDuplicatedIdRec({id:e,children:t}){if(this.get(e)!==void 0)return!0;for(let o of t)if(this.checkDuplicatedIdRec(o))return!0;return!1}addOp(e){let{parent:t,fi:o,id:i,data:a,children:s}=e;if(t!==null&&this.get(t)===void 0)return null;if(this.checkDuplicatedIdRec(e))return null;{let l=t,c=this.childrenArray(l),u={fi:o,id:i,data:a,children:s};return c=[...c,u],c.sort((d,f)=>d.fi-f.fi),e.localIndex=c.indexOf(u),{data:this.modifyArrayBy(l,c),actual:e,reverse:{type:8,id:i}}}}deleteOp(e){let{id:t}=e;if(this.get(t)===null)return null;{let o=this.parent(t);if(o===void 0)return null;let i=this.childrenArray(o),a=i.findIndex(c=>c.id===t);e.localIndex=a,i=[...i];let s=i.splice(a,1)[0];return{data:this.modifyArrayBy(o,i),actual:e,reverse:{type:7,...s,parent:o}}}}moveOp(e){let{parent:t,fi:o,id:i}=e;if(t!==null&&this.get(t)===void 0)return this.deleteOp({type:8,id:i});if(t!==null){let f=t;for(;f!==null;){if(f===void 0)throw new Error;if(f===i)throw new ji("cyclic tree");f=this.parent(f)}}let a=this.parent(i);if(a===void 0)return null;let s=a,l=this.childrenArray(a),c=l.findIndex(f=>f.id===i);l=[...l];let u=l.splice(c,1)[0],p=this.modifyArrayBy(a,l);a=t,l=p.childrenArray(a);let d=u.fi;return u={...u,fi:o},l=[...l,u],l.sort((f,h)=>f.fi-h.fi),e.localIndex=l.indexOf(u),p=p.modifyArrayBy(a,l),{data:p,actual:e,reverse:{type:9,parent:s,fi:d,id:i}}}previous(e,t){if(t===null){let i=this.childrenArray(e);return i.length===0?null:i[i.length-1].id}let o=null;for(let i of this.childrenArray(e)){if(i.id===t)return o;o=i.id}return null}traverseSortNext(e){let t=this.parent(e);if(t!==void 0){let o=this.childrenArray(t),i=o.findIndex(a=>a.id===e)+1;if(i<o.length)return o[i].id;if(t)return this.traverseSortNext(t)}}sortNext(e){let t=this.childrenArray(e);return t.length>0?t[0].id:this.traverseSortNext(e)}traverseSortPrevious(e){let t=this.childrenArray(e);return t.length>0?this.traverseSortPrevious(t[t.length-1].id):e}sortPrevious(e){let t=this.parent(e);if(t!==void 0){let o=this.childrenArray(t),i=o.findIndex(a=>a.id===e)-1;return i>=0?this.traverseSortPrevious(o[i].id):t}}getAllSorted(e){let t=[];for(let o of e){let i=this.getWithSortKey(o.id);i!==void 0&&t.push({...o,...i})}t.sort((o,i)=>Pg(o.sortKey,i.sortKey));for(let o of t)delete o.sortKey;return t}getWithSortKey(e){var t=e;let o=[],i=this.get(t),a=i;if(i!==void 0){for(;t;)o.splice(0,0,i.fi),t=this.parent(t),t!==null&&(i=this.get(t));return{...a,sortKey:o}}}insertBeforeHelper(e,t,o){return this.insertAfterHelper(e,this.previous(e,t),o)}insertAfterHelper(e,t,o){let i=this.childrenArray(e);if(t===null){if(i.length===0)return Xr(0,o,o);{let a=i[0].fi;return Xr(a-o,a,o)}}else{let a=this.get(t);if(a===void 0||this.parent(t)!==e)throw new Error("illegal args");let s=i.find(l=>l.fi>a.fi);if(s===void 0){let l=i[i.length-1].fi;return Xr(l,l+o,o)}else return Xr(a.fi,s.fi,o)}}};var Ui;(r=>{function n(e,t){if(t.type!==0)return null;if(Array.isArray(e)){let o=t.props,i={},a=[...e],s=!1;if(o)for(let l of Object.keys(o)){let c=parseInt(l);if(isNaN(c))throw new Error("wrong index");i[l]=a[c],a[c]=o[l],s=!0}return s?{data:a,actual:t,reverse:{type:0,props:i}}:null}else{let o=t.props,i={},a={...e},s=!1;if(o)for(let l of Object.keys(o)){i[l]=a[l];let c=o[l];c===void 0?delete a[l]:a[l]=c,s=!0}return s?{data:a,actual:t,reverse:{type:0,props:i}}:null}}r.runOp=n})(Ui||(Ui={}));var be=class extends Array{constructor(...e){super(...e);Object.setPrototypeOf(this,be.prototype)}deepFreeze(){let e=0;for(;e<this.length;)ws(this[e]),e++}fillCaches0(e){this.objCaches.set(e.id,e)}fillCaches(){if(this.objCaches===void 0){this.objCaches=new Map,Object.getOwnPropertyDescriptor(this,"objCaches").enumerable=!1;for(let e of this)this.fillCaches0(e)}}randomId(){this.fillCaches();let e=Array.from(this.objCaches.keys());if(e.length!==0)return e[Math.max(0,Math.floor(Math.random()*e.length)-1)]}data(e){return this.get(e)?.data}get(e){return this.fillCaches(),this.objCaches.get(e)}modifyById(e,t){if(this.get(e)===void 0)throw new Error("not expected");{let i=this,a=i.findIndex(c=>c.id===e);if(a<0)throw new Error("not expected");let s=i[a];return i=[...i],i[a]={...s,data:t},this.modifyArrayBy(i)}}modifyArrayBy(e){Object.setPrototypeOf(e,be.prototype);let t=e;return Cg()||t.fillCaches(),t}runOp(e){switch(e.type){case 4:return this.addOp(e);case 5:return this.deleteOp(e);case 6:return this.moveOp(e)}return null}addOp(e){let{fi:t,id:o,data:i}=e,a=this,s={fi:t,id:o,data:i};return a=[...a,s],a.sort((c,u)=>c.fi-u.fi),e.localIndex=a.indexOf(s),{data:this.modifyArrayBy(a),actual:e,reverse:{type:5,id:o}}}deleteOp(e){let{id:t}=e,o=this,i=o.findIndex(l=>l.id===t);if(i===-1)return null;e.localIndex=i,o=[...o];let a=o.splice(i,1)[0];return{data:this.modifyArrayBy(o),actual:e,reverse:{type:4,...a}}}moveOp(e){let{fi:t,id:o}=e,i=this;i=[...i];let a=i.findIndex(u=>u.id===o);if(a===-1)return null;let s=i[a].fi,l={...i[a],fi:t};return i[a]=l,i.sort((u,p)=>u.fi-p.fi),e.localIndex=i.indexOf(l),{data:this.modifyArrayBy(i),actual:e,reverse:{type:6,fi:s,id:o}}}previous(e){if(e===null)return this.length===0?null:this[this.length-1].id;let t=null;for(let o of this){if(o.id===e)return t;t=o.id}return null}insertBeforeHelper(e,t){return this.insertAfterHelper(this.previous(e),t)}insertAfterHelper(e,t){let o=this;if(e===null){if(o.length===0)return Xr(0,t,t);{let i=o[0].fi;return Xr(i-t,i,t)}}else{let i=this.get(e);if(i===void 0)throw new Error("illegal args");let a=o.find(s=>s.fi>i.fi);if(a===void 0){let s=o[o.length-1].fi;return Xr(s,s+t,t)}else return Xr(i.fi,a.fi,t)}}};function Hi(n){return n&&typeof n=="object"&&n instanceof Qe}var Qe=class{unusedFunOverridesTable(r){}runOp(r){let e=[],t=this,o=0,i={};for(;o<r.path.length;){if(e.push(t),t=t===void 0?void 0:t[r.path[o]],t!==void 0&&!Hi(t))return null;o+=1}t=t?dc(t):new Qe;for(let[l,c]of Object.entries(r.props)){let u=t[l];i[l]=u,c===void 0?delete t[l]:t[l]=c}for(;o>0;){if(Object.keys(t).length===0){let l=e[o-1];l&&(t=dc(l),delete t[r.path[o-1]])}else{let l=e[o-1];if(l){let c=dc(l);c[r.path[o-1]]=t,t=c}else{let c=new Qe;c[r.path[o-1]]=t,t=c}}o-=1}let a=Object.setPrototypeOf(t,Qe.prototype),s={...r,props:i};return{data:a,actual:r,reverse:s}}},Kr;(t=>{function n(o,i){return Ps(o,i)??o}t.apply=n;function r(o,i){return Yd(o,i)}t.merge=r;function e(o,i){let a=0,s=i.path,l=o;for(;a<s.length&&l!==void 0;){if(l=Ze.zoomOnce(l,s[a]),l===void 0)return i;if(!Hi(l))return;a+=1}if(l===void 0)return i;if(!!Hi(l))if(i.type===0){let c={...i.props};for(let u of Object.keys(l))delete c[u];return{...i,props:c}}else if(i.type===1||i.type===4||i.type===7){let c=$d([i],l);return c?(console.log(c),c):i}else return i}t.filterOp=e})(Kr||(Kr={}));function $d(n,r){if(r===void 0)return;let e=!1,t=n.map(o=>{let i=o.id,a=Ps(o.data,r[i]);if(e=e||a!==void 0,a===void 0&&(a=o.data),o.children){let s=$d(o.children,r);return s!==void 0?e=!0:s=o.children,{...o,id:i,data:a,children:s}}else return{...o,id:i,data:a}});if(e)return t}function eT(n,r){if(r===void 0)return;let e=!1,t=n.map(o=>{let i=o.id,a=Ps(o.data,r[i]);return e=e||a!==void 0,a===void 0&&(a=o.data),{...o,id:i,data:a}});if(e)return Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t}function Ps(n,r){if(!Hi(r))return r;if(n instanceof Ke){let e=$d(n,r);return e!==void 0&&Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e}else{if(n instanceof be)return eT(n,r);if(Array.isArray(n)){let e=!1,t=n.map((o,i)=>{let a=Ps(o,r[i]);return e=e||a!==void 0,a===void 0&&(a=o),a});return e?(Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t):void 0}else{if(n instanceof Qe)return Yd(n,r);if(n&&typeof n=="object"){let e={},t=!1;for(let[o,i]of Object.entries(n)){let a=Ps(i,r[o]);t=t||a!==void 0,a===void 0&&(a=i),e[o]=a}return t?(Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e):void 0}}}}function Yd(n,r){if(n===void 0)return r;if(r===void 0)return n;if(!Hi(r))return r;if(!Hi(n))return Kr.apply(n,r);let e=new Set;for(let o of Object.keys(n))e.add(o);for(let o of Object.keys(r))e.add(o);let t=new Qe;for(let o of e){let i=Yd(n===void 0?void 0:n[o],r===void 0?void 0:r[o]);t[o]=i}return t}function Tg(n,r){let e={cur:[],result:[],len:0};return n=Cs(n,r,e)??n,[n,e.result]}function pc(n,r){return n===null?null:(n.cur[n.len]=r,n.len+=1,n)}function fc(n){n&&(n.len-=1)}function tT(n){if(n===null)return null;n.result.push(n.cur.slice(0,n.len))}function Ig(n,r,e){let t=!1,o=n.map(i=>{let a=i.id,s=r[a];if(s!==void 0&&typeof s=="string"&&(t=!0,a=s,e!==null))throw new Error("not supported");let l=Cs(i.data,r,pc(e,a));fc(e),t=t||l!==void 0,l===void 0&&(l=i.data);let c=Ig(i.children,r,e);return c!==void 0?t=!0:c=i.children,{...i,id:a,data:l,children:c}});if(t)return o}function rT(n,r,e){let t=!1,o=n.map(i=>{let a=i.id,s=r[a];if(s!==void 0&&typeof s=="string"&&(t=!0,a=s,e!==null))throw new Error("not supported");let l=Cs(i.data,r,pc(e,a));return fc(e),t=t||l!==void 0,l===void 0&&(l=i.data),{...i,id:a,data:l}});if(t)return Object.setPrototypeOf(o,Object.getPrototypeOf(n)),o}function Cs(n,r,e){if(n instanceof Ke){let t=Ig(n,r,e);return t!==void 0&&Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t}else{if(n instanceof be)return rT(n,r,e);if(Array.isArray(n)){let t=!1,o=n.map((i,a)=>{let s=Cs(i,r,pc(e,a));return fc(e),t=t||s!==void 0,s===void 0&&(s=i),s});return t?(Object.setPrototypeOf(o,Object.getPrototypeOf(n)),o):void 0}else if(n&&typeof n=="object"&&!ki(n)){let t={},o=!1;for(let[i,a]of Object.entries(n))if(i!=="name"&&i!=="variableId"){let s=r[i];if(typeof s=="string"){if(e!==null)throw new Error("not supported");o=!0,i=s}let l=Cs(a,r,pc(e,i));fc(e),o=o||l!==void 0,l===void 0&&(l=a),t[i]=l}else t[i]=a;return o?(Object.setPrototypeOf(t,Object.getPrototypeOf(n)),t):void 0}else if(typeof n=="string"){let t=r[n];return t!==void 0&&tT(e),t}else return}}var Wi;(r=>{function n(e,t){let o=Ze.zoom(t,e.path);if(typeof o=="object"){let i={};for(let a of Object.keys(e.props))i[a]=o[a];return{...e,props:i}}else return{...e,props:{}}}r.replaceProps=n})(Wi||(Wi={}));var nt;(s=>{function n(l,c){return{...l,path:l.path.slice(c)}}s.drop=n;function r(l,c){return e(l,c)?.data??l}s.applySimple=r;function e(l,c){let u=c.path;for(var p=[];;){let d;if(l instanceof Qe&&c.type===0&&(d=l.runOp({...c,path:u.slice(p.length)}),d===null&&(d=void 0)),d===void 0&&p.length===u.length&&(l instanceof Ke||l instanceof be||l instanceof fe?d=l.runOp(c):d=Ui.runOp(l,c)),d!==void 0)if(d!==null){let m=d.data;for(let y=p.length-1;y>=0;y--){let b=u[y],S=p[y];if(S instanceof Ke){if(typeof b=="number")throw new Error("illegal arg");m=S.modifyById(b,m)}else if(S instanceof be){if(typeof b=="number")throw new Error("illegal arg");m=S.modifyById(b,m)}else if(S instanceof fe){if(typeof b=="number")throw new Error("illegal arg");m=S.modifyById(b,m)}else if(S instanceof Qe){let P={...S,[b]:m};m=Object.setPrototypeOf(P,Qe.prototype)}else if(typeof S=="object")if(Array.isArray(S)){if(typeof b=="string"&&(b=parseInt(b),isNaN(b)))throw new Error("Invalid path");let P=m;m=[...S],m[b]=P}else m={...S,[b]:m};else return null}return{data:m,actual:{...d.actual,path:u},reverse:{...d.reverse,path:u}}}else return null;let f=u[p.length],h;if(l instanceof Ke){if(typeof f=="number")throw new Error("");h=l.get(f)?.data}else if(l instanceof be){if(typeof f=="number")throw new Error("");h=l.get(f)?.data}else l!==null&&(h=l[f]);if(h!==void 0)p.push(l),l=h;else return null}}s.apply=e;function t(l,c){for(let u=0;u<l.length&&u<c.length;u++)if(l[u]!==c[u])return!0;return!1}s.pathDisjoint=t;function o(l,c){if(l.length!==c.length)return!1;for(let u=0;u<l.length;u++)if(l[u]!==c[u])return!1;return!0}s.pathEq=o;function i(l,c){return t(l.path,c.path)}s.commutative=i;function a(l,c){return l.type===0&&c.type===0&&o(l.path,c.path)?Object.keys(l.props).every(u=>c.props[u]!==void 0):!1}s.subsumed=a})(nt||(nt={}));var Os;(l=>{function n(){return[]}l.empty=n;function r(c,u){let p=[];for(let d of c){let[f,...h]=d.path;f===u&&p.push({...d,path:h})}return p}l.removePrefix=r;function e(c,u){return c.map(p=>({...p,path:[u,...p.path]}))}l.addPrefix=e;function t(c,u){return[...c,...u]}l.concat=t;function o(c,u){return[...c.filter(d=>!u.some(f=>nt.subsumed(d,f))),...u]}l.compress=o;function i(c,u){return c.every(p=>u.every(d=>nt.commutative(p,d)))}l.commutative=i;function a(c,u){for(let p of u){let d=s(c,p);d!==null&&(c=d.data)}return c}l.applyAll=a;function s(c,u){var p=c;let d=[],f=[];for(let h of u)try{if(h.type===3||h.type===5&&h.path[h.path.length-1]==="variables"){let m,y,b;if(h.type===3?(m=Ze.zoom(p,[...h.path,h.id]),b=nt.apply(p,{...h,type:2})):(m=Ze.zoom(p,[...h.path,h.id,"value"]),b=nt.apply(p,h)),b!==null){p=b.data;let[S,P]=Tg(p,{[h.id]:m});p=S;for(let C=0;C<P.length;C++){let v=P[C],A=v.pop();if(typeof A=="number"){let T=[A];for(let D=C+1;D<P.length;D++){let E=P[D],M=E[E.length-1];if(typeof M=="number"&&Ze.equal(v,E.slice(0,E.length-1)))T.push(M),P.splice(D,1);else break}let g=Ze.zoom(p,v);y=g.map((D,E)=>T.includes(E)?h.id:D),m=g,A=v.pop()}else{if(A==="alphaOverride"||A==="alpha"){m/=100;let T=m,g=Ze.zoom(p,v.slice(0,v.length-2)),D=g.layers.map(E=>E.id===v[v.length-1]?{...E,data:{...E.data,[A]:T}}:E);Object.setPrototypeOf(D,Object.getPrototypeOf(g.layers)),g.layers=D}y=h.id}d.push({type:0,path:v,props:{[A]:m}}),f.push({type:0,path:v,props:{[A]:y}})}f.push(b.reverse),d.push(b.actual)}}else{let m=nt.apply(p,h);m!==null&&(d.push(m.actual),p=m.data,f.push(m.reverse))}}catch(m){if(m instanceof ji)return null;throw m}return{data:p,actual:d,reverse:f.reverse()}}l.apply=s})(Os||(Os={}));var Mg=Symbol(),oT=Symbol(),mc=Symbol(),Un=class{reportOp(r,e,t=[]){let o=this;if(e===null)return;o._current=e.data;let i=t;for(;!(o instanceof hc);){let a=o._path,s=o._current;if(a!==""&&i.splice(0,0,a),o=o._parent,o===null)return;o.update(a,s)}o.push(i,r,e.actual,e.reverse)}deleteChildren(r){if(this._children){let e=this._children[r];if(e){let t=e[mc];t&&t(),delete this._children[r]}}}},Kd=class extends Un{constructor(r,e,t){super(),this._parent=r,this._path=e,this._current=t}update(r,e){if(Array.isArray(this._current)){if(typeof r=="string"&&(r=parseInt(r),isNaN(r)))throw new Error("Invalid path");this._current=[...this._current],this._current[r]=e}else this._current={...this._current,[r]:e}}runOp(r){this.reportOp(r,Ui.runOp(this._current,r),r.path)}},Qd=class extends Un{constructor(r,e,t){super(),this._parent=r,this._path=e,this._current=t}update(r,e){this._current={...this._current,[r]:e},Object.setPrototypeOf(this._current,fe.prototype)}runOp(r){this.reportOp(r,this._current.runOp(r))}},Eg={get(n,r){if(r===mc)return()=>{n._parent=null};if(r===Mg)return n._current;if(r===oT)return n;let{_current:e,_children:t}=n;if(r==="push"&&Array.isArray(e))throw new Error("not supported to expand array");let o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e[r],a=yc(n,r,i);return a!==i?(t===void 0&&(t={},n._children=t),t[r]=a,a):i},has(n,r){return r in n._current},ownKeys(n){return Reflect.ownKeys(n._current)},defineProperty(){throw Error("not supported")},getPrototypeOf(n){return Object.getPrototypeOf(n._current)},setPrototypeOf(){throw Error("not supported")},getOwnPropertyDescriptor(n,r){let e=n._current,t=Reflect.getOwnPropertyDescriptor(e,r);return t&&{writable:!0,configurable:!0,enumerable:t.enumerable,value:e[r]}}},nT={...Eg,set(n,r,e){let t={type:0,props:{[r]:it(e)??e}};return n.deleteChildren(r),n.runOp(t),!0},deleteProperty(n,r){let e={type:0,props:{[r]:void 0}};return n.deleteChildren(r),n.runOp(e),!0}},iT={...Eg,set(n,r,e){return e===void 0?this.deleteProperty(n,r):(n.deleteChildren(r),n.runOp({type:1,id:r,data:e})),!0},deleteProperty(n,r){return n.runOp({type:2,id:r}),!0}},qi=class extends Un{constructor(r,e,t){super(),this._children={},this._parent=r,this._path=e,this._current=t,this[mc]=()=>{this._parent=null}}unproxy(){return this._current}update(r,e){this._current=this._current.modifyById(r,e)}runOp(r){this.reportOp(r,this._current.runOp(r))}randomId(){return this._current.randomId()}isDescendantOf(r,e){return this._current.isDescendantOf(r,e)}childrenOf(r){return this._current.childrenOf(r)}traverse(r){return this._current.traverse(r)}get(r){return this._current.get(r)}parent(r){return this._current.parent(r)}traverse(r){this._current.traverse((e,t)=>{r(e,this.data(e))})}data(r){let{_current:e,_children:t}=this,o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e.get(r)?.data,a=yc(this,r,i);return a!==i?(t===void 0&&(t={},this._children=t),t[r]=a,a):i}add(r,e,t,o,i){this.runOp({type:7,parent:r,fi:e,id:t,data:o,children:i})}move(r,e,t){this.runOp({type:9,parent:r,fi:e,id:t})}insertAfter(r,e,t){let o=this._current.insertAfterHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.add(r,o[i],a.id,a.data,a.children)}}insertBefore(r,e,t){let o=this._current.insertBeforeHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.add(r,o[i],a.id,a.data,a.children)}}moveAfter(r,e,t){let o=this._current.insertAfterHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.move(r,o[i],a)}}moveBefore(r,e,t){let o=this._current.insertBeforeHelper(r,e,t.length);for(let i=0;i<t.length;i++){let a=t[i];this.move(r,o[i],a)}}delete(r){this.deleteChildren(r),this.runOp({type:8,id:r})}sortNext(r){return this._current.sortNext(r)}sortPrevious(r){return this._current.sortPrevious(r)}getAllSorted(r){return this._current.getAllSorted(r)}},$i=class extends Un{constructor(r,e,t){super(),this._children={},this._parent=r,this._path=e,this._current=t,this[mc]=()=>{this._parent=null}}unproxy(){return this._current}get length(){return this._current.length}forEach(r){let e=this.length;for(let t=0;t<e;t++){let o=this._current[t].id,i=this._current[t].fi;r(this.data(this._current[t].id),o,i)}}find(r){let e=this.length;for(let t=0;t<e;t++){let o=this._current[t].id;if(r(this.data(o),o))return this.get(o)}}update(r,e){this._current=this._current.modifyById(r,e)}randomId(){return this._current.randomId()}get(r){return{...this._current.get(r),data:this.data(r)}}data(r){let{_current:e,_children:t}=this,o=t===void 0?void 0:t[r];if(o!==void 0)return o;let i=e.get(r)?.data,a=yc(this,r,i);return a!==i?(t===void 0&&(t={},this._children=t),t[r]=a,a):i}runOp(r){this.reportOp(r,this._current.runOp(r))}add(r,e,t){this.runOp({type:4,fi:r,id:e,data:t})}move(r,e){this.runOp({type:6,fi:r,id:e})}insertAfter(r,e){let t=this._current.insertAfterHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.add(t[o],i.id,i.data)}}insertBefore(r,e){let t=this._current.insertBeforeHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.add(t[o],i.id,i.data)}}moveAfter(r,e){let t=this._current.insertAfterHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.move(t[o],i)}}moveBefore(r,e){let t=this._current.insertBeforeHelper(r,e.length);for(let o=0;o<e.length;o++){let i=e[o];this.move(t[o],i)}}delete(r){this.deleteChildren(r),this.runOp({type:5,id:r})}};function Xd(n,r,e){if(n.length>0){let t=n[n.length-1];if(t.type===0&&r.type===0&&Ze.equal(t.path,e)){Object.assign(t.props,r.props);return}}n.push({...r,path:e})}var hc=class extends Un{constructor(r){super(),this.ts=[],this.actual=[],this.reverse=[],this._current=r}update(r,e){if(r!=="")throw new Error("");this._current=e}push(r,e,t,o){Xd(this.ts,e,r),Xd(this.actual,t,r),Xd(this.reverse,o,r)}result(){return{data:this._current,ts:this.ts,actual:this.actual,reverse:this.reverse.reverse()}}};function yc(n,r,e){return e instanceof Ke?new qi(n,r,e):e instanceof be?new $i(n,r,e):e instanceof fe?new Proxy(new Qd(n,r,e),iT):e!==null&&typeof e=="object"?ki(e)?e:new Proxy(new Kd(n,r,e),nT):e}function Zd(n){let r=new hc(n);return[yc(r,"",n),r]}function tn(n,r){let[e,t]=Zd(n);return r(e),t.result()}function it(n){return n instanceof qi||n instanceof $i?n._current:n!==null&&typeof n=="object"?n[Mg]:n}var Ze;(o=>{function n(i,a){if(a.length===i.length)for(var s=0;s<i.length;){if(i[s]!==a[s])return!1;s+=1}else return!1;return!0}o.equal=n;function r(i,a,s){let l=t(s,i);if(l!==void 0&&typeof l=="object"&&l!==null){let c={...a};return Object.keys(l).forEach(u=>{delete c[u]}),c}else return a}o.removeOverridden=r;function e(i,a){if((i instanceof Ke||i instanceof qi)&&typeof a=="string")return i.data(a);if((i instanceof be||i instanceof $i)&&typeof a=="string")return i.data(a);if(typeof a=="number"&&Array.isArray(i))return i[a];if(typeof a=="string"&&typeof i=="object"&&i!==null)return i[a]}o.zoomOnce=e;function t(i,a,s=0){for(;s<a.length&&i!==void 0;)i=e(i,a[s]),s+=1;return i}o.zoom=t})(Ze||(Ze={}));function Ng(n,r){let e=[];if(r.length===n.length)for(var t=0;t<n.length;){if(r[t]==="*")e.push(n[t]);else if(n[t]!==r[t])return null;t+=1}else return null;return e}function Re(n,r){let e=[];if(r.length<=n.length)for(var t=0;t<r.length;){if(r[t]==="*")e.push(n[t]);else if(n[t]!==r[t])return null;t+=1}else return null;return e}var gc=class{},As=class extends gc{constructor(e){super();this.id=e}},Ts=class extends gc{constructor(e){super();this.data=e}};var ep;try{ep=new TextDecoder}catch{}var de,on,G=0;var Gg=[],tp=Gg,rp=0,Zt={},Ue,rn,yr=0,Qr=0,lr,Oo,qt=[],We,Dg={useRecords:!1,mapsAsObjects:!0},Is=class{},np=new Is;np.name="MessagePack 0xC1";var Yi=!1,Zr=class{constructor(r){r&&(r.useRecords===!1&&r.mapsAsObjects===void 0&&(r.mapsAsObjects=!0),r.structures?r.structures.sharedLength=r.structures.length:r.getStructures&&((r.structures=[]).uninitialized=!0,r.structures.sharedLength=0)),Object.assign(this,r)}unpack(r,e){if(de)return Hg(()=>(bc(),this?this.unpack(r,e):Zr.prototype.unpack.call(Dg,r,e)));on=e>-1?e:r.length,G=0,rp=0,Qr=0,rn=null,tp=Gg,lr=null,de=r;try{We=r.dataView||(r.dataView=new DataView(r.buffer,r.byteOffset,r.byteLength))}catch(t){throw de=null,r instanceof Uint8Array?t:new Error("Source must be a Uint8Array or Buffer but was a "+(r&&typeof r=="object"?r.constructor.name:typeof r))}if(this instanceof Zr){if(Zt=this,this.structures)return Ue=this.structures,xc();(!Ue||Ue.length>0)&&(Ue=[])}else Zt=Dg,(!Ue||Ue.length>0)&&(Ue=[]);return xc()}unpackMultiple(r,e){let t,o=0;try{Yi=!0;let i=r.length,a=this?this.unpack(r,i):wc.unpack(r,i);if(e){for(e(a);G<i;)if(o=G,e(xc())===!1)return}else{for(t=[a];G<i;)o=G,t.push(xc());return t}}catch(i){throw i.lastPosition=o,i.values=t,i}finally{Yi=!1,bc()}}_mergeStructures(r,e){r=r||[];for(let t=0,o=r.length;t<o;t++){let i=r[t];i&&(i.isShared=!0,t>=32&&(i.highByte=t-32>>5))}r.sharedLength=r.length;for(let t in e||[])if(t>=0){let o=r[t],i=e[t];i&&(o&&((r.restoreStructures||(r.restoreStructures=[]))[t]=o),r[t]=i)}return this.structures=r}decode(r,e){return this.unpack(r,e)}};function xc(){try{if(!Zt.trusted&&!Yi){let r=Ue.sharedLength||0;r<Ue.length&&(Ue.length=r)}let n=pt();if(G==on)Ue.restoreStructures&&_g(),Ue=null,de=null,Oo&&(Oo=null);else if(G>on){let r=new Error("Unexpected end of MessagePack data");throw r.incomplete=!0,r}else if(!Yi)throw new Error("Data read, but end of buffer not reached");return n}catch(n){throw Ue.restoreStructures&&_g(),bc(),(n instanceof RangeError||n.message.startsWith("Unexpected end of buffer"))&&(n.incomplete=!0),n}}function _g(){for(let n in Ue.restoreStructures)Ue[n]=Ue.restoreStructures[n];Ue.restoreStructures=null}function pt(){let n=de[G++];if(n<160)if(n<128){if(n<64)return n;{let r=Ue[n&63]||Zt.getStructures&&Fg()[n&63];return r?(r.read||(r.read=ip(r,n&63)),r.read()):n}}else if(n<144)if(n-=128,Zt.mapsAsObjects){let r={};for(let e=0;e<n;e++)r[kg()]=pt();return r}else{let r=new Map;for(let e=0;e<n;e++)r.set(pt(),pt());return r}else{n-=144;let r=new Array(n);for(let e=0;e<n;e++)r[e]=pt();return r}else if(n<192){let r=n-160;if(Qr>=G)return rn.slice(G-yr,(G+=r)-yr);if(Qr==0&&on<140){let e=r<16?ap(r):jg(r);if(e!=null)return e}return op(r)}else{let r;switch(n){case 192:return null;case 193:return lr?(r=pt(),r>0?lr[1].slice(lr.position1,lr.position1+=r):lr[0].slice(lr.position0,lr.position0-=r)):np;case 194:return!1;case 195:return!0;case 196:return Jd(de[G++]);case 197:return r=We.getUint16(G),G+=2,Jd(r);case 198:return r=We.getUint32(G),G+=4,Jd(r);case 199:return Hn(de[G++]);case 200:return r=We.getUint16(G),G+=2,Hn(r);case 201:return r=We.getUint32(G),G+=4,Hn(r);case 202:if(r=We.getFloat32(G),Zt.useFloat32>2){let e=Sc[(de[G]&127)<<1|de[G+1]>>7];return G+=4,(e*r+(r>0?.5:-.5)>>0)/e}return G+=4,r;case 203:return r=We.getFloat64(G),G+=8,r;case 204:return de[G++];case 205:return r=We.getUint16(G),G+=2,r;case 206:return r=We.getUint32(G),G+=4,r;case 207:return Zt.int64AsNumber?(r=We.getUint32(G)*4294967296,r+=We.getUint32(G+4)):r=We.getBigUint64(G),G+=8,r;case 208:return We.getInt8(G++);case 209:return r=We.getInt16(G),G+=2,r;case 210:return r=We.getInt32(G),G+=4,r;case 211:return Zt.int64AsNumber?(r=We.getInt32(G)*4294967296,r+=We.getUint32(G+4)):r=We.getBigInt64(G),G+=8,r;case 212:if(r=de[G++],r==114)return zg(de[G++]&63);{let e=qt[r];if(e)return e.read?(G++,e.read(pt())):e.noBuffer?(G++,e()):e(de.subarray(G,++G));throw new Error("Unknown extension "+r)}case 213:return r=de[G],r==114?(G++,zg(de[G++]&63,de[G++])):Hn(2);case 214:return Hn(4);case 215:return Hn(8);case 216:return Hn(16);case 217:return r=de[G++],Qr>=G?rn.slice(G-yr,(G+=r)-yr):sT(r);case 218:return r=We.getUint16(G),G+=2,Qr>=G?rn.slice(G-yr,(G+=r)-yr):lT(r);case 219:return r=We.getUint32(G),G+=4,Qr>=G?rn.slice(G-yr,(G+=r)-yr):cT(r);case 220:return r=We.getUint16(G),G+=2,Rg(r);case 221:return r=We.getUint32(G),G+=4,Rg(r);case 222:return r=We.getUint16(G),G+=2,Lg(r);case 223:return r=We.getUint32(G),G+=4,Lg(r);default:if(n>=224)return n-256;if(n===void 0){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+n)}}}var aT=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function ip(n,r){function e(){if(e.count++>2){let o=n.read=new Function("r","return function(){return {"+n.map(i=>aT.test(i)?i+":r()":"["+JSON.stringify(i)+"]:r()").join(",")+"}}")(pt);return n.highByte===0&&(n.read=Bg(r,n.read)),o()}let t={};for(let o=0,i=n.length;o<i;o++){let a=n[o];t[a]=pt()}return t}return e.count=0,n.highByte===0?Bg(r,e):e}var Bg=(n,r)=>function(){let e=de[G++];if(e===0)return r();let t=n<32?-(n+(e<<5)):n+(e<<5),o=Ue[t]||Fg()[t];if(!o)throw new Error("Record id is not defined for "+t);return o.read||(o.read=ip(o,n)),o.read()};function Fg(){let n=Hg(()=>(de=null,Zt.getStructures()));return Ue=Zt._mergeStructures(n,Ue)}var op=vc,sT=vc,lT=vc,cT=vc;function vc(n){let r;if(n<16&&(r=ap(n)))return r;if(n>64&&ep)return ep.decode(de.subarray(G,G+=n));let e=G+n,t=[];for(r="";G<e;){let o=de[G++];if((o&128)===0)t.push(o);else if((o&224)===192){let i=de[G++]&63;t.push((o&31)<<6|i)}else if((o&240)===224){let i=de[G++]&63,a=de[G++]&63;t.push((o&31)<<12|i<<6|a)}else if((o&248)===240){let i=de[G++]&63,a=de[G++]&63,s=de[G++]&63,l=(o&7)<<18|i<<12|a<<6|s;l>65535&&(l-=65536,t.push(l>>>10&1023|55296),l=56320|l&1023),t.push(l)}else t.push(o);t.length>=4096&&(r+=Mt.apply(String,t),t.length=0)}return t.length>0&&(r+=Mt.apply(String,t)),r}function Rg(n){let r=new Array(n);for(let e=0;e<n;e++)r[e]=pt();return r}function Lg(n){if(Zt.mapsAsObjects){let r={};for(let e=0;e<n;e++)r[kg()]=pt();return r}else{let r=new Map;for(let e=0;e<n;e++)r.set(pt(),pt());return r}}var Mt=String.fromCharCode;function jg(n){let r=G,e=new Array(n);for(let t=0;t<n;t++){let o=de[G++];if((o&128)>0){G=r;return}e[t]=o}return Mt.apply(String,e)}function ap(n){if(n<4)if(n<2){if(n===0)return"";{let r=de[G++];if((r&128)>1){G-=1;return}return Mt(r)}}else{let r=de[G++],e=de[G++];if((r&128)>0||(e&128)>0){G-=2;return}if(n<3)return Mt(r,e);let t=de[G++];if((t&128)>0){G-=3;return}return Mt(r,e,t)}else{let r=de[G++],e=de[G++],t=de[G++],o=de[G++];if((r&128)>0||(e&128)>0||(t&128)>0||(o&128)>0){G-=4;return}if(n<6){if(n===4)return Mt(r,e,t,o);{let i=de[G++];if((i&128)>0){G-=5;return}return Mt(r,e,t,o,i)}}else if(n<8){let i=de[G++],a=de[G++];if((i&128)>0||(a&128)>0){G-=6;return}if(n<7)return Mt(r,e,t,o,i,a);let s=de[G++];if((s&128)>0){G-=7;return}return Mt(r,e,t,o,i,a,s)}else{let i=de[G++],a=de[G++],s=de[G++],l=de[G++];if((i&128)>0||(a&128)>0||(s&128)>0||(l&128)>0){G-=8;return}if(n<10){if(n===8)return Mt(r,e,t,o,i,a,s,l);{let c=de[G++];if((c&128)>0){G-=9;return}return Mt(r,e,t,o,i,a,s,l,c)}}else if(n<12){let c=de[G++],u=de[G++];if((c&128)>0||(u&128)>0){G-=10;return}if(n<11)return Mt(r,e,t,o,i,a,s,l,c,u);let p=de[G++];if((p&128)>0){G-=11;return}return Mt(r,e,t,o,i,a,s,l,c,u,p)}else{let c=de[G++],u=de[G++],p=de[G++],d=de[G++];if((c&128)>0||(u&128)>0||(p&128)>0||(d&128)>0){G-=12;return}if(n<14){if(n===12)return Mt(r,e,t,o,i,a,s,l,c,u,p,d);{let f=de[G++];if((f&128)>0){G-=13;return}return Mt(r,e,t,o,i,a,s,l,c,u,p,d,f)}}else{let f=de[G++],h=de[G++];if((f&128)>0||(h&128)>0){G-=14;return}if(n<15)return Mt(r,e,t,o,i,a,s,l,c,u,p,d,f,h);let m=de[G++];if((m&128)>0){G-=15;return}return Mt(r,e,t,o,i,a,s,l,c,u,p,d,f,h,m)}}}}}function Jd(n){return Zt.copyBuffers?Uint8Array.prototype.slice.call(de,G,G+=n):de.subarray(G,G+=n)}function Hn(n){let r=de[G++];if(qt[r])return qt[r](de.subarray(G,G+=n));throw new Error("Unknown extension type "+r)}var Vg=new Array(4096);function kg(){let n=de[G++];if(n>=160&&n<192){if(n=n-160,Qr>=G)return rn.slice(G-yr,(G+=n)-yr);if(!(Qr==0&&on<180))return op(n)}else return G--,pt();let r=(n<<5^(n>1?We.getUint16(G):n>0?de[G]:0))&4095,e=Vg[r],t=G,o=G+n-3,i,a=0;if(e&&e.bytes==n){for(;t<o;){if(i=We.getUint32(t),i!=e[a++]){t=1879048192;break}t+=4}for(o+=3;t<o;)if(i=de[t++],i!=e[a++]){t=1879048192;break}if(t===o)return G=t,e.string;o-=3,t=G}for(e=[],Vg[r]=e,e.bytes=n;t<o;)i=We.getUint32(t),e.push(i),t+=4;for(o+=3;t<o;)i=de[t++],e.push(i);let s=n<16?ap(n):jg(n);return s!=null?e.string=s:e.string=op(n)}var zg=(n,r)=>{var e=pt();let t=n;r!==void 0&&(n=n<32?-((r<<5)+n):(r<<5)+n,e.highByte=r);let o=Ue[n];return o&&o.isShared&&((Ue.restoreStructures||(Ue.restoreStructures=[]))[n]=o),Ue[n]=e,e.read=ip(e,t),e.read()},Ug=typeof self=="object"?self:global;qt[0]=()=>{};qt[0].noBuffer=!0;qt[101]=()=>{let n=pt();return(Ug[n[0]]||Error)(n[1])};qt[105]=n=>{let r=We.getUint32(G-4);Oo||(Oo=new Map);let e=de[G],t;e>=144&&e<160||e==220||e==221?t=[]:t={};let o={target:t};Oo.set(r,o);let i=pt();return o.used?Object.assign(t,i):(o.target=i,i)};qt[112]=n=>{let r=We.getUint32(G-4),e=Oo.get(r);return e.used=!0,e.target};qt[115]=()=>new Set(pt());var sp=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(n=>n+"Array");qt[116]=n=>{let r=n[0],e=sp[r];if(!e)throw new Error("Could not find typed array for code "+r);return new Ug[e](Uint8Array.prototype.slice.call(n,1).buffer)};qt[120]=()=>{let n=pt();return new RegExp(n[0],n[1])};qt[98]=n=>{let r=(n[0]<<24)+(n[1]<<16)+(n[2]<<8)+n[3],e=G;G+=r-4,lr=[pt(),pt()],lr.position0=0,lr.position1=0;let t=G;G=e;try{return pt()}finally{G=t}};qt[255]=n=>n.length==4?new Date((n[0]*16777216+(n[1]<<16)+(n[2]<<8)+n[3])*1e3):n.length==8?new Date(((n[0]<<22)+(n[1]<<14)+(n[2]<<6)+(n[3]>>2))/1e6+((n[3]&3)*4294967296+n[4]*16777216+(n[5]<<16)+(n[6]<<8)+n[7])*1e3):n.length==12?new Date(((n[0]<<24)+(n[1]<<16)+(n[2]<<8)+n[3])/1e6+((n[4]&128?-281474976710656:0)+n[6]*1099511627776+n[7]*4294967296+n[8]*16777216+(n[9]<<16)+(n[10]<<8)+n[11])*1e3):new Date("invalid");function Hg(n){let r=on,e=G,t=rp,o=yr,i=Qr,a=rn,s=tp,l=Oo,c=lr,u=new Uint8Array(de.slice(0,on)),p=Ue,d=Ue.slice(0,Ue.length),f=Zt,h=Yi,m=n();return on=r,G=e,rp=t,yr=o,Qr=i,rn=a,tp=s,Oo=l,lr=c,de=u,Yi=h,Ue=p,Ue.splice(0,Ue.length,...d),Zt=f,We=new DataView(de.buffer,de.byteOffset,de.byteLength),m}function bc(){de=null,Oo=null,Ue=null}function Wg(n){n.unpack?qt[n.type]=n.unpack:qt[n.type]=n}var Sc=new Array(147);for(let n=0;n<256;n++)Sc[n]=+("1e"+Math.floor(45.15-n*.30103));var wc=new Zr({useRecords:!1}),uT=wc.unpack,dT=wc.unpackMultiple,pT=wc.unpack,Pc={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},fT=new Float32Array(1),l4=new Uint8Array(fT.buffer,0,4);var Cc;try{Cc=new TextEncoder}catch{}var Oc,cp,Ac=typeof Buffer<"u",lp=Ac?Buffer.allocUnsafeSlow:Uint8Array,Xg=Ac?Buffer:Uint8Array,qg=Ac?4294967296:2144337920,Y,ht,U=0,Jr,eo=null,hT=/[\u0080-\uFFFF]/,Ms=Symbol("record-id"),Wn=class extends Zr{constructor(r){super(r),this.offset=0;let e,t,o,i,a,s,l=0,c=Xg.prototype.utf8Write?function(g,D,E){return Y.utf8Write(g,D,E)}:Cc&&Cc.encodeInto?function(g,D){return Cc.encodeInto(g,Y.subarray(D)).written}:!1,u=this;r||(r={});let p=r&&r.sequential,d=r.structures||r.saveStructures,f=r.maxSharedStructures;if(f==null&&(f=d?32:0),f>8160)throw new Error("Maximum maxSharedStructure is 8160");let h=r.maxOwnStructures;h==null&&(h=d?32:64),p&&!r.saveStructures&&(this.structures=[]);let m=f>32||h+f>64,y=f+64,b=f+h+64;if(b>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let S=[],P=0,C=0;this.pack=this.encode=function(g,D){if(Y||(Y=new lp(8192),ht=new DataView(Y.buffer,0,8192),U=0),Jr=Y.length-10,Jr-U<2048?(Y=new lp(Y.length),ht=new DataView(Y.buffer,0,Y.length),Jr=Y.length-10,U=0):U=U+7&2147483640,t=U,s=u.structuredClone?new Map:null,u.bundleStrings?(eo=["",""],Y[U++]=214,Y[U++]=98,eo.position=U-t,U+=4):eo=null,o=u.structures,o){o.uninitialized&&(o=u._mergeStructures(u.getStructures()));let E=o.sharedLength||0;if(E>f)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+o.sharedLength);if(!o.transitions){o.transitions=Object.create(null);for(let M=0;M<E;M++){let N=o[M];if(!N)continue;let _,B=o.transitions;for(let V=0,k=N.length;V<k;V++){let L=N[V];_=B[L],_||(_=B[L]=Object.create(null)),B=_}B[Ms]=M+64}l=E}p||(o.nextId=E+64)}i&&(i=!1),a=o||[];try{if(v(g),eo){ht.setUint32(eo.position+t,U-eo.position-t);let E=eo;eo=null,v(E[0]),v(E[1])}if(u.offset=U,s&&s.idsToInsert){U+=s.idsToInsert.length*6,U>Jr&&T(U),u.offset=U;let E=yT(Y.subarray(t,U),s.idsToInsert);return s=null,E}return D&Qg?(Y.start=t,Y.end=U,Y):Y.subarray(t,U)}finally{if(o){if(C<10&&C++,P>1e4)o.transitions=null,C=0,P=0,S.length>0&&(S=[]);else if(S.length>0&&!p){for(let E=0,M=S.length;E<M;E++)S[E][Ms]=0;S=[]}if(i&&u.saveStructures){let E=o.sharedLength||f;o.length>E&&(o=o.slice(0,E));let M=Y.subarray(t,U);return u.saveStructures(o,l)===!1?(u._mergeStructures(u.getStructures()),u.pack(g)):(l=E,M)}}D&PT&&(U=t)}};let v=g=>{U>Jr&&(Y=T(U));var D=typeof g,E;if(D==="string"){let M=g.length;if(eo&&M>=8&&M<4096){let B=hT.test(g);eo[B?0:1]+=g,Y[U++]=193,v(B?-M:M);return}let N;M<32?N=1:M<256?N=2:M<65536?N=3:N=5;let _=M*3;if(U+_>Jr&&(Y=T(U+_)),M<64||!c){let B,V,k,L=U+N;for(B=0;B<M;B++)V=g.charCodeAt(B),V<128?Y[L++]=V:V<2048?(Y[L++]=V>>6|192,Y[L++]=V&63|128):(V&64512)===55296&&((k=g.charCodeAt(B+1))&64512)===56320?(V=65536+((V&1023)<<10)+(k&1023),B++,Y[L++]=V>>18|240,Y[L++]=V>>12&63|128,Y[L++]=V>>6&63|128,Y[L++]=V&63|128):(Y[L++]=V>>12|224,Y[L++]=V>>6&63|128,Y[L++]=V&63|128);E=L-U-N}else E=c(g,U+N,_);E<32?Y[U++]=160|E:E<256?(N<2&&Y.copyWithin(U+2,U+1,U+1+E),Y[U++]=217,Y[U++]=E):E<65536?(N<3&&Y.copyWithin(U+3,U+2,U+2+E),Y[U++]=218,Y[U++]=E>>8,Y[U++]=E&255):(N<5&&Y.copyWithin(U+5,U+3,U+3+E),Y[U++]=219,ht.setUint32(U,E),U+=4),U+=E}else if(D==="number")if(g>>>0===g)g<64?Y[U++]=g:g<256?(Y[U++]=204,Y[U++]=g):g<65536?(Y[U++]=205,Y[U++]=g>>8,Y[U++]=g&255):(Y[U++]=206,ht.setUint32(U,g),U+=4);else if(g>>0===g)g>=-32?Y[U++]=256+g:g>=-128?(Y[U++]=208,Y[U++]=g+256):g>=-32768?(Y[U++]=209,ht.setInt16(U,g),U+=2):(Y[U++]=210,ht.setInt32(U,g),U+=4);else{let M;if((M=this.useFloat32)>0&&g<4294967296&&g>=-2147483648){Y[U++]=202,ht.setFloat32(U,g);let N;if(M<4||(N=g*Sc[(Y[U]&127)<<1|Y[U+1]>>7])>>0===N){U+=4;return}else U--}Y[U++]=203,ht.setFloat64(U,g),U+=8}else if(D==="object")if(!g)Y[U++]=192;else{if(s){let N=s.get(g);if(N){if(!N.id){let _=s.idsToInsert||(s.idsToInsert=[]);N.id=_.push(N)}Y[U++]=214,Y[U++]=112,ht.setUint32(U,N.id),U+=4;return}else s.set(g,{offset:U-t})}let M=g.constructor;if(M===Object)A(g,!0);else if(M===Array){E=g.length,E<16?Y[U++]=144|E:E<65536?(Y[U++]=220,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=221,ht.setUint32(U,E),U+=4);for(let N=0;N<E;N++)v(g[N])}else if(M===Map){E=g.size,E<16?Y[U++]=128|E:E<65536?(Y[U++]=222,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=223,ht.setUint32(U,E),U+=4);for(let[N,_]of g)v(N),v(_)}else{for(let N=0,_=Oc.length;N<_;N++){let B=cp[N];if(g instanceof B){let V=Oc[N];if(V.write){V.type&&(Y[U++]=212,Y[U++]=V.type,Y[U++]=0),v(V.write.call(this,g));return}let k=Y,L=ht,W=U;Y=null;let F;try{F=V.pack.call(this,g,j=>(Y=k,k=null,U+=j,U>Jr&&T(U),{target:Y,targetView:ht,position:U-j}),v)}finally{k&&(Y=k,ht=L,U=W,Jr=Y.length-10)}F&&(F.length+U>Jr&&T(F.length+U),U=mT(F,Y,U,V.type));return}}A(g,!g.hasOwnProperty)}}else if(D==="boolean")Y[U++]=g?195:194;else if(D==="bigint"){if(g<BigInt(1)<<BigInt(63)&&g>=-(BigInt(1)<<BigInt(63)))Y[U++]=211,ht.setBigInt64(U,g);else if(g<BigInt(1)<<BigInt(64)&&g>0)Y[U++]=207,ht.setBigUint64(U,g);else if(this.largeBigIntToFloat)Y[U++]=203,ht.setFloat64(U,Number(g));else throw new RangeError(g+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");U+=8}else if(D==="undefined")this.encodeUndefinedAsNil?Y[U++]=192:(Y[U++]=212,Y[U++]=0,Y[U++]=0);else if(D==="function")v(this.writeFunction&&this.writeFunction());else throw new Error("Unknown type: "+D)},A=this.useRecords===!1?this.variableMapSize?g=>{let D=Object.keys(g),E=D.length;E<16?Y[U++]=128|E:E<65536?(Y[U++]=222,Y[U++]=E>>8,Y[U++]=E&255):(Y[U++]=223,ht.setUint32(U,E),U+=4);let M;for(let N=0;N<E;N++)v(M=D[N]),v(g[M])}:(g,D)=>{Y[U++]=222;let E=U-t;U+=2;let M=0;for(let N in g)(D||g.hasOwnProperty(N))&&(v(N),v(g[N]),M++);Y[E+++t]=M>>8,Y[E+t]=M&255}:g=>{let D=Object.keys(g),E,M=a.transitions||(a.transitions=Object.create(null)),N=0;for(let B=0,V=D.length;B<V;B++){let k=D[B];E=M[k],E||(E=M[k]=Object.create(null),N++),M=E}let _=M[Ms];if(_)_>=96&&m?(Y[U++]=((_-=96)&31)+96,Y[U++]=_>>5):Y[U++]=_;else{_=a.nextId,_||(_=64),_<y&&this.shouldShareStructure&&!this.shouldShareStructure(D)?(_=a.nextOwnId,_<b||(_=y),a.nextOwnId=_+1):(_>=b&&(_=y),a.nextId=_+1);let B=D.highByte=_>=96&&m?_-96>>5:-1;M[Ms]=_,a[_-64]=D,_<y?(D.isShared=!0,a.sharedLength=_-63,i=!0,B>=0?(Y[U++]=(_&31)+96,Y[U++]=B):Y[U++]=_):(B>=0?(Y[U++]=213,Y[U++]=114,Y[U++]=(_&31)+96,Y[U++]=B):(Y[U++]=212,Y[U++]=114,Y[U++]=_),N&&(P+=C*N),S.length>=h&&(S.shift()[Ms]=0),S.push(M),v(D))}for(let B=0,V=D.length;B<V;B++)v(g[D[B]])},T=g=>{let D;if(g>16777216){if(g-t>qg)throw new Error("Packed buffer would be larger than maximum buffer size");D=Math.min(qg,Math.round(Math.max((g-t)*(g>67108864?1.25:2),4194304)/4096)*4096)}else D=(Math.max(g-t<<2,Y.length-1)>>12)+1<<12;let E=new lp(D);return ht=new DataView(E.buffer,0,D),Y.copy?Y.copy(E,0,t,g):E.set(Y.slice(t,g)),U-=t,t=0,Jr=E.length-10,Y=E}}useBuffer(r){Y=r,ht=new DataView(Y.buffer,Y.byteOffset,Y.byteLength),U=0}};cp=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,Is];Oc=[{pack(n,r,e){let t=n.getTime()/1e3;if((this.useTimestamp32||n.getMilliseconds()===0)&&t>=0&&t<4294967296){let{target:o,targetView:i,position:a}=r(6);o[a++]=214,o[a++]=255,i.setUint32(a,t)}else if(t>0&&t<17179869184){let{target:o,targetView:i,position:a}=r(10);o[a++]=215,o[a++]=255,i.setUint32(a,n.getMilliseconds()*4e6+(t/1e3/4294967296>>0)),i.setUint32(a+4,t)}else if(isNaN(t)){if(this.onInvalidDate)return r(0),e(this.onInvalidDate());let{target:o,targetView:i,position:a}=r(3);o[a++]=212,o[a++]=255,o[a++]=255}else{let{target:o,targetView:i,position:a}=r(15);o[a++]=199,o[a++]=12,o[a++]=255,i.setUint32(a,n.getMilliseconds()*1e6),i.setBigInt64(a+4,BigInt(Math.floor(t)))}}},{pack(n,r,e){let t=Array.from(n),{target:o,position:i}=r(this.structuredClone?3:0);this.structuredClone&&(o[i++]=212,o[i++]=115,o[i++]=0),e(t)}},{pack(n,r,e){let{target:t,position:o}=r(this.structuredClone?3:0);this.structuredClone&&(t[o++]=212,t[o++]=101,t[o++]=0),e([n.name,n.message])}},{pack(n,r,e){let{target:t,position:o}=r(this.structuredClone?3:0);this.structuredClone&&(t[o++]=212,t[o++]=120,t[o++]=0),e([n.source,n.flags])}},{pack(n,r){this.structuredClone?$g(n,16,r):Yg(Ac?Buffer.from(n):new Uint8Array(n),r)}},{pack(n,r){let e=n.constructor;e!==Xg&&this.structuredClone?$g(n,sp.indexOf(e.name),r):Yg(n,r)}},{pack(n,r){let{target:e,position:t}=r(1);e[t]=193}}];function $g(n,r,e,t){let o=n.byteLength;if(o+1<256){var{target:i,position:a}=e(4+o);i[a++]=199,i[a++]=o+1}else if(o+1<65536){var{target:i,position:a}=e(5+o);i[a++]=200,i[a++]=o+1>>8,i[a++]=o+1&255}else{var{target:i,position:a,targetView:s}=e(7+o);i[a++]=201,s.setUint32(a,o+1),a+=4}i[a++]=116,i[a++]=r,i.set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),a)}function Yg(n,r){let e=n.byteLength;var t,o;if(e<256){var{target:t,position:o}=r(e+2);t[o++]=196,t[o++]=e}else if(e<65536){var{target:t,position:o}=r(e+3);t[o++]=197,t[o++]=e>>8,t[o++]=e&255}else{var{target:t,position:o,targetView:i}=r(e+5);t[o++]=198,i.setUint32(o,e),o+=4}t.set(n,o)}function mT(n,r,e,t){let o=n.length;switch(o){case 1:r[e++]=212;break;case 2:r[e++]=213;break;case 4:r[e++]=214;break;case 8:r[e++]=215;break;case 16:r[e++]=216;break;default:o<256?(r[e++]=199,r[e++]=o):o<65536?(r[e++]=200,r[e++]=o>>8,r[e++]=o&255):(r[e++]=201,r[e++]=o>>24,r[e++]=o>>16&255,r[e++]=o>>8&255,r[e++]=o&255)}return r[e++]=t,r.set(n,e),e+=o,e}function yT(n,r){let e,t=r.length*6,o=n.length-t;for(r.sort((i,a)=>i.offset>a.offset?1:-1);e=r.pop();){let i=e.offset,a=e.id;n.copyWithin(i+t,i,o),t-=6;let s=i+t;n[s++]=214,n[s++]=105,n[s++]=a>>24,n[s++]=a>>16&255,n[s++]=a>>8&255,n[s++]=a&255,o=i}return n}function nn(n){if(n.Class){if(!n.pack&&!n.write)throw new Error("Extension has no pack or write function");if(n.pack&&!n.type)throw new Error("Extension has no type (numeric code to identify the extension)");cp.unshift(n.Class),Oc.unshift(n)}Wg(n)}var Kg=new Wn({useRecords:!1}),gT=Kg.pack,xT=Kg.pack;var{NEVER:bT,ALWAYS:vT,DECIMAL_ROUND:ST,DECIMAL_FIT:wT}=Pc,Qg=512,PT=1024;var Zg=new Wn({structuredClone:!0});nn({Class:fe.prototype.constructor,type:1,write(n){return{...n}},read(n){return Object.setPrototypeOf(n,fe.prototype),n}});nn({Class:be.prototype.constructor,type:2,write(n){return[...n]},read(n){return Object.setPrototypeOf(n,be.prototype),n}});nn({Class:Ke.prototype.constructor,type:3,write(n){return[...n]},read(n){return Object.setPrototypeOf(n,Ke.prototype),n}});nn({Class:As.prototype.constructor,type:4,write(n){return n.id},read(n){return new As(n)}});nn({Class:Ts.prototype.constructor,type:5,write(n){return n.data},read(n){return new Ts(n)}});nn({Class:Qe.prototype.constructor,type:6,write(n){return{...n}},read(n){return Object.setPrototypeOf(n,Qe.prototype),n}});function CT(n){var r=0;if(n.length===0)return r;for(let e=0;e<n.length;e++){let t=n[e];r=(r<<5)-r+t,r=r&r}return r}function up(n){if(ki(n))return n;if(Array.isArray(n))return n.map(up);if(typeof n=="object"&&n!==null){let r={};for(let e of Object.keys(n).sort())r[e]=up(n[e]);return Object.setPrototypeOf(r,Object.getPrototypeOf(n)),r}else return n}var Tc;(t=>{function n(o){return Zg.pack(o)}t.serialize=n;function r(o){return Zg.unpack(o)}t.deserialize=r;function e(o){return CT(n(up(o))).toString()}t.checksum=e})(Tc||(Tc={}));var ln="personal camera",cn="a218fcc3-276b-49b9-b485-49037fd14f5f",nx=2960946,mt=5526619;var Xi;(f=>{function n(h,m){return h[0]===m[0]&&h[1]===m[1]}f.isEqual=n;function r(h,m,y){return[h[0]+(m[0]-h[0])*y,h[1]+(m[1]-h[1])*y]}f.lerp=r;function e(h,m){return[h[0]+m[0],h[1]+m[1]]}f.add=e;function t(h,m){return[h[0]-m[0],h[1]-m[1]]}f.sub=t;function o(h,m){return[h[0]*m[0],h[1]*m[1]]}f.multiply=o;function i(h,m){return[h[0]/m[0],h[1]/m[1]]}f.divide=i;function a(h,m){return Math.pow(m[0]-h[0],2)+Math.pow(m[1]-h[1],2)}f.distanceSquared=a;function s(h,m){return Math.sqrt(a(h,m))}f.distance=s;function l(h,m){return h[0]*m[0]+h[1]*m[1]}f.dot=l;function c(h,m){return[h[0]*m,h[1]*m]}f.scalarMultiply=c;function u(h,m,y){let b=f.sub(m,h),S=f.sub(y,h),P=f.dot(b,S)/f.dot(b,b),C=f.scalarMultiply(b,P);return f.add(h,C)}f.projectionOnto=u;function p(h,m,y){return s(h,u(h,m,y))}f.projectionOntoDistance=p;function d(h,m){return[(h[0]+m[0])*.5,(h[1]+m[1])*.5]}f.center=d})(Xi||(Xi={}));var an;(s=>{function n(l,c){return l[0]===c[0]&&l[1]===c[1]&&l[2]===c[2]}s.isEqual=n;function r(l,c){return[l[0]+c[0],l[1]+c[1],l[2]+c[2]]}s.add=r;function e(l,c){return[l[0]-c[0],l[1]-c[1],l[2]-c[2]]}s.sub=e;function t(l,c){return[l[0]/c[0],l[1]/c[1],l[2]/c[2]]}s.div=t;function o(l,c){return[l[0]*c[0],l[1]*c[1],l[2]*c[2]]}s.mul=o;function i(l,c){return Math.hypot(l[0]-c[0],l[1]-c[1],l[2]-c[2])}s.dist=i;function a(l,c,u){return[l[0]+(c[0]-l[0])*u,l[1]+(c[1]-l[1])*u,l[2]+(c[2]-l[2])*u]}s.lerp=a})(an||(an={}));var Jg;(e=>{function n(t,o){return t[0]===o[0]&&t[1]===o[1]&&t[2]===o[2]&&t[3]===o[3]}e.isEqual=n;function r(t,o,i){return[t[0]+(o[0]-t[0])*i,t[1]+(o[1]-t[1])*i,t[2]+(o[2]-t[2])*i,t[3]+(o[3]-t[3])*i]}e.lerp=r})(Jg||(Jg={}));var ex;(a=>{let n=180/Math.PI,r=Math.PI/180;function e(s){return typeof s=="number"?s*n:s}function t(s){return typeof s=="number"?s*r:s}function o(s){return[e(s[0]),e(s[1]),e(s[2])]}a.radToDeg=o;function i(s){return[t(s[0]),t(s[1]),t(s[2])]}a.degToRad=i})(ex||(ex={}));var sn;(o=>{o.identity=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function r(i,a){for(let s=0;s<16;s++)if(i[s]!==a[s])return!1;return!0}o.isEqual=r;function e(i){return i??o.identity}o.simplify=e;function t(i,a){let s=a.slice(0);for(var l=0,c=a.length;l<c;l+=3){let u=i[3]*a[l]+i[7]*a[l+1]+i[11]*a[l+2]+i[15];s[l]=(i[0]*a[l]+i[4]*a[l+1]+i[8]*a[l+2]+i[12])/u,s[l+1]=(i[1]*a[l]+i[5]*a[l+1]+i[9]*a[l+2]+i[13])/u,s[l+2]=(i[2]*a[l]+i[6]*a[l+1]+i[10]*a[l+2]+i[14])/u}return s}o.applyMatrix4=t})(sn||(sn={}));var wt;(p=>{function n(d){return typeof d=="object"&&typeof d.r=="number"&&typeof d.g=="number"&&typeof d.b=="number"}p.isRGB=n,p.white={r:1,g:1,b:1},p.red={r:1,g:0,b:0},p.black={r:0,g:0,b:0};function o(d){return{r:Math.round(d.r*255),g:Math.round(d.g*255),b:Math.round(d.b*255),a:1}}p.toRgb255a1=o;function i(d){return{r:d.r,g:d.g,b:d.b}}p.clone=i;function a(d){return d=Math.floor(d),{r:(d>>16&255)/255,g:(d>>8&255)/255,b:(d&255)/255}}p.fromHex=a;function s(d){return Math.round(d.r*255)*65536+Math.round(d.g*255)*256+Math.round(d.b*255)}p.toHex=s;function l(d,f){return d.r===f.r&&d.g===f.g&&d.b===f.b}p.equals=l;function c(d,f){return d.r.toFixed(2)===f.r.toFixed(2)&&d.g.toFixed(2)===f.g.toFixed(2)&&d.b.toFixed(2)===f.b.toFixed(2)}p.equalsFixed=c;function u(d,f,h){return{r:d.r+(f.r-d.r)*h,g:d.g+(f.g-d.g)*h,b:d.b+(f.b-d.b)*h}}p.lerp=u})(wt||(wt={}));var Me;(c=>{c.white={...wt.white,a:1},c.transparent={...wt.white,a:0};function e(u){return{r:u[0],g:u[1],b:u[2],a:u[3]}}c.from0to1=e;function t(u,p){return{...wt.fromHex(u),a:p}}c.fromHexAndA=t;function o(u){return{r:Math.round(u.r*255),g:Math.round(u.g*255),b:Math.round(u.b*255),a:u.a}}c.toRgb255a1=o;function i(u,p){return wt.equals(u,p)&&u.a===p.a}c.equals=i;function a(u,p){return wt.equalsFixed(u,p)&&u.a.toFixed(2)===p.a.toFixed(2)}c.equalsFixed=a;function s(u,p,d){return{r:u.r+(p.r-u.r)*d,g:u.g+(p.g-u.g)*d,b:u.b+(p.b-u.b)*d,a:u.a+(p.a-u.a)*d}}c.lerp=s;function l({r:u,g:p,b:d,a:f}=c.white){return`rgba(${u*255}, ${p*255}, ${d*255}, ${f})`}c.toStyle=l})(Me||(Me={}));var Ic;(r=>r.identity={position:[0,0,0],rotation:[0,0,0],scale:[1,1,1]})(Ic||(Ic={}));var tx;(r=>r.defaultData={mass:1,stiffness:80,damping:10,velocity:0})(tx||(tx={}));var rx;(r=>r.defaultData={control1:[.5,0],control2:[.5,1]})(rx||(rx={}));var ox;(i=>(i.linear=[0,0,1,1],i.ease=[.25,.1,.25,1],i.easeIn=[.42,0,1,1],i.easeOut=[0,0,.58,1],i.easeInOut=[.42,0,.58,1]))(ox||(ox={}));function dp(n){return typeof n=="string"&&n.length===36?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n):!1}var Nr;(e=>{e.all=["PerspectiveCamera","OrthographicCamera"];function r(t){return e.all.includes(t)}e.is=r})(Nr||(Nr={}));var un;(o=>{o.DefaultUp=[0,1,0],o.DefaultTargetOffset=1e3,o.defaultData={far:1e5,type:"OrthographicCamera",perspective:{near:70,fov:45,zoom:1},orthographic:{near:-1e5,zoom:1},up:o.DefaultUp,isUpVectorFlipped:!1,targetOffset:o.DefaultTargetOffset};function t(i){return i.type==="PerspectiveCamera"?i.perspective?.zoom??1:i.orthographic?.zoom??1}o.getZoom=t})(un||(un={}));var to;(e=>{function n(t,o=.1){return{disabled:!1,type:"linear",hideBase:!1,count:3,radial:{radius:Math.max(t[0],t[1])*2,start:0,end:360,alignment:!1,axis:"y",scale:[1,1,1],rotation:[0,0,0],position:[0,0,0]},toObject:{object:"",spreadType:"random",scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],axis:"x",seed:0,count:99,align:"normal"},linear:{scale:[1,1,1],rotation:[0,0,0],position:[t[0]+t[0]*o,0,0]},grid:{count:[2,2,2],size:t.map(i=>i*(1+o)),useCenter:!0},randomness:!1,randomnessObject:{strength:100,scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],movement:1,seed:0,freqScale:10,noiseType:"perlin"}}}e.defaultData=n;function r(t,o){let i={...t};if(OT.forEach(a=>{Object.assign(i,{[a]:o[a]??t[a]})}),i.radial={...t.radial},o.radial){let a=t.radial,s=o.radial;AT.forEach(l=>{Object.assign(i.radial,{[l]:s[l]??a[l]})})}if(i.linear={...t.linear},o.linear){let a=t.linear,s=o.linear;TT.forEach(l=>{Object.assign(i.linear,{[l]:s[l]??a[l]})})}if(i.grid={...t.grid},o.grid){let a=t.grid,s=o.grid;IT.forEach(l=>{Object.assign(i.grid,{[l]:s[l]??a[l]})})}if(i.toObject={...t.toObject},o.toObject){let a=t.toObject,s=o.toObject;MT.forEach(l=>{Object.assign(i.toObject,{[l]:s[l]??a[l]})})}if(i.randomnessObject={...t.randomnessObject},o.randomnessObject){let a=t.randomnessObject,s=o.randomnessObject;ET.forEach(l=>{Object.assign(i.randomnessObject,{[l]:s[l]??a[l]})})}return i}e.merge=r})(to||(to={}));var Mc;(t=>{t.defaultData={radial:{},linear:{},grid:{},toObject:{},randomnessObject:{}};let r=["radial","linear","grid","toObject","randomnessObject"];function e(o,i){let a=[];o.count!==void 0&&a.push({type:0,path:i,props:{count:o.count}});for(let s of r){let l=o[s];l&&Object.keys(l).length>0&&a.push({type:0,path:[...i,s],props:l})}return a}t.toOps=e})(Mc||(Mc={}));var OT=["count"],AT=["radius","start","end","position","scale","rotation"],TT=["position","scale","rotation"],IT=["count","size"],MT=["count","position","scale","rotation"],ET=["strength","scale","rotation","position","movement","seed","freqScale"];var Ec;(e=>{e.all=["PointLight","SpotLight","DirectionalLight","HemisphereLight"];function r(t){return e.all.includes(t)}e.is=r})(Ec||(Ec={}));var Nc;(e=>{function n(t){return r(t)}e.defaultData=n;function r(t){if(t==="PointLight")return{type:t,color:Me.white,intensity:1,distance:2e3,decay:1,shadows:!0,shadowResolution:1024,shadowRadius:1,penumbraSize:.5,depth:1e5};if(t==="SpotLight")return{type:t,color:Me.white,intensity:1,distance:2e3,decay:1,shadows:!0,penumbra:0,angle:30/180*Math.PI,depth:1e5,penumbraSize:.5,shadowResolution:1024,shadowRadius:1};if(t==="DirectionalLight")return{type:t,color:Me.white,intensity:1,shadows:!0,size:2e3,depth:1e5,penumbraSize:.5,shadowResolution:1024,shadowRadius:1};throw new Error("not implemented")}})(Nc||(Nc={}));var Ki;(t=>(t.defaultShapeData={type:"PlaneEmitterShape",size:[100,100,100]},t.defaultCollisionData={colliderEntityId:null,collisionBounce:.75},t.defaultData={renderMaterial:{type:"particleMaterial",color:{r:1,g:.2,b:.545,a:1},color2:{r:.945,g:.714,b:.184,a:1},coloring:"gradient",ease:"linearFadeOut",easeSize:"linearFadeOut",transparent:!0,size:[40,40],texture:"pt_default_particle",spriteRotation:[0,0]},birthRatePerSec:50,gravity:1,noiseStrength:0,noiseScale:0,noiseSeed:1,noiseType:"curl",randomRotation:0,randomScale:.2,randomMass:.5,rootObjectType:"instancedMesh",life:1,direction:[0,0,0],directionMode:"axis",speed:10,shape:t.defaultShapeData,autoPlay:!0,emitTimeDelay:0,emitTimeCycle:"infinity",emitTimeDuration:1,...t.defaultCollisionData}))(Ki||(Ki={}));var dn;(r=>r.defaultData={enabled:"visibility",fusedBody:!0,rigidBody:"positioned",density:1,pointMass:0,gravityScale:1,friction:.5,damping:0,restitution:.2,colliderType:"convex",enabledRotation:[!0,!0,!0],enabledTranslation:[!0,!0,!0]})(dn||(dn={}));var pp;(e=>{e.defaultData={castShadow:!0,receiveShadow:!0};function r(t,o){return t.castShadow===o.castShadow&&t.receiveShadow===o.receiveShadow}e.equals=r})(pp||(pp={}));var fp;(e=>{e.defaultData={flatShading:!1,wireframe:!1,side:0};function r(t,o){return t.flatShading===o.flatShading&&t.side===o.side&&t.wireframe===o.wireframe}e.equals=r})(fp||(fp={}));var Dc;(r=>r.defaultData={...fp.defaultData,...pp.defaultData})(Dc||(Dc={}));var ix;(r=>{function n(e,t){let o=[];if("material"in e){let i=typeof e.material=="string"?t.materials[e.material]??t.lib.materials[e.material]?.asset:e.material;i&&o.push(i)}else if("materials"in e)for(let i of e.materials){let a=typeof i=="string"?t.materials[i]??t.lib.materials[i]?.asset:i;a&&o.push(a)}return o}r.getMaterialData=n})(ix||(ix={}));var Qi;(e=>(e.defaultVideo={data:"",thumb:"/_assets/_videos/catThumb.png",type:"video",name:"Cat video"},e.maxSize=3e7))(Qi||(Qi={}));var ax;(r=>{function n(e){return e==="texture"||e==="video"||e==="color"||e==="depth"||e==="normal"||e==="gradient"||e==="noise"||e==="fresnel"||e==="rainbow"||e==="toon"||e==="outline"||e==="particle"||e==="transmission"||e==="matcap"||e==="displace"||e==="pattern"||e==="light"}r.is=n})(ax||(ax={}));function lx(n){return n.type!=="displace"}var sx;(r=>{function n(e){return e==="phong"||e==="toon"||e==="lambert"||e==="physical"}r.is=n})(sx||(sx={}));var cx=["mode","gradientType","noiseType","displacementType","projection","cnormal","crop","axis","side"],ux=["wrapping","image","video","name","minFilter","magFilter"],xt;(o=>{function n(i,a){let{texture:s,...l}=a;if(Object.assign(i,l),s){let c=i.texture;c&&Object.assign(c,s)}}o.patch=n;function r(i,a){return i==="light"&&a?e(a):t(i)}o.defaultData=r;function e(i){let a={mode:0,isMask:!1,visible:!0,bumpMap:void 0,bumpMapIntensity:5,roughnessMap:void 0,alphaOverride:1};switch(i){case"phong":return{...a,category:"phong",specular:{r:.2,g:.2,b:.2},shininess:5,type:"light",visible:!0,mode:0,occlusion:!0,alpha:.6};case"toon":return{...a,category:"toon",specular:{r:.2,g:.2,b:.2},shininess:10,type:"light",alpha:1};case"lambert":return{...a,category:"lambert",emissive:{r:0,g:0,b:0},type:"light",alpha:1,visible:!0,mode:0,occlusion:!0};case"physical":return{...a,category:"physical",roughness:.2,metalness:.2,reflectivity:.2,type:"light",alpha:1,visible:!0,mode:0,occlusion:!0}}}function t(i){let a={alpha:1,mode:0,isMask:!1,visible:!0};switch(i){case"texture":return{...a,type:"texture",size:[128,128],blending:0,axis:"x",side:2,projection:0,texture:{image:"image_0",wrapping:1e3,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006},crop:!1};case"video":return{...a,type:"video",size:[128,128],blending:0,axis:"x",side:2,projection:0,texture:{video:Qi.defaultVideo,wrapping:1001,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006},crop:!1};case"color":return{...a,type:"color",color:wt.fromHex(mt)};case"depth":return{...a,type:"depth",gradientType:1,smooth:!1,isVector:!0,isWorldSpace:!1,origin:[0,0,0],direction:[1,0,0],colors:[[1,1,1,1],[0,0,0,1]],steps:[0,1],near:50,far:200};case"normal":return{...a,type:"normal",cnormal:[1,1,1]};case"gradient":return{...a,type:"gradient",gradientType:0,smooth:!1,colors:[[0,0,0,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],steps:[0,1,1,1,1,1,1,1,1,1],num:2,angle:0,offset:[0,0],morph:[0,0]};case"noise":return{...a,type:"noise",size:[100,100,100],noiseType:0,scale:1,move:1,colorA:{...wt.fromHex(6710886),a:1},colorB:{...wt.fromHex(6710886),a:1},colorC:{...wt.fromHex(16777215),a:1},colorD:{...wt.fromHex(16777215),a:1},distortion:[1,1],fA:[1.7,9.2],fB:[8.3,2.8],voronoiStyle:0,highCut:1,lowCut:0,smoothness:.3,seed:0,quality:1};case"fresnel":return{...a,type:"fresnel",color:Me.fromHexAndA(16777215,1),bias:.1,scale:1,intensity:2,factor:1};case"rainbow":return{...a,type:"rainbow",filmThickness:30,movement:0,wavelengths:[0,0,0],noiseStrength:0,noiseScale:1,offset:[0,0,0]};case"toon":return{...a,type:"toon",positioning:2,colors:[[0,0,0,1],[.5,.5,.5,1],[.5,.5,.5,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],steps:[0,.475,.525,1,1,1,1,1,1,1],num:4,source:[0,1e3,0],isWorldSpace:!0,noiseStrength:0,noiseScale:1,shadowColor:Me.fromHexAndA(0,0),offset:[0,0,0]};case"outline":return{...a,type:"outline",outlineColor:Me.fromHexAndA(0,1),contourColor:Me.fromHexAndA(0,1),outlineWidth:2,contourWidth:5,outlineThreshold:.4,contourThreshold:0,outlineSmoothing:0,contourFrequency:10,contourDirection:[0,1,0],positionalLines:!1,compensation:!0};case"matcap":return{...a,type:"matcap",texture:{image:"matcap_0",wrapping:1001,repeat:[1,1],offset:[0,0],rotation:0,minFilter:1008,magFilter:1006}};case"transmission":return{...a,type:"transmission",thickness:10,ior:1.5,roughness:1};case"displace":return{visible:!0,type:"displace",displacementType:"noise",noiseType:0,scale:10,movement:1,offset:[0,0,0],intensity:8,voronoiStyle:0,smoothness:.3,seed:0,highCut:1,lowCut:0,quality:1};case"pattern":return{...a,type:"pattern",style:0,projection:0,axis:"y",blending:0,offset:[0,0],colorA:{...wt.fromHex(0),a:1},colorB:{...wt.fromHex(16777215),a:1},frequency:[10,10],size:.5,variation:0,smoothness:.5,zigzag:0,rotation:0,vertical:[0,1],horizontal:[0,1],sides:6}}}})(xt||(xt={}));var Et;(c=>{function n(u){return!u.layers.some(d=>d.data.type==="texture"&&d.data.projection!==0||d.data.type==="depth"&&!d.data.isWorldSpace||d.data.type==="noise"||d.data.type==="displace")}c.isMergable=n;function r(u){let p="";return u.layers.forEach(d=>{Object.entries(d.data).forEach(([f,h])=>{p+=`${f}${h}`,Array.isArray(h)?h.forEach(m=>p+=`${m}`):typeof h=="object"?Object.values(h).forEach(m=>{typeof m=="number"?p+=`${m.toFixed(4)}`:p+=`${m}`}):p+=`${h}`})}),p}c.getHash=r;function e(){return{layers:new be}}c.defaultEmptyData=e;function t(u="layer1",p="layer2"){return i("phong",u,p)}c.defaultData=t;function o(u,p){return{...u,name:p}}c.withName=o;function i(u,p="layer1",d="layer2"){let f=new be;return f.push({fi:0,data:xt.defaultData("light",u),id:p}),f.push({fi:1,data:xt.defaultData("color"),id:d}),{layers:f}}c.defaultTwoLayerData=i;function a(u){let p=xt.defaultData("texture");u&&Object.assign(p.texture,{image:u});let d=new be;return d.push({fi:0,data:p,id:"layer1"}),d.push({fi:1,data:{...xt.defaultData("transmission"),alpha:1},id:"layer2"}),d.push({fi:2,data:{...xt.defaultData("light","lambert"),alpha:0},id:"layer3"}),{layers:d}}c.defaultUIObjectMaterial=a;function s(u,p="phong",d="layer1",f="layer2"){let h=xt.defaultData("texture");Object.assign(h.texture,{image:u});let m=new be;return m.push({fi:0,data:h,id:d}),m.push({fi:1,data:xt.defaultData("light",p),id:f}),{layers:m}}c.defaultTwoLayerTextureData=s;function l(u,p="phong",d="layer1",f="layer2"){let h=xt.defaultData("video");Object.assign(h.texture,{video:u});let m=new be;return m.push({fi:0,data:h,id:d}),m.push({fi:1,data:xt.defaultData("light",p),id:f}),{layers:m}}c.defaultTwoLayerVideoTextureData=l})(Et||(Et={}));var Zi;(r=>{function n(){return{points:new be,roundness:0,shapeHoles:[],isClosed:!1}}r.defaultData=n})(Zi||(Zi={}));var Ji;(r=>{function n(){return{points:new be,lastInsertionPlane:null,subdivisions:12,isClosed:!1}}r.defaultData=n})(Ji||(Ji={}));var hp={type:"Ellipse",width:50,height:50,spikes:16,angle:360,innerRadius:0};var _c;(r=>{function n(e,t){let o={...e};return NT.forEach(i=>{Object.assign(o,{[i]:t[i]??e[i]})}),o}r.merge=n})(_c||(_c={}));var Bc={shape:hp,depth:1,offset:0,bevel:50,bevelSides:6,angle:0,twist:0,startScale:1,endScale:1,capType:"flat"},NT=["depth","offset","angle","twist","startScale","endScale"];var Es;(e=>{function n(t){return t==="PolygonGeometry"||t==="RectangleGeometry"||t==="StarGeometry"||t==="TriangleGeometry"||t==="EllipseGeometry"||t==="UIGeometry"}e.is2DParametricMesh=n;function r(t){return t==="PolygonGeometry"||t==="PolygonGeometry"||t==="RectangleGeometry"||t==="StarGeometry"||t==="TriangleGeometry"||t==="EllipseGeometry"||t==="PathGeometry"||t==="VectorGeometry"||t==="ConeGeometry"||t==="CubeGeometry"||t==="CylinderGeometry"||t==="DodecahedronGeometry"||t==="HelixGeometry"||t==="IcosahedronGeometry"||t==="LatheGeometry"||t==="PyramidGeometry"||t==="SphereGeometry"||t==="PlaneGeometry"||t==="BackdropGeometry"||t==="TorusGeometry"||t==="TorusKnotGeometry"||t==="BooleanGeometry"||t==="TextGeometry"||t==="InputGeometry"}e.isParametricMesh=r})(Es||(Es={}));var Rc;(r=>{function n(e,t){let o={...e};return Object.assign(o,t),o.type==="PathGeometry"&&"extrusion"in t&&t.extrusion&&(o.extrusion={...e.extrusion},Object.assign(o.extrusion,_c.merge(o.extrusion,t.extrusion))),o}r.merge=n})(Rc||(Rc={}));var Ao;(r=>{function n(e){if(e==="RectangleGeometry")return{width:320,height:320,type:e,cornerRadius:[0,0,0,0],cornerType:0,depth:0,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="UIGeometry")return{type:e,frame:"",cornerRadius:[0,0,0,0],cornerType:0,width:1,height:1};if(e==="PathGeometry")return{type:e,width:1,height:1,depth:1,path:Ji.defaultData(),extrusion:Bc};if(e==="VectorGeometry")return{width:1,height:1,type:e,subdivisions:12,shape:Zi.defaultData(),depth:0,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="BooleanGeometry")return{type:e,operation:2,width:0,height:0,depth:0,phongAngle:35};if(e==="TextGeometry")return{type:e,width:100,height:100,depth:0,horizontalAlign:1,verticalAlign:1,fontSize:16,lineHeight:1.2,letterSpacing:0,text:{textValue:""},textTransform:1,font:"Roboto_regular",editable:!1,extrudeBevelSize:0,extrudeBevelSegments:1};if(e==="InputGeometry")return{...r.defaultData("TextGeometry"),type:e,editable:!0};if(e==="SphereGeometry")return{type:"SphereGeometry",width:100,height:100,depth:100,widthSegments:64,heightSegments:64,phiStart:0,phiLength:2*Math.PI,thetaStart:0,thetaLength:180};throw new Error("not implemented")}r.defaultData=n})(Ao||(Ao={}));var Lc;(r=>r.defaultData={enabled:!1,useBackgroundColor:!1,color:wt.white,near:.1,far:2e3})(Lc||(Lc={}));var Vc;(e=>{let n={opacity:1,blendFunction:13,enabled:!1};e.defaultData={enabled:!1,pixelation:{...n,blendFunction:16,granularity:15},bloom:{...n,blendFunction:16,intensity:1,blurScale:1,luminanceThreshold:.25,luminanceSmoothing:.025,kernelSize:3},chromaticAberration:{...n,offset:[2,2]},vignette:{...n,darkness:1,offset:0},hueSaturation:{...n,hue:3,saturation:0},brightnessContrast:{...n,brightness:.25,contrast:0},depthOfField:{...n,focusDistance:100,focalLength:20,bokehScale:5},noise:{...n,blendFunction:16}}})(Vc||(Vc={}));var mp;(r=>r.defaultData={softShadowQuality:"low"})(mp||(mp={}));var yp;(r=>r.defaultData={enabled:!0,color:{r:.8274509803921568,g:.8274509803921568,b:.8274509803921568},intensity:.75})(yp||(yp={}));var gp;(r=>r.defaultData={occlusion:!1,aoFullRes:!1,radius:256,bias:.5,aoColor:{r:.19607843137254902,g:.19607843137254902,b:.19607843137254902}})(gp||(gp={}));var Ns;(r=>r.defaultData={usePhysics:!1,gravity:-10})(Ns||(Ns={}));var xp;(r=>r.defaultData={playCamera:ln,gameControlObject:null})(xp||(xp={}));var zc;(r=>r.defaultData={backgroundColor:Me.fromHexAndA(nx,1),postprocessing:Vc.defaultData,fog:Lc.defaultData,globalPhysics:Ns.defaultData,ambient:yp.defaultData,ao:gp.defaultData,shadow:mp.defaultData,publish:xp.defaultData})(zc||(zc={}));var Gc;(r=>r.defaultData={colliderType:"box",size:[100,100,100],colliderHelperVisible:!0,forceType:"collider",forceRange:"global",forceIntensity:.5,forceDambing:.95})(Gc||(Gc={}));var dx;(e=>{function n(t){return t==="Component"||t==="Instance"}e.isComponentRelated=n;function r(t){return t==="Empty"||t==="Instance"}e.isEmptyOrComponent=r})(dx||(dx={}));var ea;(o=>{o.identity={...Ic.identity,hiddenMatrix:sn.identity};function r(i){return{position:i.position,rotation:i.rotation,scale:i.scale,hiddenMatrix:i.hiddenMatrix}}o.fromObject=r;function e(i,a){return{position:a?.position||i.position,rotation:a?.rotation||i.rotation,scale:a?.scale||i.scale,hiddenMatrix:a?.hiddenMatrix||i.hiddenMatrix}}o.merge=e;function t(i,a){return Ll({position:an.isEqual(i.position,a.position)?void 0:a.position,rotation:an.isEqual(i.rotation,a.rotation)?void 0:a.rotation,scale:an.isEqual(i.scale,a.scale)?null:a.scale,hiddenMatrix:sn.isEqual(i.hiddenMatrix,a.hiddenMatrix)?void 0:a.hiddenMatrix})}o.diff=t})(ea||(ea={}));var bt;(r=>r.defaultData={states:new be,events:new be,visible:!0,raycastLock:!1,physics:dn.defaultData,pathSnapping:{pathId:null,slide:0,offset:0,orientation:"tangential"},...ea.identity,cloner:null})(bt||(bt={}));var Fc;(r=>r.defaultData={type:"Empty",...bt.defaultData})(Fc||(Fc={}));var px;(r=>r.defaultData={type:"ParticleCollider",...Gc.defaultData,...bt.defaultData})(px||(px={}));var fx;(r=>r.defaultData={type:"Component",...bt.defaultData})(fx||(fx={}));var hx;(r=>r.defaultData={type:"Particle",...bt.defaultData,...Ki.defaultData})(hx||(hx={}));var pn;(r=>r.defaultData={type:"Mesh",...bt.defaultData,...Dc.defaultData})(pn||(pn={}));var qn;(r=>r.defaultData={...bt.defaultData,...ea.identity,position:[0,0,un.DefaultTargetOffset],...un.defaultData})(qn||(qn={}));var jc;(e=>{function n(t){return{...bt.defaultData,...Nc.defaultData(t)}}e.defaultData=n,e.defaultDirectionalLightData={...e.defaultData("DirectionalLight"),position:[200,300,300],name:"Directional Light",intensity:.7}})(jc||(jc={}));var ta;(e=>{function n(t,o,i=0){for(;i<o.length;){let a=t?t[o[i]]:void 0;if(o.length===i+1)return a;if(a)t=a.descendants,i+=1;else return}}e.resolveWithDes=n;function r(t,o,i=0){let a=n(t,o,i);if(a){let s=Object.keys(a);if(s.length===1&&s[0]==="descendants")return}return a}e.resolve=r})(ta||(ta={}));var ro;(i=>{i.rootOverrideProps=["physics","events"],i.compositeNonOptionalOverrideProps=["geometry"],i.compositeEntireOverrideOverrideProps=["material"];function t(a,s){return{...bt.defaultData,...s,component:a,overrides:new Qe,physics:void 0,events:void 0,type:"Instance"}}i.ofComponent=t;function o(a){let s=ea.fromObject(a.data);return t(a.id,s)}i.fromComponentData=o})(ro||(ro={}));var To;(e=>{e.defaultData={type:"Page",...bt.defaultData,physics:{...dn.defaultData,fusedBody:!1},...zc.defaultData,camera:qn.defaultData};function r(t){return t.uiScene!==void 0}e.isUIPage=r})(To||(To={}));var kc;(a=>(a.defaultCamera={position:[0,0,1e3],scale:[1,1,1],rotation:[0,0,0],hiddenMatrix:sn.identity,name:"Play Camera",visible:!0,raycastLock:!1,physics:dn.defaultData,states:new be,events:new be,cloner:null,pathSnapping:{pathId:null,orientation:"tangential",slide:0,offset:0},...un.defaultData},a.KeysByResetCategory={States:["states"],Events:["events"],Material:["material","materials"],Geometry:["geometry"],Position:["position"],Rotation:["rotation"],Scale:["scale"],Transform:["position","scale","rotation","hiddenMatrix"],Name:["name"],Visibility:["visible","raycastLock","flatShading","wireframe","side"],Shadows:["castShadow","receiveShadow"],Cloner:["cloner"],Physics:["physics"]},a.defaultMeshObject={name:"Rectangle",...bt.defaultData,...pn.defaultData,geometry:Ao.defaultData("RectangleGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultBooleanObject={name:"Boolean",...bt.defaultData,...pn.defaultData,geometry:Ao.defaultData("BooleanGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultTextObject={name:"Text",...bt.defaultData,...pn.defaultData,geometry:Ao.defaultData("TextGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")},a.defaultInputObject={name:"Input",...bt.defaultData,...pn.defaultData,geometry:Ao.defaultData("InputGeometry"),material:Et.defaultTwoLayerData("phong","layer1","layer2")}))(kc||(kc={}));var $n;(o=>{function n(i,a){let s={name:a};return i.type==="Mesh"?(s.geometry={},"material"in i&&(s.material={layers:new Qe}),"materials"in i&&(s.materials=i.materials.map(l=>({layers:new Qe})))):Nr.is(i.type)&&(s.perspective={},s.orthographic={}),s}o.newEmpty=n;function r(i,a){if(a===void 0)return i;let s={...i};return"material"in s&&"material"in a&&a.material&&(s.material=tn(s.material,l=>{if(typeof l!="string")for(let[c,u]of Object.entries(a.material.layers)){let p=l.layers.data(c);p&&xt.patch(p,u)}}).data),s.materials&&a.materials&&(s.materials=tn(s.materials,l=>{for(let c=0;c<s.materials.length;c++){let u=a.materials[c];if(typeof u!="string")for(let[p,d]of Object.entries(u.layers)){let f=l[c]?.layers?.data(p);f&&xt.patch(f,d)}}}).data),s}function e(i,a){let s,l=[],c={orthographic:0,perspective:0,geometry:0};function u(p,d){for(let[f,h]of Object.entries(d.layers)){let{texture:m,...y}=h;if(m!==void 0&&Object.keys(m).length>0){let b={path:[...p,"layers",f,"texture"],props:m,type:0};l.push(b)}if(Object.keys(y).length>0){let b={path:[...p,"layers",f],props:y,type:0};l.push(b)}}}for(let[p,d]of Object.entries(a))if(p!=="name")if(p==="cloner")l.push(...Mc.toOps(d,["cloner"]));else if(p==="pathSnapping")l.push({path:[p],props:{slide:d.slide,offset:d.offset},type:0});else if(p==="material")u(["material"],d);else if(p==="materials")for(let[f,h]of Object.entries(d))u(["materials",f],h);else if(c[p]===0){if(p==="geometry"&&d.extrusion!==void 0){let f={path:[p,"extrusion"],props:d.extrusion,type:0};l.push(f),d={...d},delete d.extrusion}if(Object.keys(d).length>0){let f={path:[p],props:d,type:0};l.push(f)}}else s===void 0&&(s={path:[],props:{},type:0},l.push(s)),s.props[p]=d;return l}o.toOps=e;function t(i,a){if(a===void 0)return i;let s={...i};if(Object.assign(s,ea.merge(s,a)),Object.assign(s,{pathSnapping:Object.assign({},s.pathSnapping,{slide:a.pathSnapping?.slide??s.pathSnapping?.slide??0,offset:a.pathSnapping?.offset??s.pathSnapping?.offset??0})}),Nr.is(i.type)){s.orthographic={...s.orthographic},s.perspective={...s.perspective};let l=a;l.orthographic?.zoom!==void 0&&(s.orthographic.zoom=l.orthographic.zoom),l.perspective?.zoom!==void 0&&(s.perspective.zoom=l.perspective.zoom),l.isUpVectorFlipped!==void 0&&(s.isUpVectorFlipped=l.isUpVectorFlipped),l.targetOffset!==void 0&&(s.targetOffset=l.targetOffset)}else if(i.type==="Mesh")"geometry"in a&&Object.assign(s,{geometry:Rc.merge(s.geometry,a.geometry)}),(a.material||a.materials)&&(s=r(s,a)),s.cloner&&"cloner"in a&&Object.assign(s,{cloner:to.merge(s.cloner,a.cloner)});else if(i.type==="Empty")s.cloner&&"cloner"in a&&Object.assign(s,{cloner:to.merge(s.cloner,a.cloner)});else if(Ec.is(i.type)){let l=a;l.intensity!==void 0&&(s.intensity=l.intensity),l.color!==void 0&&(typeof l.color=="string"?s.color=l.color:s.color=wt.clone(l.color))}return s}o.patch=t})($n||($n={}));var ra;(r=>r.defaultData={enablePan:!0,enableZoom:!0,enableRotate:!0,enableDamping:!0,rotationLimitsMode:0,rotationVerticalOffset:{min:Math.PI/4,max:Math.PI/4},rotationHorizontalOffset:{min:Math.PI/4,max:Math.PI/4},rotationSoftLimit:2,panLimitsMode:0,panVerticalOffset:{min:250,max:250},panHorizontalOffset:{min:250,max:250},panSoftLimit:2,zoomLimitsEnabled:!1,zoomLimits:{min:.1,max:2},autoRotate:!1,autoRotateSpeed:2,autoRotateClockwise:!0,hoverRotatePanMode:0,hoverRotatePanStrength:20,hoverRotateDamping:.125,isTouchZoom:!0,orbitTouches:2,panTouches:3,resetHoverEffectOnPointerLeave:!0})(ra||(ra={}));var Dr;(r=>r.defaultData={orbitControls:ra.defaultData,playPage:cn,withBackground:!0,preventScroll:!1,preventTouchScroll:!1,hideCursor:!1,mouseEventTarget:"canvas",joystickSizeAndXYOffset:Array(12).fill(0).map((e,t)=>{let o=0,i=0;return t<5?i=-30:t<10&&(i=30),t===0||t===10||t===5?o=30:(t===4||t===11||t===9)&&(o=-30),[120,[o,i],"show"]}),settings:{image:{format:"jpg",ratio:1},video:{format:"mp4",imageFormat:"jpg",fps:30,mbps:80,ratio:Math.max(1,typeof window<"u"?Math.floor(window.devicePixelRatio):1),stopMode:"manual",duration:5e3},web:{logo:!0,compress:!0,preset:1,preload:!0,hint:!1,imageQuality:70}},stopRaycast:!0,hdTransmission:!1})(Dr||(Dr={}));var bp;(r=>r.defaultData={id:"basic",label:"Basic",style:"None",prompt:""})(bp||(bp={}));var vp;(r=>r.defaultData={weather:0,shadows:0,lightOrigin:0,temperature:0,sun:0,camera:0,environment:0,particles:0,nature:0,floor:0})(vp||(vp={}));var Io;(e=>(e.defaultData=()=>({mode:"line-art-both",prompt:"",negativePrompt:"",style:{...bp.defaultData},isRandomSeed:!0,seed:e.generateSeed(),guessMode:!1,advanced:!1,steps:20,guidanceScale:7.5,controlNetScale:1,modifiers:vp.defaultData}),e.generateSeed=()=>Math.round(Math.random()*1e5)))(Io||(Io={}));var mx;(e=>{function n(t){return t.find(o=>o.data.type==="Page"&&o.data.globalPhysics.usePhysics)!==void 0}e.physicsEnabled=n;function r(t,o,i){t.scene.objects.traverseFrom(o,(a,s)=>{if(s.type==="Instance"){let l=oa.getComponentData(t,s.component)?.data;l&&i(a,s,l.events)}else i(a,s,s.events)})}e.traverseModuleInstances=r})(mx||(mx={}));var Mo;(c=>{c.TRASH_CAN_ID="830a2708-8ed9-49cf-a68e-085299892222",c.defaultLight={fi:-1,data:jc.defaultDirectionalLightData,id:"830a2708-8ed9-49cf-a68e-085299899103",children:[]};function e(u=!0,p=[]){let d=[],f=kc.defaultMeshObject;u&&(d.push({...c.defaultLight}),d.push({fi:1,id:"7ba78968-2a55-48f2-b14c-5191da3e075e",data:f,children:[]})),d.push(...p);let h=new Ke;return h.push({fi:1,id:cn,data:{...To.defaultData,name:"Scene 1"},children:d}),h}c.createDefaultObjectTreeWithPage=e,c.defaultData={objects:e(),publish:Dr.defaultData,styles:Io.defaultData()},c.emptyDataWithoutPage=function(){return{objects:new Ke,publish:Dr.defaultData,styles:Io.defaultData()}},c.emptyDataWithPage=function(u=!0){return{objects:e(u),publish:Dr.defaultData,styles:Io.defaultData()}},c.emptyData=function(){return{objects:new Ke,publish:{...Dr.defaultData},styles:Io.defaultData()}};function s(u){return{...c.defaultData,objects:Lt(u,Ke.prototype)}}c.withObjs=s;function l(u,p){return s([{id:u,data:p,children:[],fi:0}])}c.withObj=l})(Mo||(Mo={}));var na;(r=>r.defaultData={preset:"fullscreen",allowResponsive:!1,size:[512,512],coords:[0,0],sceneScale:1,color:{r:0,g:0,b:0,a:.5}})(na||(na={}));var Uc;(e=>(e.defaultData=t=>({url:t,name:"New Webhook",parametersSchemas:new be}),e.defaultParameterValueByType=t=>t==="number"?0:t==="boolean"?!1:""))(Uc||(Uc={}));var yx;(r=>r.defaultData=(e,t="GET")=>({url:e,method:t,name:"New API",headers:new be,queries:new be,autoStart:!0}))(yx||(yx={}));var fn;(i=>{function n(a){return a.textValue!==void 0}i.isTextValue=n;function r(a){return typeof a=="number"}i.isNumber=r;function e(a){return typeof a=="boolean"}i.isBoolean=e;function t(a){return n(a)?"string":e(a)?"boolean":"number"}i.typeOfVariable=t;function o(a){return i.isTextValue(a)?Array.isArray(a.textValue)?a.textValue.map(s=>s.toString().padStart(a.padding??2,"0")).join(a.deliminator??":")+(a.suffix!==void 0?" "+a.suffix:""):a.textValue.toString():i.isBoolean(a)?a?"True":"False":i.isNumber(a)?parseFloat(a.toFixed(3)).toString():a.toString()}i.getDisplayedValue=o})(fn||(fn={}));var Sp;(r=>r.all=["images","videos","colors","audios","particles","fonts","materials","variables"])(Sp||(Sp={}));var gx;(r=>r.all=[...Sp.all,"components"])(gx||(gx={}));var xx;(r=>{function n(){return{images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,materials:new fe,components:new fe,variables:new fe,userAPIs:new fe,userWebhooks:new fe}}r.defaultData=n})(xx||(xx={}));var _r;(r=>{function n(){return{images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,materials:new fe,components:new fe,variables:new fe,userAPIs:new fe,userWebhooks:new fe}}r.defaultData=n})(_r||(_r={}));var xr;(i=>{function n(){let a={};return a["89b10010-844c-11ec-a8a3-0242ac120002"]={r:.5,g:.5,b:.5,a:1,name:"Default Color"},Lt(a,fe.prototype)}i.defaultColors=n;function r(){return Lt({},fe.prototype)}i.defaultImages=r;function e(){return{catelogs:new fe,materials:new fe,images:new fe,videos:new fe,colors:new fe,audios:new fe,particles:new fe,fonts:new fe,variables:new be,userAPIs:new fe,userWebhooks:new fe,lib:_r.defaultData()}}i.emptyData=e;function t(a){switch(a){case"number":return{value:0,name:"Number"};case"boolean":return{value:!1,name:"Boolean"};case"string":return{value:{textValue:"String value"},name:"String"};case"time":let s=[0,0,0];return{name:"Time",value:{textValue:s,deliminator:":",padding:2,suffix:"AM"},dynamicVariableType:"time",format:"HH:mm:ss",format12h24h:"12ampm",timeZone:null,hasEnd:!1,endValue:{textValue:s,deliminator:":",padding:2,suffix:"AM"},autoStart:!0,repeat:!1};case"counter":return{name:"Counter",value:0,dynamicVariableType:"counter",updateInterval:1e3,increment:1,autoStart:!0,hasEnd:!0,endValue:60,repeat:!0,randomStart:!1,range:[0,100],decimals:0};case"random":return{name:"Random",value:0,dynamicVariableType:"random",updateInterval:1e3,increment:1,autoStart:!0,isStatic:!1,hasEnd:!0,endValue:60,repeat:!0,min:0,max:100,decimals:0};default:console.error("Unknown variable type",a)}}i.defaultVariables=t;function o(a,s){if(s.format==="HH:mm:ss"){let l=Math.floor(a/3600),c=Math.floor((a-l*3600)/60),u=Math.round(a-l*3600-c*60);return{textValue:[l,c,u]}}else if(s.format==="mm:ss"){let l=Math.floor(a/60),c=Math.round(a-l*60);return{textValue:[l,c]}}else return s.format==="number"?a=Math.round(a):a=Math.round(a*1e3)/1e3,a}i.getFormattedTimerTime=o})(xr||(xr={}));import{MathUtils as qc}from"three";var Hc;(r=>r.list=["idle","move","jump","run"])(Hc||(Hc={}));var Wc;(e=>(e.defaultColliderData={type:"capsule",height:200,radius:50,position:[0,0,0],rotation:[0,0,0]},e.defaultDataThirdPerson={moveMode:"walk",forwardDirection:"+z",speedTranslate:1e3,speedRotate:100,runMultiplier:2,rotationMode:"normal",rotBy:"keys",rotByTouch:"drag",delayPos:[.3,.3],delayRot:[.3,.3],keyAssignments:[["moveNegZ","W"],["moveNegX","A"],["movePosZ","S"],["movePosX","D"],["rotPosX","\u25B2"],["rotPosY","\u25C0"],["rotNegX","\u25BC"],["rotNegY","\u25B6"],["jump","Space"],["run","\u21E7"],["none","Ctrl"]],touchControl:!0,joystickPosLoc:5,joystickRotLoc:11,jumpTouchButtonLoc:9,collider:e.defaultColliderData,colliderHelperVisible:!0,collisionEnabled:!0,jumpPower:100,resetYPosition:3e3,alignToGround:!1,autoOrientMove:!0,orientWith:"camera",orientMode:"radial",delayPosCamera:.3,delayRotCamera:.3,camera:"",cameraXAxis:"Limit",cameraYAxis:"Free",cameraRotXLimits:[0,Math.PI/2],cameraRotYLimits:[-Math.PI/2,Math.PI/2],gameActions:{idle:new be,move:new be,jump:new be,run:new be},navmesh:{enabled:!1,ch:6,cs:6,walkableClimb:5,walkableHeight:1,walkableRadius:0,zones:"all",objects:[],helperVisible:!0,destinationHelperRadius:0,destinationHelperColor:Me.fromHexAndA(3728051,1)}}))(Wc||(Wc={}));function bx(n){n.layers.forEach(r=>{if(r.type==="depth"&&r.colorA!==void 0){let e=r.colorA,t=r.colorB,o=[[e.r,e.g,e.b,e.a],[t.r,t.g,t.b,t.a]],i=[0,1];for(let s=2;s<10;s++)o.push(o[1]),i.push(1);let a={...Er(it(r),"type","visible","isVector","isWorldSpace","origin","alpha","mode"),near:Math.max(0,r.near),far:Math.max(0,r.far),colors:o,steps:i,num:2,direction:[1,0,0],smooth:!1,gradientType:1};Object.assign(r,a)}else if(r.type==="depth"&&r.gradientType===1&&(r.near<0||r.far<0)){let e={...it(r),near:Math.max(r.near,0),far:Math.max(r.far,0)};Object.assign(r,e)}})}function Eo(n,r){Object.values(n.shared.materials).forEach(e=>r(e))}function No(n,r){n.scene.objects.traverse((e,t)=>{"materials"in t?t.materials.forEach((o,i)=>{o===void 0&&(t.materials[i]=Et.defaultData(),o=t.materials[i]),typeof o!="string"&&r(o)}):"material"in t?typeof t.material!="string"&&(t.material===void 0&&(t.material=Et.defaultData()),r(t.material)):t.type==="Mesh"&&(t.material===void 0&&(t.material=Et.defaultData()),r(t.material)),"overrides"in t&&Object.values(t.overrides).forEach(o=>{o.material&&typeof o.material!="string"&&Object.getPrototypeOf(o.material)!==Qe.prototype&&r(o.material)})})}function DT(n){Object.assign(n.scene.publish,{orbitControls:{...ra.defaultData,...it(n.scene.publish.orbitControls)}})}function _T(n){Object.assign(n.scene.publish.settings,{video:{...Dr.defaultData.settings.video,...it(n.scene.publish.settings.video)}})}function BT(n){function r(e){if(e.layers){for(let t of Object.values(e.layers))if(t){for(let[o,i]of Object.entries(t))if((cx.includes(o)||typeof i=="boolean")&&delete t[o],o==="texture")for(let[a,s]of Object.entries(i))(ux.includes(a)||typeof s=="boolean")&&delete i[a]}}}n.scene.objects.traverse((e,t)=>{t.states.forEach(o=>{let i=o;i.material?r(i.material):i.materials&&i.materials.forEach(a=>{r(a)})})})}function RT(n){n.scene.publish.withBackground=!0}function LT(n){n.scene.publish.settings.web={compress:!0,preload:!0,preset:1,logo:!0,hint:!1}}function VT(n){n.scene.objects.traverse((r,e)=>{let t=e.cloner;t&&(t.radial.scale=t.radial.scale.map(o=>o+1),t.linear.scale=t.linear.scale.map(o=>o+1))})}function zT(n){n.scene.objects.traverse((r,e)=>{let t=e.geometry;t&&(t.type==="DodecahedronGeometry"||t.type==="IcosahedronGeometry")&&(t.detail=Math.round(t.detail))})}function GT(n){n.scene.objects.traverse((r,e)=>{let t=n.scene.objects.unproxy().parent(r);if(t){let o=it(n.scene.objects.data(t));o&&o.type==="Mesh"&&o.geometry.type==="BooleanGeometry"&&e.type==="Mesh"&&(e.visible=it(e).booleanExclude!==!0)}})}function FT(n){n.scene.objects.traverse((r,e)=>{if(e.type==="Mesh"){let t=e;e.geometry.type==="NonParametricGeometry"?t.material!==void 0&&delete t.material:t.materials!==void 0&&delete t.materials}})}function jT(n){function r(t){Object.setPrototypeOf(t,Qe.prototype),t.texture&&Object.setPrototypeOf(t.texture,Qe.prototype)}function e(t){Object.setPrototypeOf(t,Qe.prototype);for(let o in t)r(t[o])}n.scene.objects.traverse((t,o)=>{o.states.forEach(i=>{let a=i;if(a.material){let s=it(a.material).layers;e(s),a.material.layers=s}if(a.materials)for(let s=0;s<a.materials.length;s++){let l=a.materials[s],c=it(l).layers;e(c),l.layers=c}})})}function vx(n){n.layers===void 0&&Object.assign(n,Et.defaultTwoLayerData("lambert"))}function wp(n){!n.layers||n.layers.forEach(r=>{if(r.type==="depth"&&r.colors.length===10){let e=[...r.colors];e.push(r.colors[9]);let t=[...r.steps];t.push(r.steps[9]);let o={...it(r),colors:e,steps:t};Object.assign(r,o)}})}function kT(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&(e.geometry.type==="BooleanGeometry"||e.geometry.type==="SubdivGeometry")&&(e.geometry.phongAngle=35)})}function Sx(n){n.scene.objects.traverse((r,e)=>{"materials"in e?e.materials.forEach(t=>{typeof t!="string"&&wp(t)}):"material"in e&&typeof e.material!="string"&&wp(e.material)}),Object.values(n.shared.materials).forEach(r=>wp(r))}function UT(n){n.scene.environment.ambientLight.softShadows=!1,n.scene.environment.ambientLight.softShadowQuality="low",n.scene.objects.traverse((r,e)=>{(e.type==="DirectionalLight"||e.type==="SpotLight")&&(e.shadowResolution=1024,e.shadowRadius=1,e.depth=1e5)}),n.shared.penumbraSize=new Array(5).fill(.5)}function HT(n){n.shared.audios=Lt({},fe.prototype)}function WT(n){n.shared.videos=Lt({},fe.prototype)}function qT(n){let r=n.shared.materials;Object.entries(r).forEach(([e,t])=>{if(!t.layers){let o={name:"Untitled Material",layers:[{fi:0,data:{type:"light",category:"phong",alpha:.6,visible:!0,mode:0,specular:{r:.2,g:.2,b:.2},shininess:5},id:"layer1"},{fi:1,data:{type:"color",alpha:1,visible:!0,mode:0,color:{r:.2823529411764706,g:.2823529411764706,b:.30196078431372547}},id:"layer2"}]};Object.assign(r,{[e]:o})}})}function $T(n){Object.entries(it(n.shared.images)).filter(t=>t[1].asset===!1).map(t=>t[0]).forEach(t=>{delete n.shared.images[t]}),Object.entries(it(n.shared.audios)).filter(t=>t[1].asset===!1).map(t=>t[0]).forEach(t=>{delete n.shared.audios[t]})}function YT(n){n.scene.publish.settings.web.preload=!1}function wx(n){n.layers&&n.layers.forEach(r=>{r.type==="depth"&&r.num!==void 0&&(r.colors=r.colors.slice(0,r.num),r.steps=r.steps.slice(0,r.num),delete r.num)})}function Px(n){n.layers&&n.layers.forEach(r=>{lx(r)&&r.isMask===void 0&&(r.isMask=!1),(r.type==="texture"||r.type==="video")&&r.blending===void 0&&(r.blending=0),(r.type==="noise"||r.type==="displace"&&r.displacementType==="noise")&&(r.voronoiStyle===void 0&&(r.voronoiStyle=0),r.highCut===void 0&&(r.highCut=1),r.lowCut===void 0&&(r.lowCut=0),r.smoothness===void 0&&(r.smoothness=.3),r.seed===void 0&&(r.seed=0),r.quality===void 0&&(r.quality=1))})}function XT(n){n.shared.fonts=Lt({},fe.prototype)}function KT(n){return n.replace(".typeface","").replace(/optimer/gi,"open sans").replace("space_mono","space mono").replace(/alma_mono/gi,"varela round").replace(/droid_sans_mono/gi,"noto sans mono").replace(/droid_sans|gentilis|gnomon_(simple|foreground)|helvetiker/gi,"roboto").replace(/droid_serif/gi,"roboto slab").replace("_sans"," sans").replace("crimson_text","crimson text").replace("medium_medium","medium").replace("fatface_fatface","fatface").replace("100hairline","thin").replace("200thin","extralight").replace("300light","light").replace("500medium","medium").replace("600semi","semibold").replace("800heavy","extrabold").replace("900black","black").replace(/bodoni_(11|16|24|36|48|72|96)([^_])/gi,"bodoni_$1_$2").replace(/bodoni_(11|16|24|36|48|72|96)/gi,"bodoni moda").replace(/(thin|hairline)(_regular)?/gi,"100").replace(/(extra|ultra)light(_regular)?/gi,"200").replace(/light(_regular)?/gi,"300").replace(/_book|_normal|_roman/gi,"_regular").replace(/medium(_regular)?/gi,"500").replace(/(semi|demi)bold(_regular)?/gi,"600").replace(/(extra|ultra)bold(_regular)?/gi,"800").replace(/bold(_regular)?/gi,"700").replace(/(black|heavy|fatface)(_regular)?/gi,"900").replace(/([1-9]00)_italic/gi,"$1italic").replace(/regularitalic/gi,"italic").replace(/regularitalic/gi,"italic").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function QT(n){let r=[];n.scene.objects.traverse((e,t)=>{let o=t;if(o.type==="TextFrame"){let i=Et.defaultTwoLayerData("phong"),a=typeof o.color=="string"?n.shared.colors[o.color]:o.color;i.layers[1].data.color={r:a.r,g:a.g,b:a.b},i.layers[1].data.alpha=o.alpha;let s=KT(o.font);n.shared.fonts[s]===void 0&&(n.shared.fonts[s]={name:s});let l={name:o.name,...bt.defaultData,...pn.defaultData,flatShading:!1,wireframe:!1,geometry:{...Ao.defaultData("TextGeometry"),width:o.width,height:o.height,font:s,depth:0,horizontalAlign:o.horizontalAlign,verticalAlign:o.verticalAlign,fontSize:o.fontSize*1.40625,lineHeight:o.lineHeight/1.40625,letterSpacing:o.letterSpacing-1,text:o.text,textTransform:o.textTransform,extrudeBevelSize:0,extrudeBevelSegments:1},material:i,states:it(o.states),events:it(o.events),visible:o.visible,raycastLock:o.raycastLock,position:o.position,rotation:o.rotation,scale:o.scale,hiddenMatrix:o.hiddenMatrix},c=it(n.scene.objects).parent(e);n.scene.objects.insertAfter(c??null,e,[{id:e+"new",data:l,children:[]}]),r.push(e)}}),r.forEach(e=>{n.scene.objects.delete(e)})}function ZT(n){let r={0:"MouseDown",1:"MouseUp",2:"MouseHover",5:"KeyDown",6:"KeyUp",7:"Start",9:"LookAt",10:"Follow",11:"Scroll",12:"Audio",13:"GameControl"};n.scene.objects.traverse((e,t)=>{t.events.forEach(o=>{if(!!r[Number(o.type)])if(Object.assign(o,{type:r[Number(o.type)]}),o.type==="Audio"&&"audioEvent"in o&&(Object.assign(o,{playAudio:o.audioEvent}),delete o.audioEvent),o.type==="GameControl")Object.assign(o,{gameActions:{idle:new be,move:new be,jump:new be}});else{let i=new be;Object.assign(o,{actions:i}),(o.type==="MouseDown"||o.type==="MouseUp"||o.type==="KeyDown"||o.type==="KeyUp")&&"url"in o&&i.push({fi:0,id:qc.generateUUID(),data:{type:"Link",url:o.url,delay:0}}),"targets"in o&&(o.targets.forEach((a,s,l)=>{let c={state:void 0,repeat:0,delay:0,delayDirection:void 0,direction:"normal",duration:0,easing:4},u={easing:a.easing,duration:a.duration};a.easing===6?Object.assign(u,Er(a,"mass","stiffness","damping","velocity")):a.easing===5&&Object.assign(u,{control1:{...a.control1},control2:{...a.control2}});let p={repeat:a.repeat?-1:0,delay:a.delay,delayDirection:a.delayDirection,direction:a.cycle&&a.rewind?"pingpong-rewind":a.cycle?"pingpong":"normal"},d={state:a.state,...p,...u},f={allowSlerp:!0,type:"Transition",object:a.object,repeat:0,delay:0,delayDirection:void 0,direction:"normal",tweens:new be({fi:0,id:qc.generateUUID(),data:c},{fi:1,id:qc.generateUUID(),data:d})};i.push({fi:l,id:s,data:f})}),delete o.targets)}})})}function JT(n){n.scene.objects.traverse((r,e)=>{function t(o,i){let a=new be,s=[];if(e.events.forEach((l,c,u)=>{if(l.type==="Audio"&&l.trigger===i){let p;s.push(c),l.interaction==="play"?p={...Er(l,"interaction","audio","delay","volume","loop"),triggerAfter:"after"in l?l.after:void 0,toggle:"after"in l?l.toggle:void 0,type:"Audio"}:(l.interaction==="pause"||l.interaction==="stop")&&(p={...Er(l,"interaction","delay","object","playAudio"),type:"Audio"}),p&&a.push({fi:u,id:c,data:p})}}),s.forEach(l=>e.events.delete(l)),a.length){let l=e.events.find(c=>c.type===o)?.data;l?"actions"in l&&l.actions.insertBefore(null,a):e.events.insertBefore(null,[{id:qc.generateUUID(),data:{type:o,actions:a}}])}}t("Start","start"),t("MouseDown","mouseDown"),t("MouseUp","mouseUp"),t("KeyDown","keyDown"),t("KeyUp","keyUp")})}function Cx(n){let r=n.layers.find(e=>e.type==="light")?.data;if(r?.category==="basic"){let e=xt.defaultData("light","phong"),t=r;Object.assign(t,e),t.visible=!1}}function Ox(n){Eo(n,Cx),No(n,Cx)}function eI(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&e.geometry.type==="SubdivGeometry"&&(e.geometry.scaleBaked||(e.geometry.scaleBaked=[1,1,1]))})}function tI(n){n.scene.objects.traverse((r,e)=>{(e.type==="Empty"||e.type==="Mesh")&&e.cloner&&!e.cloner.randomnessObject&&!e.cloner.toObject&&!e.cloner.randomness&&(e.cloner={...e.cloner,toObject:{object:"",spreadType:"random",scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],axis:"x",seed:0,count:99,align:"normal"},randomness:!1,randomnessObject:{strength:100,scale:[0,0,0],rotation:[0,0,0],position:[0,0,0],movement:1,seed:0,freqScale:10,noiseType:"perlin"}})})}function rI(n){n.scene.objects.traverse((r,e)=>{e.type==="Mesh"&&e.geometry.type==="NonParametricGeometry"&&!("material"in e)&&!("materials"in e)&&(e.material=Et.defaultTwoLayerData("phong"))})}function oI(n){n.scene.publish.orbitControls.autoZoom===void 0&&(n.scene.publish.orbitControls.autoZoom=!1),n.scene.objects.traverse((r,e)=>{(e.type==="OrthographicCamera"||e.type==="PerspectiveCamera")&&(e.orthographic.autoZoom===void 0&&(e.orthographic.autoZoom=!1),e.orthographic.autoZoomFrustumSize===void 0&&(e.orthographic.autoZoomFrustumSize=790))})}function nI(n){n.scene.objects.traverse((r,e)=>{e.pathSnapping===void 0&&(e.pathSnapping={pathId:null,slide:0,offset:0,orientation:"tangential"}),e.pathSnapping.offset===void 0&&(e.pathSnapping.offset=0)})}function iI(n){n.scene.publish.mouseEventTarget===void 0&&(n.scene.publish.mouseEventTarget="canvas"),n.scene.publish.settings.web.hint===void 0&&(n.scene.publish.settings.web.hint=!1)}function aI(n){let{video:r}=n.scene.publish.settings;r.format==="gif"&&r.fps>48&&(r.fps=15)}function sI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.resetYPosition=Math.abs(t.resetYPosition-e.position[1]))})})}function lI(n){let r=n.scene.environment.usePhysics;n.scene.objects.traverse((e,t)=>{r&&t.physics===null?t.collision=!1:t.collision="visibility"})}function cI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.navmesh=Wc.defaultDataThirdPerson.navmesh)})})}function uI(n){n.scene.styles||(n.scene.styles=Io.defaultData())}function Ax(n){n.layers.forEach(r=>{r.type==="light"&&r.category!=="toon"&&r.occlusion===void 0&&(r.occlusion=!0)})}function dI(n){n.scene.environment.ambientLight.occlusion===void 0&&(n.scene.environment.ambientLight.occlusion=!1),n.scene.environment.ambientLight.aoFullRes===void 0&&(n.scene.environment.ambientLight.aoFullRes=!1),n.scene.environment.ambientLight.radius===void 0&&(n.scene.environment.ambientLight.radius=256),n.scene.environment.ambientLight.bias===void 0&&(n.scene.environment.ambientLight.bias=.5),n.scene.environment.ambientLight.aoColor===void 0&&(n.scene.environment.ambientLight.aoColor={r:.19607843137254902,g:.19607843137254902,b:.19607843137254902}),No(n,Ax),Eo(n,Ax)}function pI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&Object.assign(t.gameActions,{run:new be})})})}function fI(n){n.scene.objects.traverse((r,e)=>{e.events.forEach(t=>{t.type==="GameControl"&&(t.keyAssignments=[...t.keyAssignments,["run","\u21E7"],["none","Ctrl"]])})})}function Tx(n){n.layers&&n.layers.forEach(r=>{r.type==="light"&&r.bumpMapIntensity===void 0&&(r.bumpMapIntensity=5)})}function Ix(n,r){if(r<1&&(No(n,bx),Eo(n,bx),n.schema=1),r<2&&(DT(n),n.schema=2),r<3&&(BT(n),n.schema=3),r<4&&(RT(n),n.schema=4),r<5&&(LT(n),n.schema=5),r<6&&(VT(n),n.schema=6),r<7&&(zT(n),n.schema=7),r<8&&(n.schema=8),r<9&&(Sx(n),n.schema=9),r<10&&(kT(n),n.schema=10),r<11&&(UT(n),n.schema=11),r<12&&(Sx(n),n.schema=12),r<13&&(HT(n),n.schema=13),r<14&&(qT(n),n.schema=14),r<15&&($T(n),n.schema=15),r<16&&(YT(n),n.schema=16),r<17&&(No(n,wx),Eo(n,wx),n.schema=17),r<18&&(No(n,vx),Eo(n,vx),n.schema=18),r<19&&(_T(n),n.schema=19),r<20&&(XT(n),QT(n),n.schema=20),r<21&&(ZT(n),JT(n),n.schema=21),r<22&&(Ox(n),n.schema=22),r<23&&(eI(n),n.schema=23),r<24&&(tI(n),n.schema=24),(r<25||n.shared.videos===void 0)&&(WT(n),r<25&&(n.schema=25)),r<26&&(GT(n),n.schema=26),r<27&&(FT(n),n.schema=27),r<28&&(Ox(n),n.schema=28),r<29&&(jT(n),n.schema=29),r<30&&(rI(n),n.schema=30),r<31&&(oI(n),n.schema=31),r<33&&(nI(n),n.schema=33),r<34&&(iI(n),n.schema=34),r<35&&(aI(n),n.schema=35),r<36&&(sI(n),n.schema=36),r<37&&(lI(n),n.schema=37),r<38&&(No(n,Px),Eo(n,Px),n.schema=38),r<39&&(cI(n),n.schema=39),r<40&&(uI(n),n.schema=40),r<41&&(dI(n),n.schema=41),r<42&&(pI(n),n.schema=42),r<43&&(fI(n),n.schema=43),r<99){No(n,Tx),Eo(n,Tx),n.scene.publish.playCamera===null&&(n.scene.publish.playCamera=ln);let e=it(n.scene.objects),t=n.scene.objects;n.scene.publish.playPage=cn,t.insertBefore(null,null,[{id:cn,data:{...To.defaultData,backgroundColor:n.scene.backgroundColor,fog:n.scene.fog,postprocessing:n.scene.postprocessing,ao:Er(n.scene.environment.ambientLight,"occlusion","aoFullRes","radius","bias","aoColor"),publish:{playCamera:n.scene.publish.playCamera,gameControlObject:n.scene.publish.gameControlObject},shadow:Er(n.scene.environment.ambientLight,"softShadowQuality"),globalPhysics:{...Ns.defaultData,...Er(n.scene.environment,"usePhysics","gravity")},camera:it(n.scene.ownerCamera)??To.defaultData.camera,name:"Scene"},children:[]}]);for(let a of e)a.id!==Mo.TRASH_CAN_ID&&t.move(cn,a.fi,a.id);let o=0,i=0;n.shared.penumbraSize&&n.scene.objects.traverse((a,s)=>{s.type==="DirectionalLight"?(s.penumbraSize=n.shared.penumbraSize[Math.min(o,2)],o+=1):s.type==="SpotLight"&&(s.penumbraSize=n.shared.penumbraSize[3+Math.min(i,1)],i+=1),(s.physics===void 0||s.physics===null)&&s.type!=="Instance"&&(s.physics={},Object.assign(s.physics,dn.defaultData)),s.physics!==void 0&&s.physics!==null&&(s.physics.enabled=s.collision??"visibility",delete s.collision)}),n.schema=99}}function Mx(n){n.layers&&n.layers.forEach(r=>{r.type==="light"&&r.alphaOverride===void 0&&(r.alphaOverride=1)})}function hI(n){n.scene.objects.traverse((r,e)=>{let t=e.geometry;t&&t.type==="PathGeometry"&&(t.extrusion.capType="flat",t.extrusion.bevel=50,t.extrusion.bevelSides=6,t.extrusion.shape.type==="Custom"&&(t.extrusion.shape.shapeQuality="low"))})}function mI(n){Array.isArray(it(n.events))&&n.events?.forEach(r=>{"disabled"in r||(r.disabled=!1),(r.type==="MouseDown"||r.type==="MouseUp"||r.type==="MousePress")&&(r.mode=r.mode||"Object")})}var ia=180/Math.PI;function Ex(n){n.rotation=n.rotation.slice(0,3).map(r=>r*ia)}function Nx(n){Ex(n),n.type==="Page"&&Ex(n.camera),n.states?.forEach(e=>{e.rotation===void 0||e.rotation===null||(e.rotation=e.rotation.slice(0,3).map(t=>t*ia))});let r=n.geometry;r&&r.type==="SphereGeometry"&&(r.thetaLength=(r.thetaLength??180)*ia),r&&r.type==="TorusGeometry"&&(r.arc=r.arc*ia),r&&r.type==="PathGeometry"&&(r.extrusion.angle*=ia,r.extrusion.twist*=ia),n.type==="Mesh"&&n.geometry.type==="TextGeometry"&&(n.geometry.text={textValue:n.geometry.text}),Array.isArray(it(n.events))&&n.events?.forEach(e=>{(e.type==="MouseDown"||e.type==="MouseUp"||e.type==="MousePress"||e.type==="KeyDown"||e.type==="KeyUp"||e.type==="KeyPress"||e.type==="Collision"||e.type==="Trigger")&&(e.runMode=e.toggle?"Toggle":"Repeat")})}function yI(n){n.shared.variables=Lt({},fe.prototype)}function gI(n){let r=it(n.shared.variables);n.shared.variables=Lt(Object.entries(r??{}).map(([e,t],o)=>({fi:o,id:e,data:t})),be.prototype)}var oo=115;function Dx(n,r){r(n.data);for(let e of n.children)Dx(e,r)}function xI(n){let r=n.schema??104;r!==oo&&r<105&&(Dx(n.asset,Nx),n.schema=105)}function bI(n){n.shared.particles=Lt({},fe.prototype),n.shared.lib&&(n.shared.lib.particles=_r.defaultData().particles)}function vI(n){n.scene.objects.traverse((r,e)=>{e.type==="Particle"&&typeof e.renderMaterial.size=="number"&&Object.assign(e.renderMaterial,{size:[e.renderMaterial.size,e.renderMaterial.size]})})}function SI(n){n.scene.objects.traverse((r,e)=>{e.type==="Page"&&(e.postprocessing.depthOfField.focusDistance=100,e.postprocessing.depthOfField.focalLength=20,e.postprocessing.depthOfField.bokehScale=5)})}function wI(n){n.scene.objects.traverse((r,e)=>{Array.isArray(it(e.events))!==!1&&e.events?.forEach(t=>{let o=t.runMode;t.type==="MouseDown"||t.type==="MouseUp"||t.type==="KeyDown"||t.type==="KeyUp"||t.type==="Collision"||t.type==="Trigger"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode=o??"Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode=o==="Toggle"?"Toggle":"Normal")}):t.type==="MouseHover"||t.type==="MousePress"||t.type==="KeyPress"?t.actions?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")}):t.type==="GameControl"?(delete t.actions,Object.keys(t.gameActions).forEach(a=>{t.gameActions[a]?.forEach(s=>{s.type==="Transition"&&(s.runMode="Repeat"),s.type==="Animation"&&(s.runMode="Normal")})})):t.type==="DragDrop"?(delete t.actions,t.dragDropActions?.drag?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")}),t.dragDropActions?.drop?.forEach(i=>{(i.type==="Transition"||i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Toggle")})):t.type==="Resize"?(delete t.actions,t.breakpoints?.forEach(i=>{i.actions?.forEach(a=>{(a.type==="Transition"||a.type==="Animation"||a.type==="SwitchCamera")&&(a.runMode="Toggle")})})):t.type==="Start"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Once"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}):t.type==="VariableChange"||t.type==="Scroll"?t.actions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}):t.type==="Conditional"&&(delete t.actions,t.inActions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}),t.outActions?.forEach(i=>{i.type==="Transition"&&(i.runMode="Repeat"),(i.type==="Animation"||i.type==="SwitchCamera")&&(i.runMode="Normal")}))})})}function PI(n){n.shared.userAPIs=Lt({},fe.prototype),n.shared.userWebhooks=Lt({},fe.prototype),n.shared.lib&&(n.shared.lib.userAPIs=_r.defaultData().userAPIs,n.shared.lib.userWebhooks=_r.defaultData().userWebhooks)}function $c(n){let r=n.schema??0;if(r!==oo){console.warn("updating from ",r,"to ",oo),Ix(n,r),r<100&&(n.scene.publish.joystickSizeAndXYOffset===void 0&&(n.scene.publish.joystickSizeAndXYOffset=Dr.defaultData.joystickSizeAndXYOffset),n.schema=100),r<101&&(No(n,Mx),Eo(n,Mx),n.schema=101),r<102&&(hI(n),n.schema=102),r<104&&(n.shared.catelogs=new fe,n.shared.lib=_r.defaultData(),n.schema=104),r<105&&(yI(n),n.scene.objects.traverse((e,t)=>{Nx(t)}),n.schema=105);for(let e of Object.values(n.shared.lib.components))xI(e);r<106&&(gI(n),n.schema=106),r<107&&(n.shared.lib.variables=_r.defaultData().variables,n.schema=107),r<109&&(bI(n),n.schema=109),r<110&&(vI(n),n.schema=110),r<111&&(n.scene.objects.traverse((e,t)=>{mI(t)}),n.schema=111),r<112&&(SI(n),n.schema=112),r<113&&(wI(n),n.schema=113),r<114&&(n.scene.publish.settings.web.imageQuality===void 0&&(n.scene.publish.settings.web.imageQuality=70),n.schema=114),r<115&&(PI(n),n.schema=115)}}var oa;(c=>{c.defaultData={schema:oo,scene:Mo.defaultData,frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",na.defaultData),shared:{...xr.emptyData(),colors:xr.defaultColors()}},c.emptyDataForImports=function(){let u=Mo.emptyDataWithPage();return{schema:oo,scene:u,frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",na.defaultData),shared:{...xr.emptyData(),colors:xr.defaultColors(),images:xr.defaultImages()}}},c.emptyData=function(){return{schema:oo,scene:Mo.emptyDataWithPage(),frames:new fe().add("72fc2993-2da3-4b6b-96ac-2879db3a28bd",na.defaultData),shared:xr.emptyData()}},c.clipboard2dData=function(){return{schema:oo,scene:Mo.emptyData(),frames:new fe,shared:xr.emptyData()}},c.collabHelper={...Os,updateSchema(u){return(u.schema??0)<oo?tn(u,$c):(u.schema??0)-oo}};function i(u){let p=c.collabHelper.updateSchema(u);return typeof p=="number"?p===0?u:null:p.data}c.updateSchemaDirectly=i;function a(u){return{...u,shared:{...u.shared,lib:_r.defaultData()}}}c.withoutLib=a;function s(u,p){let d=u.scene.objects.get(p);if(d&&d.data.type==="Component")return d;{let f=u.shared.lib.components[p];if(f)return f.asset}}c.getComponentData=s;function l(u){let p=Object.values(u.shared.userAPIs);for(let d of p){let f=d.headers;for(let h of f)if(h.data.key.toLowerCase()==="authorization"&&h.data.value!=="")return!0}return!1}c.hasSensitiveData=l})(oa||(oa={}));var Yc;(r=>r.emptyImage={data:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=",name:"empty"})(Yc||(Yc={}));var _x;(r=>{function n(e){return!0}r.is=n})(_x||(_x={}));var Xc;(t=>{t.defaultData={position:[0,0],scale:[1,1],rotation:0,shear:[0,0]};function r(o,i){return{position:i?.position??o.position,rotation:i?.rotation??o.rotation,scale:i?.scale??o.scale,shear:i?.shear??o.shear}}t.merge=r;function e(o,i){return Ll({position:Xi.isEqual(o.position,i.position)?void 0:i.position,rotation:o.rotation===i.rotation?void 0:i.rotation,scale:Xi.isEqual(o.scale,i.scale)?void 0:i.scale,shear:o.shear&&i.shear&&Xi.isEqual(o.shear,i.shear)?void 0:i.shear})}t.diff=e})(Xc||(Xc={}));var Pp;(r=>r.defaultData={horizontalConstraint:0,verticalConstraint:0})(Pp||(Pp={}));var Bx;(r=>r.defaultData={direction:"row",wrap:"unwrap",align:"top-left",gap:10,rowGap:10,autoGap:!1,autoRowGap:!1,leftPadding:8,rightPadding:8,topPadding:8,bottomPadding:8})(Bx||(Bx={}));var Kc;(r=>r.defaultData={opacity:1,fill:{color:Me.fromHexAndA(mt,1),enabled:!0},stroke:{color:Me.from0to1([0,0,0,1]),thickness:1,enabled:!1,mode:"inside"},layerBlur:{radius:2,enabled:!1},backgroundBlur:{radius:2,enabled:!1},dropShadow:{offset:[10,10],blurRadius:10,color:Me.from0to1([0,0,0,1]),enabled:!1,spread:0},innerShadow:{offset:[10,10],blurRadius:10,color:Me.from0to1([0,0,0,1]),enabled:!1,spread:0}})(Kc||(Kc={}));var Yn;(i=>{function n(a,s){return{name:s}}i.newEmpty=n;function r(a,s){if(s===void 0)return a;let l={...a},c=["width","height","cornerRadius"];for(let u of c)u in l&&u in s&&s[u]!==void 0&&Object.assign(l,{[u]:s[u]});return l}function e(a,s){if(s===void 0)return a;let l={...a};return"fill"in l&&"fill"in s&&s.fill!==void 0&&Object.assign(l,{fill:{...l.fill,...s.fill}}),"stroke"in l&&"stroke"in s&&s.stroke!==void 0&&Object.assign(l,{stroke:{...l.stroke,...s.stroke}}),"layerBlur"in l&&"layerBlur"in s&&s.layerBlur!==void 0&&Object.assign(l,{layerBlur:{...l.layerBlur,...s.layerBlur}}),"backgroundBlur"in l&&"backgroundBlur"in s&&s.backgroundBlur!==void 0&&Object.assign(l,{backgroundBlur:{...l.backgroundBlur,...s.backgroundBlur}}),"dropShadow"in l&&"dropShadow"in s&&s.dropShadow!==void 0&&Object.assign(l,{dropShadow:{...l.dropShadow,...s.dropShadow}}),"innerShadow"in l&&"innerShadow"in s&&s.innerShadow!==void 0&&Object.assign(l,{innerShadow:{...l.innerShadow,...s.innerShadow}}),l}function t(a,s){if(s===void 0)return a;let l={...a};return Object.assign(l,Xc.merge(l,s)),l=r(l,s),l=e(l,s),l}i.patch=t;function o(a,s){let l,c=[];for(let[u,p]of Object.entries(s))u!=="name"&&(l===void 0&&(l={path:[],props:{},type:0},c.push(l)),l.props[u]=p);return c}i.toOps=o})(Yn||(Yn={}));var Ds;(r=>r.defaultData={...Xc.defaultData,...Pp.defaultData,states:new be,events:new be,visible:!0,raycastLock:!1})(Ds||(Ds={}));var aa;(r=>r.defaultData={...Ds.defaultData,...Kc.defaultData})(aa||(aa={}));var Qc;(r=>r.defaultData={cornerRadius:[0,0,0,0]})(Qc||(Qc={}));var Cp;(r=>r.defaultData={...aa.defaultData,type:"ellipse2d",width:100,height:100,name:"Ellipse"})(Cp||(Cp={}));var sa;(r=>r.defaultData={...aa.defaultData,...Qc.defaultData,type:"rectangle2d",width:100,height:100,name:"Rectangle"})(sa||(sa={}));var Op;(r=>r.defaultData={...aa.defaultData,type:"text2d",width:100,height:100,fontSize:12,lineHeight:1.2,letterSpacing:0,text:{textValue:"Hello world"},horizontalAlign:1,verticalAlign:1,textTransform:1,font:"Roboto_regular",name:"Text"})(Op||(Op={}));var Ap;(r=>r.defaultData={...aa.defaultData,type:"path2d",path:"",name:"Path"})(Ap||(Ap={}));var Rx;(r=>{function n(e){return e.type==="ellipse2d"||e.type==="rectangle2d"||e.type==="text2d"||e.type==="vector2d"||e.type==="path2d"}r.is=n})(Rx||(Rx={}));var _s;(r=>r.defaultData={...Ds.defaultData,name:"Group",type:"group2d"})(_s||(_s={}));var Tp;(r=>r.defaultData=()=>({...Ds.defaultData,...Qc.defaultData,...Kc.defaultData,name:"Frame",type:"frame2d",clipped:!0,width:200,height:200,fill:{color:Me.fromHexAndA(4737101,1),enabled:!0},stroke:{color:Me.fromHexAndA(0,1),thickness:1,enabled:!1,mode:"inside"},backgroundBlur:{radius:2,enabled:!1},layerBlur:{radius:2,enabled:!1}}))(Tp||(Tp={}));var Do;(i=>{function n(a){switch(a){case"rectangle2d":return{...sa.defaultData};case"ellipse2d":return{...Cp.defaultData};case"text2d":return{...Op.defaultData};case"vector2d":return{...sa.defaultData};case"path2d":return{...Ap.defaultData};case"frame2d":return{...Tp.defaultData()};case"group2d":return{..._s.defaultData}}}i.defaultData=n;function r(a){return"width"in a&&"height"in a?[typeof a.width=="number"?a.width*.5:0,typeof a.height=="number"?a.height*.5:0]:[0,0]}i.getPivot=r;function e(a){return a.type==="rectangle2d"||a.type==="ellipse2d"||a.type==="text2d"||a.type==="frame2d"}i.isResizeable=e;function t(a){return a.type==="frame2d"&&a.autoLayout!==void 0}i.isAutoLayoutable=t;function o(a){return a.type==="rectangle2d"||a.type==="frame2d"}i.hasCorners=o})(Do||(Do={}));var Zc;(e=>(e.defaultData={name:"UI",type:"scene2d",objects:new Ke},e.emptyData=function(){return{type:"scene2d",objects:new Ke}}))(Zc||(Zc={}));var Qu=xs(Vx());import{Object3D as q3,Vector3 as pr,Euler as sh,MathUtils as Cv,Matrix4 as pi}from"three";var CI=.5*(Math.sqrt(3)-1),Bs=(3-Math.sqrt(3))/6,OI=1/3,no=1/6,XW=(Math.sqrt(5)-1)/4,KW=(5-Math.sqrt(5))/20,Rs=n=>Math.floor(n)|0,zx=new Float64Array([1,1,-1,1,1,-1,-1,-1,1,0,-1,0,1,0,-1,0,0,1,0,-1,0,1,0,-1]),Mp=new Float64Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]);function Gx(n=Math.random){let r=jx(n),e=new Float64Array(r).map(o=>zx[o%12*2]),t=new Float64Array(r).map(o=>zx[o%12*2+1]);return function(i,a){let s=0,l=0,c=0,u=(i+a)*CI,p=Rs(i+u),d=Rs(a+u),f=(p+d)*Bs,h=p-f,m=d-f,y=i-h,b=a-m,S,P;y>b?(S=1,P=0):(S=0,P=1);let C=y-S+Bs,v=b-P+Bs,A=y-1+2*Bs,T=b-1+2*Bs,g=p&255,D=d&255,E=.5-y*y-b*b;if(E>=0){let _=g+r[D],B=e[_],V=t[_];E*=E,s=E*E*(B*y+V*b)}let M=.5-C*C-v*v;if(M>=0){let _=g+S+r[D+P],B=e[_],V=t[_];M*=M,l=M*M*(B*C+V*v)}let N=.5-A*A-T*T;if(N>=0){let _=g+1+r[D+1],B=e[_],V=t[_];N*=N,c=N*N*(B*A+V*T)}return 70*(s+l+c)}}function Fx(n=Math.random){let r=jx(n),e=new Float64Array(r).map(i=>Mp[i%12*3]),t=new Float64Array(r).map(i=>Mp[i%12*3+1]),o=new Float64Array(r).map(i=>Mp[i%12*3+2]);return function(a,s,l){let c,u,p,d,f=(a+s+l)*OI,h=Rs(a+f),m=Rs(s+f),y=Rs(l+f),b=(h+m+y)*no,S=h-b,P=m-b,C=y-b,v=a-S,A=s-P,T=l-C,g,D,E,M,N,_;v>=A?A>=T?(g=1,D=0,E=0,M=1,N=1,_=0):v>=T?(g=1,D=0,E=0,M=1,N=0,_=1):(g=0,D=0,E=1,M=1,N=0,_=1):A<T?(g=0,D=0,E=1,M=0,N=1,_=1):v<T?(g=0,D=1,E=0,M=0,N=1,_=1):(g=0,D=1,E=0,M=1,N=1,_=0);let B=v-g+no,V=A-D+no,k=T-E+no,L=v-M+2*no,W=A-N+2*no,F=T-_+2*no,j=v-1+3*no,H=A-1+3*no,q=T-1+3*no,re=h&255,ee=m&255,X=y&255,te=.6-v*v-A*A-T*T;if(te<0)c=0;else{let $=re+r[ee+r[X]];te*=te,c=te*te*(e[$]*v+t[$]*A+o[$]*T)}let K=.6-B*B-V*V-k*k;if(K<0)u=0;else{let $=re+g+r[ee+D+r[X+E]];K*=K,u=K*K*(e[$]*B+t[$]*V+o[$]*k)}let Z=.6-L*L-W*W-F*F;if(Z<0)p=0;else{let $=re+M+r[ee+N+r[X+_]];Z*=Z,p=Z*Z*(e[$]*L+t[$]*W+o[$]*F)}let Q=.6-j*j-H*H-q*q;if(Q<0)d=0;else{let $=re+1+r[ee+1+r[X+1]];Q*=Q,d=Q*Q*(e[$]*j+t[$]*H+o[$]*q)}return 32*(c+u+p+d)}}function jx(n){let e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){let o=t+~~(n()*(256-t)),i=e[t];e[t]=e[o],e[o]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}import{Triangle as AI}from"three";var Br=new AI,Jc=class{constructor(r){this.weightAttribute=null;let e=r.geometry;if(!e.isBufferGeometry||e.attributes.position.itemSize!==3)throw new Error("THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.");e.index&&(e=e.toNonIndexed()),this.geometry=e,this.randomFunction=Math.random,this.positionAttribute=this.geometry.getAttribute("position"),this.distribution=null}build(){let r=this.positionAttribute,e=new Float32Array(r.count/3);for(let o=0;o<r.count;o+=3){let i=1;Br.a.fromBufferAttribute(r,o),Br.b.fromBufferAttribute(r,o+1),Br.c.fromBufferAttribute(r,o+2),i*=Br.getArea(),e[o/3]=i}this.distribution=new Float32Array(r.count/3);let t=0;for(let o=0;o<e.length;o++)t+=e[o],this.distribution[o]=t;return this}setRandomGenerator(r){return this.randomFunction=r,this}sample(r,e){if(this.distribution){let t=this.distribution[this.distribution.length-1],o=this.binarySearch(this.randomFunction()*t);return this.sampleFace(o,r,e)}}binarySearch(r){if(!this.distribution)return 0;let e=this.distribution,t=0,o=e.length-1,i=-1;for(;t<=o;){let a=Math.ceil((t+o)/2);if(a===0||e[a-1]<=r&&e[a]>r){i=a;break}else r<e[a]?o=a-1:t=a+1}return i}sampleFace(r,e,t){let o=this.randomFunction(),i=this.randomFunction();return o+i>1&&(o=1-o,i=1-i),Br.a.fromBufferAttribute(this.positionAttribute,r*3),Br.b.fromBufferAttribute(this.positionAttribute,r*3+1),Br.c.fromBufferAttribute(this.positionAttribute,r*3+2),e.set(0,0,0).addScaledVector(Br.a,o).addScaledVector(Br.b,i).addScaledVector(Br.c,1-(o+i)),Br.getNormal(t),this}};import{Object3D as NI}from"three";var Hx=xs(Ux());import{Object3D as TI,Matrix4 as io}from"three";var II=new io,MI=new io,EI=new io,la;(r=>{function n(e){return e&&e.__isSPEObject}r.is=n})(la||(la={}));var ca=n=>class extends n{constructor(){super(...arguments);this.previousModelViewMatrix=new io;this.copyPreviousMatrix=!0;this.hiddenMatrix=new io;this.matrixWorldRigid=new io;this.shearScale=new io;this.shearScaleInv=new io}get __isSPEObject(){return!0}isDescendantOf(t){t instanceof TI&&(t=t.uuid);let o=this;for(;o.parent;){if(o.parent.uuid===t)return!0;o=o.parent}return!1}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.parent===null?this.matrixWorld.multiplyMatrices(this.hiddenMatrix,this.matrix):(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.hiddenMatrix),this.matrixWorld.multiplyMatrices(this.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);for(let o of this.children)o.updateMatrixWorld(t)}updateWorldMatrix(t,o){let i=this.parent;if(t&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.parent===null?this.matrixWorld.multiplyMatrices(this.hiddenMatrix,this.matrix):(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.hiddenMatrix),this.matrixWorld.multiplyMatrices(this.matrixWorld,this.matrix)),o)for(let a of this.children)a.updateWorldMatrix(!1,!0)}traverseChildren(t,o=0){for(let i of this.children)la.is(i)&&i.traverseObject(t,o+1)}traverseObject(t,o=0){if(t(this,o)!==!0)for(let a of this.children)la.is(a)&&a.traverseObject(t,o+1)}updateMatrixWorldSVD(){let t=this.matrixWorld.elements,o=[[t[0],t[4],t[8]],[t[1],t[5],t[9]],[t[2],t[6],t[10]]],{u:i,v:a,q:s}=(0,Hx.SVD)(o),l=II.set(i[0][0],i[0][1],i[0][2],0,i[1][0],i[1][1],i[1][2],0,i[2][0],i[2][1],i[2][2],0,0,0,0,1),c=MI.set(a[0][0],a[0][1],a[0][2],0,a[1][0],a[1][1],a[1][2],0,a[2][0],a[2][1],a[2][2],0,0,0,0,1),u=EI.copy(c).transpose();this.shearScale.makeScale(s[0],s[1],s[2]).multiply(u).premultiply(c),this.shearScaleInv.copy(this.shearScale).invert(),this.matrixWorldRigid.multiplyMatrices(l,u).copyPosition(this.matrixWorld),s.every(p=>Math.abs(s[0]-p)<.01)?this.hasNonUniformScale=!1:this.hasNonUniformScale=!0}attach(t,o){this.updateWorldMatrix(!0,!1);let i=new io().copy(this.matrixWorld).invert();return t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),i.multiply(t.parent.matrixWorld)),"hiddenMatrix"in t&&t.hiddenMatrix instanceof io?t.hiddenMatrix.premultiply(i):t.applyMatrix4(i),t.updateWorldMatrix(!1,!1),this.add(t),o!==void 0&&(this.children.pop(),this.children.splice(o,0,t)),this}copy(t,o=!1){return super.copy(t,o),this.hasNonUniformScale=t.hasNonUniformScale,this}onAfterRender(t,o,i,a,s,l){this.copyPreviousMatrix&&this.previousModelViewMatrix.copy(this.modelViewMatrix)}};var Ep=class extends ca(NI){},DI=n=>n.type==="Mesh",_o=class extends Ep{constructor(e){super();this.object=e;this.matrixAutoUpdate=!1,this.hasNonUniformScale=e.hasNonUniformScale}raycast(e,t){}expand(){let e=0,t=this.object.entityChildren(e);for(;t;){let o=this.children[e];o?.object!==t&&(o&&this.remove(o),o=new _o(t),this.add(o),this.children.splice(e,0,this.children.pop()),o.matrixWorldNeedsUpdate=!0,o.matrixAutoUpdate=!1,o.matrix=t.matrix,o.hiddenMatrix=t.hiddenMatrix),o.expand(),e+=1,t=this.object.entityChildren(e)}for(;this.children.length>e;)this.remove(this.children[e])}get visible(){return this.playModeVisible!==void 0?this.playModeVisible:this.object.visible||this.object.dataPatched.visible&&this.object.dataPatched.cloner?.hideBase===!0}set visible(e){}get castShadow(){return this.object.castShadow}set castShadow(e){}get receiveShadow(){return this.object.receiveShadow}set receiveShadow(e){}get isMesh(){return DI(this.object)}get isLight(){return this.object.isLight}get layers(){return this.object.layers}set layers(e){}get isCamera(){return!1}get geometry(){if(this.object.geometry)return this.object.geometry}get material(){if(this.object.material)return this.object.material}};import{Box3 as eN,BufferGeometry as tN,MeshBasicMaterial as rN}from"three";import{Matrix4 as ZE,Mesh as JE}from"three";import{Matrix4 as ru,Vector3 as $x,Euler as zI,MathUtils as Vs}from"three";import{Box3 as _I,Line3 as BI,Matrix4 as Np,Vector3 as cr}from"three";var Xn=new cr,Kn=new cr,ua=new Np,qx=[new cr(-1,1,1),new cr(-1,-1,1),new cr(1,-1,1),new cr(1,1,1),new cr(-1,1,-1),new cr(-1,-1,-1),new cr(1,-1,-1),new cr(1,1,-1)],RI=[[0,3],[1,2],[5,6],[4,7],[0,1],[3,2],[7,6],[4,5],[0,4],[1,5],[2,6],[3,7]],LI=[[0,2],[7,5],[4,1],[3,6],[4,3],[1,6]],Wx=(n,r,e)=>{n.updateEntityBoxSize(Xn,Kn),ua.copy(r).multiply(n.matrixWorld),Kn.x===0&&Kn.y===0&&Kn.z===0?e.push(new cr(Xn.x,Xn.y,Xn.z).applyMatrix4(ua)):qx.forEach(t=>{e.push(t.clone().multiply(Kn).add(Xn).applyMatrix4(ua))})},Ls=class extends _I{constructor(){super(...arguments);this.matrix=new Np;this.vertices=[];this.faces=[];this.edges=[];this.centerEdges=[]}copy(e){return super.copy(e),this.matrix.copy(e.matrix),this.vertices=e.vertices.map(t=>t.clone()),this.faces=e.faces.map(t=>t.clone()),this.edges=e.edges.map(t=>t.clone()),this.centerEdges=e.centerEdges.map(t=>t.clone()),this}setFromObjectSize(e,t=!1){e.updateWorldMatrix(!1,t),this.makeEmpty(),this.matrix.copy(e.matrixWorld);let o=new Np().copy(e.matrixWorld).invert();return this.expandByObjectSize(e,o,t)}expandByObjectSize(e,t,o=!1){let i=[];return o===!0?e.traverseEntity(a=>{if(a.visible||a.cloner&&a.data.visible){if(!("geometry"in a)){i.push(new cr);return}Wx(a,t,i)}}):Wx(e,t,i),this.setFromPoints(i)}getCenter(e){return e=super.getCenter(e),e.applyMatrix4(this.matrix),e}getPositionToCenter(e){return e=super.getCenter(e),e.applyMatrix4(ua.copy(this.matrix).setPosition(0,0,0)),e}computeVertices(){this.getSize(Kn).multiplyScalar(.5),this.getCenter(Xn),ua.copy(this.matrix).setPosition(Xn),this.vertices=qx.map(e=>e.clone().multiply(Kn).applyMatrix4(ua))}computeEdges(){this.vertices.length>0&&this.computeVertices(),this.edges=RI.map(([e,t])=>new BI(this.vertices[e],this.vertices[t])),this.centerEdges=this.edges.map(e=>e.getCenter(new cr))}computeFaces(){this.vertices.length>0&&this.computeVertices(),this.faces=LI.map(([e,t])=>this.vertices[e].clone().add(this.vertices[t]).multiplyScalar(.5))}};var Rr={Cloner:()=>{},changeEntityProptotype:()=>{},createEntity:()=>{}};import{CurvePath as VI,CubicBezierCurve3 as Dp,Vector3 as Lr}from"three";var Bp=class extends VI{constructor(){super()}getPoints(r=12){let e=[],t,o=this.getCurveLengths(),a=o[o.length-1]/o.length;for(let s=0,l=this.curves;s<l.length;s++){let c=l[s],u=s===0?o[s]:o[s]-o[s-1],p=Math.ceil(r*u/a),d=c.getPoints(p);for(let f=0;f<d.length;f++){let h=d[f];t&&t.equals(h)||(e.push(h),t=h)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}};var Rp=.001;function Lp(n,r,e){return r.clone().sub(n).cross(r.clone().sub(e)).length()<=Rp}function _p(n,r){let e=new Lr(...n.position),t=new Lr(...n.controlNext.position),o=new Lr(...r.controlPrevious.position),i=new Lr(...r.position);return Lp(e,t,i)&&Lp(e,o,i)}function tu(n){let r=n.points.map(u=>new Lr(...u.data.position)),e=[n.points[0]],t=new Lr(...e[0].data.position);for(let u=0;u<n.points.length-1;u++)Lp(t,r[u],r[u+1])||(e.push(n.points[u]),t=r[u]);e.push(n.points[n.points.length-1]);let o=n.isClosed,i=e.length-(o?0:1),a=e.length,s=[];for(let u=0;u<a;u++){let p=e[u].data,d=new Lr(...p.position),f=new Lr(...p.controlPrevious.position),h=new Lr(...p.controlNext.position),m={position:d,baseRoundness:p.roundness,controlPrevious:f,controlNext:h};if(p.roundness===0||!n.isClosed&&(u===0||u===a-1)){s[u]={...m,removedLength:0};continue}let y=o&&u==0?a-1:u-1,b=o&&u==a-1?0:u+1,S=e[y].data,P=e[b].data,C=new Lr(...S.position),v=new Lr(...P.position),A=C.clone().sub(d).normalize(),T=v.clone().sub(d).normalize();Object.assign(m,{prevDir:A,nextDir:T});let g=_p(S,p),D=_p(p,P);if(!g||!D)s[u]={...m,removedLength:0};else{let E=A.clone().add(T).normalize(),M=E.clone().cross(A).length()/A.dot(E);s[u]={...m,tan:M,removedLength:p.roundness/M}}}for(let u=0;u<i;u++){let p=u,d=o&&u===a-1?0:u+1,f=s[p],h=s[d];if(f.removedLength!==0||h.removedLength!==0){let m=f.position.distanceTo(h.position);f.removedLength=Math.min(f.removedLength,m/2),h.removedLength=Math.min(h.removedLength,m/2)}}let l=[];for(let u=0;u<i;u++){let p=u,d=o&&u===a-1?0:u+1,f=s[p],h=s[d],m=null;if(!_p(e[p].data,e[d].data))f.position.distanceTo(h.position)>Rp&&(m=new Dp(f.position,f.controlNext,h.controlPrevious,h.position));else{let y=f.position.clone(),b=h.position.clone();(f.removedLength!==0||h.removedLength!==0)&&(f.nextDir&&y.add(f.nextDir.clone().setLength(f.removedLength)),h.prevDir&&b.add(h.prevDir.clone().setLength(h.removedLength))),y.distanceTo(b)>Rp&&(m=new Dp(y,y.clone().lerp(b,.3),b.clone().lerp(y,.3),b))}l[2*u+1]=m}for(let u=0;u<a;u++){let p=s[u];if(p.removedLength===0){l[2*u]=null;continue}let d=p.position,f=p.prevDir.clone().multiplyScalar(p.removedLength).add(d),h=p.nextDir.clone().multiplyScalar(p.removedLength).add(d),m=p.tan*p.removedLength,y=p.prevDir.clone().add(p.nextDir).normalize(),b=f.clone().lerp(h,.5),S=f.distanceTo(h)/2,P=y.clone().multiplyScalar(Math.sqrt(Math.pow(m,2)-Math.pow(S,2))).add(b),C=y.clone().multiplyScalar(-m).add(P),v=d.distanceTo(C)/d.distanceTo(b),A=p.prevDir.clone().multiplyScalar(v*d.distanceTo(f)).add(d),T=A.clone().lerp(C,2),g=f.clone().lerp(A,4/3),D=h.clone().lerp(T,4/3);l[2*u]=new Dp(f,g,D,h)}let c=new Bp;return l.forEach(u=>{u&&c.add(u)}),c}var Le;(r=>{function n(e){return e&&e.__isEntity}r.is=n})(Le||(Le={}));var da=n=>Le.is(n),GI={type:"completeState",isfromEntity:!0},FI=["x","y","z"],Vp=new $x,jI=new $x().set(0,1,0),pa=n=>class extends ca(n){constructor(){super(...arguments);this.raycastLock=!1;this.scaleLock=!1;this.disposed=!1;this.stateSelection=null;this.destroyedInAction=!1;this.instances=[];this.prevState=null;this.currentState=null;this.reversibleToState=null;this.currentTransitionEvent=null;this.previousAction=null;this._singleBBox=new Ls;this._recursiveBBox=new Ls;this.singleBBoxNeedsUpdate=!0;this.recursiveBBoxNeedsUpdate=!0;this._needApplyPathSnapping=!0;this.attachedPaths=new Set}get __isEntity(){return!0}entityChildren(t){let o=this.children[t];if(Le.is(o))return o}entityChildrenCount(){let t=this.children.length;for(;t--;)if(Le.is(this.children[t]))return t+1;return 0}get isConcreteEntity(){return typeof this.identity=="string"}get isVirtualEntity(){return typeof this.identity!="string"}get isInstanceRoot(){return this.isConcreteEntity&&this.data.type==="Instance"}nearestInstanceSelfOrParent(){let t=this;for(;t.data.type!=="Instance";){let o=t.parent;if(Le.is(o))t=o;else return}return t}forInstancesRec(t){this.instances.forEach(o=>{o.disposed||t(o),o.forInstancesRec(t)})}super_Entity(t,o){typeof t=="string"&&(this.uuid=t),this.identity=t,this.data=o,this.matrixAutoUpdate=!1,this.dataPatched=this.data}changeSelectedState(t,o,i=!1){if(!(this.data.states.length===0&&!i)){for(let a of this.data.states)$n.toOps(this.data,a.data).forEach(l=>{let c=Wi.replaceProps(l,this.data);this.dataPatched=this.data,this.updateByPatchedOp(c,this.data,o)});if(t!==null){let a=this.data.states.data(t);a&&(this.dataPatched=$n.patch(this.data,a),$n.toOps(this.data,a).forEach(l=>{this.updateByPatchedOp(l,this.dataPatched,o)}))}i&&this.updateTransformState(this.dataPatched,o),this.stateSelection=t,this.updatePathSnapping(this.dataPatched.pathSnapping)}}get singleBBox(){return this.singleBBoxNeedsUpdate&&(this.singleBBoxNeedsUpdate=!1,this._singleBBox.setFromObjectSize(this,!1),this._singleBBox.computeVertices(),this._singleBBox.computeEdges(),this._singleBBox.computeFaces()),this._singleBBox}get recursiveBBox(){return this.recursiveBBoxNeedsUpdate&&(this.recursiveBBoxNeedsUpdate=!1,this._recursiveBBox.setFromObjectSize(this,!0),this._recursiveBBox.computeVertices(),this._recursiveBBox.computeEdges(),this._recursiveBBox.computeFaces()),this._recursiveBBox}updateEntityBoxSize(t,o){t.setScalar(0),o.setScalar(0)}resetBBoxNeedsUpdateSelf(){this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}resetBBoxNeedsUpdate(){this.resetBBoxNeedsUpdateSelf(),this.traverseAncestors(t=>{da(t)&&t.resetBBoxNeedsUpdateSelf()}),this.traverseEntity(t=>{t.resetBBoxNeedsUpdateSelf()})}find(t){let o;return this.traverseEntity(i=>{i.uuid===t&&(o=i)}),o}traverseSortNextHelper(){let t=this.parent;if(t){let o=t.children,i=o.indexOf(this)+1;if(Le.is(o[i]))return o[i];if(Le.is(t))return t.traverseSortNextHelper()}}sortNext(){let t=this.children;return this.children.length>0&&Le.is(this.children[0])?t[0]:this.traverseSortNextHelper()}goUp(t){let o=this;for(;t>0&&o!==null;)o=o.parent,t-=1;return o}hasAnccestorOrSelf(t){return this===t||this.hasAnccestor(t)}hasAnccestor(t){let o=this.parent;for(;o;){if(t===o)return!0;o=o.parent}return!1}countToAccestor(t){let o=0,i=this;for(;i!==t;){if(i===null)return-1;i=i.parent,o+=1}return o}forEachEntity(t){for(let o of this.children)da(o)&&t(o)}traverseEntityAncestors(t){this.traverseAncestors(o=>{Le.is(o)&&t(o)})}traverseConcreteEntity(t,o=0){if(t(this,o)!==!0)for(let a of this.children)da(a)&&a.isConcreteEntity&&a.traverseEntity(t,o+1)}traverseEntity(t,o=0){if(t(this,o)!==!0)for(let a of this.children)da(a)&&a.traverseEntity(t,o+1)}traverseVisibleEntity(t){t(this);for(let o of this.children)da(o)&&o.visible&&o.traverseVisibleEntity(t)}updateMatrix(){super.updateMatrix(),this.cloner&&this.cloner.onObjUpdateMatrix(),this.dispatchEvent({type:"updateMatrix"})}updateMatrixWorld(t){super.updateMatrixWorld(t),this.dispatchEvent({type:"updateMatrixWorld"})}copy(t,o=!1){return super.copy(t,o),this.dataPatched=t.dataPatched,this.raycastLock=t.raycastLock,this.scaleLock=t.scaleLock,this.hiddenMatrix.copy(t.hiddenMatrix),this}hasEntityChild(){return this.children.some(t=>da(t))}isAncestorOf(t){if(this.uuid===t)return!1;let o=!1;return this.traverseEntity(i=>{i.uuid===t&&(o=!0)}),o}toObjectTransformState(t=[]){this.updateWorldMatrix(!0,!1);let o={position:this.position.toArray(),rotation:[this.rotation.x*Vs.RAD2DEG,this.rotation.y*Vs.RAD2DEG,this.rotation.z*Vs.RAD2DEG],scale:this.scale.toArray(),hiddenMatrix:this.hiddenMatrix.toArray()};return Fi(o,t)}getTransformValues(t,o,i){return o[t].map((a,s)=>i?.shared.getVariable(a,[this.uuid,t,FI[s]])??a)}updateTransformState(t,o){let i=!1;return t.position&&(this.position.fromArray(this.getTransformValues("position",t,o)),i=!0),t.rotation&&(Vp.fromArray(this.getTransformValues("rotation",t,o)).multiplyScalar(Vs.DEG2RAD),this.rotation.setFromVector3(Vp),i=!0),t.scale&&(this.scale.fromArray(this.getTransformValues("scale",t,o)),i=!0),t.hiddenMatrix!==void 0&&(i=!0,this.hiddenMatrix.fromArray(t.hiddenMatrix??sn.identity)),i&&(this.updateMatrix(),this.resetBBoxNeedsUpdate(),this.invalidateClonerTransform(this),this.traverseEntityAncestors(a=>{a.invalidateClonerTransform(this)})),t.position&&t.rotation&&t.scale&&t.hiddenMatrix!==void 0&&this.updateWorldMatrix(!1,!0),i}onVariableUpdate(t=!1){if(t){this.resetBBoxNeedsUpdate();return}this.updateMatrix(),this.resetBBoxNeedsUpdate(),this.invalidateClonerTransform(this),this.traverseEntityAncestors(o=>{o.invalidateClonerTransform(this)})}dispose(){this.disposed=!0,this.cloner&&(this.cloner.removeFromParent(),this.cloner=void 0)}disposeChildrenRecursively(){for(let t of this.children)Le.is(t)&&t.disposeRecursively()}disposeRecursively(){this.dispose(),this.children.forEach(t=>{Le.is(t)&&t.disposeRecursively()})}toState(t=[]){let o={name:this.name,visible:this.visible,raycastLock:this.raycastLock,...this.toObjectTransformState(t)};return Fi(o,t)}updateByObjUpdateOp(t,o){t!==void 0&&this.updateByOp({type:0,props:t,path:[]},{...this.data,...t},o,!1)}updateByOp(t,o,i,a){let s=this.data;this.data=o;let l=t,c=Re(t.path,["states","*"]);if(c!==null){if(t.type===0){let[u]=c;if(this?.stateSelection===u){let p={...t.props};if(delete p.name,Object.values(t.props).some(d=>d===void 0)){let d=this.data;if(d!==void 0){let f=Ze.zoom(d,t.path.slice(2));if(f)for(let h in t.props)t.props[h]===void 0&&h in f&&(p[h]=f[h])}}l={...t,props:p,path:t.path.slice(2)}}}}else if(t.type===0){let u=this.stateSelection?this.data.states.data(this.stateSelection):void 0;if(u!==void 0){if(t.props.name!==void 0&&u.name){let{name:d,...f}=u;u=f}if(t.props.material!==void 0&&"material"in u){let{material:d,...f}=u;u=f}let p=Ze.removeOverridden(t.path,t.props,u);l={...t,props:p}}}if(this.updateByPatchedOpBase(l,$n.patch(this.data,this.stateSelection?this.data.states.data(this.stateSelection):void 0),i),Re(t.path,["overrides"])){let u=[],p=[...t.path];for(u.push(p[1]),p.splice(0,2);p.length>0&&p[0]==="descendants";)u.push(p[1]),p.splice(0,2);if(u[u.length-1]===void 0){if(t.type===0)for(let d of Object.keys(t.props)){u[u.length-1]=d;let f=i.scene.findInstance([this.uuid,...u]);f&&(f.overrideData=t.props[d],f.updateState(Kr.apply(f.component.data,f.overrideData),i))}}else{let d=i.scene.findInstance([this.uuid,...u]);if(d){let f=Ze.zoom(d.component.data,p);if(t={...t,path:p},t.type===0){let h=t.props;if(f)for(let[m,y]of Object.entries(t.props))y===void 0&&(h===t.props&&(h={...t.props}),h[m]=f[m]);t={...t,props:h}}d.overrideData=ta.resolve(o.overrides,u),d.updateByOp(t,nt.applySimple(d.data,t),i,!1)}}}else if(this.instances.length>0){let u;if(t.path.length===0&&t.type===0){let p;for(let d of ro.rootOverrideProps)d in t.props&&(p===void 0&&(p={}),p[d]=t.props[d]);p&&(u={...t,props:p})}else for(let p of ro.rootOverrideProps)if(Re(t.path,[p])){u=t;break}u!==void 0&&this.instances.forEach(p=>{if(p.isInstanceRoot){let d=Kr.filterOp(p.overrideData,u);d&&p.updateByOp(d,nt.applySimple(p.data,d),i,!0)}}),this.instances.forEach(p=>{if(!p.isInstanceRoot){let d=Kr.filterOp(p.overrideData,t);if(d){let f;s===p.data&&t===d?f=o:f=nt.applySimple(p.data,d),p.updateByOp(d,f,i,!0)}}})}}updateByPatchedOpBase(t,o,i){if(this.dataPatched=o,t.path.length===0&&t.type===0)t.props.type!==void 0&&!Nr.is(t.props.type)&&Rr.changeEntityProptotype(this,o,i);else if(t.path.length===1&&t.path[0]==="geometry"&&t.type===0&&"type"in t.props){Rr.changeEntityProptotype(this,o,i);for(let a of this.children)Le.is(a)&&a.updateVisible(i.scene)}this.updateByPatchedOp(t,o,i)}updateByPatchedOp(t,o,i){if(t.path.length===0&&t.type===0&&this.updateState(t.props,i),t.path[0]==="morphTargetInfluences"&&t.type===0){let s=o.morphTargetInfluences.get(t.path[1])?.data.name;s&&this.updateMorphInfluences(s,i.shared.getVariable(t.props.value,[this.uuid,"morphTargetInfluences",s]))}if(Re(t.path,["pathSnapping"])!==null&&this.updatePathSnapping(o.pathSnapping),Re(t.path,["cloner"])!==null){let a=nt.drop(t,1);a.path.length===0&&a.type===0&&a.props.disabled===!0?this.setFromClonerState(null,i):this.cloner?this.cloner.updateState(o.cloner,i.scene):(this.setFromClonerState(o.cloner,i),this.expandCloner(i.scene)),this.updateVisible(i.scene)}}updatePathSnapping(t=this.dataPatched.pathSnapping){this._updatedPathSnapping=t,this._needApplyPathSnapping=!0}get updatedPathSnapping(){return this._updatedPathSnapping}applyPathSnapping(t){let o=this._updatedPathSnapping?.pathId??this.dataPatched.pathSnapping.pathId,i=this._updatedPathSnapping?.slide??this.dataPatched.pathSnapping.slide??0,a=this._updatedPathSnapping?.offset??this.dataPatched.pathSnapping.offset??0,s=this._updatedPathSnapping?.orientation??this.dataPatched.pathSnapping.orientation;if(o===null)return;let l=t.find(o);if(!l||this._needApplyPathSnapping===!1)return;this._needApplyPathSnapping=!1;let c=l.data;if(c.geometry.path.points.length<=1)return;let u=tu(c.geometry.path),p=(i+a)%1;i+a===1&&p===0&&(p=1);let d=null;try{d=u.curves.length?u.getPointAt(p):null}catch(y){!1&&(console.warn(`The aligned path on ${this.name} is invalid. (${l.name})`),console.error(y))}if(d===null)return;let f=this.parent?this.parent?.matrixWorld:new ru;l.updateMatrixWorld();let h=new ru().multiplyMatrices(f.clone().invert(),l.matrixWorld);d.applyMatrix4(h);let m={position:d.toArray(),rotation:c.rotation};if(s==="tangential"){let y=new ru().extractRotation(l.matrixWorld),b=u.getTangentAt(p).applyMatrix4(y).add(d),S=new ru().lookAt(d,b,jI),P=Vp.setFromEuler(new zI().setFromRotationMatrix(S)).multiplyScalar(Vs.RAD2DEG);m={...m,rotation:P.toArray()}}this.updateTransformState(m),this.traverseEntity(y=>{y._cameraType&&y.dispatchEvent(GI)})}updateVisible(t){if(this.visible=this.dataPatched.visible&&(!this.dataPatched.cloner||(this.dataPatched.cloner.disabled??!1)||this.dataPatched.cloner?.hideBase!==!0),!t)return;let o=!1;this.traverseEntity(i=>{if(i.data.type==="Splat")return o=!0,!0}),o&&t.reloadSplats()}updateState_Entity(t,o){t.name!==void 0&&(this.name=t.name),t.raycastLock!==void 0&&(this.raycastLock=t.raycastLock),t.visible!==void 0&&(this.updateVisible(o?.scene),this.resetBBoxNeedsUpdate()),o&&"cloner"in t&&t.cloner!==void 0&&(this.setFromClonerState(t.cloner,o),this.updateVisible(o.scene)),this.updateTransformState(t,o)}get attachedSurfaceCloners(){return this.children.filter(t=>t instanceof Rr.Cloner&&t.parameters.type==="toObject")}setFromClonerState(t,o){this.disposed||(t===null||t.disabled?(this.cloner&&this.cloner.removeFromParent(),this.cloner=void 0):this.cloner===void 0?(this.cloner=new Rr.Cloner(this,t),o.scene.addPendingExpandCloner(this)):this.cloner.updateState(t,o.scene))}expandCloner(t){!this.disposed&&this.cloner&&this.cloner.expandClones(t)}invalidateClonerTransform(t){this.cloner&&this.cloner.invalidateTransform(t)}requestRender(){this.dispatchEvent({type:"requestRender"})}};import{BufferGeometry as HI,ConeGeometry as WI,Float32BufferAttribute as qI,MathUtils as $I}from"three";import{BufferGeometry as Xx,CylinderGeometry as kI,Float32BufferAttribute as nu,MathUtils as UI,Vector2 as Vr,Vector3 as ou}from"three";var Kx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:64,heightSegments:1,openEnded:!1,thetaStart:0,thetaLength:360,cornerRadius:8,cornerSegments:8,hollow:0},n.parameters);e.thetaLength=UI.clamp(e.thetaLength,0,360);let t=e.width/2,o=e.radiusTop??t,i=e.radiusBottom??t;return o===i?(o=t,i=t):o>i?(o=t,i=i*t/o):(o=o*t/i,i=t),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width),radiusTop:o,radiusBottom:i})}}static build(n){let{width:r,depth:e,height:t,radialSegments:o,heightSegments:i,openEnded:a,thetaStart:s,thetaLength:l,radiusTop:c,radiusBottom:u,cornerRadius:p,cornerSegments:d,hollow:f}=n.parameters,h;return l===0?(h=new Xx,h.setAttribute("position",new nu([],3))):p||f?h=new zs(c,u,t,o,i,a,s,l*Math.PI/180,p,p,d,f):h=new kI(c,u,t,o,i,a,s,l*Math.PI/180),h.scale(1,1,e/r),Object.assign(h,{userData:{...n,type:"CylinderGeometry"}})}};function hn(n,r,e){e.x=n.x*r.x,e.y=n.y,e.z=n.x*r.y}function Yx(n){return new Vr(n.y,-n.x)}var zs=class extends Xx{constructor(r,e,t,o,i,a,s,l,c,u,p,d,f=!1){super(),this.type="RoundedCylinderBufferGeometry",r=r!==void 0?r:1,e=e!==void 0?e:1,t=t||1,o=Math.floor(o)||8,i=Math.floor(i)||1,a=a!==void 0?a:!1,s=s!==void 0?s:0,l=l!==void 0?l:Math.PI*2,a&&(c=0,u=0);let h=[],m=[],y=[],b=[],S=0,P=t/2,C=new ou,v=new ou;f&&r==0&&(r=c),f&&e==0&&(e=u);let A=new Vr(r,P),T=new Vr(e,-P),g=null,D=null,E=null,M=null,N=A.clone().sub(T),_=0,B=0,V=0;d>0&&(_=Math.min(r,e)*(1-d),B=r-_,V=e-_);let k=A.clone();k.x-=_;let L=Math.PI-N.angle(),W=N.angle(),F=Math.tan(W/2),j=Math.tan(L/2),H=F+j,q=d?H:j,re=d?H:F;if(c=Math.min(c,(r-B)/q,N.length()/H),u=Math.min(u,(e-V)/re,N.length()/H),c>0){let Q=c/F;g=A.clone().sub(new Vr(Q,c)),d&&(E=g.clone(),E.x-=_-H*c),A.sub(N.clone().setLength(Q))}if(u>0){let Q=u/j;D=T.clone().sub(new Vr(Q,-u)),T.add(N.clone().setLength(Q)),d&&(M=D.clone(),M.x-=_-H*u,k.sub(N.clone().setLength(Q)))}N=A.clone().sub(T);let ee=N.length()<.5,X=[];for(let Q=0;Q<=o;Q++){let $=[],ue=Q/o,le=ue*l+s,ne=new Vr(Math.sin(le),Math.cos(le));M&&D?(te($,ue,ne,L,u,M,-1,!0),te($,ue,ne,W,u,D,-1,!1)):D?(K($,ne,D.x,0,-1),te($,ue,ne,W,u,D,-1,!1)):a||K($,ne,e,V,-1);let ce=Yx(N).normalize();if(hn(ce,ne,C),!ee)for(let ae=0;ae<=i;ae++){let me=ae/i,pe=N.clone().multiplyScalar(me).add(T);hn(pe,ne,v),m.push(v.x,v.y,v.z),y.push(C.x,C.y,C.z),b.push(ue,.5+v.y/t),$.push(S++)}if(E&&g?(te($,ue,ne,L,c,g,1,!1),te($,ue,ne,W,c,E,1,!0)):g?(te($,ue,ne,L,c,g,1,!1),K($,ne,g.x,0,1)):a||K($,ne,r,B,1),d&&!ee){let ae=Yx(N).multiplyScalar(-1).normalize();hn(ae,ne,C);for(let me=0;me<=i;me++){let pe=me/i,he=N.clone().multiplyScalar(-pe).add(k);hn(he,ne,v),m.push(v.x,v.y,v.z),y.push(C.x,C.y,C.z),b.push(ue,.5+v.y/t),$.push(S++)}}d&&!a&&$.push($[0]),X.push($)}for(let Q=0;Q<X.length-1;Q++)for(let $=0;$<X[0].length-1;$++){if(a&&d&&$==i)continue;let ue=X[Q][$],le=X[Q+1][$],ne=X[Q+1][$+1],ce=X[Q][$+1],ae=m[ne*3+0],me=m[ne*3+2];h.push(ue,le,ce),(ae!=0||me!=0)&&h.push(le,ne,ce)}l<Math.PI*2&&(Z(-1,X[0],s),Z(1,X[X.length-1],s+l)),this.setIndex(h),this.setAttribute("position",new nu(m,3)),this.setAttribute("normal",new nu(y,3)),this.setAttribute("uv",new nu(b,2));function te(Q,$,ue,le,ne,ce,ae,me){for(let pe=0;pe<p+1;pe++){let he=pe/p,xe=ae<0?he:1-he;me&&(xe-=1),xe*=le;let ye=new Vr(Math.sin(xe),Math.cos(xe)*ae),O=ye.clone().multiplyScalar(ne).add(ce);hn(O,ue,v),m.push(v.x,v.y,v.z),hn(ye,ue,C),y.push(C.x,C.y,C.z),b.push($,.5+v.y/t),Q.push(S++)}}function K(Q,$,ue,le,ne){let ce=new ou,ae=new Vr,me=[ue,le];ne<0&&me.reverse();for(let pe of me)ae.set(pe,P*ne),hn(ae,$,ce),m.push(ce.x,ce.y,ce.z),y.push(0,ne,0),b.push(.5,.5),Q.push(S++)}function Z(Q,$,ue){let le=new Vr(Math.sin(ue),Math.cos(ue)),ne=new Vr(-Math.cos(ue),Math.sin(ue)),ce=new ou,ae=Q<0?(he,xe,ye)=>h.push(he,xe,ye):(he,xe,ye)=>h.push(he,ye,xe),me=new Vr((r+e+B+V)/4,0);hn(me,le,ce),m.push(ce.x,ce.y,ce.z),y.push(ne.x,0,ne.y),b.push(.5,.5);let pe=S++;for(let he of $){let xe=m.slice(he*3,he*3+3);m.push(...xe),y.push(ne.x,0,ne.y);let ye=b.slice(he*2,he*2+2);b.push(...ye),S++}for(let he=pe+1;he<S-1;he++)ae(pe,he,he+1);ae(pe,S-1,pe+1)}}};var Qx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:32,heightSegments:8,openEnded:!1,thetaStart:0,thetaLength:360,cornerRadiusTop:8,cornerRadiusBottom:8,cornerSegments:8},n.parameters);return e.thetaLength=$I.clamp(e.thetaLength,0,360),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,depth:e,height:t,radialSegments:o,heightSegments:i,openEnded:a,thetaStart:s,thetaLength:l,cornerRadiusTop:c,cornerRadiusBottom:u,cornerSegments:p}=n.parameters,d;return l===0?(d=new HI,d.setAttribute("position",new qI([],3))):c>0||u>0||l<360?d=new zs(0,r/2,t,o,i,a,s,l*Math.PI/180,c,u,p,0,!0):d=new WI(r/2,t,o,i,a),d.scale(1,1,e/r),Object.assign(d,{userData:{...n,type:"ConeGeometry"}})}};import{BoxGeometry as YI,BufferGeometry as XI,Float32BufferAttribute as zp,Vector3 as Gs}from"three";var Zx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,widthSegments:1,heightSegments:1,depthSegments:1,cornerRadius:8,cornerSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,widthSegments:o,heightSegments:i,depthSegments:a,cornerRadius:s,cornerSegments:l}=n.parameters,c;return s===0?c=new YI(r,e,t,o,i,a):c=new Fp(r,e,t,o,i,a,s,l),Object.assign(c,{userData:{...n,type:"CubeGeometry"}})}},Gp=Math.PI/2,Fp=class extends XI{constructor(r=1,e=1,t=1,o=1,i=1,a=1,s=0,l=4){super(),this.type="BoxGeometry",o=Math.floor(o),i=Math.floor(i),a=Math.floor(a),l=Math.floor(l),s=Math.min(s,r/2,e/2,t/2);let c=[],u=[],p=[],d=[],f=0;h("z","y","x",-1,-1,t,e,r,a,i),h("z","y","x",1,-1,t,e,-r,a,i),h("x","z","y",1,1,r,t,e,o,a),h("x","z","y",1,-1,r,t,-e,o,a),h("x","y","z",1,-1,r,e,t,o,i),h("x","y","z",-1,-1,r,e,-t,o,i),s>0&&(m("z","y","x",-1,-1,1,t,e,r,a),m("z","y","x",1,-1,-1,t,e,r,a),m("z","y","x",-1,1,-1,t,e,r,a),m("z","y","x",1,1,1,t,e,r,a),m("x","y","z",-1,-1,-1,r,e,t,o),m("x","y","z",1,-1,1,r,e,t,o),m("x","y","z",-1,1,1,r,e,t,o),m("x","y","z",1,1,-1,r,e,t,o),m("y","x","z",-1,-1,1,e,r,t,i),m("y","x","z",1,-1,-1,e,r,t,i),m("y","x","z",1,1,1,e,r,t,i),m("y","x","z",-1,1,-1,e,r,t,i),y(1,1,1),y(-1,1,1),y(1,-1,1),y(-1,-1,1),y(1,1,-1),y(-1,1,-1),y(1,-1,-1),y(-1,-1,-1)),this.setIndex(c),this.setAttribute("position",new zp(u,3)),this.setAttribute("normal",new zp(p,3)),this.setAttribute("uv",new zp(d,2));function h(b,S,P,C,v,A,T,g,D,E){let M=(A-2*s)/D,N=(T-2*s)/E,_=A/2-s,B=T/2-s,V=g/2,k=D+1,L=E+1,W=0,F=new Gs;for(let j=0;j<L;j++){let H=j*N-B;for(let q=0;q<k;q++){let re=q*M-_;F[b]=re*C,F[S]=H*v,F[P]=V,u.push(F.x,F.y,F.z),F[b]=0,F[S]=0,F[P]=g>0?1:-1,p.push(F.x,F.y,F.z),d.push(q/D),d.push(1-j/E),W+=1}}for(let j=0;j<E;j++)for(let H=0;H<D;H++){let q=f+H+k*j,re=f+H+k*(j+1),ee=f+(H+1)+k*(j+1),X=f+(H+1)+k*j;c.push(q,re,X),c.push(re,ee,X)}f+=W}function m(b,S,P,C,v,A,T,g,D,E){let M=(T-2*s)/E,N=T/2-s,_=g/2-s,B=D/2,V=E+1,k=0,L=new Gs,W=new Gs;for(let F=0;F<l+1;F++){let j=F/l*Gp,H=Math.sin(j)*s,q=(1-Math.cos(j))*s,re=Math.sin(j),ee=Math.cos(j);L[S]=(_+H)*v,L[P]=(B-q)*A,W[b]=0,W[S]=re*Math.sign(L[S]),W[P]=ee*Math.sign(L[P]);for(let X=0;X<V;X++){let te=X*M-N;L[b]=te*C,u.push(L.x,L.y,L.z),p.push(W.x,W.y,W.z),d.push(X/E),d.push(0),k+=1}}for(let F=0;F<l;F++)for(let j=0;j<E;j++){let H=f+j+V*F,q=f+j+V*(F+1),re=f+(j+1)+V*(F+1),ee=f+(j+1)+V*F;c.push(H,q,ee),c.push(q,re,ee)}f+=k}function y(b,S,P){let C=new Gs,v=new Gs(r/2,e/2,t/2);v.subScalar(s);let A=[],T=b*S*P>0?(D,E,M)=>c.push(D,E,M):(D,E,M)=>c.push(D,M,E);for(let D=0;D<=l;D++){let E=[],M=Gp*(1-D/l),N=Math.cos(M),_=Math.sin(M),B=0;for(let V=0;V<=D;V++){let k=Math.cos(B),L=Math.sin(B);C.x=N*k,C.y=_,C.z=N*L;let W=v.clone().addScaledVector(C,s);u.push(b*W.x,S*W.y,P*W.z),p.push(b*C.x,S*C.y,P*C.z),d.push(0,0),E.push(f++),B+=Gp/D}A.push(E)}let g=A.length-1;for(let D=0;D<g;D++){let E=A[D],M=A[D+1],N=E.length-1;T(E[0],M[1],M[0]);for(let _=1;_<=N;_++)T(E[_-1],E[_],M[_]),T(E[_],M[_+1],M[_])}}}};import{BufferGeometry as KI,Float32BufferAttribute as jp,Triangle as QI,Vector3 as Bo,Vector2 as kp}from"three";var mn=class extends KI{constructor(r=[],e=[],t="",o=1,i=.2,a=4){super(),this.type="PolyhedronGeometryRound";let s=[],l=[],c=[];u(),p(),this.setAttribute("position",new jp(s,3)),this.setAttribute("normal",new jp(c,3)),this.setAttribute("uv",new jp(l,2));return;function u(){i=Math.min(1-1e-5,i),i==0&&(a=0);let f={IcosahedronGeometry:5,DodecahedronGeometry:3,HexahedronGeometry:3,OctahedronGeometry:4,TetrahedronGeometry:3}[t],h=new Bo,m=h.clone(),y=new QI,b=i*o,S=o-b,P=a+1,C=new Bo,v=(F,j)=>C.subVectors(F,j).normalize(),A=(F,j)=>Array(F).fill(void 0).map(j),T=A(r.length/3,(F,j)=>new Bo().fromArray(r,j*3).setLength(o)),g=[],D=1e6;for(let F=0;F<T.length;F++){let j=T[F],H=[],q,re,ee,X=1e10,te=-1;for(;(te=e.indexOf(F,te+1))!=-1;){let $=te-te%3;q=e[$+(te+1)%3],re=e[$+(te+2)%3],ee=j.distanceToSquared(T[q]),X=Math.min(X,ee),H.push([q,re,ee])}X+=1e-6;let K=[],Z=0,Q=H.length;for(let $=0;$<Q;$++){[q,re,ee]=H[Z];let ue=g[q]?.includes(F)==!0;ee<=X&&K.push(q+ +ue*D),Z=H.findIndex(le=>le[0]==re)}g.push(K)}let E=[];{let F=0,j=0,H,q,re=f==3;for(let ee=0;ee<=a;ee++){H=ee*(ee+1)/2,q=(ee+1)*(ee+2)/2;for(let X=0;X<a-ee;X++)[F,j]=[H+X+ee+2,q+X+ee+3],E.push(H,q,...re?[j,H]:[F,q],j,F),[H,q]=[F,j];E.push(H,q,H+a+2)}}let M=h.clone(),N=h.clone(),_=h.clone(),B=h.clone(),V=h.clone(),k=[],L=A(T.length,()=>A(f,()=>h.clone()));for(let F=0;F<T.length;F++){h.copy(T[F]).normalize(),M.copy(h).multiplyScalar(S);let j=g[F];for(let K=0;K<j.length;K++){let Z=j[K],Q=j[(K+1)%f];y.setFromPointsAndIndices(T,F,Z%D,Q%D),y.b.sub(y.a).setLength(1e10).add(y.a),y.c.sub(y.a).setLength(1e10).add(y.a),y.closestPointToPoint(M,L[F][K])}let H=[],q=[],re=[],ee=new Bo;a==0&&[...L[F]].reduce((K,Z)=>K.add(Z),ee).multiplyScalar(1/f);for(let K=0;K<f;K++){let Z=[],Q=(K-1+f)%f,$=L[F][Q],ue=L[F][K];h.copy($).sub(M),m.copy(ue).sub(M);let le=M.angleTo(h),ne=h.angleTo(m),ce=Math.cos(le)*b;a==0?N.copy(ee):N.copy(M).setLength(S+ce),q.push(ce);let ae=[N,$,ue];for(let me=0;me<2;me++){let pe=ae[me],he=ae[me+1];B.subVectors(pe,M),V.subVectors(he,M),_.crossVectors(B,V).normalize();for(let xe=0;xe<P;xe++){let ye=[le,ne][me]*xe/P;h.copy(B).applyAxisAngle(_,ye).add(M),H.push(h.clone()),me&&(v(h,M),Z.push([xe==0?pe:h.clone(),C.clone()]))}me&&(v(he,M),Z.push([he,C.clone()]))}re.push(Z)}k.push(re);let X=2*P,te=2;for(let K=0;K<f;K++){let Z=X*K,Q=X*((K+1)%f),$=[H[Z]];for(let le=1;le<P;le++){B=H[Z+le],V=H[Q+le],$.push(B);for(let ne=1,ce=le-te+1;ne<=ce;ne++)h.lerpVectors(B,V,ne/(ce+1)),h.sub(M).setLength(q[K]).add(M),$.push(h.clone());$.push(V)}for(let le=0;le<P;le++)$.push(H[le+P+Z]);$.push(H[Q+P]);let ue=E.map(le=>$[le]);s.push(...ue.map(le=>[le.x,le.y,le.z]).flat()),c.push(...ue.map(le=>(v(le,M),[C.x,C.y,C.z])).flat())}}let W=[];for(let F=0;F<g.length;F++)for(let j=0;j<f;j++){let H=g[F][j];if(H<D){let q=g[H].findIndex(X=>X%D==F),re=k[F][j],ee=k[H][q];for(let X=0;X<P;X++){let te=re[X],K=ee[P-X],Z=re[X+1],Q=ee[P-(X+1)];[te,K,Z,Z,K,Q].forEach($=>{s.push($[0].x,$[0].y,$[0].z),c.push($[1].x,$[1].y,$[1].z)})}W.push(re[0][0],ee[P][0],re[P][0],ee[0][0])}}for(;W.length;){let F,j,H,q;[F,j]=W.splice(0,2);let re=[F];for(;F!=j;)re.push(j),H=W.indexOf(j),q=H%2,j=W.splice(H-q,2)[1-q];C.subVectors(re[0],re[1]).cross(h.subVectors(re[0],re[2])).normalize();let ee=C.dot(re[0])<0;ee&&C.negate();for(let X=1;X<=re.length-2;X++)[re[X+ +ee],re[X+1-+ee],re[0]].forEach(te=>{s.push(te.x,te.y,te.z),c.push(C.x,C.y,C.z)})}}function p(){let d=new Bo;for(let T=0;T<s.length;T+=3){d.x=s[T+0],d.y=s[T+1],d.z=s[T+2];let g=v(d)/2/Math.PI+.5,D=A(d)/Math.PI+.5;l.push(g,1-D)}let f=new Bo,h=new Bo,m=new Bo,y=new Bo,b=new kp,S=new kp,P=new kp,C=(T,g,D,E)=>{E<0&&T.x===1&&(l[g]=T.x-1),D.x===0&&D.z===0&&(l[g]=E/2/Math.PI+.5)};for(let T=0,g=0;T<s.length;T+=9,g+=6){f.set(s[T+0],s[T+1],s[T+2]),h.set(s[T+3],s[T+4],s[T+5]),m.set(s[T+6],s[T+7],s[T+8]),b.set(l[g+0],l[g+1]),S.set(l[g+2],l[g+3]),P.set(l[g+4],l[g+5]),y.copy(f).add(h).add(m).divideScalar(3);let D=v(y);C(b,g+0,f,D),C(S,g+2,h,D),C(P,g+4,m,D)}for(let T=0;T<l.length;T+=6){let g=l[T+0],D=l[T+2],E=l[T+4],M=Math.max(g,D,E),N=Math.min(g,D,E);M>.9&&N<.1&&(g<.2&&(l[T+0]+=1),D<.2&&(l[T+2]+=1),E<.2&&(l[T+4]+=1))}function v(T){return Math.atan2(T.z,-T.x)}function A(T){return Math.atan2(-T.y,Math.sqrt(T.x*T.x+T.z*T.z))}}}static fromJSON(r){return new mn(r.vertices,r.indices,r.radius,r.corner,r.cornerSides)}};import{DodecahedronGeometry as ZI}from"three";var Jx=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,detail:0,corner:0,cornerSides:4},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,detail:o,corner:i,cornerSides:a}=n.parameters,s=o===0&&i!==0?new Fs(r*.5,i,a):new ZI(r*.5,o);return s.scale(1,e/r,t/r),Object.assign(s,{userData:{...n,type:"DodecahedronGeometry"}})}},Fs=class extends mn{constructor(r=1,e=.2,t=4){let o=(1+Math.sqrt(5))/2,i=1/o,a=[-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-o,0,-i,o,0,i,-o,0,i,o,-i,-o,0,-i,o,0,i,-o,0,i,o,0,-o,0,-i,o,0,-i,-o,0,i,o,0,i],s=[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],l="DodecahedronGeometry";super(a,s,l,r,e,t),this.type=l}static fromJSON(r){return new Fs(r.radius,r.corner,r.cornerSides)}};import{Plane as cM,Shape as h0,Vector2 as Ro,Vector3 as uM,MathUtils as Xp,LineCurve as Kp,QuadraticBezierCurve as m0,CubicBezierCurve as lu}from"three";import{CubicBezierCurve as iu,EllipseCurve as JI,LineCurve as au,LineCurve3 as eM,MathUtils as tM,QuadraticBezierCurve as Hp,SplineCurve as rM,Vector2 as Ht,Vector3 as r0}from"three";var js=1e-12,fa=class{constructor(r){this.position=new Ht;this.startPosition=new Ht;this.uuid=tM.generateUUID();this.position=r.clone()}start(){this.reset()}reset(){this.startPosition.copy(this.position)}applyOffset(r){this.position.copy(this.startPosition).add(r)}copy(r){return this.position.copy(r.position),this.startPosition.copy(r.startPosition),this}clone(){return new fa(this.position).copy(this)}toJSON(){return[this.position.x,this.position.y]}},ha=class extends fa{constructor(e){super(e.position);this.parent=e}copy(e){return super.copy(e),this}clone(){return new ha(this.parent).copy(this)}},zr=class extends fa{constructor(e,t){super(t);this.controls=[];this.roundness=0;this.areControlsDirectionsMirrored=!0;this.uuid=e,this.controls.push(new ha(this),new ha(this))}static create(e,t){let o=new zr(e,new Ht(...t.position));return o.controls[0].position.set(...t.controlPrevious.position),o.controls[1].position.set(...t.controlNext.position),o.roundness=t.roundness,o.areControlsDirectionsMirrored=t.areControlsDirectionsMirrored,o}getOppositeControl(e){let t=this.controls.indexOf(e);return t===0?this.controls[1]:t===1?this.controls[0]:null}applyOffsetToControls(e,t=1){for(let o=0,i=this.controls.length;o<i;o++){let a=this.controls[o];this.position.distanceTo(a.position)<=t?a.position.copy(this.position):a.applyOffset(e)}}controlsMoved(){return!(this.position.equals(this.controls[0].position)&&this.position.equals(this.controls[1].position))}copy(e){return super.copy(e),this.controls[0].copy(e.controls[0]),this.controls[1].copy(e.controls[1]),this.roundness=e.roundness,this.uuid=e.uuid,this}clone(){return new zr(this.uuid,this.position).copy(this)}toJSON(){return super.toJSON().concat(this.controls[0].toJSON(),this.controls[1].toJSON(),[this.roundness])}computeTangents(){let e=this.curveBefore?.getTangentAt(1),t=this.curveAfter?.getTangentAt(0);return[e,t]}computeNormals(e=new Ht,t=new Ht){let[o,i]=this.computeTangents();return o&&i&&(e0(o,e),e0(i,t)),[e,t]}computeTangent(e=new Ht){let[t,o]=this.computeTangents();return t&&o&&e.copy(t).add(o).normalize(),e}computeNormal(e=new Ht){let[t,o]=this.computeNormals();return e.copy(t).add(o).normalize(),e}};function e0(n,r=new Ht){let e=n.length();return r.set(-n.y/e,n.x/e)}var Wp=n=>n,ma=new Ht,su=new Ht,oM=new Ht,nM=new Ht,iM=new Ht,aM=new Ht,o0=new r0,n0=new r0;function i0(n){let r=new Ht;r.addVectors(n.v0,ma.subVectors(n.v1,n.v0).multiplyScalar(2/3));let e=new Ht;return e.addVectors(n.v2,su.subVectors(n.v1,n.v2).multiplyScalar(2/3)),new iu(n.v0,r,e,n.v2)}function ks(n,r,e=Number.EPSILON){return Math.abs(n-r)<e}function sM(n,r,e=Number.EPSILON){return n.distanceTo(r)<e}function lM(n,r,e=Number.EPSILON){return n.distanceTo(r)<e}function qp(n,r,e){let t=Math.sqrt(Math.pow(r.x-n.x,2)+Math.pow(r.y-n.y,2)),o=Math.sqrt(Math.pow(r.x-e.x,2)+Math.pow(r.y-e.y,2)),i=Math.sqrt(Math.pow(e.x-n.x,2)+Math.pow(e.y-n.y,2));return Math.acos((o*o+t*t-i*i)/(2*o*t))}function a0(n,r,e){return t0(n,r)&&t0(r,e)&&Up(n.position,r.position,e.position)}function Up(n,r,e){return ma.copy(r).sub(n).cross(su.copy(e).sub(n))===0}function s0(n,r,e,t,o){let i=Math.sqrt(Math.pow(r.x-n.x,2)+Math.pow(r.y-n.y,2)),a=(n.y+r.y)/2,s=(n.x+r.x)/2,l=Math.sqrt(Math.pow(e,2)-Math.pow(i/2,2))*(n.y-r.y)/i,c=Math.sqrt(Math.pow(e,2)-Math.pow(i/2,2))*(r.x-n.x)/i;return t.set(s+l,a+c),o.set(s-l,a-c),[t,o]}function l0(n,r,e){let t=n.distanceTo(e),o=r.distanceTo(e);return t<o?r:n}function c0(n,r,e,t,o,i){let a=r.x-n.x,s=r.y-n.y,l=e.x-n.x,c=e.y-n.y,u=Math.sqrt((a+l)*(a+l)+(s+c)*(s+c)),p;return qp(r,n,e)>Math.PI&&(u*=-1),ks(c,s)?p=(s+c)*(t/u-.5)*8/3/(a-l):p=(a+l)*(t/u-.5)*8/3/(c-s),o.set(r.x-p*s,r.y+p*a),i.set(e.x+p*c,e.y-p*l),[o,i]}function $p(n,r){return n.position.equals(n.controls[1].position)&&r.position.equals(r.controls[0].position)}function t0(n,r){return Up(n.position,n.controls[1].position,r.position)&&Up(n.position,r.controls[0].position,r.position)}function u0(n,r,e,t,o=.5){let i=ma.subVectors(r,n).multiplyScalar(o).add(n),a=su.subVectors(e,r).multiplyScalar(o).add(r),s=oM.subVectors(t,e).multiplyScalar(o).add(e),l=i,c=nM.subVectors(a,i).multiplyScalar(o).add(i),u=iM.subVectors(s,a).multiplyScalar(o).add(a),p=s,d=aM.subVectors(u,c).multiplyScalar(o).add(c);return[n.x,n.y,l.x,l.y,c.x,c.y,d.x,d.y,u.x,u.y,p.x,p.y,t.x,t.y]}function d0(n,r,e=12,t=!0){let o=n0.set(0,0,0),i,a=0,s=[];for(let l=0;l<r.length;l++){let c=Wp(r[l]),u=ma,p=yn(c,e);s.push(p);for(let d=0;d<=p;d++)if(c instanceof iu||c instanceof Hp||c instanceof au){if(c.getPoint(d/p,u),o.set(u.x,u.y,0),i!==void 0&&lM(i,o))continue;i===void 0&&(i=o0),i.copy(o),n.setXYZ(a,o.x,o.y,o.z),a++}}return t&&a>1&&!(n.getX(a-1)===n.getX(0)&&n.getY(a-1)===n.getY(0)&&n.getZ(a-1)===n.getZ(0))&&(n.setXYZ(a,n.getX(0),n.getY(0),n.getZ(0)),a++),n}function p0(n,r,e,t=12,o=!0){let i=n0.set(0,0,0),a=0,s=[];for(let l=0;l<r.length;l++){if(e[l]===!1)continue;let c,u=Wp(r[l]),p=ma,d=yn(u,t);s.push(d);for(let f=0;f<=d;f++)if(u instanceof iu||u instanceof Hp||u instanceof au){if(u.getPoint(f/d,p),i.set(p.x,p.y,0),c?.equals(i))continue;c===void 0?c=o0:(n.setXYZ(a,c.x,c.y,c.z),a++,n.setXYZ(a,i.x,i.y,i.z),a++),c.copy(i)}}return o&&a>1&&!(n.getX(a-1)===n.getX(0)&&n.getY(a-1)===n.getY(0)&&n.getZ(a-1)===n.getZ(0))&&(n.setXYZ(a,n.getX(0),n.getY(0),n.getZ(0)),a++),s}function Yp(n,r=12,e=!1){let t=[];for(let o=0,i=n.length;o<i;o++){let a=n[o],s=0;if(e&&a.roundedCurveCorner!==void 0){let l=yn(a.roundedCurveCorner,r)*.5;o>0&&(t[o-1]+=l),s+=l}a.curveAfter!==void 0&&(s+=yn(a.curveAfter,r)),t.push(s)}return n.length>0&&e&&n[0].roundedCurveCorner!==void 0&&(t[n.length-1]+=yn(n[0].roundedCurveCorner,r)*.5),t}function yn(n,r=12){return n&&n instanceof JI?r*2:n&&(n instanceof au||n instanceof eM)?1:n&&n instanceof rM?r*n.points.length:r}function f0(n,r,e=12,t=!0){let o,i=0;for(let a=0;a<r.length;a++){let s=Wp(r[a]),l=yn(s,e),c=ma;for(let u=0;u<=l;u++)if(s instanceof iu||s instanceof Hp||s instanceof au){if(s.getPoint(u/l,c),o!==void 0&&sM(o,c,js))continue;o===void 0&&(o=su),o.copy(c),n.push(c.x,c.y),i++}}return ks(n[0],n[n.length-2],js)&&ks(n[1],n[n.length-1],js)&&(n.pop(),n.pop()),t&&i>1&&!(ks(n[i-1],n[1],js)&&ks(n[i-2],n[0],js))&&(n.push(n[0],n[1]),i++),n}var Qp=new Ro,dM=new Ro,pM=new Ro,fM=new Ro,hM=new Ro,mM=new Ro,je=class extends h0{constructor(e=100,t=100){super();this.points=[];this.shapeHoles=[];this.plane=new cM(new uM(0,0,-1));this.subdivision=0;this.controlSnapDistance=4;this.pointIDs=0;this.isMesh2D=!1;this.isText=!1;this._roundness=0;this.isClosed=!1;this.useCubicForRoundedCorners=!0;this.uuid=Xp.generateUUID();this.needsUpdate=!1;this.roundedCurves=[];this._width=e,this._height=t}static createFromState(e,t,o){let i=new je;return i.isClosed=e.isClosed,i.points=e.points.map(a=>zr.create(a.id,a.data)),typeof e.roundness=="number"&&(i.roundness=e.roundness),i.shapeHoles=e.shapeHoles.map(a=>je.createFromState(a)),t!==void 0&&o!==void 0&&i.applySize(t,o),i.update(),i}get width(){return this._width}get height(){return this._height}get roundness(){return this._roundness}set roundness(e){if(this._roundness!==e){this._roundness=e;for(let t=0,o=this.points.length;t<o;t++)this.points[t].roundness=e;this.needsUpdate=!0}}getPointsIndexesByIds(e){return e.map(t=>this.getPointIndexById(t)).filter(t=>t>=0)}getPointIndexById(e){let t=this.points.length,o=this.points.findIndex(i=>i.uuid===e);if(o<0){let i=t;for(let a=0,s=this.shapeHoles.length;a<s;a++){let l=this.shapeHoles[a],c=l.points.length,u=l.getPointIndexById(e);if(u<0)i+=c;else return u+i}}return o}getLineIndexById(e){return this.getPointIndexById(e)}getBezierPoint(e){if(e<=this.points.length-1)return this.points[e];if(this.shapeHoles.length>0){let t=this.points.length;for(let o=0,i=this.shapeHoles.length;o<i;o++){let a=this.shapeHoles[o],s=e-t;if(s<=a.points.length-1)return a.points[s];t+=a.points.length}}throw new Error("This shape does not have a point for this index: "+e)}getBezierPointIndex(e){let t=this.points.indexOf(e);if(t>=0)return t;if(t=this.points.length,this.shapeHoles.length>0)for(let o=0,i=this.shapeHoles.length;o<i;o++){let a=this.shapeHoles[o],s=a.points.indexOf(e);if(s>=0)return t+s;t+=a.points.length}return-1}getAllPoints(){let e=[].concat(...this.shapeHoles.map(t=>t.points));return[...this.points,...e]}applySize(e,t){e===0&&(e=.001),t===0&&(t=.001),this._width=e,this._height=t}applyScale(e,t){let o=Qp.set(e,t);for(let i=0,a=this.points.length;i<a;i++){let s=this.points[i];s.position.multiply(o),s.controls[0].position.multiply(o),s.controls[1].position.multiply(o)}for(let i=0,a=this.shapeHoles.length;i<a;i++)this.shapeHoles[i].applyScale(e,t);this._update()}createPoint(e,t=0,o=Xp.generateUUID()){let i;e instanceof Ro?i=e:i=new Ro(e,t);let a=new zr(o,i);return a.roundness=this.roundness,a}addPoint(e){this.points.push(e),this.needsUpdate=!0}addPointAt(e,t){this.points.splice(t,0,e),this.needsUpdate=!0}getPointByUuid(e){for(let t=0,o=this.points.length;t<o;t++){let i=this.points[t];if(i.uuid===e)return i}for(let t=0,o=this.shapeHoles.length;t<o;t++){let a=this.shapeHoles[t].getPointByUuid(e);if(a)return a}}getFirstPoint(){return this.points[0]}getLastPoint(){return this.points[this.points.length-1]}removePoint(e){let t=this.points.indexOf(e);t>=0&&this.points.splice(t,1),this.needsUpdate=!0}removePointById(e){let t=this.points.find(o=>o.uuid===e);t&&this.removePoint(t)}update(){for(let e=0,t=this.shapeHoles.length;e<t;e++)this.shapeHoles[e].update();this._update()}extractShapePointsToBuffer(e,t=12,o=!1){this.subdivision=t,this.curveDivisions===void 0&&this.computeCurveDivisions(t);let i=o?this.roundedCurveDivisions:this.curveDivisions;return d0(e,o?this.roundedCurves:this.curves,t,this.autoClose),i.reduce((a,s)=>a+s,0)+1}computeCurveDivisions(e=12){return this.curveDivisions=Yp(this.points,e,!1),this.roundedCurveDivisions=Yp(this.points,e,!0),this.curveDivisions}extractFilteredShapePointsToBuffer(e,t,o=12){return p0(e,this.curves,t,o,this.autoClose).reduce((a,s)=>a+s,0)*2}extractShapePointsToFlatArray(e,t=12){return this.subdivision=t,this.curveDivisions===void 0&&this.computeCurveDivisions(t),f0(e,this.roundedCurves,t,this.autoClose)}getCurveIndexFromVertexId(e,t=!1){let o=0;this.curveDivisions===void 0&&this.computeCurveDivisions(this.subdivision);let i=t?this.roundedCurveDivisions:this.curveDivisions,a=0;t&&this.points[0].roundedCurveCorner!==void 0&&(a=yn(this.points[0].roundedCurveCorner,this.subdivision)*.5);let s=e-a;s<0&&(s+=i.reduce((l,c)=>l+c,0));for(let l=0,c=i.length;l<c;l++){let u=i[l];if(s<o+u)return[l,(s-o+1)/u];o+=u}return[0,1]}getCurveT(e,t,o){let i=this.points[e],a=this.points[e>=this.points.length-1?0:e+1],s=this.curveDivisions,l=s[e];if($p(i,a)){let p=i.position.distanceTo(a.position);return i.position.distanceTo(Qp.set(o.x,o.y))/p}let c=0;for(let p=0;p<e;p++)c+=s[p];return(t-c)/l}dispose(){}_applyCurveForPoint(e,t){$p(t,e)?this.lineTo(e.position.x,e.position.y):this.bezierCurveTo(t.controls[1].position.x,t.controls[1].position.y,e.controls[0].position.x,e.controls[0].position.y,e.position.x,e.position.y);let o=this.curves[this.curves.length-1];e.curveBefore=o,t.curveAfter=o;let i=o.clone();e.roundedCurveBefore=i,t.roundedCurveAfter=i,e.roundedCurveCorner=void 0,this.roundedCurves.push(i)}_update(){if(this.curves=[],this.roundedCurves=[],!this.points.length)return;for(let t=0,o=this.points.length;t<o;t++){let i=this.points[t];if(t===0)this.moveTo(i.position.x,i.position.y);else{let a=this.points[t-1];this._applyCurveForPoint(i,a)}}let e=this.getLastPoint();if(e?.curveAfter&&(e.curveAfter=void 0),this.isClosed){let t=this.points[0],o=this.points[this.points.length-1];this._applyCurveForPoint(t,o)}if(this.points.length>2){let t=0;for(let o=0,i=this.points.length;o<i;o++){let a=this.points[o],s=this.points[o-1]??this.points[this.points.length-1],l=this.points[o+1]??this.points[0],c=a.roundness,u=s&&l&&a0(s,a,l);if(!a.controlsMoved()&&c>0&&!u){let p=a.curveBefore,d=a.curveAfter;if(p===void 0||d===void 0)continue;let f=a.roundedCurveBefore,h=a.roundedCurveAfter,m=p.getLength(),y=d.getLength(),b=Math.min(c,m*.499),S=Math.min(c,y*.499),P=Math.min(b,S),C=1-P/m,v=P/y,A=p.getPointAt(C,Qp),T=d.getPointAt(v,dM);this._subSplitCurve(p,f,C,A,void 0),this._subSplitCurve(d,h,v,void 0,T);let g;if(this.useCubicForRoundedCorners){let D=qp(A,a.position,T)/2,E=Math.tan(D)*A.distanceTo(a.position),[M,N]=s0(A,T,E,pM,fM),_=l0(M,N,a.position),[B,V]=c0(_,A,T,E,hM,mM);g=new lu(A.clone(),B.clone(),V.clone(),T.clone())}else g=new m0(A.clone(),a.position.clone(),T.clone());a.roundedCurveCorner=g,this.roundedCurves.splice(o+t,0,g),t++}}}}_subSplitCurve(e,t,o,i,a){if(e instanceof Kp)i!==void 0&&t.v2.copy(i),a!==void 0&&t.v1.copy(a);else{let s=e,l=t,c=s.getUtoTmapping(o,0),u=u0(s.v0,s.v1,s.v2,s.v3,c);return i!==void 0&&(l.v0.set(u[0],u[1]),l.v1.set(u[2],u[3]),l.v2.set(u[4],u[5]),l.v3.set(u[6],u[7])),a!==void 0&&(l.v0.set(u[6],u[7]),l.v1.set(u[8],u[9]),l.v2.set(u[10],u[11]),l.v3.set(u[12],u[13])),l}return t}clone(){let e=new je(this._width,this._height);return e.points=this.points.map(t=>t.clone()),e.isClosed=this.isClosed,e.roundness=this.roundness,e.isMesh2D=this.isMesh2D,e.shapeHoles=this.shapeHoles.map(t=>t.clone()),e}toJSON(){return{points:this.points.reduce((e,t)=>e.concat(t.toJSON()),[]),shapeHoles:this.shapeHoles.map(e=>e.toJSON()),isClosed:this.isClosed,roundness:this.roundness}}fromJSON(e){this.points=[],this.pointIDs=0;let t=e.points.length/7;for(let o=0;o<t;o++){let i=o*7,a=e.points[i+0],s=e.points[i+1],l=e.points[i+2],c=e.points[i+3],u=e.points[i+4],p=e.points[i+5],d=e.points[i+6],f=new zr(Xp.generateUUID(),new Ro(a,s));f.controls[0].position.set(l,c),f.controls[1].position.set(u,p),f.roundness=d,this.points.push(f)}return this.shapeHoles=e.shapeHoles?.length?e.shapeHoles.map(o=>{let i=new je;return i.fromJSON(o),i}):[],this.isClosed=e.isClosed,this._roundness=e.roundness,this._update(),this}fromShape(e,t=!1){this.isText=t;let o=(a,s)=>{s instanceof lu&&s.v3.equals(a.position)&&a.controls[0].position.copy(s.v2)},i=a=>{let s=[],l,c;for(l=0,c=a.length;l<c;l++)a[l]instanceof m0&&(a[l]=i0(a[l]));for(l=0,c=a.length;l<c;l++){let d=a[l],f=l>0?a[l-1]:null,h;d instanceof lu?(h=this.createPoint(d.v0),h.controls[1].position.copy(d.v1)):d instanceof Kp&&(h=this.createPoint(d.v1)),h!==void 0&&(f!==null&&o(h,f),s.push(h))}let u=a[a.length-1],p=!1;return u instanceof lu?u.v3.equals(s[0].position)&&(s[0].controls[0].position.copy(u.v2),p=!0):u instanceof Kp&&u.v2.equals(s[0].position)&&(p=!0),this.isClosed=p,s};return this.points=i(e.curves),e instanceof h0&&(this.shapeHoles=e.holes.map(a=>{let s=new je;return s.fromShape(a),s})),this.update(),this}updatePoint(e,t){let o=this.getPointByUuid(e);o&&(t.position!==void 0&&o.position.fromArray(t.position),t.roundness!==void 0&&(o.roundness=t.roundness),t.areControlsDirectionsMirrored!==void 0&&(o.areControlsDirectionsMirrored=t.areControlsDirectionsMirrored),this.needsUpdate=!0)}updatePreviousControl(e,t){let i=this.getPointByUuid(e)?.controls[0];i&&(t.position&&i.position.fromArray(t.position),this.needsUpdate=!0)}updateNextControl(e,t){let i=this.getPointByUuid(e)?.controls[1];i&&(t.position&&i.position.fromArray(t.position),this.needsUpdate=!0)}};var Jp=Math.PI*2;function Zp({x:n,y:r},e,t,o,i){return{x:n*e+o,y:r*t+i}}function yM(n,r){let e=r===1.5707963267948966?.551915024494:r===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(r/4),t=Math.cos(n),o=Math.sin(n),i=Math.cos(n+r),a=Math.sin(n+r);return[{x:t-o*e,y:o+t*e},{x:i+a*e,y:a-i*e},{x:i,y:a}]}function y0(n,r,e,t){let o=n*t-r*e<0?-1:1,i=Math.min(1,Math.max(-1,n*e+r*t));return o*Math.acos(i)}function gM(n,r,e,t,o,i,a,s,l,c){let u=Math.pow(o,2),p=Math.pow(i,2),d=Math.pow(a,2),f=Math.pow(s,2),h=u*p-u*f-p*d;h<0&&(h=0),h/=u*f+p*d,h=Math.sqrt(h)*(l===c?-1:1);let m=h*o/i*s,y=h*-i/o*a,b=m+(n+e)/2,S=y+(r+t)/2,P=(a-m)/o,C=(s-y)/i,v=(-a-m)/o,A=(-s-y)/i,T=y0(1,0,P,C),g=y0(P,C,v,A);return!c&&g>0&&(g-=Jp),c&&g<0&&(g+=Jp),{centerx:b,centery:S,ang1:T,ang2:g}}function g0({px:n,py:r,cx:e,cy:t,rx:o,ry:i,largeArcFlag:a,sweepFlag:s}){let l=[];if(o===0||i===0)return[];let c=(n-e)/2,u=(r-t)/2;if(c===0&&u===0)return[];o=Math.abs(o),i=Math.abs(i);let p=Math.pow(c,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(i,2);p>1&&(o*=Math.sqrt(p),i*=Math.sqrt(p));let d=gM(n,r,e,t,o,i,c,u,a,s),{ang1:f,ang2:h}=d,{centerx:m,centery:y}=d,b=Math.abs(h)/(Jp/4);Math.abs(1-b)<1e-7&&(b=1);let S=Math.max(Math.ceil(b),1);h/=S;for(let P=0;P<S;P++)l.push(yM(f,h)),f+=h;return l.map(P=>{let{x:C,y:v}=Zp(P[0],o,i,m,y),{x:A,y:T}=Zp(P[1],o,i,m,y),{x:g,y:D}=Zp(P[2],o,i,m,y);return{x1:C,y1:v,x2:A,y2:T,x:g,y:D}})}import{BufferAttribute as fu,BufferGeometry as IM}from"three";var Fe;(function(n){n[n.ODD=0]="ODD",n[n.NONZERO=1]="NONZERO",n[n.POSITIVE=2]="POSITIVE",n[n.NEGATIVE=3]="NEGATIVE",n[n.ABS_GEQ_TWO=4]="ABS_GEQ_TWO"})(Fe||(Fe={}));var at;(function(n){n[n.POLYGONS=0]="POLYGONS",n[n.CONNECTED_POLYGONS=1]="CONNECTED_POLYGONS",n[n.BOUNDARY_CONTOURS=2]="BOUNDARY_CONTOURS"})(at||(at={}));function we(n,r){if(!n)throw r||"Assertion Failed!"}var ve=function(){function n(){}return n.vertEq=function(r,e){return r.s===e.s&&r.t===e.t},n.vertLeq=function(r,e){return r.s<e.s||r.s===e.s&&r.t<=e.t},n.transLeq=function(r,e){return r.t<e.t||r.t===e.t&&r.s<=e.s},n.edgeGoesLeft=function(r){return n.vertLeq(r.Dst,r.Org)},n.edgeGoesRight=function(r){return n.vertLeq(r.Org,r.Dst)},n.vertL1dist=function(r,e){return Math.abs(r.s-e.s)+Math.abs(r.t-e.t)},n.edgeEval=function(r,e,t){we(n.vertLeq(r,e)&&n.vertLeq(e,t));var o=e.s-r.s,i=t.s-e.s;return o+i>0?o<i?e.t-r.t+(r.t-t.t)*(o/(o+i)):e.t-t.t+(t.t-r.t)*(i/(o+i)):0},n.edgeSign=function(r,e,t){we(n.vertLeq(r,e)&&n.vertLeq(e,t));var o=e.s-r.s,i=t.s-e.s;return o+i>0?(e.t-t.t)*o+(e.t-r.t)*i:0},n.transEval=function(r,e,t){we(n.transLeq(r,e)&&n.transLeq(e,t));var o=e.t-r.t,i=t.t-e.t;return o+i>0?o<i?e.s-r.s+(r.s-t.s)*(o/(o+i)):e.s-t.s+(t.s-r.s)*(i/(o+i)):0},n.transSign=function(r,e,t){we(n.transLeq(r,e)&&n.transLeq(e,t));var o=e.t-r.t,i=t.t-e.t;return o+i>0?(e.s-t.s)*o+(e.s-r.s)*i:0},n.vertCCW=function(r,e,t){return r.s*(e.t-t.t)+e.s*(t.t-r.t)+t.s*(r.t-e.t)>=0},n.interpolate=function(r,e,t,o){return r=r<0?0:r,t=t<0?0:t,r<=t?t===0?(e+o)/2:e+(o-e)*(r/(r+t)):o+(e-o)*(t/(r+t))},n.intersect=function(r,e,t,o,i){var a,s,l;n.vertLeq(r,e)||(l=r,r=e,e=l),n.vertLeq(t,o)||(l=t,t=o,o=l),n.vertLeq(r,t)||(l=r,r=t,t=l,l=e,e=o,o=l),n.vertLeq(t,e)?n.vertLeq(e,o)?(a=n.edgeEval(r,t,e),s=n.edgeEval(t,e,o),a+s<0&&(a=-a,s=-s),i.s=n.interpolate(a,t.s,s,e.s)):(a=n.edgeSign(r,t,e),s=-n.edgeSign(r,o,e),a+s<0&&(a=-a,s=-s),i.s=n.interpolate(a,t.s,s,o.s)):i.s=(t.s+e.s)/2,n.transLeq(r,e)||(l=r,r=e,e=l),n.transLeq(t,o)||(l=t,t=o,o=l),n.transLeq(r,t)||(l=r,r=t,t=l,l=e,e=o,o=l),n.transLeq(t,e)?n.transLeq(e,o)?(a=n.transEval(r,t,e),s=n.transEval(t,e,o),a+s<0&&(a=-a,s=-s),i.t=n.interpolate(a,t.t,s,e.t)):(a=n.transSign(r,t,e),s=-n.transSign(r,o,e),a+s<0&&(a=-a,s=-s),i.t=n.interpolate(a,t.t,s,o.t)):i.t=(t.t+e.t)/2},n}(),Us=function(){function n(){this.next=null,this.prev=null,this.anEdge=null,this.trail=null,this.n=0,this.marked=!1,this.inside=!1}return n}(),cu=function(){function n(r){this.side=r,this.next=null,this.Org=null,this.Sym=null,this.Onext=null,this.Lnext=null,this.Lface=null,this.activeRegion=null,this.winding=0}return Object.defineProperty(n.prototype,"Rface",{get:function(){return this.Sym.Lface},set:function(r){this.Sym.Lface=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dst",{get:function(){return this.Sym.Org},set:function(r){this.Sym.Org=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Oprev",{get:function(){return this.Sym.Lnext},set:function(r){this.Sym.Lnext=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Lprev",{get:function(){return this.Onext.Sym},set:function(r){this.Onext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dprev",{get:function(){return this.Lnext.Sym},set:function(r){this.Lnext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Rprev",{get:function(){return this.Sym.Onext},set:function(r){this.Sym.Onext=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Dnext",{get:function(){return this.Sym.Onext.Sym},set:function(r){this.Sym.Onext.Sym=r},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"Rnext",{get:function(){return this.Sym.Lnext.Sym},set:function(r){this.Sym.Lnext.Sym=r},enumerable:!0,configurable:!0}),n}(),ya=function(){function n(){this.next=null,this.prev=null,this.anEdge=null,this.coords=[0,0,0],this.s=0,this.t=0,this.pqHandle=0,this.n=0,this.idx=0}return n}(),x0=function(){function n(){var r=new ya,e=new Us,t=new cu(0),o=new cu(1);r.next=r.prev=r,r.anEdge=null,e.next=e.prev=e,t.next=t,t.Sym=o,o.next=o,o.Sym=t,this.vHead=r,this.fHead=e,this.eHead=t,this.eHeadSym=o}return n.prototype.makeEdge_=function(r){var e=new cu(0),t=new cu(1);r.Sym.side<r.side&&(r=r.Sym);var o=r.Sym.next;return t.next=o,o.Sym.next=e,e.next=r,r.Sym.next=t,e.Sym=t,e.Onext=e,e.Lnext=t,e.Org=null,e.Lface=null,e.winding=0,e.activeRegion=null,t.Sym=e,t.Onext=t,t.Lnext=e,t.Org=null,t.Lface=null,t.winding=0,t.activeRegion=null,e},n.prototype.splice_=function(r,e){var t=r.Onext,o=e.Onext;t.Sym.Lnext=e,o.Sym.Lnext=r,r.Onext=o,e.Onext=t},n.prototype.makeVertex_=function(r,e,t){var o=r;we(o,"Vertex can't be null!");var i=t.prev;o.prev=i,i.next=o,o.next=t,t.prev=o,o.anEdge=e;var a=e;do a.Org=o,a=a.Onext;while(a!==e)},n.prototype.makeFace_=function(r,e,t){var o=r;we(o,"Face can't be null");var i=t.prev;o.prev=i,i.next=o,o.next=t,t.prev=o,o.anEdge=e,o.trail=null,o.marked=!1,o.inside=t.inside;var a=e;do a.Lface=o,a=a.Lnext;while(a!==e)},n.prototype.killEdge_=function(r){r.Sym.side<r.side&&(r=r.Sym);var e=r.next,t=r.Sym.next;e.Sym.next=t,t.Sym.next=e},n.prototype.killVertex_=function(r,e){var t=r.anEdge,o=t;do o.Org=e,o=o.Onext;while(o!==t);var i=r.prev,a=r.next;a.prev=i,i.next=a},n.prototype.killFace_=function(r,e){var t=r.anEdge,o=t;do o.Lface=e,o=o.Lnext;while(o!==t);var i=r.prev,a=r.next;a.prev=i,i.next=a},n.prototype.makeEdge=function(){var r=new ya,e=new ya,t=new Us,o=this.makeEdge_(this.eHead);return this.makeVertex_(r,o,this.vHead),this.makeVertex_(e,o.Sym,this.vHead),this.makeFace_(t,o,this.fHead),o},n.prototype.splice=function(r,e){var t=!1,o=!1;if(r!==e){if(e.Org!==r.Org&&(o=!0,this.killVertex_(e.Org,r.Org)),e.Lface!==r.Lface&&(t=!0,this.killFace_(e.Lface,r.Lface)),this.splice_(e,r),!o){var i=new ya;this.makeVertex_(i,e,r.Org),r.Org.anEdge=r}if(!t){var a=new Us;this.makeFace_(a,e,r.Lface),r.Lface.anEdge=r}}},n.prototype.delete=function(r){var e=r.Sym,t=!1;if(r.Lface!==r.Rface&&(t=!0,this.killFace_(r.Lface,r.Rface)),r.Onext===r)this.killVertex_(r.Org,null);else if(r.Rface.anEdge=r.Oprev,r.Org.anEdge=r.Onext,this.splice_(r,r.Oprev),!t){var o=new Us;this.makeFace_(o,r,r.Lface)}e.Onext===e?(this.killVertex_(e.Org,null),this.killFace_(e.Lface,null)):(r.Lface.anEdge=e.Oprev,e.Org.anEdge=e.Onext,this.splice_(e,e.Oprev)),this.killEdge_(r)},n.prototype.addEdgeVertex=function(r){var e=this.makeEdge_(r),t=e.Sym;this.splice_(e,r.Lnext),e.Org=r.Dst;var o=new ya;return this.makeVertex_(o,t,e.Org),e.Lface=t.Lface=r.Lface,e},n.prototype.splitEdge=function(r){var e=this.addEdgeVertex(r),t=e.Sym;return this.splice_(r.Sym,r.Sym.Oprev),this.splice_(r.Sym,t),r.Dst=t.Org,t.Dst.anEdge=t.Sym,t.Rface=r.Rface,t.winding=r.winding,t.Sym.winding=r.Sym.winding,t.idx=r.idx,t.Sym.idx=r.Sym.idx,t},n.prototype.connect=function(r,e){var t=!1,o=this.makeEdge_(r),i=o.Sym;if(e.Lface!==r.Lface&&(t=!0,this.killFace_(e.Lface,r.Lface)),this.splice_(o,r.Lnext),this.splice_(i,e),o.Org=r.Dst,i.Org=e.Org,o.Lface=i.Lface=r.Lface,r.Lface.anEdge=i,!t){var a=new Us;this.makeFace_(a,o,r.Lface)}return o},n.prototype.zapFace=function(r){var e=r.anEdge,t,o,i,a,s;o=e.Lnext;do t=o,o=t.Lnext,t.Lface=null,t.Rface===null&&(t.Onext===t?this.killVertex_(t.Org,null):(t.Org.anEdge=t.Onext,this.splice_(t,t.Oprev)),i=t.Sym,i.Onext===i?this.killVertex_(i.Org,null):(i.Org.anEdge=i.Onext,this.splice_(i,i.Oprev)),this.killEdge_(t));while(t!=e);a=r.prev,s=r.next,s.prev=a,a.next=s},n.prototype.countFaceVerts_=function(r){var e=r.anEdge,t=0;do t++,e=e.Lnext;while(e!==r.anEdge);return t},n.prototype.mergeConvexFaces=function(r){var e,t,o,i,a,s,l;for(e=this.fHead.next;e!==this.fHead;e=e.next)if(!!e.inside)for(t=e.anEdge,a=t.Org;o=t.Lnext,i=t.Sym,i&&i.Lface&&i.Lface.inside&&(s=this.countFaceVerts_(e),l=this.countFaceVerts_(i.Lface),s+l-2<=r&&ve.vertCCW(t.Lprev.Org,t.Org,i.Lnext.Lnext.Org)&&ve.vertCCW(i.Lprev.Org,i.Org,t.Lnext.Lnext.Org)&&(o=i.Lnext,this.delete(i),t=null,i=null)),!(t&&t.Lnext.Org===a);)t=o;return!0},n.prototype.check=function(){var r=this.fHead,e=this.vHead,t=this.eHead,o,i,a,s,l,c;for(i=r,i=r;(o=i.next)!==r;i=o){we(o.prev===i),l=o.anEdge;do we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l),we(l.Lface===o),l=l.Lnext;while(l!==o.anEdge)}for(we(o.prev===i&&o.anEdge===null),s=e,s=e;(a=s.next)!==e;s=a){we(a.prev===s),l=a.anEdge;do we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l),we(l.Org===a),l=l.Onext;while(l!==a.anEdge)}for(we(a.prev===s&&a.anEdge===null),c=t,c=t;(l=c.next)!==t;c=l)we(l.Sym.next===c.Sym),we(l.Sym!==l),we(l.Sym.Sym===l),we(l.Org!==null),we(l.Dst!==null),we(l.Lnext.Onext.Sym===l),we(l.Onext.Sym.Lnext===l);we(l.Sym.next===c.Sym&&l.Sym===this.eHeadSym&&l.Sym.Sym===l&&l.Org===null&&l.Dst===null&&l.Lface===null&&l.Rface===null)},n}(),b0=function(){function n(){this.handle=null}return n}(),v0=function(){function n(){this.key=null,this.node=0}return n}(),xM=function(){function n(r,e){this.leq=e,this.max=0,this.nodes=[],this.handles=[],this.initialized=!1,this.freeList=0,this.size=0,this.max=r,this.nodes=[],this.handles=[];for(var t=0;t<r+1;t++)this.nodes[t]=new b0,this.handles[t]=new v0;this.initialized=!1,this.nodes[1].handle=1,this.handles[1].key=null}return n.prototype.floatDown_=function(r){var e=this.nodes,t=this.handles,o,i,a;for(o=e[r].handle;;){if(a=r<<1,a<this.size&&this.leq(t[e[a+1].handle].key,t[e[a].handle].key)&&++a,we(a<=this.max),i=e[a].handle,a>this.size||this.leq(t[o].key,t[i].key)){e[r].handle=o,t[o].node=r;break}e[r].handle=i,t[i].node=r,r=a}},n.prototype.floatUp_=function(r){var e=this.nodes,t=this.handles,o,i,a;for(o=e[r].handle;;){if(a=r>>1,i=e[a].handle,a===0||this.leq(t[i].key,t[o].key)){e[r].handle=o,t[o].node=r;break}e[r].handle=i,t[i].node=r,r=a}},n.prototype.init=function(){for(var r=this.size;r>=1;--r)this.floatDown_(r);this.initialized=!0},n.prototype.min=function(){return this.handles[this.nodes[1].handle].key},n.prototype.insert=function(r){var e,t;if(e=++this.size,e*2>this.max){this.max*=2;var o,i;for(i=this.nodes.length,this.nodes.length=this.max+1,o=i;o<this.nodes.length;o++)this.nodes[o]=new b0;for(i=this.handles.length,this.handles.length=this.max+1,o=i;o<this.handles.length;o++)this.handles[o]=new v0}return this.freeList===0?t=e:(t=this.freeList,this.freeList=this.handles[t].node),this.nodes[e].handle=t,this.handles[t].node=e,this.handles[t].key=r,this.initialized&&this.floatUp_(e),t},n.prototype.extractMin=function(){var r=this.nodes,e=this.handles,t=r[1].handle,o=e[t].key;return this.size>0&&(r[1].handle=r[this.size].handle,e[r[1].handle].node=1,e[t].key=null,e[t].node=this.freeList,this.freeList=t,--this.size,this.size>0&&this.floatDown_(1)),o},n.prototype.delete=function(r){var e=this.nodes,t=this.handles,o;we(r>=1&&r<=this.max&&t[r].key!==null),o=t[r].node,e[o].handle=e[this.size].handle,t[e[o].handle].node=o,--this.size,o<=this.size&&(o<=1||this.leq(t[e[o>>1].handle].key,t[e[o].handle].key)?this.floatDown_(o):this.floatUp_(o)),t[r].key=null,t[r].node=this.freeList,this.freeList=r},n}(),ef=function(){function n(){this.eUp=null,this.nodeUp=null,this.windingNumber=0,this.inside=!1,this.sentinel=!1,this.dirty=!1,this.fixUpperEdge=!1}return n}(),S0=function(){function n(){this.key=null,this.next=null,this.prev=null}return n}(),bM=function(){function n(r,e){this.frame=r,this.leq=e,this.head=new S0,this.head.next=this.head,this.head.prev=this.head}return n.prototype.min=function(){return this.head.next},n.prototype.max=function(){return this.head.prev},n.prototype.insert=function(r){return this.insertBefore(this.head,r)},n.prototype.search=function(r){var e=this.head;do e=e.next;while(e.key!==null&&!this.leq(this.frame,r,e.key));return e},n.prototype.insertBefore=function(r,e){do r=r.prev;while(r.key!==null&&!this.leq(this.frame,r.key,e));var t=new S0;return t.key=e,t.next=r.next,r.next.prev=t,t.prev=r,r.next=t,t},n.prototype.delete=function(r){r.next.prev=r.prev,r.prev.next=r.next},n}(),vM=function(){function n(){}return n.regionBelow=function(r){return r.nodeUp.prev.key},n.regionAbove=function(r){return r.nodeUp.next.key},n.debugEvent=function(r){},n.addWinding=function(r,e){r.winding+=e.winding,r.Sym.winding+=e.Sym.winding},n.edgeLeq=function(r,e,t){var o=r.event,i=e.eUp,a=t.eUp;if(i.Dst===o)return a.Dst===o?ve.vertLeq(i.Org,a.Org)?ve.edgeSign(a.Dst,i.Org,a.Org)<=0:ve.edgeSign(i.Dst,a.Org,i.Org)>=0:ve.edgeSign(a.Dst,o,a.Org)<=0;if(a.Dst===o)return ve.edgeSign(i.Dst,o,i.Org)>=0;var s=ve.edgeEval(i.Dst,o,i.Org),l=ve.edgeEval(a.Dst,o,a.Org);return s>=l},n.deleteRegion=function(r,e){e.fixUpperEdge&&we(e.eUp.winding===0),e.eUp.activeRegion=null,r.dict.delete(e.nodeUp)},n.fixUpperEdge=function(r,e,t){we(e.fixUpperEdge),r.mesh.delete(e.eUp),e.fixUpperEdge=!1,e.eUp=t,t.activeRegion=e},n.topLeftRegion=function(r,e){var t=e.eUp.Org,o;do e=n.regionAbove(e);while(e.eUp.Org===t);if(e.fixUpperEdge){if(o=r.mesh.connect(n.regionBelow(e).eUp.Sym,e.eUp.Lnext),o===null)return null;n.fixUpperEdge(r,e,o),e=n.regionAbove(e)}return e},n.topRightRegion=function(r){var e=r.eUp.Dst;do r=n.regionAbove(r);while(r.eUp.Dst===e);return r},n.addRegionBelow=function(r,e,t){var o=new ef;return o.eUp=t,o.nodeUp=r.dict.insertBefore(e.nodeUp,o),o.fixUpperEdge=!1,o.sentinel=!1,o.dirty=!1,t.activeRegion=o,o},n.isWindingInside=function(r,e){switch(r.windingRule){case Fe.ODD:return(e&1)!==0;case Fe.NONZERO:return e!==0;case Fe.POSITIVE:return e>0;case Fe.NEGATIVE:return e<0;case Fe.ABS_GEQ_TWO:return e>=2||e<=-2}throw new Error("Invalid winding rulle")},n.computeWinding=function(r,e){e.windingNumber=n.regionAbove(e).windingNumber+e.eUp.winding,e.inside=n.isWindingInside(r,e.windingNumber)},n.finishRegion=function(r,e){var t=e.eUp,o=t.Lface;o.inside=e.inside,o.anEdge=t,n.deleteRegion(r,e)},n.finishLeftRegions=function(r,e,t){for(var o,i=null,a=e,s=e.eUp;a!==t;){if(a.fixUpperEdge=!1,i=n.regionBelow(a),o=i.eUp,o.Org!=s.Org){if(!i.fixUpperEdge){n.finishRegion(r,a);break}o=r.mesh.connect(s.Lprev,o.Sym),n.fixUpperEdge(r,i,o)}s.Onext!==o&&(r.mesh.splice(o.Oprev,o),r.mesh.splice(s,o)),n.finishRegion(r,a),s=i.eUp,a=i}return s},n.addRightEdges=function(r,e,t,o,i,a){var s,l,c,u,p=!0;c=t;do we(ve.vertLeq(c.Org,c.Dst)),n.addRegionBelow(r,e,c.Sym),c=c.Onext;while(c!==o);for(i===null&&(i=n.regionBelow(e).eUp.Rprev),l=e,u=i;s=n.regionBelow(l),c=s.eUp.Sym,c.Org===u.Org;)c.Onext!==u&&(r.mesh.splice(c.Oprev,c),r.mesh.splice(u.Oprev,c)),s.windingNumber=l.windingNumber-c.winding,s.inside=n.isWindingInside(r,s.windingNumber),l.dirty=!0,!p&&n.checkForRightSplice(r,l)&&(n.addWinding(c,u),n.deleteRegion(r,l),r.mesh.delete(u)),p=!1,l=s,u=c;l.dirty=!0,we(l.windingNumber-c.winding===s.windingNumber),a&&n.walkDirtyRegions(r,l)},n.spliceMergeVertices=function(r,e,t){r.mesh.splice(e,t)},n.vertexWeights=function(r,e,t){var o=ve.vertL1dist(e,r),i=ve.vertL1dist(t,r),a=.5*i/(o+i),s=.5*o/(o+i);r.coords[0]+=a*e.coords[0]+s*t.coords[0],r.coords[1]+=a*e.coords[1]+s*t.coords[1],r.coords[2]+=a*e.coords[2]+s*t.coords[2]},n.getIntersectData=function(r,e,t,o,i,a){e.coords[0]=e.coords[1]=e.coords[2]=0,e.idx=-1,n.vertexWeights(e,t,o),n.vertexWeights(e,i,a)},n.checkForRightSplice=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp;if(ve.vertLeq(o.Org,i.Org)){if(ve.edgeSign(i.Dst,o.Org,i.Org)>0)return!1;ve.vertEq(o.Org,i.Org)?o.Org!==i.Org&&(r.pq.delete(o.Org.pqHandle),n.spliceMergeVertices(r,i.Oprev,o)):(r.mesh.splitEdge(i.Sym),r.mesh.splice(o,i.Oprev),e.dirty=t.dirty=!0)}else{if(ve.edgeSign(o.Dst,i.Org,o.Org)<0)return!1;n.regionAbove(e).dirty=e.dirty=!0,r.mesh.splitEdge(o.Sym),r.mesh.splice(i.Oprev,o)}return!0},n.checkForLeftSplice=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp,a;if(we(!ve.vertEq(o.Dst,i.Dst)),ve.vertLeq(o.Dst,i.Dst)){if(ve.edgeSign(o.Dst,i.Dst,o.Org)<0)return!1;n.regionAbove(e).dirty=e.dirty=!0,a=r.mesh.splitEdge(o),r.mesh.splice(i.Sym,a),a.Lface.inside=e.inside}else{if(ve.edgeSign(i.Dst,o.Dst,i.Org)>0)return!1;e.dirty=t.dirty=!0,a=r.mesh.splitEdge(i),r.mesh.splice(o.Lnext,i.Sym),a.Rface.inside=e.inside}return!0},n.checkForIntersect=function(r,e){var t=n.regionBelow(e),o=e.eUp,i=t.eUp,a=o.Org,s=i.Org,l=o.Dst,c=i.Dst,u,p,d=new ya,f,h;if(we(!ve.vertEq(c,l)),we(ve.edgeSign(l,r.event,a)<=0),we(ve.edgeSign(c,r.event,s)>=0),we(a!==r.event&&s!==r.event),we(!e.fixUpperEdge&&!t.fixUpperEdge),a===s||(u=Math.min(a.t,l.t),p=Math.max(s.t,c.t),u>p))return!1;if(ve.vertLeq(a,s)){if(ve.edgeSign(c,a,s)>0)return!1}else if(ve.edgeSign(l,s,a)<0)return!1;return n.debugEvent(r),ve.intersect(l,a,c,s,d),we(Math.min(a.t,l.t)<=d.t),we(d.t<=Math.max(s.t,c.t)),we(Math.min(c.s,l.s)<=d.s),we(d.s<=Math.max(s.s,a.s)),ve.vertLeq(d,r.event)&&(d.s=r.event.s,d.t=r.event.t),f=ve.vertLeq(a,s)?a:s,ve.vertLeq(f,d)&&(d.s=f.s,d.t=f.t),ve.vertEq(d,a)||ve.vertEq(d,s)?(n.checkForRightSplice(r,e),!1):!ve.vertEq(l,r.event)&&ve.edgeSign(l,r.event,d)>=0||!ve.vertEq(c,r.event)&&ve.edgeSign(c,r.event,d)<=0?c===r.event?(r.mesh.splitEdge(o.Sym),r.mesh.splice(i.Sym,o),e=n.topLeftRegion(r,e),o=n.regionBelow(e).eUp,n.finishLeftRegions(r,n.regionBelow(e),t),n.addRightEdges(r,e,o.Oprev,o,o,!0),!0):l===r.event?(r.mesh.splitEdge(i.Sym),r.mesh.splice(o.Lnext,i.Oprev),t=e,e=n.topRightRegion(e),h=n.regionBelow(e).eUp.Rprev,t.eUp=i.Oprev,i=n.finishLeftRegions(r,t,null),n.addRightEdges(r,e,i.Onext,o.Rprev,h,!0),!0):(ve.edgeSign(l,r.event,d)>=0&&(n.regionAbove(e).dirty=e.dirty=!0,r.mesh.splitEdge(o.Sym),o.Org.s=r.event.s,o.Org.t=r.event.t),ve.edgeSign(c,r.event,d)<=0&&(e.dirty=t.dirty=!0,r.mesh.splitEdge(i.Sym),i.Org.s=r.event.s,i.Org.t=r.event.t),!1):(r.mesh.splitEdge(o.Sym),r.mesh.splitEdge(i.Sym),r.mesh.splice(i.Oprev,o),o.Org.s=d.s,o.Org.t=d.t,o.Org.pqHandle=r.pq.insert(o.Org),n.getIntersectData(r,o.Org,a,l,s,c),n.regionAbove(e).dirty=e.dirty=t.dirty=!0,!1)},n.walkDirtyRegions=function(r,e){for(var t=n.regionBelow(e),o,i;;){for(;t.dirty;)e=t,t=n.regionBelow(t);if(!e.dirty&&(t=e,e=n.regionAbove(e),e===null||!e.dirty))return;if(e.dirty=!1,o=e.eUp,i=t.eUp,o.Dst!==i.Dst&&n.checkForLeftSplice(r,e)&&(t.fixUpperEdge?(n.deleteRegion(r,t),r.mesh.delete(i),t=n.regionBelow(e),i=t.eUp):e.fixUpperEdge&&(n.deleteRegion(r,e),r.mesh.delete(o),e=n.regionAbove(t),o=e.eUp)),o.Org!==i.Org)if(o.Dst!==i.Dst&&!e.fixUpperEdge&&!t.fixUpperEdge&&(o.Dst===r.event||i.Dst===r.event)){if(n.checkForIntersect(r,e))return}else n.checkForRightSplice(r,e);o.Org===i.Org&&o.Dst===i.Dst&&(n.addWinding(i,o),n.deleteRegion(r,e),r.mesh.delete(o),e=n.regionAbove(t))}},n.connectRightVertex=function(r,e,t){var o,i=t.Onext,a=n.regionBelow(e),s=e.eUp,l=a.eUp,c=!1;if(s.Dst!==l.Dst&&n.checkForIntersect(r,e),ve.vertEq(s.Org,r.event)&&(r.mesh.splice(i.Oprev,s),e=n.topLeftRegion(r,e),i=n.regionBelow(e).eUp,n.finishLeftRegions(r,n.regionBelow(e),a),c=!0),ve.vertEq(l.Org,r.event)&&(r.mesh.splice(t,l.Oprev),t=n.finishLeftRegions(r,a,null),c=!0),c){n.addRightEdges(r,e,t.Onext,i,i,!0);return}ve.vertLeq(l.Org,s.Org)?o=l.Oprev:o=s,o=r.mesh.connect(t.Lprev,o),n.addRightEdges(r,e,o,o.Onext,o.Onext,!1),o.Sym.activeRegion.fixUpperEdge=!0,n.walkDirtyRegions(r,e)},n.connectLeftDegenerate=function(r,e,t){var o,i,a,s,l;if(o=e.eUp,ve.vertEq(o.Org,t)){we(!1),n.spliceMergeVertices(r,o,t.anEdge);return}if(!ve.vertEq(o.Dst,t)){r.mesh.splitEdge(o.Sym),e.fixUpperEdge&&(r.mesh.delete(o.Onext),e.fixUpperEdge=!1),r.mesh.splice(t.anEdge,o),n.sweepEvent(r,t);return}we(!1),e=n.topRightRegion(e),l=n.regionBelow(e),a=l.eUp.Sym,i=s=a.Onext,l.fixUpperEdge&&(we(i!==a),n.deleteRegion(r,l),r.mesh.delete(a),a=i.Oprev),r.mesh.splice(t.anEdge,a),ve.edgeGoesLeft(i)||(i=null),n.addRightEdges(r,e,a.Onext,s,i,!0)},n.connectLeftVertex=function(r,e){var t,o,i,a,s,l,c=new ef;if(c.eUp=e.anEdge.Sym,t=r.dict.search(c).key,o=n.regionBelow(t),!!o){if(a=t.eUp,s=o.eUp,ve.edgeSign(a.Dst,e,a.Org)===0){n.connectLeftDegenerate(r,t,e);return}if(i=ve.vertLeq(s.Dst,a.Dst)?t:o,t.inside||i.fixUpperEdge){if(i===t)l=r.mesh.connect(e.anEdge.Sym,a.Lnext);else{var u=r.mesh.connect(s.Dnext,e.anEdge);l=u.Sym}i.fixUpperEdge?n.fixUpperEdge(r,i,l):n.computeWinding(r,n.addRegionBelow(r,t,l)),n.sweepEvent(r,e)}else n.addRightEdges(r,t,e.anEdge,e.anEdge,null,!0)}},n.sweepEvent=function(r,e){r.event=e,n.debugEvent(r);for(var t=e.anEdge;t.activeRegion===null;)if(t=t.Onext,t===e.anEdge){n.connectLeftVertex(r,e);return}var o=n.topLeftRegion(r,t.activeRegion);we(o!==null);var i=n.regionBelow(o),a=i.eUp,s=n.finishLeftRegions(r,i,null);s.Onext===a?n.connectRightVertex(r,o,s):n.addRightEdges(r,o,s.Onext,a,a,!0)},n.addSentinel=function(r,e,t,o){var i=new ef,a=r.mesh.makeEdge();a.Org.s=t,a.Org.t=o,a.Dst.s=e,a.Dst.t=o,r.event=a.Dst,i.eUp=a,i.windingNumber=0,i.inside=!1,i.fixUpperEdge=!1,i.sentinel=!0,i.dirty=!1,i.nodeUp=r.dict.insert(i)},n.initEdgeDict=function(r){r.dict=new bM(r,n.edgeLeq);var e=r.bmax[0]-r.bmin[0],t=r.bmax[1]-r.bmin[1],o=r.bmin[0]-e,i=r.bmax[0]+e,a=r.bmin[1]-t,s=r.bmax[1]+t;n.addSentinel(r,o,i,a),n.addSentinel(r,o,i,s)},n.doneEdgeDict=function(r){for(var e,t=0;(e=r.dict.min().key)!==null;)e.sentinel||(we(e.fixUpperEdge),we(++t===1)),we(e.windingNumber===0),n.deleteRegion(r,e)},n.removeDegenerateEdges=function(r){var e,t,o,i=r.mesh.eHead;for(e=i.next;e!==i;e=t)t=e.next,o=e.Lnext,ve.vertEq(e.Org,e.Dst)&&e.Lnext.Lnext!==e&&(n.spliceMergeVertices(r,o,e),r.mesh.delete(e),e=o,o=e.Lnext),o.Lnext===e&&(o!==e&&((o===t||o===t.Sym)&&(t=t.next),r.mesh.delete(o)),(e===t||e===t.Sym)&&(t=t.next),r.mesh.delete(e))},n.initPriorityQ=function(r){var e,t,o,i=0;for(o=r.mesh.vHead,t=o.next;t!==o;t=t.next)i++;for(i+=8,e=r.pq=new xM(i,ve.vertLeq),o=r.mesh.vHead,t=o.next;t!==o;t=t.next)t.pqHandle=e.insert(t);return t!==o?!1:(e.init(),!0)},n.donePriorityQ=function(r){r.pq=null},n.removeDegenerateFaces=function(r,e){var t,o,i;for(t=e.fHead.next;t!==e.fHead;t=o)o=t.next,i=t.anEdge,we(i.Lnext!==i),i.Lnext.Lnext===i&&(n.addWinding(i.Onext,i),r.mesh.delete(i));return!0},n.computeInterior=function(r,e){e===void 0&&(e=!0);var t,o;if(n.removeDegenerateEdges(r),!n.initPriorityQ(r))return!1;for(n.initEdgeDict(r);(t=r.pq.extractMin())!==null;){for(;o=r.pq.min(),!(o===null||!ve.vertEq(o,t));)o=r.pq.extractMin(),n.spliceMergeVertices(r,t.anEdge,o.anEdge);n.sweepEvent(r,t)}return r.event=r.dict.min().key.eUp.Org,n.debugEvent(r),n.doneEdgeDict(r),n.donePriorityQ(r),n.removeDegenerateFaces(r,r.mesh)?(e&&r.mesh.check(),!0):!1},n}(),SM=function(){function n(){this.mesh=new x0,this.normal=[0,0,0],this.sUnit=[0,0,0],this.tUnit=[0,0,0],this.bmin=[0,0],this.bmax=[0,0],this.windingRule=Fe.ODD,this.dict=null,this.pq=null,this.event=null,this.vertexIndexCounter=0,this.vertices=[],this.vertexIndices=[],this.vertexCount=0,this.elements=[],this.elementCount=0}return n.prototype.dot_=function(r,e){return r[0]*e[0]+r[1]*e[1]+r[2]*e[2]},n.prototype.normalize_=function(r){var e=r[0]*r[0]+r[1]*r[1]+r[2]*r[2];if(!e)throw"Zero-size vector!";e=Math.sqrt(e),r[0]/=e,r[1]/=e,r[2]/=e},n.prototype.longAxis_=function(r){var e=0;return Math.abs(r[1])>Math.abs(r[0])&&(e=1),Math.abs(r[2])>Math.abs(r[e])&&(e=2),e},n.prototype.computeNormal_=function(r){var e,t,o,i,a,s,l=[0,0,0],c=[0,0,0],u=[0,0,0],p=[0,0,0],d=[0,0,0],f=[null,null,null],h=[null,null,null],m=this.mesh.vHead;e=m.next;for(var y=0;y<3;++y)i=e.coords[y],c[y]=i,h[y]=e,l[y]=i,f[y]=e;for(e=m.next;e!==m;e=e.next)for(var b=0;b<3;++b)i=e.coords[b],i<c[b]&&(c[b]=i,h[b]=e),i>l[b]&&(l[b]=i,f[b]=e);var S=0;if(l[1]-c[1]>l[0]-c[0]&&(S=1),l[2]-c[2]>l[S]-c[S]&&(S=2),c[S]>=l[S]){r[0]=0,r[1]=0,r[2]=1;return}for(s=0,t=h[S],o=f[S],u[0]=t.coords[0]-o.coords[0],u[1]=t.coords[1]-o.coords[1],u[2]=t.coords[2]-o.coords[2],e=m.next;e!==m;e=e.next)p[0]=e.coords[0]-o.coords[0],p[1]=e.coords[1]-o.coords[1],p[2]=e.coords[2]-o.coords[2],d[0]=u[1]*p[2]-u[2]*p[1],d[1]=u[2]*p[0]-u[0]*p[2],d[2]=u[0]*p[1]-u[1]*p[0],a=d[0]*d[0]+d[1]*d[1]+d[2]*d[2],a>s&&(s=a,r[0]=d[0],r[1]=d[1],r[2]=d[2]);s<=0&&(r[0]=r[1]=r[2]=0,r[this.longAxis_(u)]=1)},n.prototype.checkOrientation_=function(){for(var r=this.mesh.fHead,e,t=this.mesh.vHead,o,i=0,a=r.next;a!==r;a=a.next)if(o=a.anEdge,!(o.winding<=0))do i+=(o.Org.s-o.Dst.s)*(o.Org.t+o.Dst.t),o=o.Lnext;while(o!==a.anEdge);if(i<0){for(e=t.next;e!==t;e=e.next)e.t=-e.t;this.tUnit[0]=-this.tUnit[0],this.tUnit[1]=-this.tUnit[1],this.tUnit[2]=-this.tUnit[2]}},n.prototype.projectPolygon_=function(){var r=this.mesh.vHead,e=[0,0,0],t,o,i=!1;e[0]=this.normal[0],e[1]=this.normal[1],e[2]=this.normal[2],!e[0]&&!e[1]&&!e[2]&&(this.computeNormal_(e),i=!0),t=this.sUnit,o=this.tUnit;var a=this.longAxis_(e);t[a]=0,t[(a+1)%3]=1,t[(a+2)%3]=0,o[a]=0,o[(a+1)%3]=0,o[(a+2)%3]=e[a]>0?1:-1;for(var s=r.next;s!==r;s=s.next)s.s=this.dot_(s.coords,t),s.t=this.dot_(s.coords,o);i&&this.checkOrientation_();for(var l=!0,c=r.next;c!==r;c=c.next)l?(this.bmin[0]=this.bmax[0]=c.s,this.bmin[1]=this.bmax[1]=c.t,l=!1):(c.s<this.bmin[0]&&(this.bmin[0]=c.s),c.s>this.bmax[0]&&(this.bmax[0]=c.s),c.t<this.bmin[1]&&(this.bmin[1]=c.t),c.t>this.bmax[1]&&(this.bmax[1]=c.t))},n.prototype.addWinding_=function(r,e){r.winding+=e.winding,r.Sym.winding+=e.Sym.winding},n.prototype.tessellateMonoRegion_=function(r,e){var t,o;if(t=e.anEdge,!(t.Lnext!==t&&t.Lnext.Lnext!==t))throw"Mono region invalid";for(;ve.vertLeq(t.Dst,t.Org);t=t.Lprev);for(;ve.vertLeq(t.Org,t.Dst);t=t.Lnext);o=t.Lprev;for(var i=void 0;t.Lnext!==o;)if(ve.vertLeq(t.Dst,o.Org)){for(;o.Lnext!==t&&(ve.edgeGoesLeft(o.Lnext)||ve.edgeSign(o.Org,o.Dst,o.Lnext.Dst)<=0);)i=r.connect(o.Lnext,o),o=i.Sym;o=o.Lprev}else{for(;o.Lnext!==t&&(ve.edgeGoesRight(t.Lprev)||ve.edgeSign(t.Dst,t.Org,t.Lprev.Org)>=0);)i=r.connect(t,t.Lprev),t=i.Sym;t=t.Lnext}if(o.Lnext===t)throw"Mono region invalid";for(;o.Lnext.Lnext!==t;)i=r.connect(o.Lnext,o),o=i.Sym;return!0},n.prototype.tessellateInterior_=function(r){for(var e,t=r.fHead.next;t!==r.fHead;t=e)if(e=t.next,t.inside&&!this.tessellateMonoRegion_(r,t))return!1;return!0},n.prototype.discardExterior_=function(r){for(var e,t=r.fHead.next;t!==r.fHead;t=e)e=t.next,t.inside||r.zapFace(t)},n.prototype.setWindingNumber_=function(r,e,t){for(var o,i=r.eHead.next;i!==r.eHead;i=o)o=i.next,i.Rface.inside!==i.Lface.inside?i.winding=i.Lface.inside?e:-e:t?r.delete(i):i.winding=0},n.prototype.getNeighbourFace_=function(r){return!r.Rface||!r.Rface.inside?-1:r.Rface.n},n.prototype.outputPolymesh_=function(r,e,t,o){var i,a=0,s=0,l;t>3&&r.mergeConvexFaces(t);for(var c=r.vHead.next;c!==r.vHead;c=c.next)c.n=-1;for(var u=r.fHead.next;u!==r.fHead;u=u.next)if(u.n=-1,!!u.inside){i=u.anEdge,l=0;do{var c=i.Org;c.n===-1&&(c.n=s,s++),l++,i=i.Lnext}while(i!==u.anEdge);if(l>t)throw"Face vertex greater that support polygon";u.n=a,++a}this.elementCount=a,e===at.CONNECTED_POLYGONS&&(a*=2),this.elements=[],this.elements.length=a*t,this.vertexCount=s,this.vertices=[],this.vertices.length=s*o,this.vertexIndices=[],this.vertexIndices.length=s;for(var c=r.vHead.next;c!==r.vHead;c=c.next)if(c.n!==-1){var p=c.n*o;this.vertices[p+0]=c.coords[0],this.vertices[p+1]=c.coords[1],o>2&&(this.vertices[p+2]=c.coords[2]),this.vertexIndices[c.n]=c.idx}for(var d=0,u=r.fHead.next;u!==r.fHead;u=u.next)if(!!u.inside){i=u.anEdge,l=0;do{var c=i.Org;this.elements[d++]=c.n,l++,i=i.Lnext}while(i!==u.anEdge);for(var f=l;f<t;++f)this.elements[d++]=-1;if(e===at.CONNECTED_POLYGONS){i=u.anEdge;do this.elements[d++]=this.getNeighbourFace_(i),i=i.Lnext;while(i!==u.anEdge);for(var h=l;h<t;++h)this.elements[d++]=-1}}},n.prototype.outputContours_=function(r,e){var t,o,i=0,a=0;this.vertexCount=0,this.elementCount=0;for(var s=r.fHead.next;s!==r.fHead;s=s.next)if(!!s.inside){o=t=s.anEdge;do this.vertexCount++,t=t.Lnext;while(t!==o);this.elementCount++}this.elements=[],this.elements.length=this.elementCount*2,this.vertices=[],this.vertices.length=this.vertexCount*e,this.vertexIndices=[],this.vertexIndices.length=this.vertexCount;var l=0,c=0,u=0;i=0;for(var s=r.fHead.next;s!==r.fHead;s=s.next)if(!!s.inside){a=0,o=t=s.anEdge;do this.vertices[l++]=t.Org.coords[0],this.vertices[l++]=t.Org.coords[1],e>2&&(this.vertices[l++]=t.Org.coords[2]),this.vertexIndices[c++]=this.vertexIdCallback?this.vertexIdCallback(t):t.Org.idx,a++,t=t.Lnext;while(t!==o);this.elements[u++]=i,this.elements[u++]=a,i+=a}},n.prototype.addContour=function(r,e){this.mesh===null&&(this.mesh=new x0),r<2&&(r=2),r>3&&(r=3);for(var t=null,o=0;o<e.length;o+=r)t===null?(t=this.mesh.makeEdge(),this.mesh.splice(t,t.Sym)):(this.mesh.splitEdge(t),t=t.Lnext),t.Org.coords[0]=e[o+0],t.Org.coords[1]=e[o+1],r>2?t.Org.coords[2]=e[o+2]:t.Org.coords[2]=0,t.Org.idx=this.vertexIndexCounter++,this.edgeCreateCallback&&this.edgeCreateCallback(t),t.winding=1,t.Sym.winding=-1},n.prototype.tesselate=function(r,e,t,o,i,a){if(r===void 0&&(r=Fe.ODD),e===void 0&&(e=at.POLYGONS),a===void 0&&(a=!0),this.vertices=[],this.elements=[],this.vertexIndices=[],this.vertexIndexCounter=0,i&&(this.normal[0]=i[0],this.normal[1]=i[1],this.normal[2]=i[2]),this.windingRule=r,o<2&&(o=2),o>3&&(o=3),!this.mesh)return!1;this.projectPolygon_(),vM.computeInterior(this,a);var s=this.mesh;return e===at.BOUNDARY_CONTOURS?this.setWindingNumber_(s,1,!0):this.tessellateInterior_(s),a&&s.check(),e===at.BOUNDARY_CONTOURS?this.outputContours_(s,o):this.outputPolymesh_(s,e,t,o),!0},n}();function Gr(n){var r=n.windingRule,e=r===void 0?Fe.ODD:r,t=n.elementType,o=t===void 0?at.POLYGONS:t,i=n.polySize,a=i===void 0?3:i,s=n.vertexSize,l=s===void 0?2:s,c=n.normal,u=c===void 0?[0,0,1]:c,p=n.contours,d=p===void 0?[]:p,f=n.strict,h=f===void 0?!0:f,m=n.debug,y=m===void 0?!1:m;if(!d&&h)throw new Error("Contours can't be empty");if(!!d){var b=new SM;n.edgeCreateCallback&&(b.edgeCreateCallback=n.edgeCreateCallback),n.vertexIdCallback&&(b.vertexIdCallback=n.vertexIdCallback);for(var S=0;S<d.length;S++)b.addContour(l||2,d[S]);return b.tesselate(e,o,a,l,u,h),{vertices:b.vertices,vertexIndices:b.vertexIndices,vertexCount:b.vertexCount,elements:b.elements,elementCount:b.elementCount,mesh:y?b.mesh:void 0}}}var O6=Fe.ODD,A6=Fe.NONZERO,T6=Fe.POSITIVE,I6=Fe.NEGATIVE,M6=Fe.ABS_GEQ_TWO,E6=at.POLYGONS,N6=at.CONNECTED_POLYGONS,D6=at.BOUNDARY_CONTOURS;import{Box2 as OM,BufferAttribute as pu,BufferGeometry as AM,Vector2 as TM}from"three";var uu=class{constructor(r=256,e=!1){this.capacity=r,this.size=0,this.debug=e,this.debug&&console.log(`allocating with cap ${r}`);let t=r*uu.eSize;this.buffer=new ArrayBuffer(t);let o=Float32Array.BYTES_PER_ELEMENT,i=0;this.positions=new Float32Array(this.buffer,i*o,3*r),i+=3*r,this.normals=new Float32Array(this.buffer,i*o,3*r),i+=3*r,this.uvs=new Float32Array(this.buffer,i*o,2*r)}realloc(r,e=!1){if(r<this.size)throw Error("cannot shrink buffer");if(r<=this.capacity&&!e)return;this.debug&&console.log(`resizing from ${this.capacity} \u2192 ${r}`);let t=r*uu.eSize,o=new ArrayBuffer(t),i=Float32Array.BYTES_PER_ELEMENT,a=0,s=new Float32Array(o,a*i,3*r);a+=3*r;let l=new Float32Array(o,a*i,3*r);a+=3*r;let c=new Float32Array(o,a*i,2*r);e?(s.set(this.positions.subarray(0,this.size*3)),l.set(this.normals.subarray(0,this.size*3)),c.set(this.uvs.subarray(0,this.size*2))):(s.set(this.positions),l.set(this.normals),c.set(this.uvs)),this.buffer=o,this.positions=s,this.normals=l,this.uvs=c,this.capacity=r}get(r=1){let e=this.size+r;if(e>this.capacity){let o=this.capacity;for(;e>o;)o*=2;this.realloc(o)}let t=this.size;return this.size=e,t}reserve(r){let e=this.size+r;e>this.capacity&&this.realloc(e)}shrink(){this.debug&&console.log(`shrinking ${this.capacity} \u2192 ${this.size}`),this.realloc(this.size,!0)}},Hs=uu;Hs.eSize=(3+3+2)*Float32Array.BYTES_PER_ELEMENT;var Ws=class{constructor(r=[],e=(t,o)=>t<o?-1:t>o?1:0){if(this.data=r,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(r){this.data.push(r),this._up(this.length++)}pop(){if(this.length===0)return;let r=this.data[0],e=this.data.pop();return--this.length>0&&(this.data[0]=e,this._down(0)),r}peek(){return this.data[0]}_up(r){let{data:e,compare:t}=this,o=e[r];for(;r>0;){let i=r-1>>1,a=e[i];if(t(o,a)>=0)break;e[r]=a,r=i}e[r]=o}_down(r){let{data:e,compare:t}=this,o=this.length>>1,i=e[r];for(;r<o;){let a=(r<<1)+1,s=a+1;if(s<this.length&&t(e[s],e[a])<0&&(a=s),t(e[a],i)>=0)break;e[r]=e[a],r=a}e[r]=i}};function tf(n,r,e=1,t=!1){let o=1/0,i=1/0,a=-1/0,s=-1/0;for(let[S,P]of n[0])S<o&&(o=S),P<i&&(i=P),S>a&&(a=S),P>s&&(s=P);let l=a-o,c=s-i,u=Math.max(e,Math.min(l,c));if(u===e){let S=[o,i];return S.distance=0,S.distance}let p=new Ws([],(S,P)=>P.max-S.max),d=PM(n),f=new du(o+l/2,i+c/2,0,n);f.d>d.d&&(d=f);let h=2;function m(S,P,C){let v=new du(S,P,C,n);if(h++,v.max>d.d+e&&p.push(v),v.d>d.d&&(d=v,t&&console.log(`found best ${Math.round(1e4*v.d)/1e4} after ${h} probes`),d.d>r))return r}let y=u/2;for(let S=o;S<a;S+=u)for(let P=i;P<s;P+=u)m(S+y,P+y,y);for(;p.length;){let{max:S,x:P,y:C,h:v}=p.pop();if(S-d.d<=e)break;y=v/2,m(P-y,C-y,y),m(P+y,C-y,y),m(P-y,C+y,y),m(P+y,C+y,y)}t&&console.log(`num probes: ${h}
3
+ best distance: ${d.d}`);let b=[d.x,d.y];return b.distance=d.d,b.distance}function du(n,r,e,t){this.x=n,this.y=r,this.h=e,this.d=wM(n,r,t),this.max=this.d+this.h*Math.SQRT2}function wM(n,r,e){let t=!1,o=1/0;for(let i of e)for(let a=0,s=i.length,l=s-1;a<s;l=a++){let c=i[a],u=i[l];c[1]>r!=u[1]>r&&n<(u[0]-c[0])*(r-c[1])/(u[1]-c[1])+c[0]&&(t=!t),o=Math.min(o,CM(n,r,c,u))}return o===0?0:(t?1:-1)*Math.sqrt(o)}function PM(n){let r=0,e=0,t=0,o=n[0];for(let a=0,s=o.length,l=s-1;a<s;l=a++){let c=o[a],u=o[l],p=c[0]*u[1]-u[0]*c[1];e+=(c[0]+u[0])*p,t+=(c[1]+u[1])*p,r+=p*3}let i=new du(e/r,t/r,0,n);return r===0||i.d<0?new du(o[0][0],o[0][1],0,n):i}function CM(n,r,e,t){let o=e[0],i=e[1],a=t[0]-o,s=t[1]-i;if(a!==0||s!==0){let l=((n-o)*a+(r-i)*s)/(a*a+s*s);l>1?(o=t[0],i=t[1]):l>0&&(o+=a*l,i+=s*l)}return a=n-o,s=r-i,a*a+s*s}var qs={vertices:[160,160,-160,160,-160,-160,160,-160],vertexIndices:[1,0,3,2],vertexCount:4,elements:[0,4],elementCount:1,mesh:void 0},of={vertices:[],vertexIndices:[],vertexCount:0,elements:[],elementCount:0,mesh:void 0},nf={vertices:[-160,160,160,-160,160,160,-160,-160],vertexIndices:[1,3,0,2],vertexCount:4,elements:[0,1,2,1,0,3],elementCount:2,mesh:void 0},rf=(n,r)=>([e,t])=>(t<e&&(t+=r),(n>=e?n:n+r)<=t),gn=class extends AM{constructor(e,t,o=0,i=12,a=3,s=Fe.ODD,l=!1){super();this.forPathBevel=l;this.type="ShapeGeometry";this.vertexCache={};this._shape=e,this._depth=t,this._curveSegments=i,this._bevelSegmentsInput=a;let c=this._shape.extractShapePointsToFlatArray([],i),u=this._shape.shapeHoles.map(M=>{let N=M.extractShapePointsToFlatArray([],i),_=[];for(let B=N.length-1;B>=1;B-=2){let V=N[B-1],k=N[B-0];_.push(V,k)}return _}),p=[],d=[];for(let M=0;M<c.length;M+=2)d.push([c[M],c[M+1]]);p.push(d);for(let M=0;M<u.length;M++){let N=u[M],_=[];for(let B=0;B<N.length;B+=2)_.push([N[B],N[B+1]]);p.push(_)}let f;e.isText?f=new OM().setFromPoints(e.points.map(N=>N.position)).getSize(new TM).length()*.1:p[0].length===0?f=o:o>0?f=tf(p,o):f=1e-5,o<=0?(this._bevel=0,this._bevelSegments=0):(this._bevel=Math.min(o,f,t/2),this._bevelSegments=Math.floor(a));let h;try{h=Gr({windingRule:s,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[c]})}catch{h=qs}let m;try{m=Gr({windingRule:Fe.ODD,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...u]})}catch{m=of}if(!h)throw new Error("error generating geometry");let y=h.elementCount;if(m){h.elementCount+=m.elementCount;for(let M=0;M<m.elements.length;M++){let N=m.elements[M],_=M%2===0?h.vertexCount:0;h.elements.push(N+_)}for(let M=0;M<m.vertexIndices.length;M++){let N=m.vertexIndices[M],_=h.vertexCount;h.vertexIndices.push(N+_)}for(let M=0;M<m.vertices.length;M++){let N=m.vertices[M];h.vertices.push(N)}}let b=1/0,S=-1/0,P=1/0,C=-1/0;for(let M=0,N=h.vertexCount;M<N;M++){let _=M*2,B=h.vertices[_+0],V=h.vertices[_+1];B<b&&(b=B),B>S&&(S=B),V<P&&(P=V),V>C&&(C=V)}this._minX=b,this._minY=P,this._width=S-b,this._height=C-P,this._buffer=new Hs(this._computeBufferEstimatedSize(h));let v=[],A=[];for(let M=h.elementCount-1;M>=0;M--){let N=M>=y,_=M*2,B=h.elements[_+0],V=h.elements[_+1],k=B+V,L={start:B,count:V,normals:[],continuous:[],concave:[]},W=B,F=k-1,j=B+1,H=this._shape.roundedCurves.length;do{let te=W-B,K=h.vertices[F*2+0],Z=h.vertices[F*2+1],Q=h.vertices[W*2+0],$=h.vertices[W*2+1],ue=h.vertices[j*2+0],le=h.vertices[j*2+1],ne=Q-K,ce=$-Z,ae=Math.sqrt(ne*ne+ce*ce);ne/=ae,ce/=ae;let me=Q-ue,pe=$-le,he=Math.sqrt(me*me+pe*pe);me/=he,pe/=he,L.normals[te*2+0]=-pe,L.normals[te*2+1]=me,L.concave[te]=ne*pe-ce*me>0;let xe=h.vertexIndices[W];if(Array.isArray(xe))L.continuous[te]=!1;else{let[ye,O]=this._shape.getCurveIndexFromVertexId(xe-1,!0);if(O>0&&O<1)L.continuous[te]=!0;else{let ie=O===1?ye+1:ye-1;ie=(ie+H)%H;let De=O===1?0:1,Ve=this._shape.roundedCurves[ye].getTangent(O),_e=this._shape.roundedCurves[ie].getTangent(De);L.continuous[te]=Ve.dot(_e)>.95}}N&&(L.normals[te*2+0]*=-1,L.normals[te*2+1]*=-1),[F,W,j]=[W,j,j+1],j>=k&&(j-=V)}while(j!==B+1);let q=[];q.push({bevelI:0,angle:0,size:0,boundary:{vertices:h.vertices.slice(B*2,k*2),vertexCount:V,vertexIndices:new Array(V).fill(!0).map((te,K)=>[K,K]),elements:[0,V],elementCount:1,mesh:null},reverseMap:[],insetPoints:h.vertices.slice(B*2,k*2)});let re=0;for(let te=1;te<=this._bevelSegments;te++){let K=te/this._bevelSegments*Math.PI/2,Z=(1-Math.cos(K))*this._bevel,Q=[],$=[],ue=[],le=[],ne=0;for(let ae=0;ae<V;ae++){let me=ae*2,pe=(ae-1+V)%V*2,he=h.vertices[L.start*2+me+0],xe=h.vertices[L.start*2+me+1],ye=-L.normals[pe+0]*Z,O=-L.normals[pe+1]*Z,ie=-L.normals[me+0]*Z,De=-L.normals[me+1]*Z;if(L.concave[ae]||!L.concave[ae]&&N){let Ve=Math.atan2(O,ye),_e=Math.atan2(De,ie);_e>Ve&&(_e-=Math.PI*2);let Pe=_e-Ve;if(L.continuous[ae]||N){let vt=Ve+Pe/2,Ie=Math.cos(vt)*Z,gt=Math.sin(vt)*Z;Q[2*ne+0]=he+Ie*(N?-1:1),Q[2*ne+1]=xe+gt*(N?-1:1),le[ne]=ae,ne++}else{let vt=Math.max(1,Math.floor(i/4*Math.abs(Pe)/Math.PI));for(let Ie=0;Ie<=vt;Ie++){let gt=Ve+Pe*(Ie/vt),St=Math.cos(gt)*Z,Ln=Math.sin(gt)*Z;Q[2*ne+0]=he+St,Q[2*ne+1]=xe+Ln,le[ne]=ae,ne++}}}else Q[2*ne+0]=he+ye,Q[2*ne+1]=xe+O,le[ne]=ae,$[ae]=ne,ne++,Q[2*ne+0]=he,Q[2*ne+1]=xe,le[ne]=ae,ne++,Q[2*ne+0]=he+ie,Q[2*ne+1]=xe+De,le[ne]=ae,ue[ae]=ne,ne++}let ce=Gr({windingRule:Fe.POSITIVE,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[Q],edgeCreateCallback:ae=>{let pe=ae.Org.idx,he=le[pe],xe=le[(pe+1)%le.length];ae.idx=[he,xe],ae.Sym.idx=[xe,he]},vertexIdCallback:ae=>{let me=ae.Lprev.idx;return[me?me[1]:0,ae.idx?ae.idx[0]:0]}});if(!ce)throw console.log("Error"),new Error(`error generating bevel geometry for ${te}'th loop`);if(!ce.vertexCount){let ae=(te-1)/this._bevelSegments*Math.PI/2;re=(1-Math.sin(ae))*this._bevel;break}for(let ae=0;ae<ce.vertexIndices.length;ae++){let[me,pe]=ce.vertexIndices[ae];if(me===pe)continue;let he=pe;pe<me&&(he+=V);for(let xe=me;xe<he;xe++){let ye=xe%V,O=(xe+1)%V;if(!L.continuous[ye]||!L.continuous[O]){ce.vertexIndices[ae]=[me,ye],ce.vertexIndices.splice(ae+1,0,[O,pe]),ce.vertices.splice((ae+1)*2,0,ce.vertices[ae*2],ce.vertices[ae*2+1]);break}}}q.push({bevelI:te,angle:K,size:Z,boundary:ce,reverseMap:le,insetPoints:Q})}let ee=(te,K,Z)=>{let Q=0,$=te.boundary.vertexIndices.length;for(;Q<$&&Z(te.boundary.vertexIndices[K]);)K=(K+1)%$,Q++;return Q},X=v.length;for(let te=1;te<q.length;te++){let K=q[te-1],Z=q[te],Q=K.boundary.vertexIndices.length,$=Z.boundary.vertexIndices.length;if(!Q||!$)break;let ue=L.concave.length,le=0,ne=rf(le,V);for(;!K.boundary.vertexIndices.filter(ne).length||!Z.boundary.vertexIndices.filter(ne).length;)le++,ne=rf(le,V);let ce=K.boundary.vertexIndices.findIndex(ne),ae=Z.boundary.vertexIndices.findIndex(ne);do ce=(ce+1)%Q;while(ne(K.boundary.vertexIndices[ce]));do ae=(ae+1)%$;while(ne(Z.boundary.vertexIndices[ae]));le=(le+1)%V;let me=le,pe=0,he=this._buildBevelVert(L,K,(ce-1+Q)%Q,void 0,pe),xe=this._buildBevelVert(L,Z,(ae-1+$)%$,void 0,pe),ye=he,O=xe,ie,De,Ve=!1;do{pe=(le||ue)/ue,ne=rf(le,V);let _e=ee(K,ce,ne),Pe=ee(Z,ae,ne),vt=Ve;if(Ve=!1,_e&&!Pe){for(let Ie=0;Ie<_e;Ie++)ie=this._buildBevelVert(L,K,(ce+Ie)%Q,Ie/(_e-1),pe),v.push(ye.topN,ie.topP,O.topN),l===!1&&v.push(ie.bottomP,ye.bottomN,O.bottomN),ye=ie;Ve=!0}else if(!_e&&Pe)for(let Ie=0;Ie<Pe;Ie++)De=this._buildBevelVert(L,Z,(ae+Ie)%$,Ie/(Pe-1),pe),v.push(O.topN,ye.topP,De.topP),l===!1&&v.push(ye.bottomP,O.bottomN,De.bottomP),O=De;else if(_e&&Pe)if(ie=this._buildBevelVert(L,K,ce,0,pe),De=this._buildBevelVert(L,Z,ae,0,pe),vt?(v.push(ye.topN,De.topP,O.topN),v.push(ye.topN,ie.topP,De.topP),l===!1&&(v.push(De.bottomP,ye.bottomN,O.bottomN),v.push(De.bottomP,ie.bottomP,ye.bottomN))):(v.push(O.topN,ye.topN,ie.topP),v.push(O.topN,ie.topP,De.topP),l===!1&&(v.push(ie.bottomP,ye.bottomN,O.bottomN),v.push(ie.bottomP,O.bottomN,De.bottomP))),ye=ie,O=De,_e===Pe)for(let Ie=1;Ie<_e;Ie++)ie=this._buildBevelVert(L,K,(ce+Ie)%Q,Ie/(_e-1),pe),De=this._buildBevelVert(L,Z,(ae+Ie)%$,Ie/(Pe-1),pe),v.push(ye.topN,ie.topP,O.topN),v.push(O.topN,ie.topP,De.topP),l===!1&&(v.push(ie.bottomP,ye.bottomN,O.bottomN),v.push(ie.bottomP,O.bottomN,De.bottomP)),ye=ie,O=De;else if(_e>Pe){let Ie=_e/Pe,gt=0;for(let St=1;St<_e;St++)ie=this._buildBevelVert(L,K,(ce+St)%Q,St/(_e-1),pe),v.push(ye.topN,ie.topP,O.topN),l===!1&&v.push(ie.bottomP,ye.bottomN,O.bottomN),ye=ie,St>(gt+1)*Ie&&(gt++,De=this._buildBevelVert(L,Z,(ae+gt)%$,gt/(Pe-1),pe),v.push(O.topN,ie.topP,De.topP),l===!1&&v.push(ie.bottomP,O.bottomN,De.bottomP),O=De)}else{let Ie=Pe/_e,gt=0;for(let St=1;St<Pe;St++)De=this._buildBevelVert(L,Z,(ae+St)%$,St/(Pe-1),pe),v.push(O.topN,ie.topP,De.topP),l===!1&&v.push(ie.bottomP,O.bottomN,De.bottomP),O=De,St>(gt+1)*Ie&&(gt++,ie=this._buildBevelVert(L,K,(ce+gt)%Q,gt/(_e-1),pe),v.push(ye.topN,ie.topP,O.topN),l===!1&&v.push(ie.bottomP,ye.bottomN,O.bottomN),ye=ie)}ce=(ce+_e)%Q,ae=(ae+Pe)%$,le=(le+1)%ue}while(le!==me)}if(l===!1&&this._depth>this._bevel*2&&this._buildWall(q,L,v),N){let te=[];for(let K=v.length-1;K>=X+2;K-=3){let Z=v[K-2],Q=v[K-1],$=v[K-0];te.push($,Q,Z)}v.splice(X,v.length-X,...te)}if(N){let te=[];for(let K=q[q.length-1].boundary.vertices.length-1;K>=1;K-=2){let Z=q[q.length-1].boundary.vertices[K-1],Q=q[q.length-1].boundary.vertices[K-0];te.push(Z,Q)}A.push(te)}if(!N){let te=q[q.length-1],K;try{K=Gr({windingRule:q.length>1?Fe.POSITIVE:Fe.ODD,elementType:at.POLYGONS,vertexSize:2,strict:!0,contours:[te.insetPoints,...A]})}catch{K=nf}if(!K)throw new Error("Error generating geometry for surface");u.length===0&&this._bevel<f&&Object.assign(this,{useNgonForTopBottomFaceDuringBake:!0});for(let Z=0;Z<K.elementCount*3;Z+=3){let Q=this._buildSurfaceVert(K,K.elements[Z+0],re),$=this._buildSurfaceVert(K,K.elements[Z+1],re),ue=this._buildSurfaceVert(K,K.elements[Z+2],re);v.push(Q.top,$.top,ue.top),l===!1&&v.push(ue.bottom,$.bottom,Q.bottom)}}this.vertexCache={}}this._buffer.shrink();let T=new pu(Uint32Array.from(v),1),g=new pu(this._buffer.positions,3),D=new pu(this._buffer.normals,3),E=new pu(this._buffer.uvs,2);g.needsUpdate=!0,D.needsUpdate=!0,E.needsUpdate=!0,T.needsUpdate=!0,this.setAttribute("position",g),this.setAttribute("normal",D),this.setAttribute("uv",E),this.setIndex(T)}_computeBufferEstimatedSize(e){return e.vertexCount*2*(2+this._bevelSegments)}_buildWall(e,t,o){let i=e[0];for(let a=0,s=i.boundary.vertexCount;a<s;a++){let l=this._buildBevelVert(t,i,a),c=this._buildBevelVert(t,i,(a+1)%s);o.push(c.topP,l.topN,l.bottomN),o.push(c.topP,l.bottomN,c.bottomP)}}_buildSurfaceVert(e,t,o){let i=t.toString();if(i in this.vertexCache)return this.vertexCache[i];let a=e.vertices[t*2+0],s=e.vertices[t*2+1],l=(a-this._minX)/this._width,c=(s-this._minY)/this._height;this.forPathBevel&&(c=1);let u=this._buffer.get(this.forPathBevel?1:2),p=u*3,d=u*2,f={top:u+0,bottom:u+1};return this._buffer.positions[p+0]=a,this._buffer.positions[p+1]=s,this._buffer.positions[p+2]=this.forPathBevel?this._bevel:this._depth-o,this._buffer.normals[p+0]=0,this._buffer.normals[p+1]=0,this._buffer.normals[p+2]=1,this._buffer.uvs[d+0]=l,this._buffer.uvs[d+1]=c,this.forPathBevel===!1&&(this._buffer.positions[p+3]=a,this._buffer.positions[p+4]=s,this._buffer.positions[p+5]=o,this._buffer.normals[p+3]=0,this._buffer.normals[p+4]=0,this._buffer.normals[p+5]=-1,this._buffer.uvs[d+2]=l,this._buffer.uvs[d+3]=c),this.vertexCache[i]=f,f}_buildBevelVert(e,t,o,i=1,a){let s=`${t.bevelI}:${o}`;if(s in this.vertexCache&&a!==0&&a!==1&&(!a||a===this.vertexCache[s].pathBevelUCoord))return this.vertexCache[s];let[l,c]=t.boundary.vertexIndices[o],u,p,d,f;l!==c?(p=l,u=c,f=!1,d=e.continuous[p]&&e.continuous[u]):(u=l,p=(u-1+e.count)%e.count,f=e.concave[u]&&t.bevelI>0,d=e.continuous[u]||f);let h=Math.cos(t.angle),m=Math.sin(t.angle),y=o*2,b=u*2,S=p*2,P=t.boundary.vertices[y+0],C=t.boundary.vertices[y+1],v=(1-m)*this._bevel,A=(P-this._minX)/this._width,T=(C-this._minY)/this._height;this.forPathBevel&&(a!==void 0&&(A=a),T=1);let g=e.normals[b+0],D=e.normals[b+1],E=e.normals[S+0],M=e.normals[S+1];if(f){let k=E-g,L=M-D;g=g+k*(1-i),D=D+L*(1-i);let W=Math.sqrt(g*g+D*D);g/=W,D/=W}let N=this.forPathBevel?this._buffer.get(d?1:2):this._buffer.get(d?2:4),_=N*3,B=N*2,V={i:o,fi:u,topP:N+0,topN:N+0,bottomP:N+1,bottomN:N+1,pathBevelUCoord:a};return this._buffer.positions[_+0]=P,this._buffer.positions[_+1]=C,this._buffer.positions[_+2]=(this.forPathBevel?this._bevel:this._depth)-v,this._buffer.normals[_+0]=g*h,this._buffer.normals[_+1]=D*h,this._buffer.normals[_+2]=m,this._buffer.uvs[B+0]=A,this._buffer.uvs[B+1]=T,this.forPathBevel===!1&&(this._buffer.positions[_+3]=P,this._buffer.positions[_+4]=C,this._buffer.positions[_+5]=v,this._buffer.normals[_+3]=g*h,this._buffer.normals[_+4]=D*h,this._buffer.normals[_+5]=-m,this._buffer.uvs[B+2]=T,this._buffer.uvs[B+3]=A),d||(this.forPathBevel?(N+=1,_+=3,B+=2):(N+=2,_+=6,B+=4),V.topP=N+0,V.bottomP=N+1,this._buffer.positions[_+0]=P,this._buffer.positions[_+1]=C,this._buffer.positions[_+2]=(this.forPathBevel?this._bevel:this._depth)-v,this._buffer.normals[_+0]=E*h,this._buffer.normals[_+1]=M*h,this._buffer.normals[_+2]=m,this._buffer.uvs[B+0]=A,this._buffer.uvs[B+1]=T,this.forPathBevel===!1&&(this._buffer.positions[_+3]=P,this._buffer.positions[_+4]=C,this._buffer.positions[_+5]=v,this._buffer.normals[_+3]=E*h,this._buffer.normals[_+4]=M*h,this._buffer.normals[_+5]=-m,this._buffer.uvs[B+2]=T,this._buffer.uvs[B+3]=A)),this.vertexCache[s]=V,V}clone(){let e=new gn(this._shape,this._depth,this._bevel,this._curveSegments,this._bevelSegmentsInput);return e.userData=Co(this.userData),e}};var ga=class extends IM{constructor(e,t=12,o={}){super();this.type="ShapeGeometry";this.windingRule=Fe.ODD;this.elementType=at.POLYGONS;this.polySize=3;this.vertexSize=2;this.strict=!0;this._shape=e,this._curveSegments=t,this._triangulationOptions=Object.assign({windingRule:Fe.ODD,elementType:at.POLYGONS,polySize:3,vertexSize:2,strict:!0},o);let i=this._shape.extractShapePointsToFlatArray([],this._curveSegments),a=this._shape.shapeHoles.map(h=>h.extractShapePointsToFlatArray([],this._curveSegments)),s,l=!0,c=!0,u,p;for(let h=0,m=i.length/2;h<m;h++){let y=h*2,b=i[y+0],S=i[y+1];if(u!==void 0&&b!==u&&(l=!1),p!==void 0&&S!==p&&(c=!1),u=b,p=S,!l&&!c)break}if(!l&&!c)try{s=Gr({contours:[i,...a],windingRule:this._triangulationOptions.windingRule,elementType:this._triangulationOptions.elementType,polySize:this._triangulationOptions.polySize,vertexSize:this._triangulationOptions.vertexSize,strict:this._triangulationOptions.strict})}catch{s=qs}let d=s?.vertexCount??1,f=s?.elementCount??1;if(this._positionAttribute=new fu(new Float32Array(d*3),3),this._normalAttribute=new fu(new Float32Array(d*3),3),this._uvAttribute=new fu(new Float32Array(d*2),2),this._indexAttribute=new fu(new Uint32Array(f*3),1),s){let h=1/0,m=-1/0,y=1/0,b=-1/0;for(let C=0,v=d;C<v;C++){let A=C*2,T=s.vertices[A+0],g=s.vertices[A+1];T<h&&(h=T),T>m&&(m=T),g<y&&(y=g),g>b&&(b=g)}let S=m-h,P=b-y;for(let C=0,v=d;C<v;C++){let A=C*2,T=s.vertices[A+0],g=s.vertices[A+1],D=(T-h)/S,E=(g-y)/P;this._positionAttribute.setXYZ(C,T,g,0),this._normalAttribute.setXYZ(C,0,0,1),this._uvAttribute.setXY(C,D,E)}for(let C=0,v=f;C<v;C++){let A=C*3,T=s.elements[A+0],g=s.elements[A+1],D=s.elements[A+2];this._indexAttribute.setX(A+0,T),this._indexAttribute.setX(A+1,g),this._indexAttribute.setX(A+2,D)}}this.setAttribute("position",this._positionAttribute),this.setAttribute("normal",this._normalAttribute),this.setAttribute("uv",this._uvAttribute),this.setIndex(this._indexAttribute),this.setDrawRange(0,(s?.elementCount??1)*3)}clone(){let e=new ga(this._shape,this._curveSegments);return e.userData=Co(this.userData),e}};var xa=class extends gn{constructor(e,t,o=0,i=12,a=3,s=Fe.ODD){super(e,t,o,i,a,s);this.type="ShapeGeometry"}_computeBufferEstimatedSize(e){return e.vertexCount*2*(2+this._bevelSegments)}_buildWall(e,t,o){let i=e[0];for(let a=0,s=i.boundary.vertexCount;a<s;a++){let l=this._buildBevelVert(t,i,a),c=this._buildBevelVert(t,i,(a+1)%s);o.push(c.topP,l.topN,l.bottomN),o.push(c.topP,l.bottomN,c.bottomP)}}clone(){let e=new xa(this._shape,this._depth,this._bevel,this._curveSegments,this._bevelSegmentsInput);return e.userData=Co(this.userData),e}};var Jt=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,subdivisions:40,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3,windingRule:Fe.ODD},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.abs(e.depth??0),a=n.shape??r?.shape,s=a?.roundness??e.roundness;a!==void 0&&(a instanceof je?(a.width!==t||a.height!==o)&&a.applySize(t,o):a=new je(t,o).fromJSON(a),n.parameters?.roundness!==void 0&&n.parameters?.roundness>0&&a.update());let l=a??new je(t,o);return{parameters:Object.assign(e,{width:t,height:o,depth:i,roundness:s}),shape:l}}static build(n){let{depth:r,extrudeBevelSize:e,extrudeBevelSegments:t,subdivisions:o,roundness:i,windingRule:a}=n.parameters;n.shape.roundness=i;let s;return r<=0?s=new ga(n.shape,o,{windingRule:a}):s=new xa(n.shape,r,e,o,t,a),Object.assign(s,{userData:{...n,type:"VectorGeometry"}})}};import{BufferGeometry as MM,Float32BufferAttribute as EM,MathUtils as af,Vector2 as P0}from"three";var C0=Math.PI*2,va=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:64,angle:360,innerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters);return e.angle=af.clamp(e.angle,0,360),{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,spikes:t,angle:o,innerRadius:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}=n.parameters,c=n.shape,u=r*.5,p=e*.5,d=NM(c,u,p,o*Math.PI/180,t,i);c.isClosed=!0,c.update();let f;return o===0?(f=new MM,f.setAttribute("position",new EM([],3))):f=Jt.create({shape:c,parameters:{subdivisions:d,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}}),Object.assign(f,{userData:{...n,type:"EllipseGeometry"}})}};function NM(n,r,e,t,o,i){if(t>=C0)return o>30||o%4===0?(_M(n,r,e,i),Math.round(o/4)):w0(n,t,o,r,e,i);t=Math.max(t,.001);let a={x:0,y:e},s=t+Math.PI*.5,l={x:Math.cos(s)*r,y:Math.sin(s)*e},c=g0({px:a.x,py:a.y,cx:l.x,cy:l.y,rx:r,ry:e,largeArcFlag:t>Math.PI,sweepFlag:!0});return o>30||o%c.length===0?DM(n,a.x,a.y,c,o,r,e,i):w0(n,t,o,r,e,i)}function DM(n,r,e,t,o,i,a,s){let l=Math.round(o/t.length);n.addPoint(ba(r,e));for(let c=0,u=t.length;c<u;c++){let p=t[c],d=n.points[c],f=ba(p.x,p.y);d.controls[1].position.set(p.x1,p.y1),f.controls[0].position.set(p.x2,p.y2),n.addPoint(f)}return s>0?O0(n,i,a,s):n.addPoint(ba(0,0)),l}function w0(n,r,e,t,o,i){let a=-r/e;for(let s=0;s<=e;s++){let l=a*s,c=Math.sin(l)*t,u=Math.cos(l)*o;n.addPoint(ba(c,u))}return r<C0?i>0?O0(n,t,o,i):n.addPoint(ba(0,0)):(n.removePoint(n.points[n.points.length-1]),i>0&&A0(n,t,o,i)),1}function _M(n,r,e,t=0,o=0,i=0){let a=.5522847498,s=r*a,l=e*a;n.addPoint(hu(o-r,i,o-r,i-l,o-r,i+l)),n.addPoint(hu(o,i+e,o-s,i+e,o+s,i+e)),n.addPoint(hu(o+r,i,o+r,i+l,o+r,i-l)),n.addPoint(hu(o,i-e,o+s,i-e,o-s,i-e)),t>0&&A0(n,r,e,t)}function ba(n,r){return new zr(af.generateUUID(),new P0(n,r))}function hu(n,r,e,t,o,i){let a=ba(n,r);return a.controls[0].position.set(e,t),a.controls[1].position.set(o,i),a}function O0(n,r,e,t){T0(n,r,e,t).forEach(i=>n.addPoint(i))}function A0(n,r,e,t){let o=T0(n,r,e,t),i=new je;o.forEach(a=>i.addPoint(a)),i.isClosed=!0,n.shapeHoles.push(i)}function T0(n,r,e,t){let o=t*r/100,i=o*(Math.abs(e)/Math.abs(r)),a=new P0(o/r,i/e),s=n.points.map(l=>{let c=l.clone();return c.uuid=af.generateUUID(),c}).reverse();return s.forEach(l=>{l.position.multiply(a);let c=l.controls[0].position.clone().multiply(a),u=l.controls[1].position.clone().multiply(a);l.controls[0].position.copy(u),l.controls[1].position.copy(c)}),s}import{BufferGeometry as BM,Float32BufferAttribute as sf,Uint32BufferAttribute as RM,Vector3 as I0}from"three";var M0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,revolutions:2,segments:40,pathRadius:10,pathType:0,pathSegments:30,cornerRadius:30,cornerSegments:4},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??t),i=Math.abs(e.depth??t),a=Math.abs(Math.min(t,i))/2;return{parameters:Object.assign(e,{width:t,height:o,depth:i,radius:a,segments:Math.round(e.segments),pathSegments:Math.round(e.pathSegments),cornerSegments:Math.round(e.cornerSegments)})}}static build(n){let{width:r,height:e,depth:t,radius:o,revolutions:i,segments:a,pathRadius:s,pathType:l,pathSegments:c,cornerRadius:u,cornerSegments:p}=n.parameters,d=new $s(!1,r,e,t,o,i,a,s,l,c,u,p);return Object.assign(d,{userData:{...n,type:"HelixGeometry"}})}},lf=new RM([0,0,0],1),$s=class extends BM{constructor(r=!0,e=1,t=1,o=1,i=1,a=1,s=1,l=1,c=1,u=1,p=1,d=1){if(super(),a===0)return;let f=r&&a===1;f&&(d=0),p>100&&(p=100),p===0&&(d=0);let h=()=>new I0,m=new I0,y=h(),b=h(),S=h(),P,C,v,A,T,g,D,E,M=h(),N=h(),_=h(),B=h(),V=h(),k=h(),L=h(),W=h(),F=t-2*l+.001,j=F/a,H=Math.ceil(s*a),q=H+1,re=F/H,ee=-F/2,X=u+1,te=2*Math.PI/u,K=Math.PI/2/d,Z=.01,Q=Math.min((1-p/100)*l,l-Z),$=l-Q,ue=0,le=2,ne=d*le+le,ce=X*ne/le,ae=ce+X*q,me=Math.max(0,X*(q+ne)),[pe,he,xe]=[3,3,2].map(ot=>Array(me*ot).fill(0)),ye=[],O=i-l;function ie(ot,Xe){let Mr=Math.PI/2;g=Xe*re,E=2*Math.PI*(g%j)/j+Mr,g+=ee,D=Math.sin(E)*O,T=Math.cos(E)*O,r?ot.set(T,D,g):ot.set(T,g,D)}ie(m,-1e-10),ie(y,0),M.copy(m),ie(m,1);let De=m.distanceTo(y),Ve=f?0:$+Q,_e=De*H+2*Ve,Pe=Q,vt=_e-Ve;for(let ot=0;ot<=H;ot++){ie(b,ot),W.subVectors(b,M).normalize(),M.copy(b),k.copy(b).setComponent(+r+1,0).normalize(),L.crossVectors(W,k).normalize();let Xe=ot===0,Mr=ot===H,Md=Xe?3*Math.PI/2:K,Ed=Xe?Pe:vt,El=Xe?X:ae,Vn=Xe?0:me-X,ct=W.clone().multiplyScalar(Xe?-$:$).add(b),Nd=W.clone().multiplyScalar(Xe?-1:1).normalize();for(let hr=0;hr<X;hr++){let ys=hr*te;if(N.addVectors(m.copy(k).multiplyScalar(l*Math.cos(ys)),y.copy(L).multiplyScalar(l*Math.sin(ys))),_.copy(N).normalize(),Xe||Mr){f||(ue=Vn+hr,[0,1,2].forEach(Ut=>{pe[ue*3+Ut]=ct.getComponent(Ut),he[ue*3+Ut]=Nd.getComponent(Ut)}),xe[ue*2]=+Mr,xe[ue*2+1]=hr/u),y.copy(_).multiplyScalar(Q),S.addVectors(b,y);for(let Ut=0;Ut<d;Ut++){let zn=Ut*K+Md;B.addVectors(m.copy(W).multiplyScalar($*Math.sin(zn)),y.copy(_).multiplyScalar($*Math.cos(zn))),V.copy(B).normalize(),y.addVectors(S,B),B.normalize(),ue=El+Ut*X+hr,[0,1,2].forEach(yi=>{pe[ue*3+yi]=y.getComponent(yi),he[ue*3+yi]=V.getComponent(yi)});let Nl=+Xe+Math.sin(zn);xe[ue*2]=(Ed+$*Nl)/_e,xe[ue*2+1]=hr/u}}y.addVectors(b,N),ue=ce+ot*X+hr,[0,1,2].forEach(Ut=>{pe[ue*3+Ut]=y.getComponent(Ut),he[ue*3+Ut]=_.getComponent(Ut)}),xe[ue*2]=(Ve+ot*De)/_e,xe[ue*2+1]=hr/u}}let Ie=q+2*d+le,gt=1,[St,Ln]=[+f,Ie-1];for(let ot=St;ot<=Ln-1;ot++){let Xe=f&&ot===Ln-1;for(let Mr=0;Mr<X-1;Mr++)P=ot*X+Mr,C=P+1,v=(Xe?Mr:P)+X,A=(Xe?Mr+1:C)+X,ot===0?ye.push(C,A,v):ot===Ie-2?ye.push(P,C,v):ye.push(P,C,v,C,A,v)}this.setIndex(ye),this.setAttribute("position",new sf(pe,3)),this.setAttribute("normal",new sf(he,3)),this.setAttribute("uv",new sf(xe,2))}getClosedTorusIndicesForBooleanOrSubdiv(){let r=this.userData.parameters,e=Math.ceil(r.tubularSegments),t=r.radialSegments+1,o=Array.from(this.getIndex().array),i,a,s,l,c=6*(e-1)*r.radialSegments,u=e,p=u===e;for(let d=0;d<r.radialSegments;d++)i=u*t+d,a=i+1,s=(p?d:i)+t,l=(p?d+1:a)+t,o[c++]=i,o[c++]=a,o[c++]=s,o[c++]=a,o[c++]=l,o[c++]=s;return o.length=c,lf.array=o,lf.count=o.length,lf}};import{IcosahedronGeometry as LM}from"three";var E0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,detail:0,corner:0,cornerSides:4},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,detail:o,corner:i,cornerSides:a}=n.parameters,s=o===0&&i!==0?new Ys(r*.5,i,a):new LM(r*.5,o);return s.scale(1,e/r,t/r),Object.assign(s,{userData:{...n,type:"IcosahedronGeometry"}})}},Ys=class extends mn{constructor(r=1,e=.2,t=4){let o=(1+Math.sqrt(5))/2,i=[-1,o,0,1,o,0,-1,-o,0,1,-o,0,0,-1,o,0,1,o,0,-1,-o,0,1,-o,o,0,-1,o,0,1,-o,0,-1,-o,0,1],a=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],s="IcosahedronGeometry";super(i,a,s,r,e,t),this.type=s}static fromJSON(r){return new Ys(r.radius,r.corner,r.cornerSides)}};import{LatheGeometry as VM,Shape as zM}from"three";var N0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){(n.parameters?.points??[]).forEach(t=>{Array.isArray(t)&&(t.x=t[0],t.y=t[1])});let e=Object.assign({},r?.parameters??{width:100,segments:64,verticalSegments:64,points:[{x:0,y:-50,id:0},{x:50,y:-50,id:1},{x:50,y:50,id:2},{x:0,y:50,id:3}]},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{points:r,segments:e,verticalSegments:t}=n.parameters,o=new zM;o.moveTo(r[0].x,r[0].y),o.bezierCurveTo(r[1].x,r[1].y,r[2].x,r[2].y,r[3].x,r[3].y);let i=new VM(o.extractPoints(t).shape,e);return i.rotateZ(Math.PI),Object.assign(i,{userData:{...n,type:"LatheGeometry"}})}};import{BufferGeometry as G0,BufferGeometryLoader as KM,Vector3 as QM,BoxGeometry as F0}from"three";import{BufferGeometry as qM,Vector2 as pf,Vector3 as z0}from"three";import{Box3 as GM,BufferAttribute as Xs,BufferGeometry as D0,Color as df,EventDispatcher as FM,Float32BufferAttribute as Sa,Matrix3 as _0,Matrix4 as V0,MathUtils as jM,Object3D as kM,Sphere as UM,Vector2 as ur,Vector3 as zt,Vector4 as HM}from"three";var ao=new V0,cf=new kM,mu=new zt,xn=class extends FM{constructor(){super(),this.uuid=jM.generateUUID(),this.name="",this.type="Geometry",this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.elementsNeedUpdate=!1,this.verticesNeedUpdate=!1,this.uvsNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.lineDistancesNeedUpdate=!1,this.groupsNeedUpdate=!1}applyMatrix4(r){let e=new _0().getNormalMatrix(r);for(let t=0,o=this.vertices.length;t<o;t++)this.vertices[t].applyMatrix4(r);for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t];i.normal.applyMatrix3(e).normalize();for(let a=0,s=i.vertexNormals.length;a<s;a++)i.vertexNormals[a].applyMatrix3(e).normalize()}return this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this.verticesNeedUpdate=!0,this.normalsNeedUpdate=!0,this}rotateX(r){return ao.makeRotationX(r),this.applyMatrix4(ao),this}rotateY(r){return ao.makeRotationY(r),this.applyMatrix4(ao),this}rotateZ(r){return ao.makeRotationZ(r),this.applyMatrix4(ao),this}translate(r,e,t){return ao.makeTranslation(r,e,t),this.applyMatrix4(ao),this}scale(r,e,t){return ao.makeScale(r,e,t),this.applyMatrix4(ao),this}lookAt(r){return cf.lookAt(r),cf.updateMatrix(),this.applyMatrix4(cf.matrix),this}fromBufferGeometry(r){let e=this,t=r.index!==null?r.index:void 0,o=r.attributes;if(o.position===void 0)return console.error("THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion."),this;let i=o.position,a=o.normal,s=o.color,l=o.uv,c=o.uv2;c!==void 0&&(this.faceVertexUvs[1]=[]);for(let d=0;d<i.count;d++)e.vertices.push(new zt().fromBufferAttribute(i,d)),s!==void 0&&e.colors.push(new df().fromBufferAttribute(s,d));function u(d,f,h,m){let y=s===void 0?[]:[e.colors[d].clone(),e.colors[f].clone(),e.colors[h].clone()],b=a===void 0?[]:[new zt().fromBufferAttribute(a,d),new zt().fromBufferAttribute(a,f),new zt().fromBufferAttribute(a,h)],S=new wa(d,f,h,b,y,m);e.faces.push(S),l!==void 0&&e.faceVertexUvs[0].push([new ur().fromBufferAttribute(l,d),new ur().fromBufferAttribute(l,f),new ur().fromBufferAttribute(l,h)]),c!==void 0&&e.faceVertexUvs[1].push([new ur().fromBufferAttribute(c,d),new ur().fromBufferAttribute(c,f),new ur().fromBufferAttribute(c,h)])}let p=r.groups;if(p.length>0)for(let d=0;d<p.length;d++){let f=p[d],h=f.start,m=f.count;for(let y=h,b=h+m;y<b;y+=3)t!==void 0?u(t.getX(y),t.getX(y+1),t.getX(y+2),f.materialIndex):u(y,y+1,y+2,f.materialIndex)}else if(t!==void 0)for(let d=0;d<t.count;d+=3)u(t.getX(d),t.getX(d+1),t.getX(d+2));else for(let d=0;d<i.count;d+=3)u(d,d+1,d+2);return this.computeFaceNormals(),r.boundingBox!==null&&(this.boundingBox=r.boundingBox.clone()),r.boundingSphere!==null&&(this.boundingSphere=r.boundingSphere.clone()),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(mu).negate(),this.translate(mu.x,mu.y,mu.z),this}normalize(){this.computeBoundingSphere();let r=this.boundingSphere.center,e=this.boundingSphere.radius,t=e===0?1:1/e,o=new V0;return o.set(t,0,0,-t*r.x,0,t,0,-t*r.y,0,0,t,-t*r.z,0,0,0,1),this.applyMatrix4(o),this}computeFaceNormals(){let r=new zt,e=new zt;for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t],a=this.vertices[i.a],s=this.vertices[i.b],l=this.vertices[i.c];r.subVectors(l,s),e.subVectors(a,s),r.cross(e),r.normalize(),i.normal.copy(r)}}computeVertexNormals(r=!0){let e=new Array(this.vertices.length);for(let t=0,o=this.vertices.length;t<o;t++)e[t]=new zt;if(r){let t=new zt,o=new zt;for(let i=0,a=this.faces.length;i<a;i++){let s=this.faces[i],l=this.vertices[s.a],c=this.vertices[s.b],u=this.vertices[s.c];t.subVectors(u,c),o.subVectors(l,c),t.cross(o),e[s.a].add(t),e[s.b].add(t),e[s.c].add(t)}}else{this.computeFaceNormals();for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t];e[i.a].add(i.normal),e[i.b].add(i.normal),e[i.c].add(i.normal)}}for(let t=0,o=this.vertices.length;t<o;t++)e[t].normalize();for(let t=0,o=this.faces.length;t<o;t++){let i=this.faces[t],a=i.vertexNormals;a.length===3?(a[0].copy(e[i.a]),a[1].copy(e[i.b]),a[2].copy(e[i.c])):(a[0]=e[i.a].clone(),a[1]=e[i.b].clone(),a[2]=e[i.c].clone())}this.faces.length>0&&(this.normalsNeedUpdate=!0)}computeFlatVertexNormals(){this.computeFaceNormals();for(let r=0,e=this.faces.length;r<e;r++){let t=this.faces[r],o=t.vertexNormals;o.length===3?(o[0].copy(t.normal),o[1].copy(t.normal),o[2].copy(t.normal)):(o[0]=t.normal.clone(),o[1]=t.normal.clone(),o[2]=t.normal.clone())}this.faces.length>0&&(this.normalsNeedUpdate=!0)}computeMorphNormals(){for(let e=0,t=this.faces.length;e<t;e++){let o=this.faces[e];o.__originalFaceNormal?o.__originalFaceNormal.copy(o.normal):o.__originalFaceNormal=o.normal.clone(),o.__originalVertexNormals||(o.__originalVertexNormals=[]);for(let i=0,a=o.vertexNormals.length;i<a;i++)o.__originalVertexNormals[i]?o.__originalVertexNormals[i].copy(o.vertexNormals[i]):o.__originalVertexNormals[i]=o.vertexNormals[i].clone()}let r=new xn;r.faces=this.faces;for(let e=0,t=this.morphTargets.length;e<t;e++){if(!this.morphNormals[e]){this.morphNormals[e]={},this.morphNormals[e].faceNormals=[],this.morphNormals[e].vertexNormals=[];let i=this.morphNormals[e].faceNormals,a=this.morphNormals[e].vertexNormals;for(let s=0,l=this.faces.length;s<l;s++){let c=new zt,u={a:new zt,b:new zt,c:new zt};i.push(c),a.push(u)}}let o=this.morphNormals[e];r.vertices=this.morphTargets[e].vertices,r.computeFaceNormals(),r.computeVertexNormals();for(let i=0,a=this.faces.length;i<a;i++){let s=this.faces[i],l=o.faceNormals[i],c=o.vertexNormals[i];l.copy(s.normal),c.a.copy(s.vertexNormals[0]),c.b.copy(s.vertexNormals[1]),c.c.copy(s.vertexNormals[2])}}for(let e=0,t=this.faces.length;e<t;e++){let o=this.faces[e];o.normal=o.__originalFaceNormal,o.vertexNormals=o.__originalVertexNormals}}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new GM),this.boundingBox.setFromPoints(this.vertices)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new UM),this.boundingSphere.setFromPoints(this.vertices)}merge(r,e,t=0){if(!(r&&r.isGeometry)){console.error("THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.",r);return}let o,i=this.vertices.length,a=this.vertices,s=r.vertices,l=this.faces,c=r.faces,u=this.colors,p=r.colors;e!==void 0&&(o=new _0().getNormalMatrix(e));for(let d=0,f=s.length;d<f;d++){let m=s[d].clone();e!==void 0&&m.applyMatrix4(e),a.push(m)}for(let d=0,f=p.length;d<f;d++)u.push(p[d].clone());for(let d=0,f=c.length;d<f;d++){let h=c[d],m,y,b=h.vertexNormals,S=h.vertexColors,P=new wa(h.a+i,h.b+i,h.c+i);P.normal.copy(h.normal),o!==void 0&&P.normal.applyMatrix3(o).normalize();for(let C=0,v=b.length;C<v;C++)m=b[C].clone(),o!==void 0&&m.applyMatrix3(o).normalize(),P.vertexNormals.push(m);P.color.copy(h.color);for(let C=0,v=S.length;C<v;C++)y=S[C],P.vertexColors.push(y.clone());P.materialIndex=h.materialIndex+t,l.push(P)}for(let d=0,f=r.faceVertexUvs.length;d<f;d++){let h=r.faceVertexUvs[d];this.faceVertexUvs[d]===void 0&&(this.faceVertexUvs[d]=[]);for(let m=0,y=h.length;m<y;m++){let b=h[m],S=[];for(let P=0,C=b.length;P<C;P++)S.push(b[P].clone());this.faceVertexUvs[d].push(S)}}}mergeMesh(r){if(!(r&&r.isMesh)){console.error("THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.",r);return}r.matrixAutoUpdate&&r.updateMatrix(),this.merge(r.geometry,r.matrix)}mergeVertices(r=4){let e={},t=[],o=[],i=Math.pow(10,r);for(let l=0,c=this.vertices.length;l<c;l++){let u=this.vertices[l],p=Math.round(u.x*i)+"_"+Math.round(u.y*i)+"_"+Math.round(u.z*i);e[p]===void 0?(e[p]=l,t.push(this.vertices[l]),o[l]=t.length-1):o[l]=o[e[p]]}let a=[];for(let l=0,c=this.faces.length;l<c;l++){let u=this.faces[l];u.a=o[u.a],u.b=o[u.b],u.c=o[u.c];let p=[u.a,u.b,u.c];for(let d=0;d<3;d++)if(p[d]===p[(d+1)%3]){a.push(l);break}}for(let l=a.length-1;l>=0;l--){let c=a[l];this.faces.splice(c,1);for(let u=0,p=this.faceVertexUvs.length;u<p;u++)this.faceVertexUvs[u].splice(c,1)}let s=this.vertices.length-t.length;return this.vertices=t,s}setFromPoints(r){this.vertices=[];for(let e=0,t=r.length;e<t;e++){let o=r[e];this.vertices.push(new zt(o.x,o.y,o.z||0))}return this}sortFacesByMaterialIndex(){let r=this.faces,e=r.length;for(let l=0;l<e;l++)r[l]._id=l;function t(l,c){return l.materialIndex-c.materialIndex}r.sort(t);let o=this.faceVertexUvs[0],i=this.faceVertexUvs[1],a,s;o&&o.length===e&&(a=[]),i&&i.length===e&&(s=[]);for(let l=0;l<e;l++){let c=r[l]._id;a&&a.push(o[c]),s&&s.push(i[c])}a&&(this.faceVertexUvs[0]=a),s&&(this.faceVertexUvs[1]=s)}toJSON(){let r={metadata:{version:4.5,type:"Geometry",generator:"Geometry.toJSON"}};if(r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.parameters!==void 0){let h=this.parameters;for(let m in h)h[m]!==void 0&&(r[m]=h[m]);return r}let e=[];for(let h=0;h<this.vertices.length;h++){let m=this.vertices[h];e.push(m.x,m.y,m.z)}let t=[],o=[],i={},a=[],s={},l=[],c={};for(let h=0;h<this.faces.length;h++){let m=this.faces[h],y=!0,b=!1,S=this.faceVertexUvs[0][h]!==void 0,P=m.normal.length()>0,C=m.vertexNormals.length>0,v=m.color.r!==1||m.color.g!==1||m.color.b!==1,A=m.vertexColors.length>0,T=0;if(T=u(T,0,0),T=u(T,1,y),T=u(T,2,b),T=u(T,3,S),T=u(T,4,P),T=u(T,5,C),T=u(T,6,v),T=u(T,7,A),t.push(T),t.push(m.a,m.b,m.c),t.push(m.materialIndex),S){let g=this.faceVertexUvs[0][h];t.push(f(g[0]),f(g[1]),f(g[2]))}if(P&&t.push(p(m.normal)),C){let g=m.vertexNormals;t.push(p(g[0]),p(g[1]),p(g[2]))}if(v&&t.push(d(m.color)),A){let g=m.vertexColors;t.push(d(g[0]),d(g[1]),d(g[2]))}}function u(h,m,y){return y?h|1<<m:h&~(1<<m)}function p(h){let m=h.x.toString()+h.y.toString()+h.z.toString();return i[m]!==void 0||(i[m]=o.length/3,o.push(h.x,h.y,h.z)),i[m]}function d(h){let m=h.r.toString()+h.g.toString()+h.b.toString();return s[m]!==void 0||(s[m]=a.length,a.push(h.getHex())),s[m]}function f(h){let m=h.x.toString()+h.y.toString();return c[m]!==void 0||(c[m]=l.length/2,l.push(h.x,h.y)),c[m]}return r.data={},r.data.vertices=e,r.data.normals=o,a.length>0&&(r.data.colors=a),l.length>0&&(r.data.uvs=[l]),r.data.faces=t,r}clone(){return new xn().copy(this)}copy(r){this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=r.name;let e=r.vertices;for(let d=0,f=e.length;d<f;d++)this.vertices.push(e[d].clone());let t=r.colors;for(let d=0,f=t.length;d<f;d++)this.colors.push(t[d].clone());let o=r.faces;for(let d=0,f=o.length;d<f;d++)this.faces.push(o[d].clone());for(let d=0,f=r.faceVertexUvs.length;d<f;d++){let h=r.faceVertexUvs[d];this.faceVertexUvs[d]===void 0&&(this.faceVertexUvs[d]=[]);for(let m=0,y=h.length;m<y;m++){let b=h[m],S=[];for(let P=0,C=b.length;P<C;P++){let v=b[P];S.push(v.clone())}this.faceVertexUvs[d].push(S)}}let i=r.morphTargets;for(let d=0,f=i.length;d<f;d++){let h={};if(h.name=i[d].name,i[d].vertices!==void 0){h.vertices=[];for(let m=0,y=i[d].vertices.length;m<y;m++)h.vertices.push(i[d].vertices[m].clone())}if(i[d].normals!==void 0){h.normals=[];for(let m=0,y=i[d].normals.length;m<y;m++)h.normals.push(i[d].normals[m].clone())}this.morphTargets.push(h)}let a=r.morphNormals;for(let d=0,f=a.length;d<f;d++){let h={};if(a[d].vertexNormals!==void 0){h.vertexNormals=[];for(let m=0,y=a[d].vertexNormals.length;m<y;m++){let b=a[d].vertexNormals[m],S={};S.a=b.a.clone(),S.b=b.b.clone(),S.c=b.c.clone(),h.vertexNormals.push(S)}}if(a[d].faceNormals!==void 0){h.faceNormals=[];for(let m=0,y=a[d].faceNormals.length;m<y;m++)h.faceNormals.push(a[d].faceNormals[m].clone())}this.morphNormals.push(h)}let s=r.skinWeights;for(let d=0,f=s.length;d<f;d++)this.skinWeights.push(s[d].clone());let l=r.skinIndices;for(let d=0,f=l.length;d<f;d++)this.skinIndices.push(l[d].clone());let c=r.lineDistances;for(let d=0,f=c.length;d<f;d++)this.lineDistances.push(c[d]);let u=r.boundingBox;u!==null&&(this.boundingBox=u.clone());let p=r.boundingSphere;return p!==null&&(this.boundingSphere=p.clone()),this.elementsNeedUpdate=r.elementsNeedUpdate,this.verticesNeedUpdate=r.verticesNeedUpdate,this.uvsNeedUpdate=r.uvsNeedUpdate,this.normalsNeedUpdate=r.normalsNeedUpdate,this.colorsNeedUpdate=r.colorsNeedUpdate,this.lineDistancesNeedUpdate=r.lineDistancesNeedUpdate,this.groupsNeedUpdate=r.groupsNeedUpdate,this}toBufferGeometry(){let r=new uf().fromGeometry(this),e=new D0,t=new Float32Array(r.vertices.length*3);if(e.setAttribute("position",yu.call(new Xs(t,3),r.vertices)),r.normals.length>0){let o=new Float32Array(r.normals.length*3);e.setAttribute("normal",yu.call(new Xs(o,3),r.normals))}if(r.colors.length>0){let o=new Float32Array(r.colors.length*3);e.setAttribute("color",B0.call(new Xs(o,3),r.colors))}if(r.uvs.length>0){let o=new Float32Array(r.uvs.length*2);e.setAttribute("uv",R0.call(new Xs(o,2),r.uvs))}if(r.uvs2.length>0){let o=new Float32Array(r.uvs2.length*2);e.setAttribute("uv2",R0.call(new Xs(o,2),r.uvs2))}e.groups=r.groups;for(let o in r.morphTargets){let i=[],a=r.morphTargets[o];for(let s=0,l=a.length;s<l;s++){let c=a[s],u=new Sa(c.data.length*3,3);u.name=c.name,i.push(yu.call(u,c.data))}e.morphAttributes[o]=i}if(r.skinIndices.length>0){let o=new Sa(r.skinIndices.length*4,4);e.setAttribute("skinIndex",L0.call(o,r.skinIndices))}if(r.skinWeights.length>0){let o=new Sa(r.skinWeights.length*4,4);e.setAttribute("skinWeight",L0.call(o,r.skinWeights))}return r.boundingSphere!==null&&(e.boundingSphere=r.boundingSphere.clone()),r.boundingBox!==null&&(e.boundingBox=r.boundingBox.clone()),e}computeTangents(){console.error("THREE.Geometry: .computeTangents() has been removed.")}computeLineDistances(){console.error("THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.")}applyMatrix(r){return console.warn("THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4()."),this.applyMatrix4(r)}dispose(){this.dispatchEvent({type:"dispose"})}static createBufferGeometryFromObject(r){let e=new D0,t=r.geometry;if(r.isPoints||r.isLine){let o=new Sa(t.vertices.length*3,3),i=new Sa(t.colors.length*3,3);if(e.setAttribute("position",yu.call(o,t.vertices)),e.setAttribute("color",B0.call(i,t.colors)),t.lineDistances&&t.lineDistances.length===t.vertices.length){let a=new Sa(t.lineDistances.length,1);e.setAttribute("lineDistance",WM.call(a,t.lineDistances))}t.boundingSphere!==null&&(e.boundingSphere=t.boundingSphere.clone()),t.boundingBox!==null&&(e.boundingBox=t.boundingBox.clone())}else r.isMesh&&(e=t.toBufferGeometry());return e}};xn.prototype.isGeometry=!0;var uf=class{constructor(){this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.uvs2=[],this.groups=[],this.morphTargets={},this.skinWeights=[],this.skinIndices=[],this.boundingBox=null,this.boundingSphere=null,this.verticesNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.groupsNeedUpdate=!1}computeGroups(r){let e=[],t,o,i,a=r.faces;for(o=0;o<a.length;o++){let s=a[o];s.materialIndex!==i&&(i=s.materialIndex,t!==void 0&&(t.count=o*3-t.start,e.push(t)),t={start:o*3,materialIndex:i})}t!==void 0&&(t.count=o*3-t.start,e.push(t)),this.groups=e}fromGeometry(r){let e=r.faces,t=r.vertices,o=r.faceVertexUvs,i=o[0]&&o[0].length>0,a=o[1]&&o[1].length>0,s=r.morphTargets,l=s.length,c;if(l>0){c=[];for(let b=0;b<l;b++)c[b]={name:s[b].name,data:[]};this.morphTargets.position=c}let u=r.morphNormals,p=u.length,d;if(p>0){d=[];for(let b=0;b<p;b++)d[b]={name:u[b].name,data:[]};this.morphTargets.normal=d}let f=r.skinIndices,h=r.skinWeights,m=f.length===t.length,y=h.length===t.length;t.length>0&&e.length===0&&console.error("THREE.DirectGeometry: Faceless geometries are not supported.");for(let b=0;b<e.length;b++){let S=e[b];this.vertices.push(t[S.a],t[S.b],t[S.c]);let P=S.vertexNormals;if(P.length===3)this.normals.push(P[0],P[1],P[2]);else{let v=S.normal;this.normals.push(v,v,v)}let C=S.vertexColors;if(C.length===3)this.colors.push(C[0],C[1],C[2]);else{let v=S.color;this.colors.push(v,v,v)}if(i===!0){let v=o[0][b];v!==void 0?this.uvs.push(v[0],v[1],v[2]):(console.warn("THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ",b),this.uvs.push(new ur,new ur,new ur))}if(a===!0){let v=o[1][b];v!==void 0?this.uvs2.push(v[0],v[1],v[2]):(console.warn("THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ",b),this.uvs2.push(new ur,new ur,new ur))}for(let v=0;v<l;v++){let A=s[v].vertices;c[v].data.push(A[S.a],A[S.b],A[S.c])}for(let v=0;v<p;v++){let A=u[v].vertexNormals[b];d[v].data.push(A.a,A.b,A.c)}m&&this.skinIndices.push(f[S.a],f[S.b],f[S.c]),y&&this.skinWeights.push(h[S.a],h[S.b],h[S.c])}return this.computeGroups(r),this.verticesNeedUpdate=r.verticesNeedUpdate,this.normalsNeedUpdate=r.normalsNeedUpdate,this.colorsNeedUpdate=r.colorsNeedUpdate,this.uvsNeedUpdate=r.uvsNeedUpdate,this.groupsNeedUpdate=r.groupsNeedUpdate,r.boundingSphere!==null&&(this.boundingSphere=r.boundingSphere.clone()),r.boundingBox!==null&&(this.boundingBox=r.boundingBox.clone()),this}},wa=class{constructor(r,e,t,o,i,a=0){this.a=r,this.b=e,this.c=t,this.normal=o&&o.isVector3?o:new zt,this.vertexNormals=Array.isArray(o)?o:[],this.color=i&&i.isColor?i:new df,this.vertexColors=Array.isArray(i)?i:[],this.materialIndex=a}clone(){return new this.constructor().copy(this)}copy(r){this.a=r.a,this.b=r.b,this.c=r.c,this.normal.copy(r.normal),this.color.copy(r.color),this.materialIndex=r.materialIndex;for(let e=0,t=r.vertexNormals.length;e<t;e++)this.vertexNormals[e]=r.vertexNormals[e].clone();for(let e=0,t=r.vertexColors.length;e<t;e++)this.vertexColors[e]=r.vertexColors[e].clone();return this}};function WM(n){return this.array.set(n),this}function B0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyColorsArray(): color is undefined",t),i=new df),r[e++]=i.r,r[e++]=i.g,r[e++]=i.b}return this}function R0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector2sArray(): vector is undefined",t),i=new ur),r[e++]=i.x,r[e++]=i.y}return this}function yu(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector3sArray(): vector is undefined",t),i=new zt),r[e++]=i.x,r[e++]=i.y,r[e++]=i.z}return this}function L0(n){let r=this.array,e=0;for(let t=0,o=n.length;t<o;t++){let i=n[t];i===void 0&&(console.warn("THREE.BufferAttribute.copyVector4sArray(): vector is undefined",t),i=new HM),r[e++]=i.x,r[e++]=i.y,r[e++]=i.z,r[e++]=i.w}return this}var $M=["a","b","c"];function YM(n,r){switch(r){case"c":return n.c;case"b":return n.b;case"a":default:return n.a}}function ff(n,r,e){let t=Math.min(n,r),o=Math.max(n,r),i=t+"_"+o;return e.get(i)}function hf(n,r,e,t,o,i){let a=Math.min(n,r),s=Math.max(n,r),l=a+"_"+s,c;if(t.has(l))c=t.get(l);else{let u=e[a],p=e[s];c={a:u,b:p,newEdge:null,faces:[]},t.set(l,c)}c.faces.push(o),i[n].edges.push(c),i[r].edges.push(c)}function XM(n,r,e,t){let o,i,a;for(o=0,i=n.length;o<i;o++)e[o]={edges:[]};for(o=0,i=r.length;o<i;o++)a=r[o],hf(a.a,a.b,n,t,a,e),hf(a.b,a.c,n,t,a,e),hf(a.c,a.a,n,t,a,e)}function gu(n,r,e,t,o){n.push(new wa(r,e,t,void 0,void 0,o))}function Pa(n,r){return Math.abs(r-n)/2+Math.min(n,r)}function xu(n,r,e,t){n.push([r.clone(),e.clone(),t.clone()])}var bu=class{constructor(r=1){this.subdivisions=r}modify(r){r instanceof qM?r=new xn().fromBufferGeometry(r):r=r.clone(),r.mergeVertices();let e=this.subdivisions;for(;e-- >0;)this._smooth(r);return r.computeFaceNormals(),r.computeVertexNormals(),r}_smooth(r){let e=new z0,t,o,i,a,s,l=r.vertices,c=r.faces,u=r.faceVertexUvs[0],p=u!==void 0&&u.length>0,d=[],f=new Map;XM(l,c,d,f);let h=[],m,y,b,S,P,C,v;for(let Z of Array.from(f.keys())){for(y=f.get(Z),b=new z0,P=3/8,C=1/8,v=y.faces.length,v!=2&&(P=.5,C=0,v!=1),b.addVectors(y.a,y.b).multiplyScalar(P),e.set(0,0,0),a=0;a<v;a++){for(S=y.faces[a],s=0;s<3&&(m=l[YM(S,$M[s])],!(m!==y.a&&m!==y.b));s++);m&&e.add(m)}e.multiplyScalar(C),b.add(e),y.newEdge=h.length,h.push(b)}let A,T,g,D,E,M,N,_=[];for(o=0,i=l.length;o<i;o++){for(M=l[o],E=d[o].edges,t=E.length,t==3?A=3/16:t>3&&(A=3/(8*t)),T=1-t*Number(A),g=A,t<=2&&(t==2?(T=3/4,g=1/8):t==1||t==0),N=M.clone().multiplyScalar(T),e.set(0,0,0),a=0;a<t;a++)D=E[a],m=D.a!==M?D.a:D.b,e.add(m);e.multiplyScalar(Number(g)),N.add(e),_.push(N)}let B=_.concat(h),V=_.length,k,L,W,F=[],j=[],H,q,re,ee,X=new pf,te=new pf,K=new pf;for(o=0,i=c.length;o<i;o++)S=c[o],k=Number(ff(S.a,S.b,f).newEdge)+V,L=Number(ff(S.b,S.c,f).newEdge)+V,W=Number(ff(S.c,S.a,f).newEdge)+V,gu(F,k,L,W,S.materialIndex),gu(F,S.a,k,W,S.materialIndex),gu(F,S.b,L,k,S.materialIndex),gu(F,S.c,W,L,S.materialIndex),p&&(H=u[o],q=H[0],re=H[1],ee=H[2],X.set(Pa(q.x,re.x),Pa(q.y,re.y)),te.set(Pa(re.x,ee.x),Pa(re.y,ee.y)),K.set(Pa(q.x,ee.x),Pa(q.y,ee.y)),xu(j,X,te,K),xu(j,q,X,K),xu(j,re,te,X),xu(j,ee,K,te));r.vertices=B,r.faces=F,p&&(r.faceVertexUvs[0]=j)}};var Pt=new QM,j0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=n.geometry??r?.geometry??new G0().copy(new F0(100,100,100)),t;r===void 0?(e.computeBoundingBox(),e.boundingBox.getSize(Pt),t={width:Pt.x,height:Pt.y,depth:Pt.z,subdivisions:0}):t=r.parameters;let o={...t,...n.parameters};return{parameters:{width:Math.abs(o.width),height:Math.abs(o.height),depth:Math.abs(o.depth),subdivisions:Math.abs(o.subdivisions)},geometry:e}}static build(n){let{width:r,height:e,depth:t,subdivisions:o}=n.parameters,i=n.geometry??new G0().copy(new F0(100,100,100)),a=i.userData.parameters;a===void 0?(i.computeBoundingBox(),i.boundingBox.getSize(Pt)):Pt.set(a.width,a.height,a.depth),(r!==Pt.x||e!==Pt.y||t!==Pt.z)&&i.scale(Pt.x===0?1:r/Pt.x,Pt.y===0?1:e/Pt.y,Pt.z===0?1:t/Pt.z);let s=i.originalGeometry;try{o>0?(s===void 0||a?.subdivisions!==o)&&(s===void 0&&(s=i),i=new bu(o).modify(s).toBufferGeometry()):(s!==void 0&&(i=s),s=void 0,i.getAttribute("normal")===void 0&&i.computeVertexNormals())}catch{s!==void 0&&(i=s),s=void 0,i.getAttribute("normal")===void 0&&i.computeVertexNormals()}return s!==void 0&&Object.assign(i,{originalGeometry:s}),delete n.geometry,Object.assign(i,{userData:{...n,type:"NonParametricGeometry"}})}static loadFromUrl(n,r,e){new KM(e).load(n,o=>{let i=this.normalizeInputs({geometry:o});o.boundingBox.getSize(Pt);let a=100/Pt.x;Object.assign(i.parameters,{width:100,height:Pt.y*a,depth:Pt.z*a}),r(this.build(i))})}};var vu=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:5,cornerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:3},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,spikes:t,cornerRadius:o,depth:i,extrudeBevelSize:a,extrudeBevelSegments:s}=n.parameters,l=n.shape,c=r*.5,u=e*.5,p=0,d=0,f=2*Math.PI/t;for(let m=0;m<t;m++){let y=f*m,b=p+Math.sin(y)*c,S=d+Math.cos(y)*u;l.addPoint(l.createPoint(b,S))}l.isClosed=!0;for(let m=0,y=l.points.length;m<y;m++)l.points[m].roundness=o;l.roundness=o,l.update();let h=Jt.create({shape:l,parameters:{roundness:o,depth:i,extrudeBevelSize:a,extrudeBevelSegments:s}});return Object.assign(h,{userData:{...n,type:"PolygonGeometry"}})}};import{BufferGeometry as ZM,Float32BufferAttribute as mf,Vector2 as so,Vector3 as Nt}from"three";var k0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:4,heightSegments:1,cornerRadius:0,cornerSegments:8,openEnded:!1},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,radialSegments:o,heightSegments:i,openEnded:a,cornerRadius:s,cornerSegments:l}=n.parameters,c=new gf(r*.5,e,o,i,a,s,l);return c.scale(1,1,t/r),Object.assign(c,{userData:{...n,type:"PyramidGeometry"}})}};function Ks(n,r,e){e.x=n.x*r.x,e.y=n.y,e.z=n.x*r.y}function yf(n,r,e,t,o,i){let a=r.clone().sub(n),s=e.clone().sub(n),l=a.angleTo(s);if(a.normalize(),s.normalize(),t===o){let c=a.add(s).normalize();i.copy(n).addScaledVector(c,t/Math.sin(l/2))}else{let c=a.angleTo(s);i.copy(n),i.addScaledVector(a,o/Math.sin(c)),i.addScaledVector(s,t/Math.sin(c))}}function JM(n,r,e){let t=n.clone().sub(r),o=e.clone().sub(r);return t.projectOnVector(o),t.add(r)}var gf=class extends ZM{constructor(r=.5,e=1,t=4,o=1,i=!1,a=0,s=4){super(),t=Math.floor(Math.max(3,t)),o=Math.floor(o),s=Math.floor(s);let l=[],c=[],u=[],p=[],d=0,f=e/2,h=Math.PI/t,m=r*Math.cos(Math.PI/t),y=2*Math.PI/t,b=(t-2)*Math.PI/t,S=Math.PI-b,P=new Nt(0,-f,0),C=new Nt(0,f,0),v=new so(r,-f),A=new so(m,-f),T=new so(0,C.y).sub(A),g=new so(0,C.y).sub(v),D=new so(T.y,-T.x).normalize(),E=new so(g.y,-g.x).normalize(),N=r*Math.cos(Math.PI/t)*Math.tan((Math.PI-T.angle())/2)-1e-8;a=Math.min(a,N);let _;{let j=new Nt(D.x,D.y,0),H=new Nt(Math.cos(y)*j.x,j.y,Math.sin(y)*j.x);_=j.angleTo(H)}let B=a/Math.tan((Math.PI-T.angle())/2),V=a/Math.tan((Math.PI-_)/2),k=new Nt;if(!i){c.push(P.x,P.y,P.z),u.push(0,-1,0),p.push(0,0);let j=d++,H=[],q=v.clone(),re=B/Math.cos(Math.PI/t);q.x-=re;for(let ee=0;ee<t;ee++){let X=ee/t*Math.PI*2+h,te=new so(Math.sin(X),Math.cos(X));Ks(q,te,k),c.push(k.x,k.y,k.z),u.push(0,-1,0),p.push(0,0),H.push(d++)}for(let ee=0;ee<H.length;ee++)l.push(H[ee],j,H[(ee+1)%H.length])}let L=[];{let j=new Nt,H=new Nt,q=new Nt,re=new Nt,ee=new Nt,X=new Nt;for(let te=0;te<t;te++){let K=te/t*Math.PI*2+h,Z=(te+.5)/t*Math.PI*2+h,Q=(te+1)/t*Math.PI*2+h,$=new so(Math.sin(K),Math.cos(K)),ue=new so(Math.sin(Z),Math.cos(Z)),le=new so(Math.sin(Q),Math.cos(Q));Ks(v,$,H),Ks(v,le,q),Ks(D,ue,j),yf(C,H,q,V,V,re),c.push(re.x,re.y,re.z),yf(H,C,q,V,B,ee),c.push(ee.x,ee.y,ee.z),yf(q,H,C,B,V,X),c.push(X.x,X.y,X.z),u.push(j.x,j.y,j.z),u.push(j.x,j.y,j.z),u.push(j.x,j.y,j.z),p.push(0,0),p.push(0,0),p.push(0,0);let ne=d++,ce=d++,ae=d++;if(l.push(ne,ce,ae),a>0){{let he=H.clone().add(q).multiplyScalar(.5),xe=C.clone().sub(he).normalize(),O=P.clone().sub(he).normalize().add(xe).normalize().multiplyScalar(-1),ie=X.clone().sub(ee);W(he,ie,O,T.angle())}let me,pe;{let he=new Nt;Ks(E,le,he);let xe=X.clone().add(re).multiplyScalar(.5);xe=JM(xe,q,C);let ye=X.clone().sub(re);[me,pe]=W(xe,ye,he,_,re.y)}{let he=me,xe=he.clone().setY(0).normalize(),ye=new Nt(0,-1,0),O=xe.clone().cross(ye);F(he,xe,ye,O)}L.concat(pe);{let he=T.angle(),xe=Math.PI-he,ye=C.clone();ye.y-=a/Math.sin(he-Math.PI/2);let O=new Nt,ie=[];for(let Ve=0;Ve<s;Ve++){let _e=[],Pe=Math.PI/2-xe*Ve/s,vt=Math.cos(Pe),Ie=Math.sin(Pe),gt=Z;for(let St=0;St<=Ve;St++){let Ln=Math.cos(gt),ot=Math.sin(gt);j.x=vt*ot,j.y=Ie,j.z=vt*Ln,O.copy(ye).addScaledVector(j,a),c.push(O.x,O.y,O.z),u.push(j.x,j.y,j.z),p.push(0,0),_e.push(d++),gt+=Math.PI*2/Ve/t}ie.push(_e)}pe.reverse(),ie.push(pe);let De=ie.length-1;for(let Ve=0;Ve<De;Ve++){let _e=ie[Ve],Pe=ie[Ve+1],vt=_e.length-1;l.push(Pe[1],_e[0],Pe[0]);for(let Ie=1;Ie<=vt;Ie++)l.push(_e[Ie],_e[Ie-1],Pe[Ie]),l.push(Pe[Ie+1],_e[Ie],Pe[Ie])}}}}}this.setIndex(l),this.setAttribute("position",new mf(c,3)),this.setAttribute("normal",new mf(u,3)),this.setAttribute("uv",new mf(p,2));function W(j,H,q,re,ee){let X=-re/2,te=(Math.PI-re)/2,K=H.clone().normalize().cross(q);j.addScaledVector(q,-a/Math.sin(te));let Z=new Nt,Q=new Nt,$=1,ue=d,le=[];for(let ne=0;ne<=s;ne++){let ce=X+ne/s*re;Q.set(0,0,0),Q.addScaledVector(K,Math.sin(ce)),Q.addScaledVector(q,Math.cos(ce));for(let ae=0;ae<=$;ae++){let me=ae/$-.5;if(Z.copy(j),Z.addScaledVector(H,me),Z.addScaledVector(Q,a),ee!=null){let pe=Math.max(0,Z.y-ee);Z.addScaledVector(H,-pe/H.y)}c.push(Z.x,Z.y,Z.z),u.push(Q.x,Q.y,Q.z),p.push(0,0),ae===0&&le.push(d),d++}}for(let ne=0;ne<s;ne++)for(let ce=0;ce<$;ce++){let ae=ue+ce+($+1)*ne,me=ae+($+1),pe=me+1,he=ae+1;l.push(ae,me,he),l.push(me,pe,he)}return[j.clone().addScaledVector(H,.5),le]}function F(j,H,q,re){let ee=Math.PI/2,X=g.angle()-ee,te=[],K=new Nt,Z=new Nt;for(let $=0;$<=s;$++){let ue=[],le=$/s;for(let ne=0;ne<=$;ne++){let ae=(($?ne/$:0)-.5)*S,me=Math.cos(ae),pe=Math.sin(ae),he=Math.atan(Math.tan(X)*me),xe=(ee+he)*le,ye=Math.cos(xe),O=Math.sin(xe);K.set(0,0,0),K.addScaledVector(H,O*me),K.addScaledVector(q,ye),K.addScaledVector(re,O*pe),Z.copy(j).addScaledVector(K,a),c.push(Z.x,Z.y,Z.z),u.push(K.x,K.y,K.z),p.push(0,0),ue.push(d++)}te.push(ue)}let Q=te.length-1;for(let $=0;$<Q;$++){let ue=te[$],le=te[$+1],ne=ue.length-1;l.push(ue[0],le[1],le[0]);for(let ce=1;ce<=ne;ce++)l.push(ue[ce-1],ue[ce],le[ce]),l.push(ue[ce],le[ce+1],le[ce])}}}};var Ca=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,cornerRadius:[0,0,0,0],cornerType:1,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters),t=Object.assign(r?.ui??{enabledIndieCorners:!1},n.ui);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)}),ui:t}}static build(n){let r=n.shape,{width:e,height:t,cornerRadius:o,cornerType:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}=n.parameters,c={x:e*.5,y:t*.5},u={x:-c.x,y:-c.y},p={x:c.x,y:c.y};function d(C,v,A){return v>e&&A>t?Math.min(C*e/v,C*t/A):v>e?C*e/v:A>t?C*t/A:C}let f=[];f[0]=o[0]===0?0:d(o[0],o[0]+o[3],o[0]+o[1]),f[1]=o[1]===0?0:d(o[1],o[1]+o[2],o[1]+o[0]),f[2]=o[2]===0?0:d(o[2],o[2]+o[1],o[2]+o[3]),f[3]=o[3]===0?0:d(o[3],o[3]+o[0],o[3]+o[2]);let h=u.x,m=p.x,y=p.y,b=u.y;r.addPoint(r.createPoint(h,y)),r.addPoint(r.createPoint(m,y)),r.addPoint(r.createPoint(m,b)),r.addPoint(r.createPoint(h,b)),r.isClosed=!0;let S=!0;for(let C=0,v=r.points.length;C<v;C++)r.points[C].roundness=f[C],C>0&&f[C]!==f[C-1]&&(S=!1);S&&(r.roundness=f[0]),r.useCubicForRoundedCorners=i!==1,r.update();let P=Jt.create({shape:r,parameters:{depth:a,extrudeBevelSize:s,extrudeBevelSegments:l}});return Object.assign(P,{userData:{...n,type:"RectangleGeometry"}})}};import{BufferGeometry as eE,Float32BufferAttribute as tE,MathUtils as U0,SphereGeometry as rE}from"three";var H0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,widthSegments:64,heightSegments:64,phiStart:0,phiLength:2*Math.PI,thetaStart:0,thetaLength:180},n.parameters);return e.thetaLength=U0.clamp(e.thetaLength,0,180),{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r=100,height:e=r,depth:t=r,widthSegments:o=64,heightSegments:i=64,phiStart:a,phiLength:s,thetaStart:l,thetaLength:c}=n.parameters,u;return c===0?(u=new eE,u.setAttribute("position",new tE([],3))):u=new rE(.5*r,o,i,a,s,l,c*U0.DEG2RAD),u.scale(1,e/r,t/r),Object.assign(u,{userData:{...n,type:"SphereGeometry"}})}};import{PlaneGeometry as oE}from"three";var W0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,widthSegments:8,heightSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:0})}}static build(n){let{width:r=100,height:e=r,widthSegments:t=8,heightSegments:o=8}=n.parameters,i=new oE(r,e,t,o);return i.scale(1,1,1),Object.assign(i,{userData:{...n,type:"PlaneGeometry"}})}};import{BufferGeometry as nE,Float32BufferAttribute as xf,Vector3 as iE}from"three";var q0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,angle:90,cornerRadius:24,cornerSegments:8},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width)})}}static build(n){let{width:r,height:e,depth:t,angle:o,cornerRadius:i,cornerSegments:a}=n.parameters,s=new bf(r,e,t,o,i,a);return Object.assign(s,{userData:{...n,type:"BackdropGeometry"}})}},bf=class extends nE{constructor(r=1,e=1,t=1,o=90,i=10,a=24){super(),this.type="BackdropGeometry";let s=[],l=[],c=[],u=.001;i==0&&(a=1),a=Math.max(1,Math.floor(a)),i=Math.min(i,100),o=Math.min(180-u,o),o*=Math.PI/180;let p=[],d=Math.PI/2,f=(Z=0,Q=0,$=0)=>new iE(Z,Q,$),h=f(),m=f(),[y,b,S]=[e/2,r/2,t/2],P=-b,C=+b,[v,A,T]=[f(P,-y,+S),f(P,-y,-S),f(P,+y,-S)],g=(Z,Q=!1)=>Math.sin(Z-Math.PI/(1+ +Q)),D=(Z,Q=!1)=>Math.cos(Z-Math.PI/(1+ +Q));T.y=Math.sin(o)*e-y;let E=Math.cos(o)*e-S,M=v.z-u;o<=d?(T.z=Math.min(E,M),T.z==M&&(T.y-=(E-M)/Math.tan(d-o))):A.z=Math.min(A.z-E-S,v.z-u),h.subVectors(v,A),m.subVectors(T,A);let N=Math.min(h.length(),m.length())*i/100,_=N*Math.tan(o/2),B=N/Math.cos(o/2),V=h.clone().normalize().add(m.normalize()).setLength(B).add(A);h.set(0,g(o,!0),D(o,!0)),p.push([T,h.clone()]);let k=(Math.PI-o)/a;for(let Z=0;Z<=a;Z++){let Q=d+o+Z*k;h.set(0,Math.sin(Q)*_,Math.cos(Q)*_),h.add(V),m.set(0,g(Q),D(Q)),p.push([h.clone(),m.clone()])}p.push([v,f(0,1,0)]);let L=Math.sin(k/2)*_*2,W=p.length-1,F=p[0][0].distanceTo(p[1][0]),j=p[W-1][0].distanceTo(p[W][0]),H=F+L*a+j;p[0].push(1);for(let Z=0;Z<=a;Z++)p[Z+1].push(1-(F+Z*L)/H);p[W].push(0);let[q,re,ee]=p[0],X,te,K;for(let Z=1;Z<p.length;Z++)[X,te,K]=p[Z],s.push(P,q.y,q.z,P,X.y,X.z,C,q.y,q.z,C,q.y,q.z,P,X.y,X.z,C,X.y,X.z),l.push(0,re.y,re.z,0,te.y,te.z,0,re.y,re.z,0,re.y,re.z,0,te.y,te.z,0,te.y,te.z),c.push(0,ee,0,K,1,ee,1,ee,0,K,1,K),[q,re,ee]=[X,te,K];this.setAttribute("position",new xf(s,3)),this.setAttribute("normal",new xf(l,3)),this.setAttribute("uv",new xf(c,2))}};var Su=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,innerRadiusPercent:38.19,spikes:5,cornerRadius:0,angle:360,extrudeBevelSize:0,extrudeBevelSegments:1},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e,innerRadiusPercent:t,spikes:o,cornerRadius:i,angle:a,depth:s,extrudeBevelSize:l,extrudeBevelSegments:c}=n.parameters,u=n.shape,p=r*.5,d=e*.5,f=0,h=0,m=a*Math.PI/360/o,y=Math.PI/2*3*-1,b=p*t/100,S=d*t/100;if(o===3&&t===50){m=2*Math.PI/o;for(let C=0;C<o;C++){let v=m*C,A=f+Math.sin(v)*p,T=h+Math.cos(v)*d;u.addPoint(u.createPoint(A,T))}}else for(let C=0;C<o;C++){let v=f+Math.cos(y)*p,A=h+Math.sin(y)*d;u.addPoint(u.createPoint(v,A)),y+=m,v=f+Math.cos(y)*b,A=h+Math.sin(y)*S,C<=o,u.addPoint(u.createPoint(v,A)),y+=m}u.isClosed=!0;for(let C=0,v=u.points.length;C<v;C++)u.points[C].roundness=i;u.roundness=i,u.update();let P=Jt.create({shape:u,parameters:{roundness:i,depth:s,extrudeBevelSize:l,extrudeBevelSegments:c}});return Object.assign(P,{userData:{...n,type:"StarGeometry"}})}};import{PlaneGeometry as aE}from"three";var $0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r,height:e}=n.parameters,t=new aE(r,e);return Object.assign(t,{userData:{...n,type:"TextFrameGeometry"}})}};import{BufferGeometry as sE,Float32BufferAttribute as lE,MathUtils as cE}from"three";var Y0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,radialSegments:32,tubularSegments:64,arc:360,cornerRadius:30,cornerSegments:8},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.round(Math.abs(e.depth??e.width*.25));return{parameters:Object.assign(e,{width:t,height:o,depth:i})}}static build(n){let{width:r,height:e,depth:t,radialSegments:o,tubularSegments:i,arc:a,cornerRadius:s,cornerSegments:l}=n.parameters,c=uE(r,e,t,r*.5,a,i,0,0,o,s,l);return c.scale(1,e/r,1),Object.assign(c,{userData:{...n,type:"TorusGeometry"}})}};function uE(n,r,e,t,o,i,a,s,l,c,u){[r,e]=[e,r],a=r/2;let p=cE.clamp(o/360,0,1);if(p===0){let d=new sE;return d.setAttribute("position",new lE([],3)),d}return p===1&&(c=0),new $s(!0,n,r,e,t,p,i,a,s,l,c,u)}import{TorusKnotGeometry as dE}from"three";var X0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,tubularSegments:64,radialSegments:32,p:2,q:3},n.parameters);return{parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width),depth:Math.abs(e.depth??e.width),tube:e.tube??e.width*.125})}}static build(n){let{width:r,tube:e,tubularSegments:t,radialSegments:o,p:i,q:a}=n.parameters,s=r*.5;s!==e&&(s-=e);let l=new dE(s,e,t,o,i,a);return Object.assign(l,{userData:{...n,type:"TorusKnotGeometry"}})}};var K0=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,depth:0,spikes:5,cornerRadius:0,extrudeBevelSize:0,extrudeBevelSegments:1,isRect:!1},n.parameters);return{shape:n.shape&&n.shape instanceof je?n.shape:new je,parameters:Object.assign(e,{width:Math.abs(e.width),height:Math.abs(e.height??e.width*(e.isRect?1:Math.sqrt(3)/2)),depth:Math.abs(e.depth??0)})}}static build(n){let{width:r=100,height:e,cornerRadius:t,depth:o,extrudeBevelSize:i,extrudeBevelSegments:a,isRect:s}=n.parameters,l=n.shape,c=r*.5,u=e*.5;s?(l.addPoint(l.createPoint(-c,u)),l.addPoint(l.createPoint(c,-u)),l.addPoint(l.createPoint(-c,-u))):(l.addPoint(l.createPoint(0,u)),l.addPoint(l.createPoint(c,-u)),l.addPoint(l.createPoint(-c,-u))),l.isClosed=!0;for(let d=0,f=l.points.length;d<f;d++)l.points[d].roundness=t;l.roundness=t,l.update();let p=Jt.create({shape:l,parameters:{roundness:t,depth:o,extrudeBevelSize:i,extrudeBevelSegments:a}});return Object.assign(p,{userData:{...n,type:"TriangleGeometry"}})}};import{Vector2 as eb,Vector3 as Dt,Matrix3 as CE,Matrix4 as Qn,BufferGeometry as tb,BufferAttribute as Oa,MathUtils as Pu}from"three";function Q0(n,r){let e=2*Math.PI;return(n%e+e)%e===(r%e+e)%e}function pE(n){return/^(rgba)?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(n.toLowerCase())}function fE(n,r,e){let t,o,i,a=Math.floor(n*6),s=n*6-a,l=e*(1-r),c=e*(1-s*r),u=e*(1-(1-s)*r);switch(a%6){case 0:t=e,o=u,i=l;break;case 1:t=c,o=e,i=l;break;case 2:t=l,o=e,i=u;break;case 3:t=l,o=c,i=e;break;case 4:t=u,o=l,i=e;break;case 5:default:t=e,o=l,i=c;break}return{r:t*255,g:o*255,b:i*255}}function hE(n,r,e){n/=255,r/=255,e/=255;let t=Math.max(n,r,e),o=Math.min(n,r,e),i=t,a=t-o,s=t==0?0:a/t,l;if(t==o)l=0;else{switch(t){case n:l=(r-e)/a+(r<e?6:0);break;case r:l=(e-n)/a+2;break;case e:default:l=(n-r)/a+4;break}l/=6}return{h:l,s,v:i}}function mE(n){return n=Math.floor(n),{r:n>>16&255,g:n>>8&255,b:n&255}}function yE(n,r,e){return(n<<16)+(r<<8)+e}function gE(n,r,e){return n=Math.round(n),r=Math.round(r),e=Math.round(e),"#"+[n,r,e].map(t=>t.toString(16).padStart(2,"0")).join("").toUpperCase()}function xE(n){let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;n=n.replace(r,(t,o,i,a)=>String(o+o+i+i+a+a));let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}var Z0={parseRgba:pE,hsvToRgb:fE,rgbToHsv:hE,hexToRgb:mE,rgbToHex:yE,rgbToHexString:gE,hexStringToRgb:xE};function Lo(n){return{all:n=n||new Map,on:function(r,e){var t=n.get(r);t?t.push(e):n.set(r,[e])},off:function(r,e){var t=n.get(r);t&&(e?t.splice(t.indexOf(e)>>>0,1):n.set(r,[]))},emit:function(r,e){var t=n.get(r);t&&t.slice().map(function(o){o(e)}),(t=n.get("*"))&&t.slice().map(function(o){o(r,e)})}}}var wu=class{constructor(r,e,t){this.id=r;this.userAPI=e;this.result=void 0;this.error="null";this.isPrefetched=!1;this.isLoading=!1;this.isLoaded=!1;this.prefetchPromise=new Promise(r=>r());this.emitter=Lo();this._innerCallUserAPI=async r=>{this.emitter.emit("start",{userAPIId:this.id}),this.isLoading=!0,this.isLoading=!1;try{this.result=await PE(this.userAPI,r),this.error="null",this.emitter.emit("success",{userAPIId:this.id})}catch(e){let t=e.message?.split("_:_")?.[0]?.replace("status:","")??"null";this.error=t,this.result=null,this.emitter.emit("error",{userAPIId:this.id})}this.isLoading=!1,this.isPrefetched=!0,this.isLoaded=!0};e?.integration?.type==="OpenAI"?this.result={content:""}:e.method==="GET"&&e.url!==""&&(this.prefetchPromise=this.prefetch(t)),this._debouncedCallUserAPI=this._innerCallUserAPI,this._updateDebouncedCallUserAPI(),this._debouncedPrefetch=uc(this.prefetch,1e3,{trailing:!0})}_updateDebouncedCallUserAPI(){this._debouncedCallUserAPI=this.userAPI.debounce!==void 0&&this.userAPI.debounce>0?uc(this._innerCallUserAPI,this.userAPI.debounce,{leading:!0,trailing:!0}):this._innerCallUserAPI}async prefetch(r){await this.callUserAPI(r)}async callUserAPI(r){await this._debouncedCallUserAPI(r)}update(r,e,t=!0){this.userAPI=r,this._updateDebouncedCallUserAPI(),this.userAPI.url!==""&&this.userAPI.method==="GET"&&t&&this._debouncedPrefetch(e)}retrieveValue(r){if(this.result)try{return Ze.zoom(this.result,r)}catch(e){console.error(e)}}retrieveZoomedKeyValues(r){if(this.result){let e=r&&r.length?Ze.zoom(this.result,r):this.result;if(wE(e))return Object.entries(e);if(SE(e))return e.map((t,o)=>[o.toString(),t]);throw vE(e)?new Error("This path points to a value, use retrieveValue() instead. "+r?.join(".")):new Error("Path error"+r?.join("."))}}dispose(){}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}get autostart(){return this.userAPI.autoStart}};function bE(n){let r=new Headers;return n.headers.forEach(e=>{e.data.key!==""&&r.append(e.data.key,e.data.value)}),r}function vE(n){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null}function SE(n){return Array.isArray(n)}function wE(n){return typeof n=="object"&&n!==null}async function PE(n,r,e=new AbortController){let t,o=n.url,i=n.proxy?.enabled??!1,a;if(n.integration?.type==="OpenAI"){let l=Qs(n.integration.prompt===""?[]:JSON.parse(n.integration.prompt),r),c=n.integration.behavior===""?[]:Qs(JSON.parse(n.integration.behavior),r);a=`{
4
4
  "model": "${n.integration.model}",
5
5
  "messages": [${n.integration.useBehavior?`
6
6
  {
@@ -12,20 +12,20 @@ best distance: ${d.d}`);let g=[d.x,d.y];return g.distance=d.d,g.distance}functio
12
12
  "content": "${l}"
13
13
  }
14
14
  ]
15
- }`}if(i){o=`${!1&&window.location.search.includes("api-dev")?"https://api-dev.spline.design/":"https://apis.spline.design/"}file/${n.proxy.fileId}/external-api/request?uuidexternalapi=${n.proxy.proxyId}`;let u;a!==void 0?u=a:n.method==="POST"&&n.body&&(u=Js(JSON.parse(n.body),r)),u!==void 0&&(o+=`&data=${encodeURIComponent(u.replace(/(\r\n|\n|\r|\t)/gm,""))}`)}else n.integration?.type==="OpenAI"?t=a:n.method==="POST"&&n.body&&(t=Js(JSON.parse(n.body),r));let s=await fetch(o,{method:i?"GET":n.method,headers:i?void 0:SE(n),signal:e.signal,body:t});if(!s.ok)throw new Error("status:"+s.status+"_:_"+s.statusText);if(n.integration?.type==="OpenAI"){let l=await s.json();return i&&(l=l.response),{content:l.choices[0].message.content}}else{let l=await s.json();return i&&(l=l.response),l}}var eb=(n,r)=>{if(typeof n=="string"){let e=r.getVariable(n);if(e)return eb(e,r)}return hn.isBoolean(n)?hn.getDisplayedValue(n).toLowerCase():hn.getDisplayedValue(n)},Js=(n,r)=>n.map((e,t)=>{if("text"in e)return e.text;if("type"in e){if(e.type==="paragraph")return(t>0?`
16
- `:"")+Js(e.children,r);if(e.type==="variable"){let o=r.getVariable(e.variableId);if(o!==void 0)return eb(o,r)}}return""}).join("");var TE=new Zn,IE=new Zn;function ME(n,r,e){let t=[new Dt,new Dt,new Dt],o=[new Dt,new Dt,new Dt];return n.extractBasis(t[0],t[1],t[2]),r.extractBasis(o[0],o[1],o[2]),t.forEach((i,a)=>{let s=o[a],l=Tu.lerp(i.length(),s.length(),e);i.lerp(s,e).setLength(l)}),new Zn().makeBasis(t[0],t[1],t[2])}var ob=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,height:100,depth:1,subdivisions:12,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.abs(e.depth??0),a=r?.shapeData??Sa.create({parameters:gp}).userData.shape;return{path:n.path??ea.defaultData(),parameters:Object.assign(e,{width:t,height:o,depth:i,extrusion:{...Vc,...e.extrusion}}),shapeData:a}}static build(n){if(n.path.points.length>=2){let e=new Pf(n);return Object.assign(e,{userData:{...n,type:"PathGeometry"}})}else return Object.assign(new rb,{userData:{...n,type:"PathGeometry"}})}},Pf=class extends rb{constructor(e){super();this.type="PathExtrusionGeometry",this.inputs=e,this.build()}_isGeometryClosed(){return this.inputs.path.isClosed&&this.inputs.parameters.extrusion.depth===1}_isOpenEnded(){let e=this.inputs.parameters.extrusion;return!(this.inputs.path.isClosed&&e.depth===1)||!Z0(e.twist,0)||e.startScale!==e.endScale}build(){let e=this._extractPathPoints();if(e.length<2)return;let t=this._computeBasisMatrices(e),{depth:o,offset:i}=this.inputs.parameters.extrusion;o=Math.max(0,Math.min(o,1)),i=Math.max(0,Math.min(i,1));let a=this.inputs.path.isClosed?e.length:e.length-1,s=Math.floor(i*a),l=this.inputs.path.isClosed?Math.ceil((o+i)*a):Math.ceil(Math.min(1,o+i)*a),c=Math.min(Math.max(2,l-s+1),a+2),u=[],p=[];for(let F=0;F<c;F++){let j=this.inputs.path.isClosed?(F+s)%e.length:Math.min(F+s,e.length-1);u.push(e[j].clone()),p.push(t[j].clone())}let d=(F,j,H)=>{u[F]=u[F].clone().lerp(u[j],H),p[F]=ME(p[F],p[j],H)},h=0,f=i*a%1;(!this.inputs.path.isClosed||o<=1)&&(f||i===0)&&(h=f,d(0,1,h));let m=0,y=(i+o)*a%1;if((this.inputs.path.isClosed&&o<=1||!this.inputs.path.isClosed&&i+o<1)&&y&&(m=y,d(u.length-1,u.length-2,1-m)),o===0){let F=u.length-1;u[F].copy(u[0]),p[F].copy(p[0])}this._applyPathModifiers(p,h,m);let{bevel:g,bevelSides:v}=this.inputs.parameters.extrusion,w=g>0?this.inputs.parameters.extrusion.capType:"flat",O=5;this.inputs.parameters.extrusion.shape.type==="Custom"&&(O=this.inputs.parameters.extrusion.shape.shapeQuality==="low"?5:12);let{regions:S,infos:C,vertices:T}=this._computeShapePoints(O),x=0,N;w==="round"&&(N=new xn(this.inputs.shapeData,2*g,g,O,v,void 0,!0),x=N.getAttribute("position").count);let E=0,M=0;C.sort((F,j)=>F.start-j.start),C.forEach(F=>{F.verticesStart=E,F.verticesCount=F.continuous.reduce((j,H,q)=>j+(q===0||!H?2:1),0),M+=F.verticesCount,E=M});let D=M*c,_,B=0;if(this._isOpenEnded()&&w==="flat"){try{_=Gr({windingRule:Ge.ODD,elementType:at.POLYGONS,polySize:3,vertexSize:2,strict:!0,contours:S})}catch{_=lf}B=_.vertexCount}let V=D+2*B+x*2,k=D+2*B,L={positions:new Float32Array(V*3),normals:new Float32Array(V*3),uvs:new Float32Array(V*2)},W=[];if(C.forEach(F=>{this._extrudeRegion(F,T,p,u,L,W,this._isGeometryClosed()&&!this._isOpenEnded())}),_&&(this._closeEnd(_,D,W,L,p[0],u[0],!1),this._closeEnd(_,D+B,W,L,p[p.length-1],u[u.length-1],!0)),N){L.positions.set(N.getAttribute("position").array,k*3),L.normals.set(N.getAttribute("normal").array,k*3),L.uvs.set(N.getAttribute("uv").array,k*2);for(let q=k;q<k+x;q++)L.uvs[q*2+1]=1e-4;let F=W.length;W.push(...N.getIndex().array.map(q=>q+k)),k+=x,L.positions.set(N.getAttribute("position").array,k*3),L.normals.set(N.getAttribute("normal").array,k*3),L.uvs.set(N.getAttribute("uv").array,k*2);let j=W.length;W.push(...N.getIndex().array.map(q=>q+k)),this.setAttribute("position",new Aa(L.positions,3)),this.setAttribute("normal",new Aa(L.normals,3)),this.setAttribute("uv",new Aa(L.uvs,2)),this.setIndex(W);let H=TE;H.copy(p[p.length-1]).setPosition(u[u.length-1]),this.applyMatrix4OnRange(H,k,V),H.copy(p[0]).setPosition(u[0]).multiply(IE.makeScale(1,1,-1)),this.applyMatrix4OnRange(H,k-x,k),this.reverseIndicesOnRange(F,j)}else this.setAttribute("position",new Aa(L.positions,3)),this.setAttribute("normal",new Aa(L.normals,3)),this.setAttribute("uv",new Aa(L.uvs,2)),this.setIndex(W)}_extractPathPoints(){let t=iu(this.inputs.path).getPoints(this.inputs.path.subdivisions);if(t.length<2)return[];let o=[t[0]];return t.forEach(a=>{o[o.length-1].distanceToSquared(a)>.001&&o.push(a)}),this.inputs.path.isClosed&&o[o.length-1].distanceTo(o[0])<.001&&o.pop(),o}_computeBasisMatrices(e){let t=[],o=e.length,i=this.inputs.path.isClosed,a=new Dt,s=new Dt,l=new Dt,c=new Dt,u=new Dt(0,1,0);for(let y=0;y<o;y++){let g=e[y],v;y===0?v=i?e[e.length-2]:g.clone().multiplyScalar(2).sub(e[1]):v=e[y-1];let w;y===o-1?w=i?e[1]:g.clone().multiplyScalar(2).sub(e[y-1]):w=e[y+1];let O=g.clone().sub(v).normalize(),S=w.clone().sub(g).normalize(),C=O.clone().add(S).normalize();l.copy(C),y===0&&(C.equals(u)||C.clone().negate().equals(u))&&u.set(0,0,1);let T=u.clone().cross(C).normalize(),x=C.clone().cross(T).normalize();u.copy(x),c.copy(T),y===0&&(a.copy(x),s.copy(C));let N=new Zn().makeBasis(T,x,C);t.push(N)}let p=i?s:l,d=i?a:new Dt(0,1,0),h=p.clone().cross(c).normalize(),f=Math.acos(d.dot(h));if(isNaN(f))return t;let m=d.clone().cross(h);p.dot(m)>0&&(f*=-1);for(let y=1;y<t.length;y++){let g=new Zn().makeRotationZ(f*y/t.length);t[y].multiply(g)}return t}_applyPathModifiers(e,t,o){let i=e.length,{angle:a,twist:s,startScale:l,endScale:c}=this.inputs.parameters.extrusion,u=new Zn,p=new Zn;return e.forEach((d,h)=>{let f=h===0?0:h===i-1?1:(h-t)/(i-(o===0?0:1)-(t+(1-o)));u.makeRotationZ(Tu.lerp(a,a+s,f)*Tu.DEG2RAD);let m=Tu.lerp(l,c,f);p.makeScale(m,m,m),d.multiply(u).multiply(p)}),e}_computeShapePoints(e=12,t=Ge.ODD){let o=this.inputs.shapeData,i=o.extractShapePointsToFlatArray([],e),a=o.shapeHoles.map(m=>{let y=m.extractShapePointsToFlatArray([],e),g=[];for(let v=y.length-1;v>=1;v-=2){let w=y[v-1],O=y[v-0];g.push(w,O)}return g}),s;try{s=Gr({windingRule:t,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[i]})}catch{s=Ys}let l;try{l=Gr({windingRule:Ge.ODD,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...a]})}catch{l=sf}if(!s)throw new Error("error generating geometry");let c=s.elementCount;if(l){s.elementCount+=l.elementCount;for(let m=0;m<l.elements.length;m++){let y=l.elements[m],g=m%2===0?s.vertexCount:0;s.elements.push(y+g)}for(let m=0;m<l.vertexIndices.length;m++){let y=l.vertexIndices[m],g=s.vertexCount;s.vertexIndices.push(y+g)}for(let m=0;m<l.vertices.length;m++){let y=l.vertices[m];s.vertices.push(y)}}let u=1/0,p=-1/0,d=1/0,h=-1/0;for(let m=0,y=s.vertexCount;m<y;m++){let g=m*2,v=s.vertices[g+0],w=s.vertices[g+1];v<u&&(u=v),v>p&&(p=v),w<d&&(d=w),w>h&&(h=w)}let f=[];for(let m=s.elementCount-1;m>=0;m--){let y=m>=c,g=m*2,v=s.elements[g+0],w=s.elements[g+1],O=v+w,S={start:v,count:w,normals:[],isHole:y,continuous:[],verticesStart:0,verticesCount:0};f.push(S);let C=v,T=O-1,x=v+1,N=o.roundedCurves.length;do{let E=C-v,M=s.vertices[T*2+0],D=s.vertices[T*2+1],_=s.vertices[C*2+0],B=s.vertices[C*2+1],V=s.vertices[x*2+0],k=s.vertices[x*2+1],L=_-M,W=B-D,F=Math.sqrt(L*L+W*W);L/=F,W/=F;let j=_-V,H=B-k,q=Math.sqrt(j*j+H*H);j/=q,H/=q,S.normals[E*2+0]=-H,S.normals[E*2+1]=j;let re=s.vertexIndices[C];if(Array.isArray(re))S.continuous[E]=!1;else{let[ee,X]=o.getCurveIndexFromVertexId(re-1,!0);if(X>0&&X<1)S.continuous[E]=!0;else{let te=X===1?ee+1:ee-1;te=(te+N)%N;let K=X===1?0:1,Z=o.roundedCurves[ee].getTangent(X),Q=o.roundedCurves[te].getTangent(K);S.continuous[E]=Z.dot(Q)>.95}}y&&(S.normals[E*2+0]*=-1,S.normals[E*2+1]*=-1),[T,C,x]=[C,x,x+1],x>=O&&(x-=w)}while(x!==v+1)}return{regions:[i,...a],infos:f,vertices:s.vertices}}_insertVertex(e,t,o,i,a){let s=t*2,l=t*3;e.positions[l+0]=o.x,e.positions[l+1]=o.y,e.positions[l+2]=o.z,e.normals[l+0]=i.x,e.normals[l+1]=i.y,e.normals[l+2]=i.z,e.uvs[s+0]=a.x,e.uvs[s+1]=a.y}_extrudeRegion(e,t,o,i,a,s,l){let c=new Dt,u=new Dt,p=new Dt,d=new Dt,h=new tb;o.forEach((m,y)=>{let g=i[y],v=e.verticesStart*o.length+e.verticesCount*y;for(let w=0;w<e.count;w++){let O=(e.start+w)*2;if(c.set(t[O+0],t[O+1],0),p.copy(c).applyMatrix4(m).add(g),e.continuous[w])d.set(e.normals[w*2+0],e.normals[w*2+1],0);else{let S=w===0?(e.start+e.count-1)*2:O-2;u.set(t[S+0],t[S+1],0),d.copy(c).sub(u),d.set(-d.y,d.x,0),e.isHole||d.negate()}if(d.applyMatrix4(m).normalize(),h.set(w===0?1:w/e.count,y/(o.length-1)),this._insertVertex(a,v,p,d,h),v++,!e.continuous[w]||w===0){if(w===0)d.set(e.normals[w*2+0],e.normals[w*2+1],0),h.set(0,y/(o.length-1));else{let S=w===e.count-1?e.start*2:O+2;u.set(t[S+0],t[S+1],0),d.copy(u).sub(c),d.set(-d.y,d.x,0),e.isHole||d.negate()}d.applyMatrix4(m).normalize(),this._insertVertex(a,v,p,d,h),v++}}});let f=o.length-1;for(let m=0;m<f;m++){let y=e.verticesStart*o.length+e.verticesCount*m,g=e.verticesStart*o.length+e.verticesCount*(m+1),v=0;for(let w=0;w<e.count;w++){(!e.continuous[w]||w===0)&&v++;let O=w===e.count-1?0:v+1,S=y+v,C=y+O,T=g+O,x=g+v;e.isHole?s.push(S,T,C,S,x,T):s.push(S,C,T,S,T,x),v++}}}_closeEnd(e,t,o,i,a,s,l){let c=e.vertexCount,u=new Dt(0,0,l?-1:1).applyMatrix4(a),p=new Dt,d=new tb;for(let f=0;f<c;f++){let m=2*f;p.set(e.vertices[m+0],e.vertices[m+1],0).applyMatrix4(a).add(s),this._insertVertex(i,t+f,p,u,d)}let h=e.elements;for(let f=0;f<e.elementCount;f++){let m=3*f,y=h[m+0]+t,g=h[m+(l?1:2)]+t,v=h[m+(l?2:1)]+t;o.push(y,g,v)}}applyMatrix4OnRange(e,t,o){let i=e.elements,a=new AE().getNormalMatrix(e).elements,s,l,c,u,p=this.attributes.position,d=this.attributes.normal;if(!p||!d)return;let h=p.array,f=d.array,m=p.itemSize;for(let y=t*m,g=o*m;y<g;y+=m){if(y===t)debugger;s=h[y+0],l=h[y+1],c=h[y+2],u=1/(i[3]*s+i[7]*l+i[11]*c+i[15]),h[y+0]=(i[0]*s+i[4]*l+i[8]*c+i[12])*u,h[y+1]=(i[1]*s+i[5]*l+i[9]*c+i[13])*u,h[y+2]=(i[2]*s+i[6]*l+i[10]*c+i[14])*u,s=f[y+0],l=f[y+1],c=f[y+2],f[y+0]=a[0]*s+a[3]*l+a[6]*c,f[y+1]=a[1]*s+a[4]*l+a[7]*c,f[y+2]=a[2]*s+a[5]*l+a[8]*c}p.needsUpdate=!0,d.needsUpdate=!0}reverseIndicesOnRange(e,t){let o=this.index;if(o){for(let i=e;i<t;i+=3){let a=o.getX(i),s=o.getX(i+1),l=o.getX(i+2);o.setXYZ(i,l,s,a)}o.needsUpdate=!0}}};import{BufferAttribute as nb,BufferGeometry as Cf}from"three";import{mergeBufferGeometries as NE}from"three/examples/jsm/utils/BufferGeometryUtils.js";function ib(){let n=new Cf;return n.setAttribute("position",new nb(new Float32Array([]),3)),n.setIndex(new nb(new Uint16Array([]),1)),n}var DE=ib().attributes,_E=12,BE=1,Jn=class extends Cf{constructor(e,t){super();this.charWidths=[];this.charCoords=[];this.wrappedText=[];this.isLowResolution=!1;this.vectorShapes=[];Object.assign(this.attributes,DE),this.userData={parameters:e,type:"TextGeometry"};let o=t.getFont(e.font);o?.isLoaded?(this.font=o,this.update(e)):this.updateFont(e.font,t).then(()=>{this.update(e),t?.requestRender()})}async updateFont(e,t){let o=t.getFont(e);o&&(this.font=o,await o.loadingPromise)}update(e){let t=this.font;if(this.userData={parameters:e,type:"TextGeometry"},!t?.isLoaded){console.warn("Cannot update text because its font is not loaded");return}let{width:o,height:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l,text:c,textTransform:u}=e,p=hn.getDisplayedValue(c),d=u===2?p.toUpperCase():u===3?p.toLowerCase():p,h=RE(e,t,d),{shapes:f,charWidths:m,charCoords:y}=t.generateShapes(h,e),g=(typeof o=="number"?o:1)*.5,v=(typeof i=="number"?i:1)*.5,w=f.map(C=>new je().fromShape(C,!0));this.vectorShapes=w;let O=w.map(C=>Jt.create({shape:C,parameters:{depth:a,extrudeBevelSegments:l,extrudeBevelSize:s,windingRule:a<=0?Ge.NONZERO:Ge.ODD,subdivisions:this.isLowResolution&&a>0?BE:_E}})),S=O.length?NE(O):ib();S.translate(-g,v,0),this.dispose(),this.wrappedText=h,this.charCoords=y,this.charWidths=m,this.deleteAttribute("extrudeNormal"),Object.entries(S.attributes).forEach(([C,T])=>{this.setAttribute(C,T)}),this.setIndex(S.index),this.computeBoundingSphere()}clone(){let e=Lt(new Cf,Jn.prototype);return e.copy(this),console.log("CloneGeometry",this,e),e}copy(e){return Object.entries(e.attributes).forEach(([t,o])=>{this.setAttribute(t,o)}),this.setIndex(e.index),this.userData={parameters:{...e.userData.parameters},type:"TextGeometry"},this}async setText(e){this.font&&await this.font.loadingPromise,await this.update({...this.userData.parameters,text:{textValue:e}})}get text(){return this.userData.parameters.text??""}};function RE(n,r,e){let t=[""],o="";for(let i of e)o+=i,i===" "||i===`
15
+ }`}if(i){o=`${!1&&window.location.search.includes("api-dev")?"https://api-dev.spline.design/":"https://apis.spline.design/"}file/${n.proxy.fileId}/external-api/request?uuidexternalapi=${n.proxy.proxyId}`;let u;a!==void 0?u=a:n.method==="POST"&&n.body&&(u=Qs(JSON.parse(n.body),r)),u!==void 0&&(o+=`&data=${encodeURIComponent(u.replace(/(\r\n|\n|\r|\t)/gm,""))}`)}else n.integration?.type==="OpenAI"?t=a:n.method==="POST"&&n.body&&(t=Qs(JSON.parse(n.body),r));let s=await fetch(o,{method:i?"GET":n.method,headers:i?void 0:bE(n),signal:e.signal,body:t});if(!s.ok)throw new Error("status:"+s.status+"_:_"+s.statusText);if(n.integration?.type==="OpenAI"){let l=await s.json();return i&&(l=l.response),{content:l.choices[0].message.content}}else{let l=await s.json();return i&&(l=l.response),l}}var J0=(n,r)=>{if(typeof n=="string"){let e=r.getVariable(n);if(e)return J0(e,r)}return fn.isBoolean(n)?fn.getDisplayedValue(n).toLowerCase():fn.getDisplayedValue(n)},Qs=(n,r)=>n.map((e,t)=>{if("text"in e)return e.text;if("type"in e){if(e.type==="paragraph")return(t>0?`
16
+ `:"")+Qs(e.children,r);if(e.type==="variable"){let o=r.getVariable(e.variableId);if(o!==void 0)return J0(o,r)}}return""}).join("");var OE=new Qn,AE=new Qn;function TE(n,r,e){let t=[new Dt,new Dt,new Dt],o=[new Dt,new Dt,new Dt];return n.extractBasis(t[0],t[1],t[2]),r.extractBasis(o[0],o[1],o[2]),t.forEach((i,a)=>{let s=o[a],l=Pu.lerp(i.length(),s.length(),e);i.lerp(s,e).setLength(l)}),new Qn().makeBasis(t[0],t[1],t[2])}var rb=class{static create(n){return this.build(this.normalizeInputs(n))}static normalizeInputs(n,r){let e=Object.assign({},r?.parameters??{width:100,height:100,depth:1,subdivisions:12,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3},n.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),i=Math.abs(e.depth??0),a=r?.shapeData??va.create({parameters:hp}).userData.shape;return{path:n.path??Ji.defaultData(),parameters:Object.assign(e,{width:t,height:o,depth:i,extrusion:{...Bc,...e.extrusion}}),shapeData:a}}static build(n){if(n.path.points.length>=2){let e=new vf(n);return Object.assign(e,{userData:{...n,type:"PathGeometry"}})}else return Object.assign(new tb,{userData:{...n,type:"PathGeometry"}})}},vf=class extends tb{constructor(e){super();this.type="PathExtrusionGeometry",this.inputs=e,this.build()}_isGeometryClosed(){return this.inputs.path.isClosed&&this.inputs.parameters.extrusion.depth===1}_isOpenEnded(){let e=this.inputs.parameters.extrusion;return!(this.inputs.path.isClosed&&e.depth===1)||!Q0(e.twist,0)||e.startScale!==e.endScale}build(){let e=this._extractPathPoints();if(e.length<2)return;let t=this._computeBasisMatrices(e),{depth:o,offset:i}=this.inputs.parameters.extrusion;o=Math.max(0,Math.min(o,1)),i=Math.max(0,Math.min(i,1));let a=this.inputs.path.isClosed?e.length:e.length-1,s=Math.floor(i*a),l=this.inputs.path.isClosed?Math.ceil((o+i)*a):Math.ceil(Math.min(1,o+i)*a),c=Math.min(Math.max(2,l-s+1),a+2),u=[],p=[];for(let F=0;F<c;F++){let j=this.inputs.path.isClosed?(F+s)%e.length:Math.min(F+s,e.length-1);u.push(e[j].clone()),p.push(t[j].clone())}let d=(F,j,H)=>{u[F]=u[F].clone().lerp(u[j],H),p[F]=TE(p[F],p[j],H)},f=0,h=i*a%1;(!this.inputs.path.isClosed||o<=1)&&(h||i===0)&&(f=h,d(0,1,f));let m=0,y=(i+o)*a%1;if((this.inputs.path.isClosed&&o<=1||!this.inputs.path.isClosed&&i+o<1)&&y&&(m=y,d(u.length-1,u.length-2,1-m)),o===0){let F=u.length-1;u[F].copy(u[0]),p[F].copy(p[0])}this._applyPathModifiers(p,f,m);let{bevel:b,bevelSides:S}=this.inputs.parameters.extrusion,P=b>0?this.inputs.parameters.extrusion.capType:"flat",C=5;this.inputs.parameters.extrusion.shape.type==="Custom"&&(C=this.inputs.parameters.extrusion.shape.shapeQuality==="low"?5:12);let{regions:v,infos:A,vertices:T}=this._computeShapePoints(C),g=0,D;P==="round"&&(D=new gn(this.inputs.shapeData,2*b,b,C,S,void 0,!0),g=D.getAttribute("position").count);let E=0,M=0;A.sort((F,j)=>F.start-j.start),A.forEach(F=>{F.verticesStart=E,F.verticesCount=F.continuous.reduce((j,H,q)=>j+(q===0||!H?2:1),0),M+=F.verticesCount,E=M});let N=M*c,_,B=0;if(this._isOpenEnded()&&P==="flat"){try{_=Gr({windingRule:Fe.ODD,elementType:at.POLYGONS,polySize:3,vertexSize:2,strict:!0,contours:v})}catch{_=nf}B=_.vertexCount}let V=N+2*B+g*2,k=N+2*B,L={positions:new Float32Array(V*3),normals:new Float32Array(V*3),uvs:new Float32Array(V*2)},W=[];if(A.forEach(F=>{this._extrudeRegion(F,T,p,u,L,W,this._isGeometryClosed()&&!this._isOpenEnded())}),_&&(this._closeEnd(_,N,W,L,p[0],u[0],!1),this._closeEnd(_,N+B,W,L,p[p.length-1],u[u.length-1],!0)),D){L.positions.set(D.getAttribute("position").array,k*3),L.normals.set(D.getAttribute("normal").array,k*3),L.uvs.set(D.getAttribute("uv").array,k*2);for(let q=k;q<k+g;q++)L.uvs[q*2+1]=1e-4;let F=W.length;W.push(...D.getIndex().array.map(q=>q+k)),k+=g,L.positions.set(D.getAttribute("position").array,k*3),L.normals.set(D.getAttribute("normal").array,k*3),L.uvs.set(D.getAttribute("uv").array,k*2);let j=W.length;W.push(...D.getIndex().array.map(q=>q+k)),this.setAttribute("position",new Oa(L.positions,3)),this.setAttribute("normal",new Oa(L.normals,3)),this.setAttribute("uv",new Oa(L.uvs,2)),this.setIndex(W);let H=OE;H.copy(p[p.length-1]).setPosition(u[u.length-1]),this.applyMatrix4OnRange(H,k,V),H.copy(p[0]).setPosition(u[0]).multiply(AE.makeScale(1,1,-1)),this.applyMatrix4OnRange(H,k-g,k),this.reverseIndicesOnRange(F,j)}else this.setAttribute("position",new Oa(L.positions,3)),this.setAttribute("normal",new Oa(L.normals,3)),this.setAttribute("uv",new Oa(L.uvs,2)),this.setIndex(W)}_extractPathPoints(){let t=tu(this.inputs.path).getPoints(this.inputs.path.subdivisions);if(t.length<2)return[];let o=[t[0]];return t.forEach(a=>{o[o.length-1].distanceToSquared(a)>.001&&o.push(a)}),this.inputs.path.isClosed&&o[o.length-1].distanceTo(o[0])<.001&&o.pop(),o}_computeBasisMatrices(e){let t=[],o=e.length,i=this.inputs.path.isClosed,a=new Dt,s=new Dt,l=new Dt,c=new Dt,u=new Dt(0,1,0);for(let y=0;y<o;y++){let b=e[y],S;y===0?S=i?e[e.length-2]:b.clone().multiplyScalar(2).sub(e[1]):S=e[y-1];let P;y===o-1?P=i?e[1]:b.clone().multiplyScalar(2).sub(e[y-1]):P=e[y+1];let C=b.clone().sub(S).normalize(),v=P.clone().sub(b).normalize(),A=C.clone().add(v).normalize();l.copy(A),y===0&&(A.equals(u)||A.clone().negate().equals(u))&&u.set(0,0,1);let T=u.clone().cross(A).normalize(),g=A.clone().cross(T).normalize();u.copy(g),c.copy(T),y===0&&(a.copy(g),s.copy(A));let D=new Qn().makeBasis(T,g,A);t.push(D)}let p=i?s:l,d=i?a:new Dt(0,1,0),f=p.clone().cross(c).normalize(),h=Math.acos(d.dot(f));if(isNaN(h))return t;let m=d.clone().cross(f);p.dot(m)>0&&(h*=-1);for(let y=1;y<t.length;y++){let b=new Qn().makeRotationZ(h*y/t.length);t[y].multiply(b)}return t}_applyPathModifiers(e,t,o){let i=e.length,{angle:a,twist:s,startScale:l,endScale:c}=this.inputs.parameters.extrusion,u=new Qn,p=new Qn;return e.forEach((d,f)=>{let h=f===0?0:f===i-1?1:(f-t)/(i-(o===0?0:1)-(t+(1-o)));u.makeRotationZ(Pu.lerp(a,a+s,h)*Pu.DEG2RAD);let m=Pu.lerp(l,c,h);p.makeScale(m,m,m),d.multiply(u).multiply(p)}),e}_computeShapePoints(e=12,t=Fe.ODD){let o=this.inputs.shapeData,i=o.extractShapePointsToFlatArray([],e),a=o.shapeHoles.map(m=>{let y=m.extractShapePointsToFlatArray([],e),b=[];for(let S=y.length-1;S>=1;S-=2){let P=y[S-1],C=y[S-0];b.push(P,C)}return b}),s;try{s=Gr({windingRule:t,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[i]})}catch{s=qs}let l;try{l=Gr({windingRule:Fe.ODD,elementType:at.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...a]})}catch{l=of}if(!s)throw new Error("error generating geometry");let c=s.elementCount;if(l){s.elementCount+=l.elementCount;for(let m=0;m<l.elements.length;m++){let y=l.elements[m],b=m%2===0?s.vertexCount:0;s.elements.push(y+b)}for(let m=0;m<l.vertexIndices.length;m++){let y=l.vertexIndices[m],b=s.vertexCount;s.vertexIndices.push(y+b)}for(let m=0;m<l.vertices.length;m++){let y=l.vertices[m];s.vertices.push(y)}}let u=1/0,p=-1/0,d=1/0,f=-1/0;for(let m=0,y=s.vertexCount;m<y;m++){let b=m*2,S=s.vertices[b+0],P=s.vertices[b+1];S<u&&(u=S),S>p&&(p=S),P<d&&(d=P),P>f&&(f=P)}let h=[];for(let m=s.elementCount-1;m>=0;m--){let y=m>=c,b=m*2,S=s.elements[b+0],P=s.elements[b+1],C=S+P,v={start:S,count:P,normals:[],isHole:y,continuous:[],verticesStart:0,verticesCount:0};h.push(v);let A=S,T=C-1,g=S+1,D=o.roundedCurves.length;do{let E=A-S,M=s.vertices[T*2+0],N=s.vertices[T*2+1],_=s.vertices[A*2+0],B=s.vertices[A*2+1],V=s.vertices[g*2+0],k=s.vertices[g*2+1],L=_-M,W=B-N,F=Math.sqrt(L*L+W*W);L/=F,W/=F;let j=_-V,H=B-k,q=Math.sqrt(j*j+H*H);j/=q,H/=q,v.normals[E*2+0]=-H,v.normals[E*2+1]=j;let re=s.vertexIndices[A];if(Array.isArray(re))v.continuous[E]=!1;else{let[ee,X]=o.getCurveIndexFromVertexId(re-1,!0);if(X>0&&X<1)v.continuous[E]=!0;else{let te=X===1?ee+1:ee-1;te=(te+D)%D;let K=X===1?0:1,Z=o.roundedCurves[ee].getTangent(X),Q=o.roundedCurves[te].getTangent(K);v.continuous[E]=Z.dot(Q)>.95}}y&&(v.normals[E*2+0]*=-1,v.normals[E*2+1]*=-1),[T,A,g]=[A,g,g+1],g>=C&&(g-=P)}while(g!==S+1)}return{regions:[i,...a],infos:h,vertices:s.vertices}}_insertVertex(e,t,o,i,a){let s=t*2,l=t*3;e.positions[l+0]=o.x,e.positions[l+1]=o.y,e.positions[l+2]=o.z,e.normals[l+0]=i.x,e.normals[l+1]=i.y,e.normals[l+2]=i.z,e.uvs[s+0]=a.x,e.uvs[s+1]=a.y}_extrudeRegion(e,t,o,i,a,s,l){let c=new Dt,u=new Dt,p=new Dt,d=new Dt,f=new eb;o.forEach((m,y)=>{let b=i[y],S=e.verticesStart*o.length+e.verticesCount*y;for(let P=0;P<e.count;P++){let C=(e.start+P)*2;if(c.set(t[C+0],t[C+1],0),p.copy(c).applyMatrix4(m).add(b),e.continuous[P])d.set(e.normals[P*2+0],e.normals[P*2+1],0);else{let v=P===0?(e.start+e.count-1)*2:C-2;u.set(t[v+0],t[v+1],0),d.copy(c).sub(u),d.set(-d.y,d.x,0),e.isHole||d.negate()}if(d.applyMatrix4(m).normalize(),f.set(P===0?1:P/e.count,y/(o.length-1)),this._insertVertex(a,S,p,d,f),S++,!e.continuous[P]||P===0){if(P===0)d.set(e.normals[P*2+0],e.normals[P*2+1],0),f.set(0,y/(o.length-1));else{let v=P===e.count-1?e.start*2:C+2;u.set(t[v+0],t[v+1],0),d.copy(u).sub(c),d.set(-d.y,d.x,0),e.isHole||d.negate()}d.applyMatrix4(m).normalize(),this._insertVertex(a,S,p,d,f),S++}}});let h=o.length-1;for(let m=0;m<h;m++){let y=e.verticesStart*o.length+e.verticesCount*m,b=e.verticesStart*o.length+e.verticesCount*(m+1),S=0;for(let P=0;P<e.count;P++){(!e.continuous[P]||P===0)&&S++;let C=P===e.count-1?0:S+1,v=y+S,A=y+C,T=b+C,g=b+S;e.isHole?s.push(v,T,A,v,g,T):s.push(v,A,T,v,T,g),S++}}}_closeEnd(e,t,o,i,a,s,l){let c=e.vertexCount,u=new Dt(0,0,l?-1:1).applyMatrix4(a),p=new Dt,d=new eb;for(let h=0;h<c;h++){let m=2*h;p.set(e.vertices[m+0],e.vertices[m+1],0).applyMatrix4(a).add(s),this._insertVertex(i,t+h,p,u,d)}let f=e.elements;for(let h=0;h<e.elementCount;h++){let m=3*h,y=f[m+0]+t,b=f[m+(l?1:2)]+t,S=f[m+(l?2:1)]+t;o.push(y,b,S)}}applyMatrix4OnRange(e,t,o){let i=e.elements,a=new CE().getNormalMatrix(e).elements,s,l,c,u,p=this.attributes.position,d=this.attributes.normal;if(!p||!d)return;let f=p.array,h=d.array,m=p.itemSize;for(let y=t*m,b=o*m;y<b;y+=m){if(y===t)debugger;s=f[y+0],l=f[y+1],c=f[y+2],u=1/(i[3]*s+i[7]*l+i[11]*c+i[15]),f[y+0]=(i[0]*s+i[4]*l+i[8]*c+i[12])*u,f[y+1]=(i[1]*s+i[5]*l+i[9]*c+i[13])*u,f[y+2]=(i[2]*s+i[6]*l+i[10]*c+i[14])*u,s=h[y+0],l=h[y+1],c=h[y+2],h[y+0]=a[0]*s+a[3]*l+a[6]*c,h[y+1]=a[1]*s+a[4]*l+a[7]*c,h[y+2]=a[2]*s+a[5]*l+a[8]*c}p.needsUpdate=!0,d.needsUpdate=!0}reverseIndicesOnRange(e,t){let o=this.index;if(o){for(let i=e;i<t;i+=3){let a=o.getX(i),s=o.getX(i+1),l=o.getX(i+2);o.setXYZ(i,l,s,a)}o.needsUpdate=!0}}};import{BufferAttribute as ob,BufferGeometry as Sf}from"three";import{mergeBufferGeometries as ME}from"three/examples/jsm/utils/BufferGeometryUtils.js";function nb(){let n=new Sf;return n.setAttribute("position",new ob(new Float32Array([]),3)),n.setIndex(new ob(new Uint16Array([]),1)),n}var EE=nb().attributes,NE=12,DE=1,Zn=class extends Sf{constructor(e,t){super();this.charWidths=[];this.charCoords=[];this.wrappedText=[];this.isLowResolution=!1;this.vectorShapes=[];Object.assign(this.attributes,EE),this.userData={parameters:e,type:"TextGeometry"};let o=t.getFont(e.font);o?.isLoaded?(this.font=o,this.update(e)):this.updateFont(e.font,t).then(()=>{this.update(e),t?.requestRender()})}async updateFont(e,t){let o=t.getFont(e);o&&(this.font=o,await o.loadingPromise)}update(e){let t=this.font;if(this.userData={parameters:e,type:"TextGeometry"},!t?.isLoaded){console.warn("Cannot update text because its font is not loaded");return}let{width:o,height:i,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l,text:c,textTransform:u}=e,p=fn.getDisplayedValue(c),d=u===2?p.toUpperCase():u===3?p.toLowerCase():p,f=_E(e,t,d),{shapes:h,charWidths:m,charCoords:y}=t.generateShapes(f,e),b=(typeof o=="number"?o:1)*.5,S=(typeof i=="number"?i:1)*.5,P=h.map(A=>new je().fromShape(A,!0));this.vectorShapes=P;let C=P.map(A=>Jt.create({shape:A,parameters:{depth:a,extrudeBevelSegments:l,extrudeBevelSize:s,windingRule:a<=0?Fe.NONZERO:Fe.ODD,subdivisions:this.isLowResolution&&a>0?DE:NE}})),v=C.length?ME(C):nb();v.translate(-b,S,0),this.dispose(),this.wrappedText=f,this.charCoords=y,this.charWidths=m,this.deleteAttribute("extrudeNormal"),Object.entries(v.attributes).forEach(([A,T])=>{this.setAttribute(A,T)}),this.setIndex(v.index),this.computeBoundingSphere()}clone(){let e=Lt(new Sf,Zn.prototype);return e.copy(this),console.log("CloneGeometry",this,e),e}copy(e){return Object.entries(e.attributes).forEach(([t,o])=>{this.setAttribute(t,o)}),this.setIndex(e.index),this.userData={parameters:{...e.userData.parameters},type:"TextGeometry"},this}async setText(e){this.font&&await this.font.loadingPromise,await this.update({...this.userData.parameters,text:{textValue:e}})}get text(){return this.userData.parameters.text??""}};function _E(n,r,e){let t=[""],o="";for(let i of e)o+=i,i===" "||i===`
17
17
  `?(t[t.length-1]+=o,o="",i===`
18
- `&&t.push("")):r.getTextWidth(t[t.length-1]+o,n)>n.width&&(t[t.length-1].length&&t.push(""),r.getTextWidth(t[t.length-1]+o,n)>n.width&&(o.length===1?(t[t.length-1]+=o,o=""):(t[t.length-1]+=o.slice(0,-1),o=o[o.length-1],t.push(""))));return t[t.length-1]+=o,t}import{BufferGeometry as Af,BufferAttribute as cb,Uint32BufferAttribute as Tf,Float32BufferAttribute as If,Matrix4 as FE,Vector3 as tl,Sphere as jE,Box3 as kE,BoxGeometry as UE}from"three";var sb,Mu=new Promise(n=>{sb=n}),ab=!1;var Iu;function lb(){if(ab)return;if(Iu)return Iu;async function n(){let e=!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.9.44/build",o=import("./process.js"),[i,a]=await Promise.all([o,fetch(`${e}/process.wasm`).then(c=>c.arrayBuffer())]),s=i.default,l=await s({wasmBinary:a});sb(l),ab=!0}return Iu=n(),Iu}import{BufferGeometryLoader as LE}from"three";var VE=["font"];function Vo(n,r,e,t){let o,i,a;n.type==="PathGeometry"?(i=JSON.parse(JSON.stringify(n)),a=[[],["extrusion"]]):(i={...n},a=[[]]);for(let c of a){let u=i;for(let p of c)u=u[p];for(o in u){let p=u[o];hp(p)&&!VE.includes(o)&&(u[o]=r.getVariable(p,[t.uuid,"geometry",...c,o]),hp(u[o])&&(u[o]=1))}}let s={parameters:i,type:i.type};if(i.type==="PathGeometry")s.path=i.path;else if(i.type==="VectorGeometry"){let c=je.createFromState(i.shape,i.width,i.height);s.shape=c}else if(i.type==="NonParametricGeometry"){if(i.data.groups&&i.data.groups?.forEach(c=>c.materialIndex=Math.max(c.materialIndex??0,0)),s.geometry=new LE().parse(i),s.geometry.groups.length===0){let c=s.geometry;c.addGroup(0,Math.max(c.getIndex()?.count??0,c.getAttribute("position").count),0)}}else if(i.type==="SubdivGeometry"){let c=new yt(i,e);return c.data=n,c}else{if(i.type==="TextGeometry")return new Jn(i,r);if(i.type==="InputGeometry")return new Jn(i,r);if(i.type==="UIGeometry")return Oa.create({parameters:{width:i.width,height:i.height,cornerRadius:i.cornerRadius,cornerType:i.cornerType}})}let l;try{l=Of(s)}catch(c){console.error(c)}if(!l){let c=je.createFromState(Ji.defaultData(),100,100);s.shape=c,l=Of(s)}return l}import{Matrix4 as zE}from"three";var GE=new zE;function el(n,r,e,t){let o=n.position.array,i=n.normal.array,a=GE.makeScale(r,e,t).invert().elements,s,l,c;for(var u=0,p=o.length;u<p;u+=3)o[u]*=r,o[u+1]*=e,o[u+2]*=t,s=i[u],l=i[u+1],c=i[u+2],i[u]=a[0]*s+a[4]*l+a[8]*c,i[u+1]=a[1]*s+a[5]*l+a[9]*c,i[u+2]=a[2]*s+a[6]*l+a[10]*c;n.position.needsUpdate=!0,n.normal.needsUpdate=!0}var Eu=new kE,Ta=new tl,Se;Mu.then(n=>{Se=n});var ub=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),db=new Uint32Array([0,1,2,3]),pb=new Uint8Array([4]),yt=class extends Af{constructor(e,t){super();this.data=e;this.flatShading=t;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,t){this.freeSubdivPointer();let o=this.data.scaleBaked,i=sn.div(t,o);this.subdividedGeometry&&el(this.subdividedGeometry.attributes,...i),this.originalGeometry&&el(this.originalGeometry.attributes,...i),this.data=e;let a=this.userData.parameters;this.userData.parameters={width:a.width*i[0],height:a.height*i[1],depth:a.depth*i[2]},this.originalGeometry.boundingSphere.center.multiply(Ta.fromArray(i));let s=Ta.set(a.width,a.height,a.depth).length();this.originalGeometry.boundingSphere.radius=s/2}ensureSubdivPointer(){return this.subdivPointer===0&&this.rebuild(),this.subdivPointer}rebuild(){let e,t,o;try{({originalGeometry:e,subdividedGeometry:t,subdivPointer:o}=yt.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new UE(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=t??void 0;let i=this.subdividedGeometry??this.originalGeometry;Object.assign(this,i),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(yt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new jE,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;Eu.setFromBufferAttribute(t),Eu.getCenter(o),e.boundingSphere.radius=o.distanceTo(Eu.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),Eu.getSize(Ta);let i={width:Ta.x,height:Ta.y,depth:Ta.z};return this.userData.parameters=i,i}static build(e,t,o,i){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),t&&(Se.free_bvh(t),Se.free_subdivision_surface(t));try{a=yt.allocate(e,i)}catch(u){console.error(u,e),a=yt.allocate({positionWASM:ub,indexWASM:db,verticesPerFaceWASM:pb},i)}if(Se.set_destination_refinement_level(a,0),s=yt.buildLevel(a,!0,c),e.subdivisions>0)try{Se.set_destination_refinement_level(a,e.subdivisions),l=yt.buildLevel(a,!1,c)}catch{try{Se.set_destination_refinement_level(a,e.subdivisions-1),l=yt.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,t,o){e.widthSegments>16&&(e.widthSegments=16),e.heightSegments>16&&(e.heightSegments=16),e.depthSegments>16&&(e.depthSegments=16),e.radialSegments>16&&(e.radialSegments=16),e.type==="DodecahedronGeometry"&&(e.detail=0);let i=e.shape!==void 0||e.path!==void 0?t.geometry:Vo(e,o,!1),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=i.getClosedTorusIndicesForBooleanOrSubdiv():a=i.getIndex();let s,l,c,u;({positions:s,triIndices:u}=Df(i.getAttribute("position"),a));let p;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let d=e.radialSegments*e.heightSegments*3*2,h=d+e.radialSegments*3;p=[d,h]}return{indices:l,verticesPerFace:c}=_f(s,u,i,p),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,t){let o,i,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,i=e.indexWASM,a=e.verticesPerFaceWASM):(o=ub,i=db,a=pb);let c=o.length,u=i.length,p=a.length,d=o.length+s.length+l.length,h=i.length+a.length,f=d*Float32Array.BYTES_PER_ELEMENT+h*Uint32Array.BYTES_PER_ELEMENT,m=d*Float32Array.BYTES_PER_ELEMENT,y=h*Uint32Array.BYTES_PER_ELEMENT,g=Se._malloc(f),v=new Float32Array(Se.HEAPF32.buffer,g,d),w=new Uint32Array(Se.HEAPU32.buffer,g+m,h);v.set(o,0),v.set(s,o.length),v.set(l,o.length+s.length),w.set(i,0),w.set(a,i.length);let O;e?.scaleBaked?.some(C=>C!==1)&&(O=new FE().makeScale(...e.scaleBaked)),t&&(O?O.premultiply(t):O=t);let S=O?Se.alloc_subdivision_surface2(g,c,g+m,u,g+m+i.length*Uint32Array.BYTES_PER_ELEMENT,p,O.elements):Se.alloc_subdivision_surface(g,c,g+m,u,g+m+i.length*Uint32Array.BYTES_PER_ELEMENT,p);return Se._free(g),S}static buildLevel(e,t,o,i,a){let s=a?Se.get_mesh_data2(e,t?Se.Level.CONTROL:Se.Level.REFINED,o,a.elements):Se.get_mesh_data(e,t?Se.Level.CONTROL:Se.Level.REFINED,o),l=8,c=Se.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),p=0,d=Se.HEAPU32[c[p]>>2],h=Se.HEAPF32.subarray(d>>2,(d>>2)+u[p]);p++;let f=Se.HEAPU32[c[p]>>2],m=Se.HEAPF32.subarray(f>>2,(f>>2)+u[p]);p++;let y=Se.HEAPU32[c[p]>>2],g=Se.HEAPU32.subarray(y>>2,(y>>2)+u[p]);p++;let v=Se.HEAPU32[c[p]>>2],w=Se.HEAPU32.subarray(v>>2,(v>>2)+u[p]);if(p++,i===void 0){let O=new Af;if(O.setIndex(new Tf(w,1)),O.setAttribute("position",new If(h,3)),O.setAttribute("normal",new If(m,3)),t){O.setAttribute("faceMap",new Tf(g,1));let S=new Float32Array(m.length/3*4).fill(0);O.setAttribute("color",new cb(S,4))}return Se.free_mesh_data(s),O.userData.type="SubdivGeometry",O}i.getAttribute("position").copyArray(h),i.getAttribute("normal").copyArray(m),i.attributes.position.needsUpdate=!0,i.attributes.normal.needsUpdate=!0,Se.free_mesh_data(s)}static freeSubdivPointer(e){Se.free_bvh(e),Se.free_subdivision_surface(e)}static buildControlCageWireframe(e,t,o){let i=Se.get_wireframe_data_for_base_level(e),a=4,s=Se.HEAPU32.subarray(i>>2,(i>>2)+a),l=s.subarray(2,2+2),c=0,u=Se.HEAPU32[s[c]>>2],p=Se.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Se.HEAPU32[s[c]>>2],h=Se.HEAPU32.subarray(d>>2,(d>>2)+l[c]);if(t===void 0){let f=new Af;f.setAttribute("position",new If(p,3));let m=new Float32Array(p.length);for(let y=0,g=p.length;y<g;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return f.setAttribute("color",new cb(m,3)),f.setIndex(new Tf(h,1)),Se.free_wireframe_data_for_base_level(i),f}t.getAttribute("position").copyArray(p),t.attributes.position.needsUpdate=!0,Se.free_wireframe_data_for_base_level(i)}static updateCollabMesh(e,t,o){let i=t===0;i||Se.set_destination_refinement_level(e,t);let a=o?Se.get_topological_data2(e,i?Se.Level.CONTROL:Se.Level.REFINED,o.elements):Se.get_topological_data(e,i?Se.Level.CONTROL:Se.Level.REFINED),s=6,l=Se.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,p=Se.HEAPU32[l[u]>>2],d=new Float32Array(Se.HEAPF32.subarray(p>>2,(p>>2)+c[u]));u++;let h=Se.HEAPU32[l[u]>>2],f=new Uint32Array(Se.HEAPU32.subarray(h>>2,(h>>2)+c[u]));u++;let m=Se.HEAPU32[l[u]>>2],y=new Uint8Array(Se.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Se.free_topological_data(a),{positions:d,indices:f,verticesPerFace:y}}};var fb=["getX","getY","getZ"];function Df(n,r){let e={},t=r?r.count:n.count,o=0,i=[],a=[],s=1e4;for(let c=0;c<t;c++){let u=r?r.getX(c):c,p="";for(let d=0;d<3;d++)p+=`${~~(n[fb[d]](u)*s)},`;if(p in e)i.push(e[p]);else{for(let d=0;d<3;d++)a.push(n[fb[d]](u));e[p]=o,i.push(o),o++}}let l=[];for(let c=0;c<i.length;c+=3)i[c]===i[c+1]||i[c]===i[c+2]||i[c+1]===i[c+2]||l.push(i[c],i[c+1],i[c+2]);return{positions:a,triIndices:l}}var Nu=new tl,Mf=new tl,Ef=new tl,Nf=new tl;function _f(n,r,e,t){let o=[],i=[];if(e.userData.shape!==void 0&&e.userData.parameters.depth===0&&e.userData.shape.shapeHoles.length===0){let l=e.userData.shape.extractShapePointsToFlatArray([]),c=e.userData.parameters.spikes;if(e.userData.type==="EllipseGeometry"&&c<=24&&c%4===0&&e.userData.parameters.angle>=360){let d=l.length/2/c;l=l.filter((h,f)=>Math.floor(f/2)%d===0)}let u=0;for(let d=0;d<l.length;d+=2)u+=(l[d]-l[(d===0?l.length:d)-2])*(l[d+1]+l[(d===0?l.length:d)-1]);n.length=0;let p=0;if(u<0)for(let d=0;d<l.length;d+=2)n.push(l[d],l[d+1],0),o.push(p++);else for(let d=l.length-2;d>=0;d-=2)n.push(l[d],l[d+1],0),o.push(p++);return i.push(p),{indices:o,verticesPerFace:i}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<r.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((n[r[s]*3+2]===a||n[r[s]*3+2]===0)&&l++,(n[r[s+1]*3+2]===a||n[r[s+1]*3+2]===0)&&l++,(n[r[s+2]*3+2]===a||n[r[s+2]*3+2]===0)&&l++,l===3)break}if(r[s+1]===r[s+3]&&r[s+2]===r[s+5]||r[s+0]===r[s+3]&&r[s+2]===r[s+4]){Nu.set(n[r[s]*3],n[r[s]*3+1],n[r[s]*3+2]),Mf.set(n[r[s+1]*3],n[r[s+1]*3+1],n[r[s+1]*3+2]),Ef.set(n[r[s+4]*3],n[r[s+4]*3+1],n[r[s+4]*3+2]),Nf.set(n[r[s+5]*3],n[r[s+5]*3+1],n[r[s+5]*3+2]),Mf.sub(Nu).normalize(),Ef.sub(Nu).normalize(),Nf.sub(Nu).normalize();let l=Mf.cross(Ef).dot(Nf);Math.abs(l)>.005||t&&t.some((c,u)=>u%2===1?!1:s>=t[u]&&s<t[u+1])?(o.push(r[s],r[s+1],r[s+2]),i.push(3),s+=3):(o.push(r[s],r[s+1],r[s+4],r[s+5]),i.push(4),s+=6)}else o.push(r[s],r[s+1],r[s+2]),i.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let p=0,d=0;p<n.length;p+=3,d++)n[p+2]===0&&(l.push(d),u++),n[p+2]===a&&c.push(d);if(e.userData.parameters.extrudeBevelSize===0){let p=c[0];c[0]=c[1],c[1]=p}l.reverse(),o.push(...l,...c),i.push(u,u)}return{indices:o,verticesPerFace:i}}var vr={};H1(vr,{calcBoolean:()=>YE,calcBooleanTopological:()=>$E,freeMeshSet:()=>ZE,getMeshSet:()=>XE,hasOpenEdges:()=>KE,transformMeshSet:()=>QE});var HE,hb=new Promise(n=>{HE=n});import{Float32BufferAttribute as mb,Sphere as WE}from"three";var Ne,Ia;hb.then(n=>Ne=n);function qE(n,r,e){let t,o;n.userData.parameters.type==="TorusGeometry"&&n.userData.parameters.arc===Math.PI*2?o=n.getClosedTorusIndicesForBooleanOrSubdiv():o=n.getIndex();let{positions:i,triIndices:a}=Df(n.getAttribute("position"),o),s;if(r&&e){let{indices:l,verticesPerFace:c}=_f(i,a,n);s=c.length,t=[];for(let u=0,p=0;u<s;u++){t.push(c[u]);for(let d=0;d<c[u];d++)t.push(l[p++])}}else{let l=a.length;t=Array(l+l/3),s=0;for(let c=0,u=0;u<t.length;)t[u++]=3,s++,t[u++]=a[c++],t[u++]=a[c++],t[u++]=a[c++]}return{positions:i,faceIndices:t,nFaces:s}}function yb(n){let r=n.length,e=r*Uint32Array.BYTES_PER_ELEMENT,t=r*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(n[0])?e:t,i=Ne._malloc(o);return(Number.isInteger(n[0])?new Uint32Array(Ne.HEAPU32.buffer,i,r):new Float32Array(Ne.HEAPF32.buffer,i,r)).set(n,0),i}function gb(n){switch(n){case 0:return Ne.OP.UNION;case 1:return Ne.OP.INTERSECTION;case 2:return Ne.OP.A_MINUS_B;case 3:return Ne.OP.B_MINUS_A;case 4:return Ne.OP.SYMMETRIC_DIFFERENCE;case 5:return Ne.OP.ALL;default:throw new Error("Unknown boolean operation "+n)}}function $E(n,r){Ia===void 0&&(Ia=Ne.init_csg());let e=yb(n),t=Ne.csg_calc_topological(Ia,e,n.length,gb(r));Ne._free(e);let o=6,i=Ne.HEAPU32.subarray(t>>2,(t>>2)+o),a=i.subarray(3,3+3),s=0,l=Ne.HEAPU32[i[s]>>2],c=new Float32Array(Ne.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=Ne.HEAPU32[i[s]>>2],p=new Uint32Array(Ne.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let d=Ne.HEAPU32[i[s]>>2],h=new Uint8Array(Ne.HEAPU32.subarray(d>>2,(d>>2)+a[s]));return Ne.free_mesh_data(t),{positions:c,indices:p,verticesPerFace:h}}function YE(n,r,e,t){Ia===void 0&&(Ia=Ne.init_csg());let o=yb(n),i=Ne.csg_calc(Ia,o,n.length,t,gb(r));Ne._free(o);let a=5,s=Ne.HEAPU32.subarray(i>>2,(i>>2)+a),l=s.subarray(2,2+3),c=0,u=Ne.HEAPU32[s[c]>>2],p=Ne.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Ne.HEAPU32[s[c]>>2],h=Ne.HEAPF32.subarray(d>>2,(d>>2)+l[c]);c++;let f=l[c];e.setAttribute("position",new mb(p,3)),e.setAttribute("normal",new mb(h,3));let m=Ne.HEAPF32.subarray((i>>2)+5,(i>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new WE),e.boundingSphere.center.set(m[0],m[1],m[2]),e.boundingSphere.radius=(m[3]**2+m[4]**2+m[5]**2)**.5,e.userData.parameters={width:m[3]*2,height:m[4]*2,depth:m[5]*2},Ne.free_mesh_data(i),f}function XE(n,r,e){if(Ne===void 0)return-1;let t,o,i;if(r&&n.userData.positions!==void 0){let g=n.userData;i=g.verticesPerFace.length,t=g.positions,o=Array(g.verticesPerFace.reduce((v,w)=>v+w,0)+i);for(let v=0,w=0,O=0;v<g.verticesPerFace.length;v++){o[O++]=g.verticesPerFace[v];for(let S=0;S<g.verticesPerFace[v];S++)o[O++]=g.indices[w++]}}else({positions:t,faceIndices:o,nFaces:i}=qE(n,r,e));let a=t.length,s=o.length,l=t.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,p=l*Float32Array.BYTES_PER_ELEMENT,d=c*Uint32Array.BYTES_PER_ELEMENT,h=Ne._malloc(u),f=new Float32Array(Ne.HEAPF32.buffer,h,l),m=new Uint32Array(Ne.HEAPU32.buffer,h+p,c);f.set(t,0),m.set(o,0);let y=Ne.get_csg_mesh(h,a,h+p,s,i);return Ne._free(h),y}function KE(n){return Ne.has_open_edges(n)}function QE(n,r){Ne.transform_csg_mesh(n,r.elements)}function ZE(n){Ne.free_csg_mesh(n)}var JE={ConeGeometry:Zx,CubeGeometry:Jx,CylinderGeometry:Qx,DodecahedronGeometry:e0,EllipseGeometry:Sa,HelixGeometry:E0,IcosahedronGeometry:N0,LatheGeometry:D0,NonParametricGeometry:k0,PolygonGeometry:Cu,PyramidGeometry:U0,RectangleGeometry:Oa,SphereGeometry:W0,PlaneGeometry:q0,BackdropGeometry:$0,StarGeometry:Ou,TextFrameGeometry:Y0,TorusGeometry:X0,TorusKnotGeometry:K0,TriangleGeometry:Q0,PathGeometry:ob,VectorGeometry:Jt},Of=n=>JE[n.type].create(n);function Ma(n){return n!==null&&"booleanOp"in n}var Ea=class extends fa(tN){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new eN}updateVisible(e){super.updateVisible(e),this.visible=!Ma(this.parent)&&this.visible,Ma(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(vr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),Ma(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof Ea&&(e.freeBooleanPointer(),Ma(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,t){let o=super.updateTransformState(e,t);return o&&Ma(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),Ma(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var Du=new rN;function rl(n,r=0,e=n.count,t,o){let i=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let p=r;p<e;p++){let d=n.getX(p),h=n.getY(p),f=n.getZ(p);d<i&&(i=d),h<a&&(a=h),f<s&&(s=f),d>l&&(l=d),h>c&&(c=h),f>u&&(u=f)}Du.min.set(i,a,s),Du.max.set(l,c,u),Du.getCenter(t),Du.getSize(o).multiplyScalar(.5)}var iN=new oN,aN=new nN,Ct=class extends Ea{constructor(r,e){super(iN,aN),this.super_Entity(r,e)}updateState(r,e){this.updateState_Entity(r,e)}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?rl(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};import{Box3 as BD,Matrix4 as RD,Sphere as fv,Vector3 as LD}from"three";import{BufferAttribute as ND,Float32BufferAttribute as pv,MathUtils as ah,Vector3 as sh}from"three";import{ShaderMaterial as oD}from"three";var zo=class{constructor(r){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(zo.uuidContext===null)throw new Error("plz startContext");zo.uuidContext===zo.globalContext?this.uuid="_gid"+zo.uuidContext.nodeContextUuid++:this.uuid="_uid"+zo.uuidContext.nodeContextUuid++,this.type=r,this.name=""}static startContext(r){this.uuidContext===null||this.uuidContext===zo.globalContext?this.uuidContext=r:console.error("Can't start context twice")}static endContext(r){this.uuidContext!==r&&console.error("Can't end context twice"),this.uuidContext=null}analyze(r,e){e=e??{},r.analyzing=!0,this.build(r.addFlow(e.slot,e.cache,e.context),"v4"),r.clearVertexNodeCode(),r.clearFragmentNodeCode(),r.removeFlow(),r.analyzing=!1}analyzeAndFlow(r,e,t){return t=t??{},this.analyze(r,t),this.flow(r,e,t)}flow(r,e,t){t=t??{},r.addFlow(t.slot,t.cache,t.context);let o={result:this.build(r,e),code:r.clearNodeCode(),extra:r.context.extra};return r.removeFlow(),o}build(r,e,t){e=e??this.getType(r,e);let o=r.getNodeData(t??this);return r.analyzing&&this.appendDepsNode(r,o,e),r.nodes.indexOf(this)===-1&&r.nodes.push(this),this.updateFrame!==void 0&&r.updaters.indexOf(this)===-1&&r.updaters.push(this),this.generate(r,e,t)}updateFrame(r){}generateReadonly(r,e,t,o,i,a){return""}generate(r,e,t,o,i){return""}parse(r,e,t,o){}appendDepsNode(r,e,t){e.deps=(e.deps||0)+1;let o=r.getTypeLength(t);(o>(e.outputMax||0)||this.getType(r,t))&&(e.outputMax=o,e.output=t)}setName(r){this.name=r}getName(){return this.name}getType(r,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},qe=zo;qe.globalContext={nodeContextUuid:0},qe.uuidContext=zo.globalContext;import{CubeReflectionMapping as gN,CubeRefractionMapping as xN,CubeUVReflectionMapping as bN,LinearEncoding as Tb,sRGBEncoding as vN}from"three";var ol=class{constructor(r){r=r??{},this.name=r.name,this.type=r.type,this.node=r.node,this.size=r.size,this.needsUpdate=r.needsUpdate}get value(){return this.node.value}set value(r){this.node.value=r}};var Bf=class{constructor(){this.nodes={};this.keywords={}}add(r){this.nodes[r.name]=r}addKeyword(r,e,t){t=t!==void 0?t:!0,this.keywords[r]={callback:e,cache:t}}remove(r){delete this.nodes[r.name]}removeKeyword(r){delete this.keywords[r]}get(r){return this.nodes[r]}getKeyword(r,e){return this.keywords[r].callback(e)}getKeywordData(r){return this.keywords[r]}contains(r){return this.nodes[r]!==void 0}containsKeyword(r){return this.keywords[r]!==void 0}},Ot=new Bf;import{Vector2 as xb}from"three";import{MathUtils as sN}from"three";var ge=class extends qe{constructor(e,t){super(e);this.scope="";t=t??{},this.shared=t.shared!==void 0?t.shared:!0,this.unique=t.unique!==void 0?t.unique:!1}build(e,t,o,i){if(t=t??this.getType(e),this.getShared(e,t)){let a=this.getUnique(e,t);a&&this.uuid===void 0&&(this.uuid=sN.generateUUID()),o=e.getUUID(o??this.getUUID(),!a);let s=e.getNodeData(o),l=s.output||this.getType(e);if(e.analyzing)return(s.deps||0)>0||this.getLabel()?(this.appendDepsNode(e,s,t),this.generate(e,t,o)):super.build(e,t,o);if(a)return s.name=s.name||super.build(e,t,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,t,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,t);{c=super.generate(e,t,o,s.output,i);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,t)}}return super.build(e,t,o)}getShared(e,t){return t!=="sampler2D"&&t!=="samplerCube"&&this.shared}getUnique(e,t){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let t=this.uuid;return typeof this.scope=="string"&&(t=this.scope+"-"+t),t}getTemp(e,t){t=t||this.uuid;let o=e.getVars()[t];return o?o.name:void 0}generate(e,t,o,i,a){return this.getShared(e,t)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,i??this.getType(e),a,this.getLabel()).name}};var $e=class extends ge{constructor(e,t){t=t??{},t.shared=t.shared!==void 0?t.shared:!1;super(e,t);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,t,o,i,a,s){o=e.getUUID(o??this.getUUID()),i=i??this.getType(e);let l=e.getNodeData(o);return this.getReadonly()&&this.generateReadonly!==void 0?this.generateReadonly(e,t,o,i,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(i,this,a,s,this.getLabel())),e.format(l.vertex.name,i,t)):(l.fragment||(l.fragment=e.createFragmentUniform(i,this,a,s,this.getLabel())),e.format(l.fragment.name,i,t))}};var st=class extends $e{constructor(e=0,t){super("v2");this.nodeType="Vector2";this.value=e instanceof xb?e:new xb(e,t)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}generateReadonly(e,t,o,i,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",i,t)}};import{Vector3 as bb}from"three";var Gt=class extends $e{constructor(e=0,t,o){super("v3");this.nodeType="Vector3";this.value=e instanceof bb?e:new bb(e,t,o)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}get z(){return this.value.z}set z(e){this.value.z=e}generateReadonly(e,t,o,i,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",i,t)}};import{Color as lN}from"three";var At=class extends lN{constructor(e,t,o,i){super(e,t,o);this.isColorA=!0;this.a=i}setRGBA(e,t,o,i){super.setRGB(e,t,o),this.a=i}copy(e){return super.copy(e),this.a="a"in e?e.a:1,this}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}equals(e){return super.equals(e)&&this.a===e.a}setStyle(e,t="srgb"){let o;if(e==="transparent")return this.setRGBA(0,0,0,0),this;if(o=/^((?:rgb|hsl)a?)\(([^)]*)\)/.exec(e)){let i,a=o[1],s=o[2];switch(a){case"rgb":case"rgba":if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="rgba"?parseFloat(i[4]):1,super.setStyle(e,t);break;case"hsl":case"hsla":if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="hsla"?parseFloat(i[4]):1,super.setStyle(e,t);break}}return super.setStyle(e,t)}get x(){return this.r}get y(){return this.g}get z(){return this.b}get w(){return this.a}set x(e){this.r=e}set y(e){this.g=e}set z(e){this.b=e}set w(e){this.a=e}};var er=class extends $e{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof At?e:new At(e.r,e.g,e.b,e.a)}generateReadonly(e,t,o,i,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",i,t)}};var cN=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,vb=/[a-z_0-9]+/gi,J=class extends ge{constructor(e,t,o,i,a){super(a);this.src="";this.nodeType="Function";this.useKeywords=!0;this.includes=[];this.extensions={};this.keywords={};this.isMethod=a===void 0,this.isInterface=!1,this.parse(e,t,o,i)}getShared(e,t){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}}getIncludeByName(e){if(this.includes){let t=this.includes.length;for(;t--;)if(this.includes[t].name===e)return this.includes[t]}}generate(e,t,o,i,a){let s,l=0,c=this.src;if(this.includes)for(let p=0;p<this.includes.length;p++)e.include(this.includes[p],this);for(let p in this.extensions)e.extensions[p]=!0;let u=[];for(;s=vb.exec(this.src);)u.push(s);for(let p=0;p<u.length;p++){let d=u[p],h=d[0],f=this.isMethod?!this.getInputByName(h):!0,m=h;if(this.keywords[h]||this.useKeywords&&f&&Ot.containsKeyword(h)){let y=this.keywords[h];if(!y){let g=Ot.getKeywordData(h);g.cache&&(y=e.keywords[h]),y=y||Ot.getKeyword(h,e),g.cache&&(e.keywords[h]=y)}m=y.build(e)}h!==m&&c[d.index+l-1]!=="."&&(c=c.substring(0,d.index+l)+m+c.substring(d.index+h.length+l),l+=m.length-h.length),this.getIncludeByName(m)===void 0&&Ot.contains(m)&&e.include(Ot.get(m))}return t==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),t)}parse(e,t,o,i){if(this.src=e||"",this.includes=t??[],this.extensions=o??{},this.keywords=i??{},this.isMethod){let a=cN.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(vb);if(s){let l=0;for(;l<s.length;){let c=s[l++],u;c==="in"||c==="out"||c==="inout"?u=s[l++]:(u=c,c="");let p=s[l++];this.inputs.push({name:p,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var uN=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,Rf=class extends ge{constructor(e="",t){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||Rf.PI,void 0,void 0,void 0,t)}getType(e){return e.getTypeByFormat(this.type)}parse(e,t,o,i,a){this.src=e||"";let s,l,c="",u=uN.exec(e);this.useDefine=a??this.src.charAt(0)==="#",u&&u.length>1?(l=u[1],s=u[2],c=u[3]):(s=this.src,l="f"),this.name=s,this.type=l,this.value=c}build(e,t){if(t==="source"){if(this.value)return this.useDefine?"#define "+this.name+" "+this.value:"const "+this.type+" "+this.name+" = "+this.value+";";if(this.useDefine)return this.src}return e.include(this),e.format(this.name,this.getType(e),t)}generate(e,t,o,i,a){return e.format(this.name,this.getType(e),t)}},Fe=Rf;Fe.PI="PI",Fe.PI2="PI2",Fe.RECIPROCAL_PI="RECIPROCAL_PI",Fe.RECIPROCAL_PI2="RECIPROCAL_PI2",Fe.LOG2="LOG2",Fe.EPSILON="EPSILON";var dN=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
19
- )*?)}`,"gim"),pN=new RegExp("s*(w*?)s*(w*?)(=|;)","gim"),Na=class extends ge{constructor(e=""){super();this.inputs=[];this.src="";this.nodeType="Struct";this.parse(e)}getType(e){return e.getTypeByFormat(this.name)}getInputByName(e){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}generate(e,t,o,i,a){return t==="source"?this.src+";":e.format("( "+this.src+" )",this.getType(e),t)}parse(e=""){this.src=e,this.inputs=[];let t=dN.exec(e);if(t){let o=t[2],i;for(;i=pN.exec(o);)this.inputs.push({type:i[1],name:i[2]});this.name=t[1]}else this.name="";this.type=this.name}};var Da=class extends ge{constructor(e){super("v2",{shared:!1});this.nodeType="UV";this.index=e??0}generate(e,t){e.requires.uv[this.index]=!0;let o=this.index>0?this.index+1:"",i=e.isShader("vertex")?"uv"+o:"vUv"+o;return e.format(i,this.getType(e),t)}};Ot.addKeyword("uv",function(){return new Da});Ot.addKeyword("uv2",function(){return new Da(1)});import{LinearEncoding as fN,sRGBEncoding as hN}from"three";var ei=class extends ge{constructor(e,t){super("v4");this.nodeType="ColorSpace";this.input=e,this.method=t??ei.LINEAR_TO_LINEAR,this.hashProperties=["method"]}static getEncodingComponents(e){switch(e){case fN:return["Linear"];case hN:return["sRGB"];default:return[]}}generate(e,t){let o=this.input.build(e,"v4"),i=this.getType(e),a=ei.Nodes[this.method],s=e.include(a);if(s===ei.LINEAR_TO_LINEAR)return e.format(o,i,t);if(a.inputs?.length===2){let l=this.factor.build(e,"f");return e.format(s+"( "+o+", "+l+" )",i,t)}else return e.format(s+"( "+o+" )",i,t)}fromEncoding(e){let t=ei.getEncodingComponents(e);this.method="LinearTo"+t[0],this.factor=t[1]}fromDecoding(e){let t=ei.getEncodingComponents(e);this.method=t[0]+"ToLinear",this.factor=t[1]}},$t=ei;$t.Nodes={LinearToLinear:new J(["vec4 LinearToLinear( in vec4 value ) {"," return value;","}"].join(`
18
+ `&&t.push("")):r.getTextWidth(t[t.length-1]+o,n)>n.width&&(t[t.length-1].length&&t.push(""),r.getTextWidth(t[t.length-1]+o,n)>n.width&&(o.length===1?(t[t.length-1]+=o,o=""):(t[t.length-1]+=o.slice(0,-1),o=o[o.length-1],t.push(""))));return t[t.length-1]+=o,t}import{BufferGeometry as Pf,BufferAttribute as lb,Uint32BufferAttribute as Cf,Float32BufferAttribute as Of,Matrix4 as zE,Vector3 as Js,Sphere as GE,Box3 as FE,BoxGeometry as jE}from"three";var ab,Ou=new Promise(n=>{ab=n}),ib=!1;var Cu;function sb(){if(ib)return;if(Cu)return Cu;async function n(){let e=!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.9.46/build",o=import("./process.js"),[i,a]=await Promise.all([o,fetch(`${e}/process.wasm`).then(c=>c.arrayBuffer())]),s=i.default,l=await s({wasmBinary:a});ab(l),ib=!0}return Cu=n(),Cu}import{BufferGeometryLoader as BE}from"three";var RE=["font"];function Vo(n,r,e,t){let o,i,a;n.type==="PathGeometry"?(i=JSON.parse(JSON.stringify(n)),a=[[],["extrusion"]]):(i={...n},a=[[]]);for(let c of a){let u=i;for(let p of c)u=u[p];for(o in u){let p=u[o];dp(p)&&!RE.includes(o)&&(u[o]=r.getVariable(p,[t.uuid,"geometry",...c,o]),dp(u[o])&&(u[o]=1))}}let s={parameters:i,type:i.type};if(i.type==="PathGeometry")s.path=i.path;else if(i.type==="VectorGeometry"){let c=je.createFromState(i.shape,i.width,i.height);s.shape=c}else if(i.type==="NonParametricGeometry"){if(i.data.groups&&i.data.groups?.forEach(c=>c.materialIndex=Math.max(c.materialIndex??0,0)),s.geometry=new BE().parse(i),s.geometry.groups.length===0){let c=s.geometry;c.addGroup(0,Math.max(c.getIndex()?.count??0,c.getAttribute("position").count),0)}}else if(i.type==="SubdivGeometry"){let c=new yt(i,e);return c.data=n,c}else{if(i.type==="TextGeometry")return new Zn(i,r);if(i.type==="InputGeometry")return new Zn(i,r);if(i.type==="UIGeometry")return Ca.create({parameters:{width:i.width,height:i.height,cornerRadius:i.cornerRadius,cornerType:i.cornerType}})}let l;try{l=wf(s)}catch(c){console.error(c)}if(!l){let c=je.createFromState(Zi.defaultData(),100,100);s.shape=c,l=wf(s)}return l}import{Matrix4 as LE}from"three";var VE=new LE;function Zs(n,r,e,t){let o=n.position.array,i=n.normal.array,a=VE.makeScale(r,e,t).invert().elements,s,l,c;for(var u=0,p=o.length;u<p;u+=3)o[u]*=r,o[u+1]*=e,o[u+2]*=t,s=i[u],l=i[u+1],c=i[u+2],i[u]=a[0]*s+a[4]*l+a[8]*c,i[u+1]=a[1]*s+a[5]*l+a[9]*c,i[u+2]=a[2]*s+a[6]*l+a[10]*c;n.position.needsUpdate=!0,n.normal.needsUpdate=!0}var Au=new FE,Aa=new Js,Se;Ou.then(n=>{Se=n});var cb=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),ub=new Uint32Array([0,1,2,3]),db=new Uint8Array([4]),yt=class extends Pf{constructor(e,t){super();this.data=e;this.flatShading=t;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,t){this.freeSubdivPointer();let o=this.data.scaleBaked,i=an.div(t,o);this.subdividedGeometry&&Zs(this.subdividedGeometry.attributes,...i),this.originalGeometry&&Zs(this.originalGeometry.attributes,...i),this.data=e;let a=this.userData.parameters;this.userData.parameters={width:a.width*i[0],height:a.height*i[1],depth:a.depth*i[2]},this.originalGeometry.boundingSphere.center.multiply(Aa.fromArray(i));let s=Aa.set(a.width,a.height,a.depth).length();this.originalGeometry.boundingSphere.radius=s/2}ensureSubdivPointer(){return this.subdivPointer===0&&this.rebuild(),this.subdivPointer}rebuild(){let e,t,o;try{({originalGeometry:e,subdividedGeometry:t,subdivPointer:o}=yt.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new jE(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=t??void 0;let i=this.subdividedGeometry??this.originalGeometry;Object.assign(this,i),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(yt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new GE,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;Au.setFromBufferAttribute(t),Au.getCenter(o),e.boundingSphere.radius=o.distanceTo(Au.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),Au.getSize(Aa);let i={width:Aa.x,height:Aa.y,depth:Aa.z};return this.userData.parameters=i,i}static build(e,t,o,i){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),t&&(Se.free_bvh(t),Se.free_subdivision_surface(t));try{a=yt.allocate(e,i)}catch(u){console.error(u,e),a=yt.allocate({positionWASM:cb,indexWASM:ub,verticesPerFaceWASM:db},i)}if(Se.set_destination_refinement_level(a,0),s=yt.buildLevel(a,!0,c),e.subdivisions>0)try{Se.set_destination_refinement_level(a,e.subdivisions),l=yt.buildLevel(a,!1,c)}catch{try{Se.set_destination_refinement_level(a,e.subdivisions-1),l=yt.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,t,o){e.widthSegments>16&&(e.widthSegments=16),e.heightSegments>16&&(e.heightSegments=16),e.depthSegments>16&&(e.depthSegments=16),e.radialSegments>16&&(e.radialSegments=16),e.type==="DodecahedronGeometry"&&(e.detail=0);let i=e.shape!==void 0||e.path!==void 0?t.geometry:Vo(e,o,!1),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=i.getClosedTorusIndicesForBooleanOrSubdiv():a=i.getIndex();let s,l,c,u;({positions:s,triIndices:u}=Mf(i.getAttribute("position"),a));let p;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let d=e.radialSegments*e.heightSegments*3*2,f=d+e.radialSegments*3;p=[d,f]}return{indices:l,verticesPerFace:c}=Ef(s,u,i,p),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,t){let o,i,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,i=e.indexWASM,a=e.verticesPerFaceWASM):(o=cb,i=ub,a=db);let c=o.length,u=i.length,p=a.length,d=o.length+s.length+l.length,f=i.length+a.length,h=d*Float32Array.BYTES_PER_ELEMENT+f*Uint32Array.BYTES_PER_ELEMENT,m=d*Float32Array.BYTES_PER_ELEMENT,y=f*Uint32Array.BYTES_PER_ELEMENT,b=Se._malloc(h),S=new Float32Array(Se.HEAPF32.buffer,b,d),P=new Uint32Array(Se.HEAPU32.buffer,b+m,f);S.set(o,0),S.set(s,o.length),S.set(l,o.length+s.length),P.set(i,0),P.set(a,i.length);let C;e?.scaleBaked?.some(A=>A!==1)&&(C=new zE().makeScale(...e.scaleBaked)),t&&(C?C.premultiply(t):C=t);let v=C?Se.alloc_subdivision_surface2(b,c,b+m,u,b+m+i.length*Uint32Array.BYTES_PER_ELEMENT,p,C.elements):Se.alloc_subdivision_surface(b,c,b+m,u,b+m+i.length*Uint32Array.BYTES_PER_ELEMENT,p);return Se._free(b),v}static buildLevel(e,t,o,i,a){let s=a?Se.get_mesh_data2(e,t?Se.Level.CONTROL:Se.Level.REFINED,o,a.elements):Se.get_mesh_data(e,t?Se.Level.CONTROL:Se.Level.REFINED,o),l=8,c=Se.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),p=0,d=Se.HEAPU32[c[p]>>2],f=Se.HEAPF32.subarray(d>>2,(d>>2)+u[p]);p++;let h=Se.HEAPU32[c[p]>>2],m=Se.HEAPF32.subarray(h>>2,(h>>2)+u[p]);p++;let y=Se.HEAPU32[c[p]>>2],b=Se.HEAPU32.subarray(y>>2,(y>>2)+u[p]);p++;let S=Se.HEAPU32[c[p]>>2],P=Se.HEAPU32.subarray(S>>2,(S>>2)+u[p]);if(p++,i===void 0){let C=new Pf;if(C.setIndex(new Cf(P,1)),C.setAttribute("position",new Of(f,3)),C.setAttribute("normal",new Of(m,3)),t){C.setAttribute("faceMap",new Cf(b,1));let v=new Float32Array(m.length/3*4).fill(0);C.setAttribute("color",new lb(v,4))}return Se.free_mesh_data(s),C.userData.type="SubdivGeometry",C}i.getAttribute("position").copyArray(f),i.getAttribute("normal").copyArray(m),i.attributes.position.needsUpdate=!0,i.attributes.normal.needsUpdate=!0,Se.free_mesh_data(s)}static freeSubdivPointer(e){Se.free_bvh(e),Se.free_subdivision_surface(e)}static buildControlCageWireframe(e,t,o){let i=Se.get_wireframe_data_for_base_level(e),a=4,s=Se.HEAPU32.subarray(i>>2,(i>>2)+a),l=s.subarray(2,2+2),c=0,u=Se.HEAPU32[s[c]>>2],p=Se.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Se.HEAPU32[s[c]>>2],f=Se.HEAPU32.subarray(d>>2,(d>>2)+l[c]);if(t===void 0){let h=new Pf;h.setAttribute("position",new Of(p,3));let m=new Float32Array(p.length);for(let y=0,b=p.length;y<b;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return h.setAttribute("color",new lb(m,3)),h.setIndex(new Cf(f,1)),Se.free_wireframe_data_for_base_level(i),h}t.getAttribute("position").copyArray(p),t.attributes.position.needsUpdate=!0,Se.free_wireframe_data_for_base_level(i)}static updateCollabMesh(e,t,o){let i=t===0;i||Se.set_destination_refinement_level(e,t);let a=o?Se.get_topological_data2(e,i?Se.Level.CONTROL:Se.Level.REFINED,o.elements):Se.get_topological_data(e,i?Se.Level.CONTROL:Se.Level.REFINED),s=6,l=Se.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,p=Se.HEAPU32[l[u]>>2],d=new Float32Array(Se.HEAPF32.subarray(p>>2,(p>>2)+c[u]));u++;let f=Se.HEAPU32[l[u]>>2],h=new Uint32Array(Se.HEAPU32.subarray(f>>2,(f>>2)+c[u]));u++;let m=Se.HEAPU32[l[u]>>2],y=new Uint8Array(Se.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Se.free_topological_data(a),{positions:d,indices:h,verticesPerFace:y}}};var pb=["getX","getY","getZ"];function Mf(n,r){let e={},t=r?r.count:n.count,o=0,i=[],a=[],s=1e4;for(let c=0;c<t;c++){let u=r?r.getX(c):c,p="";for(let d=0;d<3;d++)p+=`${~~(n[pb[d]](u)*s)},`;if(p in e)i.push(e[p]);else{for(let d=0;d<3;d++)a.push(n[pb[d]](u));e[p]=o,i.push(o),o++}}let l=[];for(let c=0;c<i.length;c+=3)i[c]===i[c+1]||i[c]===i[c+2]||i[c+1]===i[c+2]||l.push(i[c],i[c+1],i[c+2]);return{positions:a,triIndices:l}}var Tu=new Js,Af=new Js,Tf=new Js,If=new Js;function Ef(n,r,e,t){let o=[],i=[];if(e.userData.shape!==void 0&&e.userData.parameters.depth===0&&e.userData.shape.shapeHoles.length===0){let l=e.userData.shape.extractShapePointsToFlatArray([]),c=e.userData.parameters.spikes;if(e.userData.type==="EllipseGeometry"&&c<=24&&c%4===0&&e.userData.parameters.angle>=360){let d=l.length/2/c;l=l.filter((f,h)=>Math.floor(h/2)%d===0)}let u=0;for(let d=0;d<l.length;d+=2)u+=(l[d]-l[(d===0?l.length:d)-2])*(l[d+1]+l[(d===0?l.length:d)-1]);n.length=0;let p=0;if(u<0)for(let d=0;d<l.length;d+=2)n.push(l[d],l[d+1],0),o.push(p++);else for(let d=l.length-2;d>=0;d-=2)n.push(l[d],l[d+1],0),o.push(p++);return i.push(p),{indices:o,verticesPerFace:i}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<r.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((n[r[s]*3+2]===a||n[r[s]*3+2]===0)&&l++,(n[r[s+1]*3+2]===a||n[r[s+1]*3+2]===0)&&l++,(n[r[s+2]*3+2]===a||n[r[s+2]*3+2]===0)&&l++,l===3)break}if(r[s+1]===r[s+3]&&r[s+2]===r[s+5]||r[s+0]===r[s+3]&&r[s+2]===r[s+4]){Tu.set(n[r[s]*3],n[r[s]*3+1],n[r[s]*3+2]),Af.set(n[r[s+1]*3],n[r[s+1]*3+1],n[r[s+1]*3+2]),Tf.set(n[r[s+4]*3],n[r[s+4]*3+1],n[r[s+4]*3+2]),If.set(n[r[s+5]*3],n[r[s+5]*3+1],n[r[s+5]*3+2]),Af.sub(Tu).normalize(),Tf.sub(Tu).normalize(),If.sub(Tu).normalize();let l=Af.cross(Tf).dot(If);Math.abs(l)>.005||t&&t.some((c,u)=>u%2===1?!1:s>=t[u]&&s<t[u+1])?(o.push(r[s],r[s+1],r[s+2]),i.push(3),s+=3):(o.push(r[s],r[s+1],r[s+4],r[s+5]),i.push(4),s+=6)}else o.push(r[s],r[s+1],r[s+2]),i.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let p=0,d=0;p<n.length;p+=3,d++)n[p+2]===0&&(l.push(d),u++),n[p+2]===a&&c.push(d);if(e.userData.parameters.extrudeBevelSize===0){let p=c[0];c[0]=c[1],c[1]=p}l.reverse(),o.push(...l,...c),i.push(u,u)}return{indices:o,verticesPerFace:i}}var vr={};k1(vr,{calcBoolean:()=>qE,calcBooleanTopological:()=>WE,freeMeshSet:()=>KE,getMeshSet:()=>$E,hasOpenEdges:()=>YE,transformMeshSet:()=>XE});var kE,fb=new Promise(n=>{kE=n});import{Float32BufferAttribute as hb,Sphere as UE}from"three";var Ne,Ta;fb.then(n=>Ne=n);function HE(n,r,e){let t,o;n.userData.parameters.type==="TorusGeometry"&&n.userData.parameters.arc===Math.PI*2?o=n.getClosedTorusIndicesForBooleanOrSubdiv():o=n.getIndex();let{positions:i,triIndices:a}=Mf(n.getAttribute("position"),o),s;if(r&&e){let{indices:l,verticesPerFace:c}=Ef(i,a,n);s=c.length,t=[];for(let u=0,p=0;u<s;u++){t.push(c[u]);for(let d=0;d<c[u];d++)t.push(l[p++])}}else{let l=a.length;t=Array(l+l/3),s=0;for(let c=0,u=0;u<t.length;)t[u++]=3,s++,t[u++]=a[c++],t[u++]=a[c++],t[u++]=a[c++]}return{positions:i,faceIndices:t,nFaces:s}}function mb(n){let r=n.length,e=r*Uint32Array.BYTES_PER_ELEMENT,t=r*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(n[0])?e:t,i=Ne._malloc(o);return(Number.isInteger(n[0])?new Uint32Array(Ne.HEAPU32.buffer,i,r):new Float32Array(Ne.HEAPF32.buffer,i,r)).set(n,0),i}function yb(n){switch(n){case 0:return Ne.OP.UNION;case 1:return Ne.OP.INTERSECTION;case 2:return Ne.OP.A_MINUS_B;case 3:return Ne.OP.B_MINUS_A;case 4:return Ne.OP.SYMMETRIC_DIFFERENCE;case 5:return Ne.OP.ALL;default:throw new Error("Unknown boolean operation "+n)}}function WE(n,r){Ta===void 0&&(Ta=Ne.init_csg());let e=mb(n),t=Ne.csg_calc_topological(Ta,e,n.length,yb(r));Ne._free(e);let o=6,i=Ne.HEAPU32.subarray(t>>2,(t>>2)+o),a=i.subarray(3,3+3),s=0,l=Ne.HEAPU32[i[s]>>2],c=new Float32Array(Ne.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=Ne.HEAPU32[i[s]>>2],p=new Uint32Array(Ne.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let d=Ne.HEAPU32[i[s]>>2],f=new Uint8Array(Ne.HEAPU32.subarray(d>>2,(d>>2)+a[s]));return Ne.free_mesh_data(t),{positions:c,indices:p,verticesPerFace:f}}function qE(n,r,e,t){Ta===void 0&&(Ta=Ne.init_csg());let o=mb(n),i=Ne.csg_calc(Ta,o,n.length,t,yb(r));Ne._free(o);let a=5,s=Ne.HEAPU32.subarray(i>>2,(i>>2)+a),l=s.subarray(2,2+3),c=0,u=Ne.HEAPU32[s[c]>>2],p=Ne.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Ne.HEAPU32[s[c]>>2],f=Ne.HEAPF32.subarray(d>>2,(d>>2)+l[c]);c++;let h=l[c];e.setAttribute("position",new hb(p,3)),e.setAttribute("normal",new hb(f,3));let m=Ne.HEAPF32.subarray((i>>2)+5,(i>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new UE),e.boundingSphere.center.set(m[0],m[1],m[2]),e.boundingSphere.radius=(m[3]**2+m[4]**2+m[5]**2)**.5,e.userData.parameters={width:m[3]*2,height:m[4]*2,depth:m[5]*2},Ne.free_mesh_data(i),h}function $E(n,r,e){if(Ne===void 0)return-1;let t,o,i;if(r&&n.userData.positions!==void 0){let b=n.userData;i=b.verticesPerFace.length,t=b.positions,o=Array(b.verticesPerFace.reduce((S,P)=>S+P,0)+i);for(let S=0,P=0,C=0;S<b.verticesPerFace.length;S++){o[C++]=b.verticesPerFace[S];for(let v=0;v<b.verticesPerFace[S];v++)o[C++]=b.indices[P++]}}else({positions:t,faceIndices:o,nFaces:i}=HE(n,r,e));let a=t.length,s=o.length,l=t.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,p=l*Float32Array.BYTES_PER_ELEMENT,d=c*Uint32Array.BYTES_PER_ELEMENT,f=Ne._malloc(u),h=new Float32Array(Ne.HEAPF32.buffer,f,l),m=new Uint32Array(Ne.HEAPU32.buffer,f+p,c);h.set(t,0),m.set(o,0);let y=Ne.get_csg_mesh(f,a,f+p,s,i);return Ne._free(f),y}function YE(n){return Ne.has_open_edges(n)}function XE(n,r){Ne.transform_csg_mesh(n,r.elements)}function KE(n){Ne.free_csg_mesh(n)}var QE={ConeGeometry:Qx,CubeGeometry:Zx,CylinderGeometry:Kx,DodecahedronGeometry:Jx,EllipseGeometry:va,HelixGeometry:M0,IcosahedronGeometry:E0,LatheGeometry:N0,NonParametricGeometry:j0,PolygonGeometry:vu,PyramidGeometry:k0,RectangleGeometry:Ca,SphereGeometry:H0,PlaneGeometry:W0,BackdropGeometry:q0,StarGeometry:Su,TextFrameGeometry:$0,TorusGeometry:Y0,TorusKnotGeometry:X0,TriangleGeometry:K0,PathGeometry:rb,VectorGeometry:Jt},wf=n=>QE[n.type].create(n);function Ia(n){return n!==null&&"booleanOp"in n}var Ma=class extends pa(JE){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new ZE}updateVisible(e){super.updateVisible(e),this.visible=!Ia(this.parent)&&this.visible,Ia(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(vr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),Ia(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof Ma&&(e.freeBooleanPointer(),Ia(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,t){let o=super.updateTransformState(e,t);return o&&Ia(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),Ia(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var Iu=new eN;function el(n,r=0,e=n.count,t,o){let i=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let p=r;p<e;p++){let d=n.getX(p),f=n.getY(p),h=n.getZ(p);d<i&&(i=d),f<a&&(a=f),h<s&&(s=h),d>l&&(l=d),f>c&&(c=f),h>u&&(u=h)}Iu.min.set(i,a,s),Iu.max.set(l,c,u),Iu.getCenter(t),Iu.getSize(o).multiplyScalar(.5)}var oN=new tN,nN=new rN,Ct=class extends Ma{constructor(r,e){super(oN,nN),this.super_Entity(r,e)}updateState(r,e){this.updateState_Entity(r,e)}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?el(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};import{Box3 as _3,Matrix4 as B3,Sphere as pv,Vector3 as R3}from"three";import{BufferAttribute as E3,Float32BufferAttribute as dv,MathUtils as oh,Vector3 as nh}from"three";import{ShaderMaterial as r3}from"three";var zo=class{constructor(r){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(zo.uuidContext===null)throw new Error("plz startContext");zo.uuidContext===zo.globalContext?this.uuid="_gid"+zo.uuidContext.nodeContextUuid++:this.uuid="_uid"+zo.uuidContext.nodeContextUuid++,this.type=r,this.name=""}static startContext(r){this.uuidContext===null||this.uuidContext===zo.globalContext?this.uuidContext=r:console.error("Can't start context twice")}static endContext(r){this.uuidContext!==r&&console.error("Can't end context twice"),this.uuidContext=null}analyze(r,e){e=e??{},r.analyzing=!0,this.build(r.addFlow(e.slot,e.cache,e.context),"v4"),r.clearVertexNodeCode(),r.clearFragmentNodeCode(),r.removeFlow(),r.analyzing=!1}analyzeAndFlow(r,e,t){return t=t??{},this.analyze(r,t),this.flow(r,e,t)}flow(r,e,t){t=t??{},r.addFlow(t.slot,t.cache,t.context);let o={result:this.build(r,e),code:r.clearNodeCode(),extra:r.context.extra};return r.removeFlow(),o}build(r,e,t){e=e??this.getType(r,e);let o=r.getNodeData(t??this);return r.analyzing&&this.appendDepsNode(r,o,e),r.nodes.indexOf(this)===-1&&r.nodes.push(this),this.updateFrame!==void 0&&r.updaters.indexOf(this)===-1&&r.updaters.push(this),this.generate(r,e,t)}updateFrame(r){}generateReadonly(r,e,t,o,i,a){return""}generate(r,e,t,o,i){return""}parse(r,e,t,o){}appendDepsNode(r,e,t){e.deps=(e.deps||0)+1;let o=r.getTypeLength(t);(o>(e.outputMax||0)||this.getType(r,t))&&(e.outputMax=o,e.output=t)}setName(r){this.name=r}getName(){return this.name}getType(r,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},qe=zo;qe.globalContext={nodeContextUuid:0},qe.uuidContext=zo.globalContext;import{CubeReflectionMapping as mN,CubeRefractionMapping as yN,CubeUVReflectionMapping as gN,LinearEncoding as Ab,sRGBEncoding as xN}from"three";var tl=class{constructor(r){r=r??{},this.name=r.name,this.type=r.type,this.node=r.node,this.size=r.size,this.needsUpdate=r.needsUpdate}get value(){return this.node.value}set value(r){this.node.value=r}};var Nf=class{constructor(){this.nodes={};this.keywords={}}add(r){this.nodes[r.name]=r}addKeyword(r,e,t){t=t!==void 0?t:!0,this.keywords[r]={callback:e,cache:t}}remove(r){delete this.nodes[r.name]}removeKeyword(r){delete this.keywords[r]}get(r){return this.nodes[r]}getKeyword(r,e){return this.keywords[r].callback(e)}getKeywordData(r){return this.keywords[r]}contains(r){return this.nodes[r]!==void 0}containsKeyword(r){return this.keywords[r]!==void 0}},Ot=new Nf;import{Vector2 as gb}from"three";import{MathUtils as iN}from"three";var ge=class extends qe{constructor(e,t){super(e);this.scope="";t=t??{},this.shared=t.shared!==void 0?t.shared:!0,this.unique=t.unique!==void 0?t.unique:!1}build(e,t,o,i){if(t=t??this.getType(e),this.getShared(e,t)){let a=this.getUnique(e,t);a&&this.uuid===void 0&&(this.uuid=iN.generateUUID()),o=e.getUUID(o??this.getUUID(),!a);let s=e.getNodeData(o),l=s.output||this.getType(e);if(e.analyzing)return(s.deps||0)>0||this.getLabel()?(this.appendDepsNode(e,s,t),this.generate(e,t,o)):super.build(e,t,o);if(a)return s.name=s.name||super.build(e,t,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,t,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,t);{c=super.generate(e,t,o,s.output,i);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,t)}}return super.build(e,t,o)}getShared(e,t){return t!=="sampler2D"&&t!=="samplerCube"&&this.shared}getUnique(e,t){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let t=this.uuid;return typeof this.scope=="string"&&(t=this.scope+"-"+t),t}getTemp(e,t){t=t||this.uuid;let o=e.getVars()[t];return o?o.name:void 0}generate(e,t,o,i,a){return this.getShared(e,t)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,i??this.getType(e),a,this.getLabel()).name}};var $e=class extends ge{constructor(e,t){t=t??{},t.shared=t.shared!==void 0?t.shared:!1;super(e,t);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,t,o,i,a,s){o=e.getUUID(o??this.getUUID()),i=i??this.getType(e);let l=e.getNodeData(o);return this.getReadonly()&&this.generateReadonly!==void 0?this.generateReadonly(e,t,o,i,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(i,this,a,s,this.getLabel())),e.format(l.vertex.name,i,t)):(l.fragment||(l.fragment=e.createFragmentUniform(i,this,a,s,this.getLabel())),e.format(l.fragment.name,i,t))}};var st=class extends $e{constructor(e=0,t){super("v2");this.nodeType="Vector2";this.value=e instanceof gb?e:new gb(e,t)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}generateReadonly(e,t,o,i,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",i,t)}};import{Vector3 as xb}from"three";var Gt=class extends $e{constructor(e=0,t,o){super("v3");this.nodeType="Vector3";this.value=e instanceof xb?e:new xb(e,t,o)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}get z(){return this.value.z}set z(e){this.value.z=e}generateReadonly(e,t,o,i,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",i,t)}};import{Color as aN}from"three";var At=class extends aN{constructor(e,t,o,i){super(e,t,o);this.isColorA=!0;this.a=i}setRGBA(e,t,o,i){super.setRGB(e,t,o),this.a=i}copy(e){return super.copy(e),this.a="a"in e?e.a:1,this}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}equals(e){return super.equals(e)&&this.a===e.a}setStyle(e,t="srgb"){let o;if(e==="transparent")return this.setRGBA(0,0,0,0),this;if(o=/^((?:rgb|hsl)a?)\(([^)]*)\)/.exec(e)){let i,a=o[1],s=o[2];switch(a){case"rgb":case"rgba":if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="rgba"?parseFloat(i[4]):1,super.setStyle(e,t);break;case"hsl":case"hsla":if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="hsla"?parseFloat(i[4]):1,super.setStyle(e,t);break}}return super.setStyle(e,t)}get x(){return this.r}get y(){return this.g}get z(){return this.b}get w(){return this.a}set x(e){this.r=e}set y(e){this.g=e}set z(e){this.b=e}set w(e){this.a=e}};var er=class extends $e{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof At?e:new At(e.r,e.g,e.b,e.a)}generateReadonly(e,t,o,i,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",i,t)}};var sN=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,bb=/[a-z_0-9]+/gi,J=class extends ge{constructor(e,t,o,i,a){super(a);this.src="";this.nodeType="Function";this.useKeywords=!0;this.includes=[];this.extensions={};this.keywords={};this.isMethod=a===void 0,this.isInterface=!1,this.parse(e,t,o,i)}getShared(e,t){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}}getIncludeByName(e){if(this.includes){let t=this.includes.length;for(;t--;)if(this.includes[t].name===e)return this.includes[t]}}generate(e,t,o,i,a){let s,l=0,c=this.src;if(this.includes)for(let p=0;p<this.includes.length;p++)e.include(this.includes[p],this);for(let p in this.extensions)e.extensions[p]=!0;let u=[];for(;s=bb.exec(this.src);)u.push(s);for(let p=0;p<u.length;p++){let d=u[p],f=d[0],h=this.isMethod?!this.getInputByName(f):!0,m=f;if(this.keywords[f]||this.useKeywords&&h&&Ot.containsKeyword(f)){let y=this.keywords[f];if(!y){let b=Ot.getKeywordData(f);b.cache&&(y=e.keywords[f]),y=y||Ot.getKeyword(f,e),b.cache&&(e.keywords[f]=y)}m=y.build(e)}f!==m&&c[d.index+l-1]!=="."&&(c=c.substring(0,d.index+l)+m+c.substring(d.index+f.length+l),l+=m.length-f.length),this.getIncludeByName(m)===void 0&&Ot.contains(m)&&e.include(Ot.get(m))}return t==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),t)}parse(e,t,o,i){if(this.src=e||"",this.includes=t??[],this.extensions=o??{},this.keywords=i??{},this.isMethod){let a=sN.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(bb);if(s){let l=0;for(;l<s.length;){let c=s[l++],u;c==="in"||c==="out"||c==="inout"?u=s[l++]:(u=c,c="");let p=s[l++];this.inputs.push({name:p,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var lN=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,Df=class extends ge{constructor(e="",t){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||Df.PI,void 0,void 0,void 0,t)}getType(e){return e.getTypeByFormat(this.type)}parse(e,t,o,i,a){this.src=e||"";let s,l,c="",u=lN.exec(e);this.useDefine=a??this.src.charAt(0)==="#",u&&u.length>1?(l=u[1],s=u[2],c=u[3]):(s=this.src,l="f"),this.name=s,this.type=l,this.value=c}build(e,t){if(t==="source"){if(this.value)return this.useDefine?"#define "+this.name+" "+this.value:"const "+this.type+" "+this.name+" = "+this.value+";";if(this.useDefine)return this.src}return e.include(this),e.format(this.name,this.getType(e),t)}generate(e,t,o,i,a){return e.format(this.name,this.getType(e),t)}},Ge=Df;Ge.PI="PI",Ge.PI2="PI2",Ge.RECIPROCAL_PI="RECIPROCAL_PI",Ge.RECIPROCAL_PI2="RECIPROCAL_PI2",Ge.LOG2="LOG2",Ge.EPSILON="EPSILON";var cN=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
19
+ )*?)}`,"gim"),uN=new RegExp("s*(w*?)s*(w*?)(=|;)","gim"),Ea=class extends ge{constructor(e=""){super();this.inputs=[];this.src="";this.nodeType="Struct";this.parse(e)}getType(e){return e.getTypeByFormat(this.name)}getInputByName(e){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}generate(e,t,o,i,a){return t==="source"?this.src+";":e.format("( "+this.src+" )",this.getType(e),t)}parse(e=""){this.src=e,this.inputs=[];let t=cN.exec(e);if(t){let o=t[2],i;for(;i=uN.exec(o);)this.inputs.push({type:i[1],name:i[2]});this.name=t[1]}else this.name="";this.type=this.name}};var Na=class extends ge{constructor(e){super("v2",{shared:!1});this.nodeType="UV";this.index=e??0}generate(e,t){e.requires.uv[this.index]=!0;let o=this.index>0?this.index+1:"",i=e.isShader("vertex")?"uv"+o:"vUv"+o;return e.format(i,this.getType(e),t)}};Ot.addKeyword("uv",function(){return new Na});Ot.addKeyword("uv2",function(){return new Na(1)});import{LinearEncoding as dN,sRGBEncoding as pN}from"three";var Jn=class extends ge{constructor(e,t){super("v4");this.nodeType="ColorSpace";this.input=e,this.method=t??Jn.LINEAR_TO_LINEAR,this.hashProperties=["method"]}static getEncodingComponents(e){switch(e){case dN:return["Linear"];case pN:return["sRGB"];default:return[]}}generate(e,t){let o=this.input.build(e,"v4"),i=this.getType(e),a=Jn.Nodes[this.method],s=e.include(a);if(s===Jn.LINEAR_TO_LINEAR)return e.format(o,i,t);if(a.inputs?.length===2){let l=this.factor.build(e,"f");return e.format(s+"( "+o+", "+l+" )",i,t)}else return e.format(s+"( "+o+" )",i,t)}fromEncoding(e){let t=Jn.getEncodingComponents(e);this.method="LinearTo"+t[0],this.factor=t[1]}fromDecoding(e){let t=Jn.getEncodingComponents(e);this.method=t[0]+"ToLinear",this.factor=t[1]}},$t=Jn;$t.Nodes={LinearToLinear:new J(["vec4 LinearToLinear( in vec4 value ) {"," return value;","}"].join(`
20
20
  `)),sRGBToLinear:new J(["vec4 sRGBToLinear( in vec4 value ) {"," return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );","}"].join(`
21
21
  `)),LinearTosRGB:new J(["vec4 LinearTosRGB( in vec4 value ) {"," return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );","}"].join(`
22
- `))},$t.LINEAR_TO_LINEAR="LinearToLinear",$t.SRGB_TO_LINEAR="sRGBToLinear",$t.LINEAR_TO_SRGB="LinearTosRGB";var ke=class extends J{constructor(e="",t,o,i,a){super(e,a,i,o,t);this.nodeType="Expression"}};import{Texture as mN}from"three";var Yt=class extends $e{constructor(e=new mN,t,o,i){super("v4",{shared:!0});this.nodeType="Texture";this.value=e,this.uv=t??new Da,this.bias=o,this.project=i!==void 0?i:!1}getTexture(e,t){return super.generate(e,t,this.value.uuid,"t")}generate(e,t){if(t==="sampler2D")return this.getTexture(e,t);let o=this.getTexture(e,t),i=this.uv.build(e,this.project?"v4":"v2"),a=this.bias?this.bias.build(e,"f"):void 0;a===void 0&&e.context.bias&&(a=e.context.bias.setTexture(this).build(e,"f"));let s,l;this.project?s="texture2DProj":s=a?"tex2DBias":"tex2D",a?l=s+"( "+o+", "+i+", "+a+" )":l=s+"( "+o+", "+i+" )";let c={include:e.isShader("vertex"),ignoreCache:!0},u=this.getType(e);return e.addContext(c),this.colorSpace=this.colorSpace??new $t(new ke("",u)),this.colorSpace.fromDecoding(e.getTextureEncodingFromMap(this.value)),this.colorSpace.input.parse(l),l=this.colorSpace.build(e,u),e.removeContext(),e.format(l,u,t)}};var se=class extends $e{constructor(e){super("f");this.nodeType="Float";this.value=e??0}generateReadonly(e,t,o,i,a,s){return e.format(this.value+(this.value%1?"":".0"),i,t)}};var nl=class extends ge{constructor(e,t){super();this.inputs=[];this.nodeType="FunctionCall";this.value=e,this.inputs=t??[]}getFunction(){return this.value}getType(e){return this.value.getType(e)}generate(e,t,o,i,a){i=this.getType(e);let s=this.value,l=s.build(e,t)+"( ",c=[];if(s.inputs){for(let u=0;u<s.inputs.length;u++){let p=s.inputs[u],d=this.inputs[u]||this.inputs[p.name];c.push(d.build(e,e.getTypeByFormat(p.type)))}l+=c.join(", ")+" )"}return e.format(l,i,t)}};var Lf=class extends ge{constructor(e,t,o=Lf.ADD){super();this.nodeType="Operator";this.type=e.type,this.a=e,this.b=t,this.op=o}getType(e){let t=this.a.getType(e),o=this.b.getType(e);return e.isTypeMatrix(t)?"v4":e.getTypeLength(o)>e.getTypeLength(t)?o:t}generate(e,t){let o=this.getType(e);this.type=o;let i=this.a.build(e,o),a=this.b.build(e,o);return e.format("( "+i+" "+this.op+" "+a+" )",o,t)}},_t=Lf;_t.ADD="+",_t.SUB="-",_t.MUL="*",_t.DIV="/";var Ye=class extends ge{constructor(e,t=Ye.ABS,o,i){super();this.nodeType="Math";this.a=e,typeof t!="string"?this.b=t:i=t,typeof o!="string"?this.c=o:i=o,this.method=i,this.hashProperties=["method"]}getNumInputs(e){switch(this.method){case Ye.MIX:case Ye.CLAMP:case Ye.REFRACT:case Ye.SMOOTHSTEP:case Ye.FACEFORWARD:return 3;case Ye.MIN:case Ye.MAX:case Ye.MOD:case Ye.STEP:case Ye.REFLECT:case Ye.DISTANCE:case Ye.DOT:case Ye.CROSS:case Ye.POW:return 2;default:return 1}}getInputType(e){let t=e.getTypeLength(this.a.getType(e)),o=this.b?e.getTypeLength(this.b.getType(e)):0,i=this.c?e.getTypeLength(this.c.getType(e)):0;return t>o&&t>i?this.a.getType(e):o>i?this.b.getType(e):this.c.getType(e)}getType(e){switch(this.method){case Ye.LENGTH:case Ye.DISTANCE:case Ye.DOT:return"f";case Ye.CROSS:return"v3"}return this.getInputType(e)}generate(e,t){let o,i,a,s=this.a?e.getTypeLength(this.a.getType(e)):0,l=this.b?e.getTypeLength(this.b.getType(e)):0,c=this.c?e.getTypeLength(this.c.getType(e)):0,u=this.getInputType(e),p=this.getType(e);switch(this.type=p,this.method){case Ye.NEGATE:return e.format("( -"+this.a.build(e,u)+" )",u,t);case Ye.INVERT:return e.format("( 1.0 - "+this.a.build(e,u)+" )",u,t);case Ye.CROSS:o=this.a.build(e,"v3"),i=this.b.build(e,"v3");break;case Ye.STEP:o=this.a.build(e,s===1?"f":u),i=this.b.build(e,u);break;case Ye.MIN:case Ye.MAX:case Ye.MOD:o=this.a.build(e,u),i=this.b.build(e,l===1?"f":u);break;case Ye.REFRACT:o=this.a.build(e,u),i=this.b.build(e,u),a=this.c.build(e,"f");break;case Ye.MIX:o=this.a.build(e,u),i=this.b.build(e,u),a=this.c.build(e,c===1?"f":u);break;default:o=this.a.build(e,u),this.b&&(i=this.b.build(e,u)),this.c&&(a=this.c.build(e,u));break}let d=[];d.push(o),i&&d.push(i),a&&d.push(a);let h=this.getNumInputs(e);if(d.length!==h)throw Error(`Arguments not match used in "${this.method}". Require ${h}, currently ${d.length}.`);return e.format(this.method+"( "+d.join(", ")+" )",p,t)}},Ce=Ye;Ce.RAD="radians",Ce.DEG="degrees",Ce.EXP="exp",Ce.EXP2="exp2",Ce.LOG="log",Ce.LOG2="log2",Ce.SQRT="sqrt",Ce.INV_SQRT="inversesqrt",Ce.FLOOR="floor",Ce.CEIL="ceil",Ce.NORMALIZE="normalize",Ce.FRACT="fract",Ce.SATURATE="saturate",Ce.SIN="sin",Ce.COS="cos",Ce.TAN="tan",Ce.ASIN="asin",Ce.ACOS="acos",Ce.ARCTAN="atan",Ce.ABS="abs",Ce.SIGN="sign",Ce.LENGTH="length",Ce.NEGATE="negate",Ce.INVERT="invert",Ce.MIN="min",Ce.MAX="max",Ce.MOD="mod",Ce.STEP="step",Ce.REFLECT="reflect",Ce.DISTANCE="distance",Ce.DOT="dot",Ce.CROSS="cross",Ce.POW="pow",Ce.MIX="mix",Ce.CLAMP="clamp",Ce.REFRACT="refract",Ce.SMOOTHSTEP="smoothstep",Ce.FACEFORWARD="faceforward";var _a=class extends ge{constructor(e,t,o){super("v4");this.nodeType="TextureCubeUV";this.value=e,this.uv=t,this.bias=o}bilinearCubeUV(e,t,o,i){let a=new nl(_a.Nodes.bilinearCubeUV,[t,o,i]);this.colorSpaceTL=this.colorSpaceTL??new $t(new ke("","v4")),this.colorSpaceTL.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceTL.input.parse(a.build(e)+".tl"),this.colorSpaceTR=this.colorSpaceTR??new $t(new ke("","v4")),this.colorSpaceTR.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceTR.input.parse(a.build(e)+".tr"),this.colorSpaceBL=this.colorSpaceBL??new $t(new ke("","v4")),this.colorSpaceBL.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceBL.input.parse(a.build(e)+".bl"),this.colorSpaceBR=this.colorSpaceBR??new $t(new ke("","v4")),this.colorSpaceBR.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceBR.input.parse(a.build(e)+".br");let s={include:e.isShader("vertex"),ignoreCache:!0};e.addContext(s),this.colorSpaceTLExp=new ke(this.colorSpaceTL.build(e,"v4"),"v4"),this.colorSpaceTRExp=new ke(this.colorSpaceTR.build(e,"v4"),"v4"),this.colorSpaceBLExp=new ke(this.colorSpaceBL.build(e,"v4"),"v4"),this.colorSpaceBRExp=new ke(this.colorSpaceBR.build(e,"v4"),"v4"),e.removeContext();let l=new ke("mix( mix( cubeUV_TL, cubeUV_TR, cubeUV.f.x ), mix( cubeUV_BL, cubeUV_BR, cubeUV.f.x ), cubeUV.f.y )","v4");return l.keywords.cubeUV_TL=this.colorSpaceTLExp,l.keywords.cubeUV_TR=this.colorSpaceTRExp,l.keywords.cubeUV_BL=this.colorSpaceBLExp,l.keywords.cubeUV_BR=this.colorSpaceBRExp,l.keywords.cubeUV=a,l}generate(e,t){if(e.isShader("fragment")){let o=this.uv,i=this.bias||e.context.roughness,a=new nl(_a.Nodes.roughnessToMip,[i]),s=new Ce(a,_a.Nodes.m0,_a.Nodes.cubeUV_maxMipLevel,Ce.CLAMP),l=new Ce(s,Ce.FLOOR),c=new Ce(s,Ce.FRACT),u=this.bilinearCubeUV(e,this.value,o,l),p=this.bilinearCubeUV(e,this.value,o,new _t(l,new se(1).setReadonly(!0),_t.ADD)),d=new Ce(u,p,c,Ce.MIX);return e.format(d.build(e),"v4",t)}else return console.warn("TextureCubeUVNode is not compatible with "+e.shader+" shader."),e.format("vec4( 0.0 )",this.getType(e),t)}},Ba=_a;Ba.Nodes=function(){let e=new Na(`struct TextureCubeUVData {
22
+ `))},$t.LINEAR_TO_LINEAR="LinearToLinear",$t.SRGB_TO_LINEAR="sRGBToLinear",$t.LINEAR_TO_SRGB="LinearTosRGB";var ke=class extends J{constructor(e="",t,o,i,a){super(e,a,i,o,t);this.nodeType="Expression"}};import{Texture as fN}from"three";var Yt=class extends $e{constructor(e=new fN,t,o,i){super("v4",{shared:!0});this.nodeType="Texture";this.value=e,this.uv=t??new Na,this.bias=o,this.project=i!==void 0?i:!1}getTexture(e,t){return super.generate(e,t,this.value.uuid,"t")}generate(e,t){if(t==="sampler2D")return this.getTexture(e,t);let o=this.getTexture(e,t),i=this.uv.build(e,this.project?"v4":"v2"),a=this.bias?this.bias.build(e,"f"):void 0;a===void 0&&e.context.bias&&(a=e.context.bias.setTexture(this).build(e,"f"));let s,l;this.project?s="texture2DProj":s=a?"tex2DBias":"tex2D",a?l=s+"( "+o+", "+i+", "+a+" )":l=s+"( "+o+", "+i+" )";let c={include:e.isShader("vertex"),ignoreCache:!0},u=this.getType(e);return e.addContext(c),this.colorSpace=this.colorSpace??new $t(new ke("",u)),this.colorSpace.fromDecoding(e.getTextureEncodingFromMap(this.value)),this.colorSpace.input.parse(l),l=this.colorSpace.build(e,u),e.removeContext(),e.format(l,u,t)}};var se=class extends $e{constructor(e){super("f");this.nodeType="Float";this.value=e??0}generateReadonly(e,t,o,i,a,s){return e.format(this.value+(this.value%1?"":".0"),i,t)}};var rl=class extends ge{constructor(e,t){super();this.inputs=[];this.nodeType="FunctionCall";this.value=e,this.inputs=t??[]}getFunction(){return this.value}getType(e){return this.value.getType(e)}generate(e,t,o,i,a){i=this.getType(e);let s=this.value,l=s.build(e,t)+"( ",c=[];if(s.inputs){for(let u=0;u<s.inputs.length;u++){let p=s.inputs[u],d=this.inputs[u]||this.inputs[p.name];c.push(d.build(e,e.getTypeByFormat(p.type)))}l+=c.join(", ")+" )"}return e.format(l,i,t)}};var _f=class extends ge{constructor(e,t,o=_f.ADD){super();this.nodeType="Operator";this.type=e.type,this.a=e,this.b=t,this.op=o}getType(e){let t=this.a.getType(e),o=this.b.getType(e);return e.isTypeMatrix(t)?"v4":e.getTypeLength(o)>e.getTypeLength(t)?o:t}generate(e,t){let o=this.getType(e);this.type=o;let i=this.a.build(e,o),a=this.b.build(e,o);return e.format("( "+i+" "+this.op+" "+a+" )",o,t)}},_t=_f;_t.ADD="+",_t.SUB="-",_t.MUL="*",_t.DIV="/";var Ye=class extends ge{constructor(e,t=Ye.ABS,o,i){super();this.nodeType="Math";this.a=e,typeof t!="string"?this.b=t:i=t,typeof o!="string"?this.c=o:i=o,this.method=i,this.hashProperties=["method"]}getNumInputs(e){switch(this.method){case Ye.MIX:case Ye.CLAMP:case Ye.REFRACT:case Ye.SMOOTHSTEP:case Ye.FACEFORWARD:return 3;case Ye.MIN:case Ye.MAX:case Ye.MOD:case Ye.STEP:case Ye.REFLECT:case Ye.DISTANCE:case Ye.DOT:case Ye.CROSS:case Ye.POW:return 2;default:return 1}}getInputType(e){let t=e.getTypeLength(this.a.getType(e)),o=this.b?e.getTypeLength(this.b.getType(e)):0,i=this.c?e.getTypeLength(this.c.getType(e)):0;return t>o&&t>i?this.a.getType(e):o>i?this.b.getType(e):this.c.getType(e)}getType(e){switch(this.method){case Ye.LENGTH:case Ye.DISTANCE:case Ye.DOT:return"f";case Ye.CROSS:return"v3"}return this.getInputType(e)}generate(e,t){let o,i,a,s=this.a?e.getTypeLength(this.a.getType(e)):0,l=this.b?e.getTypeLength(this.b.getType(e)):0,c=this.c?e.getTypeLength(this.c.getType(e)):0,u=this.getInputType(e),p=this.getType(e);switch(this.type=p,this.method){case Ye.NEGATE:return e.format("( -"+this.a.build(e,u)+" )",u,t);case Ye.INVERT:return e.format("( 1.0 - "+this.a.build(e,u)+" )",u,t);case Ye.CROSS:o=this.a.build(e,"v3"),i=this.b.build(e,"v3");break;case Ye.STEP:o=this.a.build(e,s===1?"f":u),i=this.b.build(e,u);break;case Ye.MIN:case Ye.MAX:case Ye.MOD:o=this.a.build(e,u),i=this.b.build(e,l===1?"f":u);break;case Ye.REFRACT:o=this.a.build(e,u),i=this.b.build(e,u),a=this.c.build(e,"f");break;case Ye.MIX:o=this.a.build(e,u),i=this.b.build(e,u),a=this.c.build(e,c===1?"f":u);break;default:o=this.a.build(e,u),this.b&&(i=this.b.build(e,u)),this.c&&(a=this.c.build(e,u));break}let d=[];d.push(o),i&&d.push(i),a&&d.push(a);let f=this.getNumInputs(e);if(d.length!==f)throw Error(`Arguments not match used in "${this.method}". Require ${f}, currently ${d.length}.`);return e.format(this.method+"( "+d.join(", ")+" )",p,t)}},Ce=Ye;Ce.RAD="radians",Ce.DEG="degrees",Ce.EXP="exp",Ce.EXP2="exp2",Ce.LOG="log",Ce.LOG2="log2",Ce.SQRT="sqrt",Ce.INV_SQRT="inversesqrt",Ce.FLOOR="floor",Ce.CEIL="ceil",Ce.NORMALIZE="normalize",Ce.FRACT="fract",Ce.SATURATE="saturate",Ce.SIN="sin",Ce.COS="cos",Ce.TAN="tan",Ce.ASIN="asin",Ce.ACOS="acos",Ce.ARCTAN="atan",Ce.ABS="abs",Ce.SIGN="sign",Ce.LENGTH="length",Ce.NEGATE="negate",Ce.INVERT="invert",Ce.MIN="min",Ce.MAX="max",Ce.MOD="mod",Ce.STEP="step",Ce.REFLECT="reflect",Ce.DISTANCE="distance",Ce.DOT="dot",Ce.CROSS="cross",Ce.POW="pow",Ce.MIX="mix",Ce.CLAMP="clamp",Ce.REFRACT="refract",Ce.SMOOTHSTEP="smoothstep",Ce.FACEFORWARD="faceforward";var Da=class extends ge{constructor(e,t,o){super("v4");this.nodeType="TextureCubeUV";this.value=e,this.uv=t,this.bias=o}bilinearCubeUV(e,t,o,i){let a=new rl(Da.Nodes.bilinearCubeUV,[t,o,i]);this.colorSpaceTL=this.colorSpaceTL??new $t(new ke("","v4")),this.colorSpaceTL.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceTL.input.parse(a.build(e)+".tl"),this.colorSpaceTR=this.colorSpaceTR??new $t(new ke("","v4")),this.colorSpaceTR.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceTR.input.parse(a.build(e)+".tr"),this.colorSpaceBL=this.colorSpaceBL??new $t(new ke("","v4")),this.colorSpaceBL.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceBL.input.parse(a.build(e)+".bl"),this.colorSpaceBR=this.colorSpaceBR??new $t(new ke("","v4")),this.colorSpaceBR.fromDecoding(e.getTextureEncodingFromMap(this.value.value)),this.colorSpaceBR.input.parse(a.build(e)+".br");let s={include:e.isShader("vertex"),ignoreCache:!0};e.addContext(s),this.colorSpaceTLExp=new ke(this.colorSpaceTL.build(e,"v4"),"v4"),this.colorSpaceTRExp=new ke(this.colorSpaceTR.build(e,"v4"),"v4"),this.colorSpaceBLExp=new ke(this.colorSpaceBL.build(e,"v4"),"v4"),this.colorSpaceBRExp=new ke(this.colorSpaceBR.build(e,"v4"),"v4"),e.removeContext();let l=new ke("mix( mix( cubeUV_TL, cubeUV_TR, cubeUV.f.x ), mix( cubeUV_BL, cubeUV_BR, cubeUV.f.x ), cubeUV.f.y )","v4");return l.keywords.cubeUV_TL=this.colorSpaceTLExp,l.keywords.cubeUV_TR=this.colorSpaceTRExp,l.keywords.cubeUV_BL=this.colorSpaceBLExp,l.keywords.cubeUV_BR=this.colorSpaceBRExp,l.keywords.cubeUV=a,l}generate(e,t){if(e.isShader("fragment")){let o=this.uv,i=this.bias||e.context.roughness,a=new rl(Da.Nodes.roughnessToMip,[i]),s=new Ce(a,Da.Nodes.m0,Da.Nodes.cubeUV_maxMipLevel,Ce.CLAMP),l=new Ce(s,Ce.FLOOR),c=new Ce(s,Ce.FRACT),u=this.bilinearCubeUV(e,this.value,o,l),p=this.bilinearCubeUV(e,this.value,o,new _t(l,new se(1).setReadonly(!0),_t.ADD)),d=new Ce(u,p,c,Ce.MIX);return e.format(d.build(e),"v4",t)}else return console.warn("TextureCubeUVNode is not compatible with "+e.shader+" shader."),e.format("vec4( 0.0 )",this.getType(e),t)}},_a=Da;_a.Nodes=function(){let e=new Ea(`struct TextureCubeUVData {
23
23
  vec4 tl;
24
24
  vec4 tr;
25
25
  vec4 br;
26
26
  vec4 bl;
27
27
  vec2 f;
28
- }`),t=new Fe("float cubeUV_maxMipLevel 8.0",!0),o=new Fe("float cubeUV_minMipLevel 4.0",!0),i=new Fe("float cubeUV_maxTileSize 256.0",!0),a=new Fe("float cubeUV_minTileSize 16.0",!0),s=new J(`float getFace(vec3 direction) {
28
+ }`),t=new Ge("float cubeUV_maxMipLevel 8.0",!0),o=new Ge("float cubeUV_minMipLevel 4.0",!0),i=new Ge("float cubeUV_maxTileSize 256.0",!0),a=new Ge("float cubeUV_minTileSize 16.0",!0),s=new J(`float getFace(vec3 direction) {
29
29
  vec3 absDirection = abs(direction);
30
30
  float face = -1.0;
31
31
  if (absDirection.x > absDirection.z) {
@@ -84,7 +84,7 @@ best distance: ${d.d}`);let g=[d.x,d.y];return g.distance=d.d,g.distance}functio
84
84
  uv.x -= texelSize;
85
85
  vec4 bl = texture2D(envMap, uv);
86
86
  return TextureCubeUVData( tl, tr, br, bl, f );
87
- }`,[e,s,l,t,o,i,a]);c.useKeywords=!1;let u=new Fe("float r0 1.0",!0),p=new Fe("float v0 0.339",!0),d=new Fe("float m0 -2.0",!0),h=new Fe("float r1 0.8",!0),f=new Fe("float v1 0.276",!0),m=new Fe("float m1 -1.0",!0),y=new Fe("float r4 0.4",!0),g=new Fe("float v4 0.046",!0),v=new Fe("float m4 2.0",!0),w=new Fe("float r5 0.305",!0),O=new Fe("float v5 0.016",!0),S=new Fe("float m5 3.0",!0),C=new Fe("float r6 0.21",!0),T=new Fe("float v6 0.0038",!0),x=new Fe("float m6 4.0",!0),N=[u,p,d,h,f,m,y,g,v,w,O,S,C,T,x],E=new J(`float roughnessToMip(float roughness) {
87
+ }`,[e,s,l,t,o,i,a]);c.useKeywords=!1;let u=new Ge("float r0 1.0",!0),p=new Ge("float v0 0.339",!0),d=new Ge("float m0 -2.0",!0),f=new Ge("float r1 0.8",!0),h=new Ge("float v1 0.276",!0),m=new Ge("float m1 -1.0",!0),y=new Ge("float r4 0.4",!0),b=new Ge("float v4 0.046",!0),S=new Ge("float m4 2.0",!0),P=new Ge("float r5 0.305",!0),C=new Ge("float v5 0.016",!0),v=new Ge("float m5 3.0",!0),A=new Ge("float r6 0.21",!0),T=new Ge("float v6 0.0038",!0),g=new Ge("float m6 4.0",!0),D=[u,p,d,f,h,m,y,b,S,P,C,v,A,T,g],E=new J(`float roughnessToMip(float roughness) {
88
88
  float mip = 0.0;
89
89
  if (roughness >= r1) {
90
90
  mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;
@@ -98,7 +98,7 @@ best distance: ${d.d}`);let g=[d.x,d.y];return g.distance=d.d,g.distance}functio
98
98
  mip = -2.0 * log2(1.16 * roughness);// 1.16 = 1.79^0.25
99
99
  }
100
100
  return mip;
101
- }`,N);return{bilinearCubeUV:c,roughnessToMip:E,m0:d,cubeUV_maxMipLevel:t}}();var ti=class extends ge{constructor(e){super("v3");this.nodeType="Normal";this.scope=e??ti.VIEW}getShared(){return this.scope===ti.WORLD}build(e,t,o,i){let a=e.context[this.scope+"Normal"];return a?a.build(e,t,o,i):super.build(e,t,o)}generate(e,t,o,i,a){let s;switch(this.scope){case ti.VIEW:e.isShader("vertex")?s="transformedNormal":s="geometryNormal";break;case ti.LOCAL:e.isShader("vertex")?s="objectNormal":(e.requires.normal=!0,s="vObjectNormal");break;case ti.WORLD:e.isShader("vertex")?s="inverseTransformDirection( transformedNormal, viewMatrix ).xyz":(e.requires.worldNormal=!0,s="vWNormal");break}return e.format(s,this.getType(e),t)}},Bt=ti;Bt.LOCAL="local",Bt.WORLD="world",Bt.VIEW="view",Bt.NORMAL="normal";Ot.addKeyword("viewNormal",function(){return new Bt(Bt.VIEW)});Ot.addKeyword("localNormal",function(){return new Bt(Bt.NORMAL)});Ot.addKeyword("worldNormal",function(){return new Bt(Bt.WORLD)});var lo=class extends ge{constructor(e){super("v3");this.nodeType="Position";this.scope=e??lo.LOCAL}getType(){switch(this.scope){case lo.PROJECTION:return"v4"}return this.type}getShader(){switch(this.scope){case lo.LOCAL:case lo.WORLD:return!1}return!0}generate(e,t,o,i,a){let s;switch(this.scope){case lo.LOCAL:e.isShader("vertex")?s="transformed":(e.requires.position=!0,s="vPosition");break;case lo.WORLD:if(e.isShader("vertex"))return"( modelMatrix * vec4( transformed, 1.0 ) ).xyz";e.requires.worldPosition=!0,s="vWPosition";break;case lo.VIEW:s=e.isShader("vertex")?"-mvPosition.xyz":"vViewPosition";break;case lo.PROJECTION:s=e.isShader("vertex")?"( projectionMatrix * modelViewMatrix * vec4( position, 1.0 ) )":"vec4( 0.0 )";break}return e.format(s,this.getType(),t)}},tr=lo;tr.LOCAL="local",tr.WORLD="world",tr.VIEW="view",tr.PROJECTION="projection";Ot.addKeyword("position",function(){return new tr});Ot.addKeyword("worldPosition",function(){return new tr(tr.WORLD)});Ot.addKeyword("viewPosition",function(){return new tr(tr.VIEW)});var Fr=class extends ge{constructor(e){super("v3");this.nodeType="Reflect";this.scope=e??Fr.CUBE}getUnique(e){return!e.context.viewNormal}getType(){switch(this.scope){case Fr.SPHERE:return"v2"}return this.type}generate(e,t){let o=this.getUnique(e);if(e.isShader("fragment")){let i;switch(this.scope){case Fr.VECTOR:{let a=new Bt(Bt.VIEW),s=e.context.roughness,l=a.build(e,"v3"),c=new tr(tr.VIEW).build(e,"v3"),u=s?s.build(e,"f"):void 0,p=`reflect( -normalize( ${c} ), ${l} )`;u&&(p=`normalize( mix( ${p}, ${l}, ${u} * ${u} ) )`);let d=`inverseTransformDirection( ${p}, viewMatrix )`;o?(e.addNodeCode(`vec3 reflectVec = ${d};`),i="reflectVec"):i=d;break}case Fr.CUBE:{let a=new Fr(Fr.VECTOR).build(e,"v3"),s="vec3( -"+a+".x, "+a+".yz )";o?(e.addNodeCode(`vec3 reflectCubeVec = ${s};`),i="reflectCubeVec"):i=s;break}case Fr.SPHERE:{let s="normalize( ( viewMatrix * vec4( "+new Fr(Fr.VECTOR).build(e,"v3")+", 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) ).xy * 0.5 + 0.5";o?(e.addNodeCode(`vec2 reflectSphereVec = ${s};`),i="reflectSphereVec"):i=s;break}}return e.format(i,this.getType(),t)}else return console.warn("ReflectNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.type,t)}},co=Fr;co.CUBE="cube",co.SPHERE="sphere",co.VECTOR="vector";var _u=class extends ge{constructor(e=new Yt,t,o){super("v4");this.nodeType="TextureCube";this.value=e,this.radianceNode=new Ba(this.value,t??new co(co.VECTOR),o),this.irradianceNode=new Ba(this.value,new Bt(Bt.WORLD),new se(1).setReadonly(!0))}generate(e,t){return e.isShader("fragment")?(e.require("irradiance"),e.context.bias&&e.context.bias.setTexture(this.value),(e.slot==="irradiance"?this.irradianceNode:this.radianceNode).build(e,t)):(console.warn("TextureCubeNode is not compatible with "+e.shader+" shader."),e.format("vec4( 0.0 )",this.getType(e),t))}};import{CubeTexture as yN}from"three";var Bu=class extends $e{constructor(e=new yN,t,o){super("v4",{shared:!0});this.nodeType="CubeTexture";this.value=e,this.uv=t??new co,this.bias=o}getTexture(e,t){return super.generate(e,t,this.value.uuid,"tc")}generate(e,t){if(t==="samplerCube")return this.getTexture(e,t);let o=this.getTexture(e,t),i=this.uv?.build(e,"v3"),a=this.bias?this.bias.build(e,"f"):void 0;a===void 0&&e.context.bias&&(a=e.context.bias.setTexture(this).build(e,"f"));let s;a?s="texCubeBias( "+o+", "+i+", "+a+" )":s="texCube( "+o+", "+i+" )";let l={include:e.isShader("vertex"),ignoreCache:!0},c=this.getType(e);return e.addContext(l),this.colorSpace=this.colorSpace??new $t(new ke("",c)),this.colorSpace.fromDecoding(e.getTextureEncodingFromMap(this.value)),this.colorSpace.input.parse(s),s=this.colorSpace.build(e,c),e.removeContext(),e.format(s,c,t)}};var Sb=`
101
+ }`,D);return{bilinearCubeUV:c,roughnessToMip:E,m0:d,cubeUV_maxMipLevel:t}}();var ei=class extends ge{constructor(e){super("v3");this.nodeType="Normal";this.scope=e??ei.VIEW}getShared(){return this.scope===ei.WORLD}build(e,t,o,i){let a=e.context[this.scope+"Normal"];return a?a.build(e,t,o,i):super.build(e,t,o)}generate(e,t,o,i,a){let s;switch(this.scope){case ei.VIEW:e.isShader("vertex")?s="transformedNormal":s="geometryNormal";break;case ei.LOCAL:e.isShader("vertex")?s="objectNormal":(e.requires.normal=!0,s="vObjectNormal");break;case ei.WORLD:e.isShader("vertex")?s="inverseTransformDirection( transformedNormal, viewMatrix ).xyz":(e.requires.worldNormal=!0,s="vWNormal");break}return e.format(s,this.getType(e),t)}},Bt=ei;Bt.LOCAL="local",Bt.WORLD="world",Bt.VIEW="view",Bt.NORMAL="normal";Ot.addKeyword("viewNormal",function(){return new Bt(Bt.VIEW)});Ot.addKeyword("localNormal",function(){return new Bt(Bt.NORMAL)});Ot.addKeyword("worldNormal",function(){return new Bt(Bt.WORLD)});var lo=class extends ge{constructor(e){super("v3");this.nodeType="Position";this.scope=e??lo.LOCAL}getType(){switch(this.scope){case lo.PROJECTION:return"v4"}return this.type}getShader(){switch(this.scope){case lo.LOCAL:case lo.WORLD:return!1}return!0}generate(e,t,o,i,a){let s;switch(this.scope){case lo.LOCAL:e.isShader("vertex")?s="transformed":(e.requires.position=!0,s="vPosition");break;case lo.WORLD:if(e.isShader("vertex"))return"( modelMatrix * vec4( transformed, 1.0 ) ).xyz";e.requires.worldPosition=!0,s="vWPosition";break;case lo.VIEW:s=e.isShader("vertex")?"-mvPosition.xyz":"vViewPosition";break;case lo.PROJECTION:s=e.isShader("vertex")?"( projectionMatrix * modelViewMatrix * vec4( position, 1.0 ) )":"vec4( 0.0 )";break}return e.format(s,this.getType(),t)}},tr=lo;tr.LOCAL="local",tr.WORLD="world",tr.VIEW="view",tr.PROJECTION="projection";Ot.addKeyword("position",function(){return new tr});Ot.addKeyword("worldPosition",function(){return new tr(tr.WORLD)});Ot.addKeyword("viewPosition",function(){return new tr(tr.VIEW)});var Fr=class extends ge{constructor(e){super("v3");this.nodeType="Reflect";this.scope=e??Fr.CUBE}getUnique(e){return!e.context.viewNormal}getType(){switch(this.scope){case Fr.SPHERE:return"v2"}return this.type}generate(e,t){let o=this.getUnique(e);if(e.isShader("fragment")){let i;switch(this.scope){case Fr.VECTOR:{let a=new Bt(Bt.VIEW),s=e.context.roughness,l=a.build(e,"v3"),c=new tr(tr.VIEW).build(e,"v3"),u=s?s.build(e,"f"):void 0,p=`reflect( -normalize( ${c} ), ${l} )`;u&&(p=`normalize( mix( ${p}, ${l}, ${u} * ${u} ) )`);let d=`inverseTransformDirection( ${p}, viewMatrix )`;o?(e.addNodeCode(`vec3 reflectVec = ${d};`),i="reflectVec"):i=d;break}case Fr.CUBE:{let a=new Fr(Fr.VECTOR).build(e,"v3"),s="vec3( -"+a+".x, "+a+".yz )";o?(e.addNodeCode(`vec3 reflectCubeVec = ${s};`),i="reflectCubeVec"):i=s;break}case Fr.SPHERE:{let s="normalize( ( viewMatrix * vec4( "+new Fr(Fr.VECTOR).build(e,"v3")+", 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) ).xy * 0.5 + 0.5";o?(e.addNodeCode(`vec2 reflectSphereVec = ${s};`),i="reflectSphereVec"):i=s;break}}return e.format(i,this.getType(),t)}else return console.warn("ReflectNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.type,t)}},co=Fr;co.CUBE="cube",co.SPHERE="sphere",co.VECTOR="vector";var Mu=class extends ge{constructor(e=new Yt,t,o){super("v4");this.nodeType="TextureCube";this.value=e,this.radianceNode=new _a(this.value,t??new co(co.VECTOR),o),this.irradianceNode=new _a(this.value,new Bt(Bt.WORLD),new se(1).setReadonly(!0))}generate(e,t){return e.isShader("fragment")?(e.require("irradiance"),e.context.bias&&e.context.bias.setTexture(this.value),(e.slot==="irradiance"?this.irradianceNode:this.radianceNode).build(e,t)):(console.warn("TextureCubeNode is not compatible with "+e.shader+" shader."),e.format("vec4( 0.0 )",this.getType(e),t))}};import{CubeTexture as hN}from"three";var Eu=class extends $e{constructor(e=new hN,t,o){super("v4",{shared:!0});this.nodeType="CubeTexture";this.value=e,this.uv=t??new co,this.bias=o}getTexture(e,t){return super.generate(e,t,this.value.uuid,"tc")}generate(e,t){if(t==="samplerCube")return this.getTexture(e,t);let o=this.getTexture(e,t),i=this.uv?.build(e,"v3"),a=this.bias?this.bias.build(e,"f"):void 0;a===void 0&&e.context.bias&&(a=e.context.bias.setTexture(this).build(e,"f"));let s;a?s="texCubeBias( "+o+", "+i+", "+a+" )":s="texCube( "+o+", "+i+" )";let l={include:e.isShader("vertex"),ignoreCache:!0},c=this.getType(e);return e.addContext(l),this.colorSpace=this.colorSpace??new $t(new ke("",c)),this.colorSpace.fromDecoding(e.getTextureEncodingFromMap(this.value)),this.colorSpace.input.parse(s),s=this.colorSpace.build(e,c),e.removeContext(),e.format(s,c,t)}};var vb=`
102
102
  uniform int frameIndex;
103
103
  uniform vec2 resolution;
104
104
  uniform mat4 previousModelViewMatrix;
@@ -106,7 +106,7 @@ uniform mat4 previousProjectionMatrix;
106
106
 
107
107
  varying vec4 vCurrentPosition;
108
108
  varying vec4 vPreviousPosition;
109
- `,wb=`
109
+ `,Sb=`
110
110
  layout(location = 1) out vec4 gVelocity;
111
111
 
112
112
  uniform int frameIndex;
@@ -148,7 +148,7 @@ float getNoiseInterleavedGradient(vec2 screenPos) {
148
148
  return fract(magic.z * fract(dot(screenPos, magic.xy)));
149
149
  }
150
150
 
151
- `,Pb=`
151
+ `,wb=`
152
152
  // TODO: This could be generated CPU side and passed to the shader every frame
153
153
  const vec2 haltonSequence[16] = vec2[16](
154
154
  vec2( 0.000000,-0.333334),
@@ -185,7 +185,7 @@ vPreviousPosition.xy += OUTLINE_COMPENSATION;
185
185
  #endif
186
186
  gl_Position = currentPositionJittered;
187
187
 
188
- `,Cb=`
188
+ `,Pb=`
189
189
  vec2 oldPos = vPreviousPosition.xy;
190
190
  oldPos /= vPreviousPosition.w;
191
191
  oldPos.xy = (oldPos.xy+1.)/2.0;
@@ -200,14 +200,14 @@ vec2 velocity = (newPos - oldPos);
200
200
  if (gl_FragColor.a <= 0.0) discard;
201
201
 
202
202
  gVelocity = vec4(velocity, 0.0, 1.0);
203
- `,Ob=`
203
+ `,Cb=`
204
204
  layout(location = 1) out vec4 gVelocity;
205
- `,Ab=`
205
+ `,Ob=`
206
206
  // Discard fully transparent pixels
207
207
  if (gl_FragColor.a <= 0.0) discard;
208
208
 
209
209
  gVelocity = vec4(0.0, 0.0, 0.0, 1.0);
210
- `;var Ib=["x","y","z","w"],SN=["float","vec2","vec3","vec4"],wN={float:"f",vec2:"v2",vec3:"v3",vec4:"v4",mat4:"v4",int:"i",bool:"b","float[]":"f[]","vec4[]":"v4[]"},PN={t:"sampler2D",tc:"samplerCube",b:"bool",i:"int",f:"float",c:"vec3",v2:"vec2",v3:"vec3",v4:"vec4",m3:"mat3",m4:"mat4","f[]":"float[]","v4[]":"vec4[]"},Ra=class{constructor(){this.includes={consts:{},functions:{},structs:{}};this.cache="";this.slot="";this.shader="";this.context={};this.needsJitter=!0;this.getIncludesCode=function(){function r(e,t){return e.deps.length-t.deps.length}return function(t,o){let i=this.getIncludes(t,o);if(!i)return"";let a="";i=i.sort(r);for(let s=0;s<i.length;s++)i[s].src&&(a+=i[s].src+`
210
+ `;var Tb=["x","y","z","w"],bN=["float","vec2","vec3","vec4"],vN={float:"f",vec2:"v2",vec3:"v3",vec4:"v4",mat4:"v4",int:"i",bool:"b","float[]":"f[]","vec4[]":"v4[]"},SN={t:"sampler2D",tc:"samplerCube",b:"bool",i:"int",f:"float",c:"vec3",v2:"vec2",v3:"vec3",v4:"vec4",m3:"mat3",m4:"mat4","f[]":"float[]","v4[]":"vec4[]"},Ba=class{constructor(){this.includes={consts:{},functions:{},structs:{}};this.cache="";this.slot="";this.shader="";this.context={};this.needsJitter=!0;this.getIncludesCode=function(){function r(e,t){return e.deps.length-t.deps.length}return function(t,o){let i=this.getIncludes(t,o);if(!i)return"";let a="";i=i.sort(r);for(let s=0;s<i.length;s++)i[s].src&&(a+=i[s].src+`
211
211
  `);return a}}();this.slots=[],this.caches=[],this.contexts=[],this.keywords={},this.nodeData={},this.fragmentVariables={},this.fragmentParsVariables={},this.vertexParsVariables={},this.requires={uv:[],color:[],transparent:!1,irradiance:!1,position:!1,worldPosition:!1,normal:!1,worldNormal:!1,vWorldViewDir:!1,modelMatrix:!1,viewMatrix:!1,projectionMatrix:!1},this.includes={consts:[],functions:[],structs:[]},this.attributes={},this.prefixCode=["#ifdef TEXTURE_LOD_EXT"," #define texCube(a, b) textureCube(a, b)"," #define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)"," #define tex2D(a, b) texture2D(a, b)"," #define tex2DBias(a, b, c) texture2DLodEXT(a, b, c)","#else"," #define texCube(a, b) textureCube(a, b)"," #define texCubeBias(a, b, c) textureCube(a, b, c)"," #define tex2D(a, b) texture2D(a, b)"," #define tex2DBias(a, b, c) texture2D(a, b, c)","#endif",`
212
212
  // NOTE: Include Spline's blending modes. This could be part of BlendNode
213
213
  #define SPE_BLENDING_NORMAL 0
@@ -245,20 +245,20 @@ layout(location = 1) out vec4 gVelocity;
245
245
  `),fragment:["float accumAlpha = 0.0;",`void accumulateAlpha(float alpha) {
246
246
  accumAlpha += (1.0 - accumAlpha) * alpha;
247
247
  }`,""].join(`
248
- `)},this.code={vertex:"",fragment:""},this.nodeCode={vertex:"",fragment:""},this.resultCode={vertex:"",fragment:""},this.finalCode={vertex:"",fragment:""},this.inputs={uniforms:{list:[],vertex:[],fragment:[]},arrayUniforms:{list:[],vertex:[],fragment:[]},vars:{varying:[],vertex:[],fragment:[]}},this.defines={},this.uniforms={},this.extensions={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!1},this.updaters=[],this.nodes=[],this.analyzing=!1}build(r,e){this.addVertexParsCode(Sb),this.addFragmentParsCode(wb),this.buildShader("vertex",r),this.buildShader("fragment",e);for(let t=0;t<this.requires.uv.length;t++)if(this.requires.uv[t]){let o=t>0?t+1:"";this.addVaryCode("varying vec2 vUv"+o+";"),t>0&&this.addVertexParsCode("attribute vec2 uv"+o+";"),this.addVertexFinalCode("vUv"+o+" = uv"+o+";")}return this.requires.color[0]&&(this.addVaryCode("varying vec4 vColor;"),this.addVertexParsCode("attribute vec4 color;"),this.addVertexFinalCode("vColor = color;")),this.requires.color[1]&&(this.addVaryCode("varying vec4 vColor2;"),this.addVertexParsCode("attribute vec4 color2;"),this.addVertexFinalCode("vColor2 = color2;")),this.requires.position&&(this.addVaryCode("varying vec3 vPosition;"),this.addVertexFinalCode("vPosition = transformed;")),this.requires.worldPosition,this.requires.normal&&(this.addVaryCode("varying vec3 vObjectNormal;"),this.addVertexFinalCode("vObjectNormal = normal;")),this.requires.modelMatrix&&this.addFragmentParsCode("uniform mat4 modelMatrix;"),this.requires.viewMatrix&&this.addFragmentParsCode("uniform mat4 viewMatrix;"),this.requires.projectionMatrix&&this.addFragmentParsCode("uniform mat4 projectionMatrix;"),this.requires.worldNormal&&(this.addVaryCode("varying vec3 vWNormal;"),this.addVertexFinalCode("vWNormal = inverseTransformDirection( transformedNormal, viewMatrix ).xyz;")),this.requires.vWorldViewDir&&(this.addVaryCode("varying vec3 vWorldViewDir;"),this.addVertexFinalCode("vWorldViewDir = isPerspectiveMatrix( projectionMatrix ) ? ( (modelMatrix * vec4(position, 1.0)).xyz - cameraPosition ) : vec3( -viewMatrix[0][2], -viewMatrix[1][2], -viewMatrix[2][2] );")),this.needsJitter&&(this.addVertexFinalCode(Pb),this.addFragmentFinalCode(Cb)),this}buildShader(r,e){this.resultCode[r]=e.build(this.setShader(r),"v4")}setMaterial(r,e){return this.defines={},this}addFlow(r,e,t){return this.addSlot(r).addCache(e).addContext(t)}removeFlow(){return this.removeSlot().removeCache().removeContext()}addCache(r){return this.cache=r??"",this.caches.push(this.cache),this}removeCache(){return this.caches.pop(),this.cache=this.caches[this.caches.length-1]||"",this}addContext(r){return this.context=Object.assign({},this.context,r),this.context.extra=this.context.extra||{},this.contexts.push(this.context),this}removeContext(){return this.contexts.pop(),this.context=this.contexts[this.contexts.length-1]||{},this}addSlot(r){return this.slot=r||"",this.slots.push(this.slot),this}removeSlot(){return this.slots.pop(),this.slot=this.slots[this.slots.length-1]||"",this}addFragmentVariable(r,e){this.fragmentVariables[r]===void 0&&(this.addFragmentCode(`${e} ${r};`),this.fragmentVariables[r]="")}addFragmentParsVariable(r,e){this.fragmentParsVariables[r]===void 0&&(this.addFragmentParsCode(`${e} ${r};`),this.fragmentParsVariables[r]="")}addVertexParsVariable(r,e){this.vertexParsVariables[r]===void 0&&(this.addVertexParsCode(`${e} ${r};`),this.vertexParsVariables[r]="")}addVertexCode(r){this.addCode(r,"vertex")}addFragmentCode(r){this.addCode(r,"fragment")}addCode(r,e){this.code[e??this.shader]+=r+`
248
+ `)},this.code={vertex:"",fragment:""},this.nodeCode={vertex:"",fragment:""},this.resultCode={vertex:"",fragment:""},this.finalCode={vertex:"",fragment:""},this.inputs={uniforms:{list:[],vertex:[],fragment:[]},arrayUniforms:{list:[],vertex:[],fragment:[]},vars:{varying:[],vertex:[],fragment:[]}},this.defines={},this.uniforms={},this.extensions={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!1},this.updaters=[],this.nodes=[],this.analyzing=!1}build(r,e){this.addVertexParsCode(vb),this.addFragmentParsCode(Sb),this.buildShader("vertex",r),this.buildShader("fragment",e);for(let t=0;t<this.requires.uv.length;t++)if(this.requires.uv[t]){let o=t>0?t+1:"";this.addVaryCode("varying vec2 vUv"+o+";"),t>0&&this.addVertexParsCode("attribute vec2 uv"+o+";"),this.addVertexFinalCode("vUv"+o+" = uv"+o+";")}return this.requires.color[0]&&(this.addVaryCode("varying vec4 vColor;"),this.addVertexParsCode("attribute vec4 color;"),this.addVertexFinalCode("vColor = color;")),this.requires.color[1]&&(this.addVaryCode("varying vec4 vColor2;"),this.addVertexParsCode("attribute vec4 color2;"),this.addVertexFinalCode("vColor2 = color2;")),this.requires.position&&(this.addVaryCode("varying vec3 vPosition;"),this.addVertexFinalCode("vPosition = transformed;")),this.requires.worldPosition,this.requires.normal&&(this.addVaryCode("varying vec3 vObjectNormal;"),this.addVertexFinalCode("vObjectNormal = normal;")),this.requires.modelMatrix&&this.addFragmentParsCode("uniform mat4 modelMatrix;"),this.requires.viewMatrix&&this.addFragmentParsCode("uniform mat4 viewMatrix;"),this.requires.projectionMatrix&&this.addFragmentParsCode("uniform mat4 projectionMatrix;"),this.requires.worldNormal&&(this.addVaryCode("varying vec3 vWNormal;"),this.addVertexFinalCode("vWNormal = inverseTransformDirection( transformedNormal, viewMatrix ).xyz;")),this.requires.vWorldViewDir&&(this.addVaryCode("varying vec3 vWorldViewDir;"),this.addVertexFinalCode("vWorldViewDir = isPerspectiveMatrix( projectionMatrix ) ? ( (modelMatrix * vec4(position, 1.0)).xyz - cameraPosition ) : vec3( -viewMatrix[0][2], -viewMatrix[1][2], -viewMatrix[2][2] );")),this.needsJitter&&(this.addVertexFinalCode(wb),this.addFragmentFinalCode(Pb)),this}buildShader(r,e){this.resultCode[r]=e.build(this.setShader(r),"v4")}setMaterial(r,e){return this.defines={},this}addFlow(r,e,t){return this.addSlot(r).addCache(e).addContext(t)}removeFlow(){return this.removeSlot().removeCache().removeContext()}addCache(r){return this.cache=r??"",this.caches.push(this.cache),this}removeCache(){return this.caches.pop(),this.cache=this.caches[this.caches.length-1]||"",this}addContext(r){return this.context=Object.assign({},this.context,r),this.context.extra=this.context.extra||{},this.contexts.push(this.context),this}removeContext(){return this.contexts.pop(),this.context=this.contexts[this.contexts.length-1]||{},this}addSlot(r){return this.slot=r||"",this.slots.push(this.slot),this}removeSlot(){return this.slots.pop(),this.slot=this.slots[this.slots.length-1]||"",this}addFragmentVariable(r,e){this.fragmentVariables[r]===void 0&&(this.addFragmentCode(`${e} ${r};`),this.fragmentVariables[r]="")}addFragmentParsVariable(r,e){this.fragmentParsVariables[r]===void 0&&(this.addFragmentParsCode(`${e} ${r};`),this.fragmentParsVariables[r]="")}addVertexParsVariable(r,e){this.vertexParsVariables[r]===void 0&&(this.addVertexParsCode(`${e} ${r};`),this.vertexParsVariables[r]="")}addVertexCode(r){this.addCode(r,"vertex")}addFragmentCode(r){this.addCode(r,"fragment")}addCode(r,e){this.code[e??this.shader]+=r+`
249
249
  `}addVertexNodeCode(r){this.addNodeCode(r,"vertex")}addFragmentNodeCode(r){this.addNodeCode(r,"fragment")}addNodeCode(r,e){this.nodeCode[e??this.shader]+=r+`
250
250
  `}clearNodeCode(r){r=r??this.shader;let e=this.nodeCode[r];return this.nodeCode[r]="",e}clearVertexNodeCode(){return this.clearNodeCode("vertex")}clearFragmentNodeCode(){return this.clearNodeCode("fragment")}addVertexFinalCode(r){this.addFinalCode(r,"vertex")}addFragmentFinalCode(r){this.addFinalCode(r,"fragment")}addFinalCode(r,e){this.finalCode[e??this.shader]+=r+`
251
251
  `}addVertexParsCode(r){this.addParsCode(r,"vertex")}addFragmentParsCode(r){this.addParsCode(r,"fragment")}addParsCode(r,e){this.parsCode[e??this.shader]+=r+`
252
252
  `}addVaryCode(r){this.addVertexParsCode(r),this.addFragmentParsCode(r)}isCache(r){return this.caches.indexOf(r)!==-1}isSlot(r){return this.slots.indexOf(r)!==-1}define(r,e){this.defines[r]=e===void 0?1:e}require(r){this.requires[r]=!0}isDefined(r){return this.defines[r]!==void 0}getVar(r,e,t,o="varying",i="V",a=""){let s=this.getVars(o),l=s[r];if(!l){let c=s.length;l={name:t||"node"+i+c+(a?"_"+a:""),type:e},s.push(l),s[r]=l}return l}getTempVar(r,e,t,o){return this.getVar(r,e,t,this.shader,"T",o)}getAttribute(r,e){if(!this.attributes[r]){let t=this.getVar(r,e);this.addVertexParsCode("attribute "+e+" "+r+";"),this.addVertexFinalCode(t.name+" = "+r+";"),this.attributes[r]={varying:t,name:r,type:e}}return this.attributes[r]}getCode(r){return[this.prefixCode,this.parsCode[r],this.getVarListCode(this.getVars("varying"),"varying"),this.getVarListCode(this.inputs.uniforms[r],"uniform"),this.getVarListCode(this.inputs.arrayUniforms[r],"uniform"),this.getIncludesCode("consts",r),this.getIncludesCode("structs",r),this.getIncludesCode("functions",r),"void main() {",this.getVarListCode(this.getVars(r)),this.code[r],this.resultCode[r],this.finalCode[r],"}"].join(`
253
253
  `)}getVarListCode(r,e){e=e??"";let t="";for(let o=0,i=r.length;o<i;++o){let a=r[o],s=a.type,l=a.name,c=a.size,u=this.getFormatByType(s);if(u===void 0)throw new Error("Node pars "+u+" not found.");u.includes("[]")?t+=e+" "+u.substring(0,u.length-2)+" "+l+`[${c}];
254
254
  `:t+=e+" "+u+" "+l+`;
255
- `}return t}getVars(r){return this.inputs.vars[r??this.shader]}getNodeData(r){let e=r instanceof qe?r.uuid:r;return this.nodeData[e]=this.nodeData[e]||{}}createUniform(r,e,t,o,i,a){if(e.includes("[]")){let s=this.inputs.arrayUniforms,l=s.list.length,c=new ol({type:e,size:t.size,name:o||"nodeUA"+l+(a?"_"+a:""),node:t,needsUpdate:i});return s.list.push(c),s[r].push(c),s[r][c.name]=c,this.uniforms[c.name]=c,c}else{let s=this.inputs.uniforms,l=s.list.length,c=new ol({type:e,name:o||"nodeU"+l+(a?"_"+a:""),node:t,needsUpdate:i});return s.list.push(c),s[r].push(c),s[r][c.name]=c,this.uniforms[c.name]=c,c}}createVertexUniform(r,e,t,o,i){return this.createUniform("vertex",r,e,t,o,i)}createFragmentUniform(r,e,t,o,i){return this.createUniform("fragment",r,e,t,o,i)}include(r,e,t){let o;if(r=typeof r=="string"?Ot.get(r):r,this.context.include===!1)return r.name;r instanceof J?o=this.includes.functions:r instanceof Fe?o=this.includes.consts:r instanceof Na&&(o=this.includes.structs);let i=o[this.shader]=o[this.shader]||[];if(r){let a=i[r.name];if(a||(a=i[r.name]={node:r,deps:[]},i.push(a),a.src=r.build(this,"source")),r instanceof J&&e&&i[e.name]&&i[e.name].deps.indexOf(r)===-1&&(i[e.name].deps.push(r),r.includes?.length)){let s=0;do this.include(r.includes[s++],e);while(s<r.includes.length)}return t&&(a.src=t),r.name}else throw new Error("Include not found.")}colorToVectorProperties(r){return r.replace("r","x").replace("g","y").replace("b","z").replace("a","w")}colorToVector(r){return r.replace(/c/g,"v3")}getIncludes(r,e){return this.includes[r][e||this.shader]}getConstructorFromLength(r){return SN[r-1]}isTypeMatrix(r){return/^m/.test(r)}getTypeLength(r){return r==="f"?1:parseInt(this.colorToVector(r).substr(1))}getTypeFromLength(r){return r===1?"f":"v"+r}findNode(...r){for(let e=0;e<arguments.length;e++){let t=r[e];if(t?.isNode)return t}}resolve(...r){for(let e=0;e<arguments.length;e++){let t=r[e];if(t!==void 0){if(t.isNode)return t;if(t.isTexture)switch(t.mapping){case gN:case xN:return new Bu(t);case bN:return new _u(new Yt(t));default:return new Yt(t)}else{if(t.isVector2)return new st(t);if(t.isVector3)return new Gt(t);if(t.isVector4)return new er(t)}}}}format(r,e,t){switch(this.colorToVector(t+" <- "+e)){case"f <- v2":return r+".x";case"f <- v3":return r+".x";case"f <- v4":return r+".x";case"f <- i":case"f <- b":return"float( "+r+" )";case"v2 <- f":return"vec2( "+r+" )";case"v2 <- v3":return r+".xy";case"v2 <- v4":return r+".xy";case"v2 <- i":case"v2 <- b":return"vec2( float( "+r+" ) )";case"v3 <- f":return"vec3( "+r+" )";case"v3 <- v2":return"vec3( "+r+", 0.0 )";case"v3 <- v4":return r+".xyz";case"v3 <- i":case"v3 <- b":return"vec2( float( "+r+" ) )";case"v4 <- f":return"vec4( "+r+" )";case"v4 <- v2":return"vec4( "+r+", 0.0, 1.0 )";case"v4 <- v3":return"vec4( "+r+", 1.0 )";case"v4 <- i":case"v4 <- b":return"vec4( float( "+r+" ) )";case"i <- f":case"i <- b":return"int( "+r+" )";case"i <- v2":return"int( "+r+".x )";case"i <- v3":return"int( "+r+".x )";case"i <- v4":return"int( "+r+".x )";case"b <- f":return"( "+r+" != 0.0 )";case"b <- v2":return"( "+r+" != vec2( 0.0 ) )";case"b <- v3":return"( "+r+" != vec3( 0.0 ) )";case"b <- v4":return"( "+r+" != vec4( 0.0 ) )";case"b <- i":return"( "+r+" != 0 )"}return r}getTypeByFormat(r){return wN[r]||r}getFormatByType(r){return PN[r]||r}getUUID(r,e){return e=e!==void 0?e:!0,e&&this.cache&&(r=this.cache+"-"+r),r}getElementByIndex(r){return Ib[r]}getIndexByElement(r){return Ib.indexOf(r)}isShader(r){return this.shader===r}setShader(r){return this.shader=r,this}mergeDefines(r){for(let e in r)this.defines[e]=r[e];return this.defines}mergeUniform(r){for(let e in r)this.uniforms[e]=r[e];return this.uniforms}getTextureEncodingFromMap(r){let e;return r?r.isTexture&&(e=r.encoding):e=Tb,e===Tb&&this.context.gamma&&(e=vN),e}};import{MathUtils as JN,Vector2 as Hr,Vector3 as fo,Vector4 as Za}from"three";var He=class extends $e{constructor(e=0,t,o,i){super("c");this.nodeType="Color";this.value=e instanceof At?e:new At(e||0,t,o,i)}setRGBA(e){this.value.setRGBA(e.r,e.g,e.b,e.a)}generate(e,t,o,i,a,s){o=e.getUUID(o??this.getUUID()),i=i??this.getType(e);let l=e.getNodeData(o),c=this.getReadonly()&&this.generateReadonly!==void 0;if(this.alpha){let u=this.alpha.build(e,"f");e.addFragmentNodeCode(`accumAlpha += ( 1.0 - accumAlpha ) * ${u};`)}return c?this.generateReadonly(e,t,o,i,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(i,this,a,s,this.getLabel())),e.format(l.vertex.name,i,t)):(l.fragment||(l.fragment=e.createFragmentUniform(i,this,a,s,this.getLabel())),e.format(l.fragment.name,i,t))}generateReadonly(e,t,o,i,a,s){return e.format("vec3("+this.value.r+", "+this.value.g+", "+this.value.b+")",i,t)}};var Be=class extends $e{constructor(e){super("i");this.nodeType="Int";this.value=Math.floor(e??0)}generateReadonly(e,t,o,i,a,s){return e.format(this.value.toString(),i,t)}};import{UniformsLib as IN,UniformsUtils as MN}from"three";var ft=class extends $e{constructor(e){super("b");this.nodeType="Bool";this.value=e??!1}generateReadonly(e,t,o,i){return e.format(this.value?"true":"false",i,t)}};var jr=class extends $e{constructor(e=1,t){super("f[]");this.nodeType="FloatArray";this.size=e,this.value=Array.isArray(t)?t:typeof t=="number"?new Array(e).fill(t):new Array(e).fill(0)}};import{Vector3 as CN}from"three";var vn=class extends $e{};var Ru=class extends vn{constructor(e){super("v3");this.image=e;this._value=new CN}get value(){return this._value.x=this.image.isVideo?this.image.img.videoWidth??0:this.image.img.width,this._value.y=this.image.isVideo?this.image.img.videoHeight??0:this.image.img.height,this._value}};var ri=class extends vn{constructor(e,t,o=1008,i=1006){super("t");this.image=e;this.wrap=t;this.minFilter=o;this.magFilter=i}get value(){return this.image.getTexture(this.wrap,this.minFilter,this.magFilter)}};import{Matrix3 as ON}from"three";var La=class extends $e{constructor(e){super("m3");this.nodeType="Matrix3";this.value=e??new ON}generateReadonly(e,t,o,i,a,s){return e.format("mat3("+this.value.elements.join(", ")+")",i,t)}get elements(){return this.value.elements}set elements(e){this.value.fromArray(e)}};import{Matrix4 as AN}from"three";var Ft=class extends $e{constructor(e){super("m4");this.nodeType="Matrix4";this.value=e??new AN}generateReadonly(e,t,o,i,a,s){return e.format("mat4("+this.value.elements.join(", ")+")",i,t)}get elements(){return this.value.elements}set elements(e){this.value.fromArray(e)}};import{MathUtils as TN,Matrix3 as Eb}from"three";function Mb(n,r,e,t=0){n.setUvTransform(e[0],e[1],r[0],r[1],0,0,0).premultiply(new Eb().makeRotation(t*TN.DEG2RAD))}var Lu=class extends La{constructor(e,t,o=0){super(new Eb);this.repeat=e;this.offset=t;this.rotation=o;Mb(this.value,e,t,o)}updateMatrix(){Mb(this.value,this.repeat,this.offset,this.rotation)}};import{Vector4 as Nb}from"three";var kr=class extends $e{constructor(e=1,t){super("v4[]");this.nodeType="Vector4Array";this.size=e,this.value=Array.isArray(t)?t:t instanceof Nb?new Array(e).fill(t):new Array(e).fill(new Nb(0))}};var Va=class extends ge{constructor(e,t,o,i){super("v3");this.nodeType="Blend";this.a=e,this.b=t,this.alpha=o,this.mode=i}generate(e,t){if(e.isShader("fragment")){let o=[];return o.push(this.a.build(e,"c")),o.push(this.b.build(e,"c")),o.push(this.alpha.build(e,"f")),o.push(this.mode.build(e,"i")),e.format("spe_blend("+o.join(",")+")",this.getType(e),t)}else return console.warn("BlendNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}};var Vf=class extends ge{constructor(e,t){super("v3");this.nodeType="CustomColor";this.color=e,this.alpha=t,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){let o=e.include(Vf.Nodes.customColor);e.addFragmentVariable(this.calpha,"float");let i=[];return i.push(this.color.build(e,"v3")),i.push(this.mask?`luminance(${this.mask.build(e,"v3")})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("CustomColorNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},oi=Vf;oi.Nodes=function(){return{customColor:new J(`vec3 customColor(vec3 color, float mask, float alpha, out float calpha) {
255
+ `}return t}getVars(r){return this.inputs.vars[r??this.shader]}getNodeData(r){let e=r instanceof qe?r.uuid:r;return this.nodeData[e]=this.nodeData[e]||{}}createUniform(r,e,t,o,i,a){if(e.includes("[]")){let s=this.inputs.arrayUniforms,l=s.list.length,c=new tl({type:e,size:t.size,name:o||"nodeUA"+l+(a?"_"+a:""),node:t,needsUpdate:i});return s.list.push(c),s[r].push(c),s[r][c.name]=c,this.uniforms[c.name]=c,c}else{let s=this.inputs.uniforms,l=s.list.length,c=new tl({type:e,name:o||"nodeU"+l+(a?"_"+a:""),node:t,needsUpdate:i});return s.list.push(c),s[r].push(c),s[r][c.name]=c,this.uniforms[c.name]=c,c}}createVertexUniform(r,e,t,o,i){return this.createUniform("vertex",r,e,t,o,i)}createFragmentUniform(r,e,t,o,i){return this.createUniform("fragment",r,e,t,o,i)}include(r,e,t){let o;if(r=typeof r=="string"?Ot.get(r):r,this.context.include===!1)return r.name;r instanceof J?o=this.includes.functions:r instanceof Ge?o=this.includes.consts:r instanceof Ea&&(o=this.includes.structs);let i=o[this.shader]=o[this.shader]||[];if(r){let a=i[r.name];if(a||(a=i[r.name]={node:r,deps:[]},i.push(a),a.src=r.build(this,"source")),r instanceof J&&e&&i[e.name]&&i[e.name].deps.indexOf(r)===-1&&(i[e.name].deps.push(r),r.includes?.length)){let s=0;do this.include(r.includes[s++],e);while(s<r.includes.length)}return t&&(a.src=t),r.name}else throw new Error("Include not found.")}colorToVectorProperties(r){return r.replace("r","x").replace("g","y").replace("b","z").replace("a","w")}colorToVector(r){return r.replace(/c/g,"v3")}getIncludes(r,e){return this.includes[r][e||this.shader]}getConstructorFromLength(r){return bN[r-1]}isTypeMatrix(r){return/^m/.test(r)}getTypeLength(r){return r==="f"?1:parseInt(this.colorToVector(r).substr(1))}getTypeFromLength(r){return r===1?"f":"v"+r}findNode(...r){for(let e=0;e<arguments.length;e++){let t=r[e];if(t?.isNode)return t}}resolve(...r){for(let e=0;e<arguments.length;e++){let t=r[e];if(t!==void 0){if(t.isNode)return t;if(t.isTexture)switch(t.mapping){case mN:case yN:return new Eu(t);case gN:return new Mu(new Yt(t));default:return new Yt(t)}else{if(t.isVector2)return new st(t);if(t.isVector3)return new Gt(t);if(t.isVector4)return new er(t)}}}}format(r,e,t){switch(this.colorToVector(t+" <- "+e)){case"f <- v2":return r+".x";case"f <- v3":return r+".x";case"f <- v4":return r+".x";case"f <- i":case"f <- b":return"float( "+r+" )";case"v2 <- f":return"vec2( "+r+" )";case"v2 <- v3":return r+".xy";case"v2 <- v4":return r+".xy";case"v2 <- i":case"v2 <- b":return"vec2( float( "+r+" ) )";case"v3 <- f":return"vec3( "+r+" )";case"v3 <- v2":return"vec3( "+r+", 0.0 )";case"v3 <- v4":return r+".xyz";case"v3 <- i":case"v3 <- b":return"vec2( float( "+r+" ) )";case"v4 <- f":return"vec4( "+r+" )";case"v4 <- v2":return"vec4( "+r+", 0.0, 1.0 )";case"v4 <- v3":return"vec4( "+r+", 1.0 )";case"v4 <- i":case"v4 <- b":return"vec4( float( "+r+" ) )";case"i <- f":case"i <- b":return"int( "+r+" )";case"i <- v2":return"int( "+r+".x )";case"i <- v3":return"int( "+r+".x )";case"i <- v4":return"int( "+r+".x )";case"b <- f":return"( "+r+" != 0.0 )";case"b <- v2":return"( "+r+" != vec2( 0.0 ) )";case"b <- v3":return"( "+r+" != vec3( 0.0 ) )";case"b <- v4":return"( "+r+" != vec4( 0.0 ) )";case"b <- i":return"( "+r+" != 0 )"}return r}getTypeByFormat(r){return vN[r]||r}getFormatByType(r){return SN[r]||r}getUUID(r,e){return e=e!==void 0?e:!0,e&&this.cache&&(r=this.cache+"-"+r),r}getElementByIndex(r){return Tb[r]}getIndexByElement(r){return Tb.indexOf(r)}isShader(r){return this.shader===r}setShader(r){return this.shader=r,this}mergeDefines(r){for(let e in r)this.defines[e]=r[e];return this.defines}mergeUniform(r){for(let e in r)this.uniforms[e]=r[e];return this.uniforms}getTextureEncodingFromMap(r){let e;return r?r.isTexture&&(e=r.encoding):e=Ab,e===Ab&&this.context.gamma&&(e=xN),e}};import{MathUtils as ZN,Vector2 as Hr,Vector3 as fo,Vector4 as Qa}from"three";var He=class extends $e{constructor(e=0,t,o,i){super("c");this.nodeType="Color";this.value=e instanceof At?e:new At(e||0,t,o,i)}setRGBA(e){this.value.setRGBA(e.r,e.g,e.b,e.a)}generate(e,t,o,i,a,s){o=e.getUUID(o??this.getUUID()),i=i??this.getType(e);let l=e.getNodeData(o),c=this.getReadonly()&&this.generateReadonly!==void 0;if(this.alpha){let u=this.alpha.build(e,"f");e.addFragmentNodeCode(`accumAlpha += ( 1.0 - accumAlpha ) * ${u};`)}return c?this.generateReadonly(e,t,o,i,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(i,this,a,s,this.getLabel())),e.format(l.vertex.name,i,t)):(l.fragment||(l.fragment=e.createFragmentUniform(i,this,a,s,this.getLabel())),e.format(l.fragment.name,i,t))}generateReadonly(e,t,o,i,a,s){return e.format("vec3("+this.value.r+", "+this.value.g+", "+this.value.b+")",i,t)}};var Be=class extends $e{constructor(e){super("i");this.nodeType="Int";this.value=Math.floor(e??0)}generateReadonly(e,t,o,i,a,s){return e.format(this.value.toString(),i,t)}};import{UniformsLib as TN,UniformsUtils as IN}from"three";var ft=class extends $e{constructor(e){super("b");this.nodeType="Bool";this.value=e??!1}generateReadonly(e,t,o,i){return e.format(this.value?"true":"false",i,t)}};var jr=class extends $e{constructor(e=1,t){super("f[]");this.nodeType="FloatArray";this.size=e,this.value=Array.isArray(t)?t:typeof t=="number"?new Array(e).fill(t):new Array(e).fill(0)}};import{Vector3 as wN}from"three";var bn=class extends $e{};var Nu=class extends bn{constructor(e){super("v3");this.image=e;this._value=new wN}get value(){return this._value.x=this.image.isVideo?this.image.img.videoWidth??0:this.image.img.width,this._value.y=this.image.isVideo?this.image.img.videoHeight??0:this.image.img.height,this._value}};var ti=class extends bn{constructor(e,t,o=1008,i=1006){super("t");this.image=e;this.wrap=t;this.minFilter=o;this.magFilter=i}get value(){return this.image.getTexture(this.wrap,this.minFilter,this.magFilter)}};import{Matrix3 as PN}from"three";var Ra=class extends $e{constructor(e){super("m3");this.nodeType="Matrix3";this.value=e??new PN}generateReadonly(e,t,o,i,a,s){return e.format("mat3("+this.value.elements.join(", ")+")",i,t)}get elements(){return this.value.elements}set elements(e){this.value.fromArray(e)}};import{Matrix4 as CN}from"three";var Ft=class extends $e{constructor(e){super("m4");this.nodeType="Matrix4";this.value=e??new CN}generateReadonly(e,t,o,i,a,s){return e.format("mat4("+this.value.elements.join(", ")+")",i,t)}get elements(){return this.value.elements}set elements(e){this.value.fromArray(e)}};import{MathUtils as ON,Matrix3 as Mb}from"three";function Ib(n,r,e,t=0){n.setUvTransform(e[0],e[1],r[0],r[1],0,0,0).premultiply(new Mb().makeRotation(t*ON.DEG2RAD))}var Du=class extends Ra{constructor(e,t,o=0){super(new Mb);this.repeat=e;this.offset=t;this.rotation=o;Ib(this.value,e,t,o)}updateMatrix(){Ib(this.value,this.repeat,this.offset,this.rotation)}};import{Vector4 as Eb}from"three";var kr=class extends $e{constructor(e=1,t){super("v4[]");this.nodeType="Vector4Array";this.size=e,this.value=Array.isArray(t)?t:t instanceof Eb?new Array(e).fill(t):new Array(e).fill(new Eb(0))}};var La=class extends ge{constructor(e,t,o,i){super("v3");this.nodeType="Blend";this.a=e,this.b=t,this.alpha=o,this.mode=i}generate(e,t){if(e.isShader("fragment")){let o=[];return o.push(this.a.build(e,"c")),o.push(this.b.build(e,"c")),o.push(this.alpha.build(e,"f")),o.push(this.mode.build(e,"i")),e.format("spe_blend("+o.join(",")+")",this.getType(e),t)}else return console.warn("BlendNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}};var Bf=class extends ge{constructor(e,t){super("v3");this.nodeType="CustomColor";this.color=e,this.alpha=t,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){let o=e.include(Bf.Nodes.customColor);e.addFragmentVariable(this.calpha,"float");let i=[];return i.push(this.color.build(e,"v3")),i.push(this.mask?`luminance(${this.mask.build(e,"v3")})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("CustomColorNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},ri=Bf;ri.Nodes=function(){return{customColor:new J(`vec3 customColor(vec3 color, float mask, float alpha, out float calpha) {
256
256
  float lalpha = alpha * mask;
257
257
  calpha = lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0);
258
258
  accumAlpha += (1.0 - accumAlpha) * lalpha;
259
259
 
260
260
  return color;
261
- }`)}}();var zf=class extends ge{constructor(e,t){super("v3");this.nodeType="CustomNormal";this.cnormal=e,this.alpha=t,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){let o=e.include(zf.Nodes.customNormal);e.addFragmentVariable(this.calpha,"float");let i=[];return i.push(this.cnormal.build(e,"v3")),i.push("normal"),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("CustomNormalNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},za=zf;za.Nodes=function(){return{customNormal:new J(`vec3 customNormal(vec3 cnormal, vec3 norm, float mask, float alpha, out float calpha) {
261
+ }`)}}();var Rf=class extends ge{constructor(e,t){super("v3");this.nodeType="CustomNormal";this.cnormal=e,this.alpha=t,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){let o=e.include(Rf.Nodes.customNormal);e.addFragmentVariable(this.calpha,"float");let i=[];return i.push(this.cnormal.build(e,"v3")),i.push("normal"),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("CustomNormalNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Va=Rf;Va.Nodes=function(){return{customNormal:new J(`vec3 customNormal(vec3 cnormal, vec3 norm, float mask, float alpha, out float calpha) {
262
262
  vec3 normal = packNormalToRGB( norm ).rgb;
263
263
  normal *= step( vec3(0.5), cnormal );
264
264
 
@@ -267,7 +267,7 @@ layout(location = 1) out vec4 gVelocity;
267
267
  accumAlpha += ( 1.0 - accumAlpha ) * lalpha;
268
268
 
269
269
  return normal;
270
- }`)}}();var Ga=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,h){super("v3");this.nodeType="CustomTexture";this.texture=e,this.textureSize=t,this.crop=o,this.projection=i,this.axis=a,this.side=s,this.size=l,this.blending=c,this.mat=u,this.isMask=h,this.alpha=p,this.mode=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){e.require("position"),e.require("normal"),e.require("uv"),e.requires.uv=[!0],e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0;let o=`g${this.uuid.toString().replace(/-/g,"")}`,i;switch(this.projection.value){case 3:i=e.include(Ga.Nodes.cylindrical);break;case 2:i=e.include(Ga.Nodes.spherical);break;case 1:let s=["vec3(1.0, 0.0, 0.0)","vec3(0.0, 1.0, 0.0)","vec3(0.0, 0.0, 1.0)"][this.axis.value],l=["zy","xz","xy"][this.axis.value],c=new J(`
270
+ }`)}}();var za=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,f){super("v3");this.nodeType="CustomTexture";this.texture=e,this.textureSize=t,this.crop=o,this.projection=i,this.axis=a,this.side=s,this.size=l,this.blending=c,this.mat=u,this.isMask=f,this.alpha=p,this.mode=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){e.require("position"),e.require("normal"),e.require("uv"),e.requires.uv=[!0],e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0;let o=`g${this.uuid.toString().replace(/-/g,"")}`,i;switch(this.projection.value){case 3:i=e.include(za.Nodes.cylindrical);break;case 2:i=e.include(za.Nodes.spherical);break;case 1:let s=["vec3(1.0, 0.0, 0.0)","vec3(0.0, 1.0, 0.0)","vec3(0.0, 0.0, 1.0)"][this.axis.value],l=["zy","xz","xy"][this.axis.value],c=new J(`
271
271
  vec3 ${o}_planarTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) {
272
272
  vec2 projected = (1. + (position.${l})) / 2.;
273
273
  vec2 uvs = ( mat * vec3( (projected * 2. - 1.) / (size * .5), 1. ) / 2. + 0.5 ).xy;
@@ -291,7 +291,7 @@ layout(location = 1) out vec4 gVelocity;
291
291
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
292
292
 
293
293
  return col;
294
- }`);i=e.include(c);break;case 4:i=e.include(Ga.Nodes.triplanar);break;default:i=e.include(Ga.Nodes.uv);break}e.addFragmentVariable(this.calpha,"float");let a=[];if(a.push("normal"),a.push(this.texture.generate(e,"t")),a.push(this.textureSize.build(e,"v2")),a.push(this.crop.build(e,"f")),a.push(this.mat.build(e,"mat3")),a.push(this.size.build(e,"v2")),a.push(this.blending.build(e,"f")),a.push(this.isMask.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.mode.build(e,"i")),a.push(this.calpha),this.projection.value===4){let s=`${o}_writeUvs`,l=s+"0",c=s+"1",u=s+"2",p=`${o}_triplanarWeights`;e.addFragmentVariable(l,"vec2"),e.addFragmentVariable(c,"vec2"),e.addFragmentVariable(u,"vec2"),e.addFragmentVariable(p,"vec3"),a.push(l),a.push(c),a.push(u),a.push(p)}else{let s=`${o}_writeUvs`;e.addFragmentVariable(s,"vec2"),a.push(s)}return e.format(i+"("+a.join(",")+")",this.getType(e),t)}},Sn=Ga;Sn.Nodes=function(){let e=new J(`
294
+ }`);i=e.include(c);break;case 4:i=e.include(za.Nodes.triplanar);break;default:i=e.include(za.Nodes.uv);break}e.addFragmentVariable(this.calpha,"float");let a=[];if(a.push("normal"),a.push(this.texture.generate(e,"t")),a.push(this.textureSize.build(e,"v2")),a.push(this.crop.build(e,"f")),a.push(this.mat.build(e,"mat3")),a.push(this.size.build(e,"v2")),a.push(this.blending.build(e,"f")),a.push(this.isMask.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.mode.build(e,"i")),a.push(this.calpha),this.projection.value===4){let s=`${o}_writeUvs`,l=s+"0",c=s+"1",u=s+"2",p=`${o}_triplanarWeights`;e.addFragmentVariable(l,"vec2"),e.addFragmentVariable(c,"vec2"),e.addFragmentVariable(u,"vec2"),e.addFragmentVariable(p,"vec3"),a.push(l),a.push(c),a.push(u),a.push(p)}else{let s=`${o}_writeUvs`;e.addFragmentVariable(s,"vec2"),a.push(s)}return e.format(i+"("+a.join(",")+")",this.getType(e),t)}},vn=za;vn.Nodes=function(){let e=new J(`
295
295
  vec3 cylindricalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop, mat3 mat, vec2 size, float blending, bool isMask, float mask, float alpha, int mode, out float calpha, out vec2 writeUv) {
296
296
  vec3 posN = normalize(position);
297
297
  float u = 0.5 + atan(posN.z, posN.x) / (2.*3.1415);
@@ -446,7 +446,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
446
446
 
447
447
  return col;//n * 0.5 + 0.5;
448
448
  }
449
- `);return{cylindrical:e,spherical:t,uv:o,triplanar:i}}();var Fa=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,h){super("v3");this.nodeType="Depth";this.gradientType=e,this.smooth=t,this.near=o,this.far=i,this.isVector=a,this.isWorldSpace=s,this.origin=l,this.direction=c,this.colors=u,this.steps=p,this.isMask=h,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){let o=`g${this.uuid.toString().replace(/-/g,"")}`,i=new J(`vec3 ${o}_sdepth(float near, float far, vec3 origin, vec3 direction, vec4 colors[${o}_MAX_COLORS], float steps[${o}_MAX_COLORS], bool isMask, float mask, float alpha, out float calpha) {
449
+ `);return{cylindrical:e,spherical:t,uv:o,triplanar:i}}();var Ga=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,f){super("v3");this.nodeType="Depth";this.gradientType=e,this.smooth=t,this.near=o,this.far=i,this.isVector=a,this.isWorldSpace=s,this.origin=l,this.direction=c,this.colors=u,this.steps=p,this.isMask=f,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){let o=`g${this.uuid.toString().replace(/-/g,"")}`,i=new J(`vec3 ${o}_sdepth(float near, float far, vec3 origin, vec3 direction, vec4 colors[${o}_MAX_COLORS], float steps[${o}_MAX_COLORS], bool isMask, float mask, float alpha, out float calpha) {
450
450
  vec4 color = colors[0];
451
451
  #ifdef ${o}_IS_VECTOR
452
452
  #ifdef ${o}_LINEAR
@@ -486,7 +486,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
486
486
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
487
487
 
488
488
  return color.rgb;
489
- }`,[Fa.Nodes.vectorLinearWorldSpaceDepth,Fa.Nodes.vectorLinearObjectSpaceDepth,Fa.Nodes.vectorSphericalObjectSpaceDepth,Fa.Nodes.vectorSphericalWorldSpaceDepth]);if(e.isShader("fragment")){e.define(`${o}_MAX_COLORS`,this.colors.value.length),this.smooth.value&&e.define(`${o}_SMOOTH`),this.isVector.value>.5&&e.define(`${o}_IS_VECTOR`),this.gradientType.value===0&&e.define(`${o}_LINEAR`),this.isWorldSpace.value>.5&&e.define(`${o}_WORLDSPACE`),e.require("worldPosition"),e.addFragmentVariable(this.calpha,"float");let a=e.include(i),s=[];return s.push(this.near.build(e,"f")),s.push(this.far.build(e,"f")),s.push(this.origin.build(e,"v3")),s.push(this.direction.build(e,"v3")),s.push(this.colors.build(e,"v4[]")),s.push(this.steps.build(e,"f[]")),s.push(this.isMask.build(e,"b")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(a+"("+s.join(",")+")",this.getType(e),t)}else return console.warn("DepthNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},ja=Fa;ja.Nodes=function(){let e=new J(`float vectorLinearWorldSpaceDepth(vec3 direction, vec3 origin, float near, float far) {
489
+ }`,[Ga.Nodes.vectorLinearWorldSpaceDepth,Ga.Nodes.vectorLinearObjectSpaceDepth,Ga.Nodes.vectorSphericalObjectSpaceDepth,Ga.Nodes.vectorSphericalWorldSpaceDepth]);if(e.isShader("fragment")){e.define(`${o}_MAX_COLORS`,this.colors.value.length),this.smooth.value&&e.define(`${o}_SMOOTH`),this.isVector.value>.5&&e.define(`${o}_IS_VECTOR`),this.gradientType.value===0&&e.define(`${o}_LINEAR`),this.isWorldSpace.value>.5&&e.define(`${o}_WORLDSPACE`),e.require("worldPosition"),e.addFragmentVariable(this.calpha,"float");let a=e.include(i),s=[];return s.push(this.near.build(e,"f")),s.push(this.far.build(e,"f")),s.push(this.origin.build(e,"v3")),s.push(this.direction.build(e,"v3")),s.push(this.colors.build(e,"v4[]")),s.push(this.steps.build(e,"f[]")),s.push(this.isMask.build(e,"b")),s.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),s.push(this.alpha.build(e,"f")),s.push(this.calpha),e.format(a+"("+s.join(",")+")",this.getType(e),t)}else return console.warn("DepthNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Fa=Ga;Fa.Nodes=function(){let e=new J(`float vectorLinearWorldSpaceDepth(vec3 direction, vec3 origin, float near, float far) {
490
490
  vec3 n = normalize(direction);
491
491
  float dist = (n.x*(vWPosition.x - origin.x) + n.y*(vWPosition.y - origin.y) + n.z*(vWPosition.z - origin.z));
492
492
  return ( dist - near ) / ( far - near );
@@ -500,7 +500,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
500
500
  }`),i=new J(`float vectorSphericalObjectSpaceDepth(vec3 origin, float near, float far) {
501
501
  float dist = length(position - origin);
502
502
  return ( dist - near ) / ( far - near );
503
- }`);return{vectorLinearWorldSpaceDepth:e,vectorLinearObjectSpaceDepth:t,vectorSphericalWorldSpaceDepth:o,vectorSphericalObjectSpaceDepth:i}}();var il=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Fresnel";this.color=e,this.bias=t,this.scale=o,this.intensity=i,this.factor=a,this.isMask=c,this.alpha=s,this.mode=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let o=new J(`vec3 fresnel(vec3 color, float bias, float scale, float intensity, float factor, bool isMask, float mask, float alpha, int mode, out float calpha) {
503
+ }`);return{vectorLinearWorldSpaceDepth:e,vectorLinearObjectSpaceDepth:t,vectorSphericalWorldSpaceDepth:o,vectorSphericalObjectSpaceDepth:i}}();var ol=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Fresnel";this.color=e,this.bias=t,this.scale=o,this.intensity=i,this.factor=a,this.isMask=c,this.alpha=s,this.mode=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let o=new J(`vec3 fresnel(vec3 color, float bias, float scale, float intensity, float factor, bool isMask, float mask, float alpha, int mode, out float calpha) {
504
504
  float fresnel = bias + scale * pow( abs( factor + dot( normalize( vWorldViewDir ), normalize( vWNormal ) ) ), intensity );
505
505
 
506
506
  float lalpha = clamp(fresnel, 0.0, 1.0) * alpha * mask;
@@ -508,7 +508,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
508
508
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
509
509
 
510
510
  return color;
511
- }`),i=e.include(o),a=[];return a.push(this.color.build(e,"c")),a.push(this.bias.build(e,"f")),a.push(this.scale.build(e,"f")),a.push(this.intensity.build(e,"f")),a.push(this.factor.build(e,"f")),a.push(this.isMask.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.mode.build(e,"i")),a.push(this.calpha),e.format(i+"("+a.join(",")+")",this.getType(e),t)}else return console.warn("FresnelNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}};var Gf=class extends ge{constructor(e,t,o,i,a,s,l,c,u){super("v3");this.nodeType="Gradient";this.gradientType=e,this.smooth=t,this.colors=o,this.steps=i,this.offset=a,this.morph=s,this.angle=l,this.isMask=u,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){e.define("GRAD_MAX",10),e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let o=e.include(Gf.Nodes.gradient),i=[];return i.push(this.gradientType.build(e,"i")),i.push(this.smooth.build(e,"b")),i.push(this.colors.build(e,"v4[]")),i.push(this.steps.build(e,"f[]")),i.push(this.offset.build(e,"v2")),i.push(this.morph.build(e,"v2")),i.push(this.angle.build(e,"f")),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("GradientNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},ka=Gf;ka.Nodes=function(){return{gradient:new J(`vec3 gradient(int gradientType, bool smoothed, vec4 colors[GRAD_MAX], float steps[GRAD_MAX], vec2 offset, vec2 morph, float angle, bool isMask, float mask, float alpha, out float calpha) {
511
+ }`),i=e.include(o),a=[];return a.push(this.color.build(e,"c")),a.push(this.bias.build(e,"f")),a.push(this.scale.build(e,"f")),a.push(this.intensity.build(e,"f")),a.push(this.factor.build(e,"f")),a.push(this.isMask.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.mode.build(e,"i")),a.push(this.calpha),e.format(i+"("+a.join(",")+")",this.getType(e),t)}else return console.warn("FresnelNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}};var Lf=class extends ge{constructor(e,t,o,i,a,s,l,c,u){super("v3");this.nodeType="Gradient";this.gradientType=e,this.smooth=t,this.colors=o,this.steps=i,this.offset=a,this.morph=s,this.angle=l,this.isMask=u,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){e.define("GRAD_MAX",10),e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let o=e.include(Lf.Nodes.gradient),i=[];return i.push(this.gradientType.build(e,"i")),i.push(this.smooth.build(e,"b")),i.push(this.colors.build(e,"v4[]")),i.push(this.steps.build(e,"f[]")),i.push(this.offset.build(e,"v2")),i.push(this.morph.build(e,"v2")),i.push(this.angle.build(e,"f")),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("GradientNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},ja=Lf;ja.Nodes=function(){return{gradient:new J(`vec3 gradient(int gradientType, bool smoothed, vec4 colors[GRAD_MAX], float steps[GRAD_MAX], vec2 offset, vec2 morph, float angle, bool isMask, float mask, float alpha, out float calpha) {
512
512
  vec4 color = colors[0];
513
513
  vec2 m = morph / vUv.xy;
514
514
  vec2 rot = vec2( 0.5 + m.x, m.y );
@@ -550,7 +550,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
550
550
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
551
551
 
552
552
  return color.xyz;
553
- }`)}}();var Ff=class extends ge{constructor(e,t,o,i,a){super("v3");this.nodeType="Matcap";this.texture=e,this.isMask=i,this.alpha=t,this.mode=o,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`,this.rotation=a}generate(e,t){if(e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let o=e.include(Ff.Nodes.matcap);e.require("normal"),e.requires.normal=!0;let i=[];return i.push(this.texture.generate(e,"t")),i.push("normal"),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.mode.build(e,"i")),i.push(this.calpha),i.push(this.rotation.build(e,"f")),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("MatcapNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Ua=Ff;Ua.Nodes=function(){return{matcap:new J(`vec3 matcap(sampler2D matcapTex, vec3 normal, bool isMask, float mask, float alpha, int mode, out float calpha, float rotation) {
553
+ }`)}}();var Vf=class extends ge{constructor(e,t,o,i,a){super("v3");this.nodeType="Matcap";this.texture=e,this.isMask=i,this.alpha=t,this.mode=o,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`,this.rotation=a}generate(e,t){if(e.isShader("fragment")){e.addFragmentVariable(this.calpha,"float");let o=e.include(Vf.Nodes.matcap);e.require("normal"),e.requires.normal=!0;let i=[];return i.push(this.texture.generate(e,"t")),i.push("normal"),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.mode.build(e,"i")),i.push(this.calpha),i.push(this.rotation.build(e,"f")),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("MatcapNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},ka=Vf;ka.Nodes=function(){return{matcap:new J(`vec3 matcap(sampler2D matcapTex, vec3 normal, bool isMask, float mask, float alpha, int mode, out float calpha, float rotation) {
554
554
  vec3 viewDir = normalize( vViewPosition );
555
555
  vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
556
556
  vec3 y = cross( viewDir, x );
@@ -564,7 +564,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
564
564
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
565
565
 
566
566
  return matcapColor.rgb;
567
- }`)}}();var al=(a=>(a.SIMPLEX="simplex3d",a.SIMPLEX_FRACTAL="simplex3dFractal",a.ASHIMA="simplexAshima",a.FBM="fbm",a.PERLIN="perlin",a.VORONOI="voronoi",a))(al||{}),Rt=function(){let r=new J(`vec3 random3(vec3 c) {
567
+ }`)}}();var Rt=function(){let r=new J(`vec3 random3(vec3 c) {
568
568
  float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
569
569
  vec3 r;
570
570
  r.z = fract(512.0*j);
@@ -573,7 +573,39 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
573
573
  j *= .125;
574
574
  r.y = fract(512.0*j);
575
575
  return r-0.5;
576
- }`),e=new J(`float simplex3d(vec3 p) {
576
+ }`),e=new J(`float simplexFast(vec3 p) {
577
+ vec3 s = floor(p + dot(p, vec3(F3)));
578
+ mediump vec3 x = p - s + dot(s, vec3(G3));
579
+ mediump vec3 hs = s;
580
+
581
+ mediump vec3 e = step(vec3(0.0), x - x.yzx);
582
+ mediump vec3 i1 = e*(1.0 - e.zxy);
583
+ mediump vec3 i2 = 1.0 - e.zxy*(1.0 - e);
584
+
585
+ mediump vec3 x1 = x - i1 + G3;
586
+ mediump vec3 x2 = x - i2 + 2.0*G3;
587
+ mediump vec3 x3 = x - 1.0 + 3.0*G3;
588
+
589
+ mediump vec4 w, d;
590
+
591
+ w.x = dot(x, x);
592
+ w.y = dot(x1, x1);
593
+ w.z = dot(x2, x2);
594
+ w.w = dot(x3, x3);
595
+
596
+ w = max(0.6 - w, 0.0);
597
+
598
+ d.x = dot(random3(hs), x);
599
+ d.y = dot(random3(hs + i1), x1);
600
+ d.z = dot(random3(hs + i2), x2);
601
+ d.w = dot(random3(hs + 1.0), x3);
602
+
603
+ w *= w;
604
+ w *= w;
605
+ d *= w;
606
+
607
+ return dot(d, vec4(52.0));
608
+ }`,[r]);e.keywords.F3=new Ge("float F3 0.3333333"),e.keywords.G3=new Ge("float G3 0.1666667");let t=new J(`float simplexPrecise(vec3 p) {
577
609
  vec3 s = floor(p + dot(p, vec3(F3)));
578
610
  vec3 x = p - s + dot(s, vec3(G3));
579
611
 
@@ -604,15 +636,15 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
604
636
  d *= w;
605
637
 
606
638
  return dot(d, vec4(52.0));
607
- }`,[r]);e.keywords.F3=new Fe("float F3 0.3333333"),e.keywords.G3=new Fe("float G3 0.1666667");let t=new J(`float simplex3dFractal(vec3 m) {
639
+ }`,[r]);t.keywords.F3=new Ge("float F3 0.3333333"),t.keywords.G3=new Ge("float G3 0.1666667");let o=new J(`float simplexFractal(vec3 m) {
608
640
  mat3 rot1 = mat3(-0.37, 0.36, 0.85,-0.14,-0.93, 0.34,0.92, 0.01,0.4);
609
641
  mat3 rot2 = mat3(-0.55,-0.39, 0.74, 0.33,-0.91,-0.24,0.77, 0.12,0.63);
610
642
  mat3 rot3 = mat3(-0.71, 0.52,-0.47,-0.08,-0.72,-0.68,-0.7,-0.45,0.56);
611
- return 0.5333333 * simplex3d(m * rot1)
612
- + 0.2666667 * simplex3d(2.0 * m * rot2)
613
- + 0.1333333 * simplex3d(4.0 * m * rot3)
614
- + 0.0666667 * simplex3d(8.0 * m);
615
- }`,[e]),o=new J("vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}"),i=new J("vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}"),a=new J(`float simplexAshima(vec3 v) {
643
+ return 0.5333333 * simplexFast(m * rot1)
644
+ + 0.2666667 * simplexFast(2.0 * m * rot2)
645
+ + 0.1333333 * simplexFast(4.0 * m * rot3)
646
+ + 0.0666667 * simplexFast(8.0 * m);
647
+ }`,[e]),i=new J("vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}"),a=new J("vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}"),s=new J(`float simplexAshima(vec3 v) {
616
648
  const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
617
649
  const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
618
650
  vec3 i = floor(v + dot(v, C.yyy) );
@@ -657,7 +689,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
657
689
  m = m * m;
658
690
  return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
659
691
  dot(p2,x2), dot(p3,x3) ) );
660
- }`,[o,i]),s=new J("vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}"),l=new J("vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);}",[s]),c=new J(`float noise(vec3 p){
692
+ }`,[i,a]),l=new J("vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}"),c=new J("vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);}",[l]),u=new J(`float noise(vec3 p){
661
693
  vec3 a = floor(p);
662
694
  vec3 d = p - a;
663
695
  d = d * d * (3.0 - 2.0 * d);
@@ -672,7 +704,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
672
704
  vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
673
705
  vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
674
706
  return o4.y * d.y + o4.x * (1.0 - d.y);
675
- }`,[l]),u=new J(`float fbm(vec3 x) {
707
+ }`,[c]),p=new J(`float fbm(vec3 x) {
676
708
  float v = 0.0;
677
709
  float a = 0.5;
678
710
  vec3 shift = vec3(100);
@@ -682,7 +714,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
682
714
  a *= 0.5;
683
715
  }
684
716
  return v;
685
- }`,[c]);u.keywords.NUM_OCTAVES=new Fe(`int NUM_OCTAVES ${5}`);let p=new J("vec3 fade(vec3 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}"),d=new J(`float perlin(vec3 P){
717
+ }`,[u]);p.keywords.NUM_OCTAVES=new Ge(`int NUM_OCTAVES ${5}`);let d=new J("vec3 fade(vec3 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}"),f=new J(`float perlin(vec3 P){
686
718
  vec3 Pi0 = floor(P);
687
719
  vec3 Pi1 = Pi0 + vec3(1.0);
688
720
  Pi0 = mod(Pi0, 289.0);
@@ -741,17 +773,17 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
741
773
  vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
742
774
  float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
743
775
  return 2.2 * n_xyz;
744
- }`,[o,i,p]),h=new J(`float hashwithoutsine13(vec3 p3)
776
+ }`,[i,a,d]),h=new J(`float hashwithoutsine13(vec3 p3)
745
777
  {
746
778
  p3 = fract(p3 * .1031);
747
779
  p3 += dot(p3, p3.yzx + 33.33);
748
780
  return fract((p3.x + p3.y) * p3.z);
749
- }`),f=new J(`vec3 hashwithoutsine33(vec3 p3)
781
+ }`),m=new J(`vec3 hashwithoutsine33(vec3 p3)
750
782
  {
751
783
  p3 = fract(p3 * vec3(.1031, .1030, .0973));
752
784
  p3 += dot(p3, p3.yxz+33.33);
753
785
  return fract((p3.xxy + p3.yxx)*p3.zyx);
754
- }`),m=new J(`float metric(in vec3 p)
786
+ }`),y=new J(`float metric(in vec3 p)
755
787
  {
756
788
  // L2
757
789
  return length(p);
@@ -759,17 +791,17 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
759
791
  // Chebyshev
760
792
  // vec3 a = abs(p);
761
793
  // return max(a.x, max(a.y, a.z));
762
- }`),y=new J(`float smin( float a, float b, float k )
794
+ }`),b=new J(`float smin( float a, float b, float k )
763
795
  {
764
796
  float h = smoothstep(0.0, 1.0, 0.5 + 0.5 * (b - a) / k);
765
797
  float correction = k * h * (1.0 - h);
766
798
  return mix(b, a, h) - correction;
767
- }`),g=new J(`float smax( float a, float b, float k )
799
+ }`),S=new J(`float smax( float a, float b, float k )
768
800
  {
769
801
  float h = smoothstep(1.0, 0.0, 0.5 + 0.5 * (a - b) / k);
770
802
  float correction = k * h * (1.0 - h);
771
803
  return mix(a, b, h) + correction;
772
- }`),v=new J(`float remap(float value, float input_min, float input_max, float output_min, float output_max) {
804
+ }`),P=new J(`float remap(float value, float input_min, float input_max, float output_min, float output_max) {
773
805
  // Compute width of each interval
774
806
  float input_width = input_max - input_min;
775
807
  float output_width = output_max - output_min;
@@ -779,7 +811,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
779
811
 
780
812
  // Convert the 0-1 range into a value in output range
781
813
  return output_min + (scaled * output_width);
782
- }`),w=new J(`float voronoi(in vec3 x, in int style, in float smoothness, in float seed, in int quality)
814
+ }`),C=new J(`float voronoi(in vec3 x, in int style, in float smoothness, in float seed, in int quality)
783
815
  {
784
816
  // Integer and fractional parts of this point's coordinates
785
817
  ivec3 p = ivec3(floor(x));
@@ -917,8 +949,8 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
917
949
  return hashwithoutsine13(vec3(p + mb) + seed);
918
950
  }
919
951
  }
920
- `,[h,f,m,y,g,v]);return{simplex:e,simplexFractal:t,simplexAshima:a,fbm:u,perlin:d,voronoi:w}}();var Ha=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,h,f,m,y,g,v,w,O){super("v3");this.nodeType="Noise";this.scale=e,this.size=t,this.move=o,this.fA=i,this.fB=a,this.distortion=s,this.colorA=l,this.colorB=c,this.colorC=u,this.colorD=p,this.noiseType=h,this.voronoiStyle=m,this.highCut=y,this.lowCut=g,this.smoothness=v,this.seed=w,this.quality=O,this.isMask=f,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t,o,i,a){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let s=Object.values(al)[this.noiseType.value],l=s=="voronoi"?`
921
- float v = ${s}(st + move, voronoiStyle, smoothness, seed, quality);
952
+ `,[h,m,y,b,S,P]);return{simplexFast:e,simplexPrecise:t,simplexFractal:o,simplexAshima:s,fbm:p,perlin:f,voronoi:C}}();var Ua=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,f,h,m,y,b,S,P,C){super("v3");this.nodeType="Noise";this.scale=e,this.size=t,this.move=o,this.fA=i,this.fB=a,this.distortion=s,this.colorA=l,this.colorB=c,this.colorC=u,this.colorD=p,this.noiseType=f,this.voronoiStyle=m,this.highCut=y,this.lowCut=b,this.smoothness=S,this.seed=P,this.quality=C,this.isMask=h,this.alpha=d,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t,o,i,a){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let l=["simplexFast","simplexFractal","simplexAshima","fbm","perlin","voronoi"][this.noiseType.value],c=l=="voronoi"?`
953
+ float v = ${l}(st + move, voronoiStyle, smoothness, seed, quality);
922
954
 
923
955
  // Apply clipping to colors
924
956
  v = remap(v, lowCut, highCut, 0.0, 1.0);
@@ -928,18 +960,18 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
928
960
  // Note that the voronoi mode only uses colors "A" and "C" from the UI
929
961
  vec4 color = mix(colorA, colorC, v);
930
962
  `:`
931
- vec3 q = vec3(${s}(st),
932
- ${s}(st + vec3(1.0)),
933
- ${s}(st + vec3(1.0)));
934
- vec3 r = vec3(${s}(st + vec3(distortion, 1.0) * q + vec3(fA, 1.0) + move),
935
- ${s}(st + vec3(distortion, 1.0) * q + vec3(fB, 1.0) + move),
936
- ${s}(st * q));
937
- float f = ${s}(st + r);
963
+ vec3 q = vec3(${l}(st),
964
+ ${l}(st + vec3(1.0)),
965
+ ${l}(st + vec3(1.0)));
966
+ vec3 r = vec3(${l}(st + vec3(distortion, 1.0) * q + vec3(fA, 1.0) + move),
967
+ ${l}(st + vec3(distortion, 1.0) * q + vec3(fB, 1.0) + move),
968
+ ${l}(st * q));
969
+ float f = ${l}(st + r);
938
970
  vec4 color;
939
971
  color = mix(colorA, colorB, clamp((f * f) * 4.0, 0.0, 1.0));
940
972
  color = mix(color, colorC, clamp(length(q), 0.0, 1.0));
941
973
  color = mix(color, colorD, clamp(length(r.x), 0.0, 1.0));
942
- `,c=new J(`vec3 ${s}customNoise(float scale, vec3 size, float move, vec2 fA, vec2 fB, vec2 distortion, vec4 colorA, vec4 colorB, vec4 colorC, vec4 colorD, int voronoiStyle, float highCut, float lowCut, float smoothness, float seed, int quality, bool isMask, float mask, float alpha, out float calpha)
974
+ `,u=new J(`vec3 ${l}customNoise(float scale, vec3 size, float move, vec2 fA, vec2 fB, vec2 distortion, vec4 colorA, vec4 colorB, vec4 colorC, vec4 colorD, int voronoiStyle, float highCut, float lowCut, float smoothness, float seed, int quality, bool isMask, float mask, float alpha, out float calpha)
943
975
  {
944
976
  // Prevent scale of zero
945
977
  scale = max(abs(scale), 0.001);
@@ -947,14 +979,14 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
947
979
  vec3 st = position / size;
948
980
  st /= scale;
949
981
 
950
- ${l}
982
+ ${c}
951
983
 
952
984
  float lalpha = alpha * color.a * mask;
953
985
  calpha = mix(lalpha / clamp(lalpha + accumAlpha, 0.00001, 1.0), lalpha, float(isMask));
954
986
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
955
987
 
956
988
  return clamp(color, 0.0, 1.0).rgb;
957
- }`,[Rt.simplex,Rt.simplexFractal,Rt.simplexAshima,Rt.fbm,Rt.perlin,Rt.voronoi]),u=e.include(c),p=[];return p.push(this.scale.build(e,"f")),p.push(this.size.build(e,"v3")),p.push(this.move.build(e,"f")),p.push(this.fA.build(e,"v2")),p.push(this.fB.build(e,"v2")),p.push(this.distortion.build(e,"v2")),p.push(this.colorA.build(e,"v4")),p.push(this.colorB.build(e,"v4")),p.push(this.colorC.build(e,"v4")),p.push(this.colorD.build(e,"v4")),p.push(this.voronoiStyle.build(e,"i")),p.push(this.highCut.build(e,"f")),p.push(this.lowCut.build(e,"f")),p.push(this.smoothness.build(e,"f")),p.push(this.seed.build(e,"f")),p.push(this.quality.build(e,"i")),p.push(this.isMask.build(e,"b")),p.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),p.push(this.alpha.build(e,"f")),p.push(this.calpha),e.format(u+"("+p.join(",")+")",this.getType(e),t)}};Ha.numOctaves=5;var jf=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,h,f,m,y,g){super("v3");this.nodeType="Outline";this.firstTime=!0,this.outlineColor=e,this.contourColor=t,this.outlineWidth=o,this.contourWidth=i,this.contourThreshold=a,this.outlineThreshold=s,this.contourFrequency=l,this.outlineSmoothing=c,this.contourDirection=u,this.positionalLines=p,this.compensation=d,this.resolution=h,this.normalMap=f,this.depthMap=m,this.pixelRatio=y,this.alpha=g,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){let o=`g${this.uuid.toString().replace(/-/g,"")}`;if(e.require("vWorldViewDir"),e.require("worldNormal"),e.extensions.derivatives=!0,this.compensation.value&&e.define("OUTLINE_COMPENSATION",`${o}_offset`),this.firstTime){let i=this.outlineWidth.build(e,"f"),a=this.resolution.build(e,"v2"),s=this.compensation.build(e,"b"),l=this.pixelRatio.build(e,"f");e.addVertexParsVariable("randomColor","attribute vec3"),e.addVertexParsVariable("extrudeNormal","attribute vec3"),e.addVertexParsVariable(i,"uniform float"),e.addVertexParsVariable(a,"uniform vec2"),e.addVertexParsVariable(s,"uniform bool"),e.addVertexParsVariable(l,"uniform float"),e.addVertexParsVariable("vID","flat out float"),e.addFragmentParsVariable("vID","flat in float"),e.addVertexFinalCode(`
989
+ }`,[Rt.simplexFast,Rt.simplexFractal,Rt.simplexAshima,Rt.fbm,Rt.perlin,Rt.voronoi]),p=e.include(u),d=[];return d.push(this.scale.build(e,"f")),d.push(this.size.build(e,"v3")),d.push(this.move.build(e,"f")),d.push(this.fA.build(e,"v2")),d.push(this.fB.build(e,"v2")),d.push(this.distortion.build(e,"v2")),d.push(this.colorA.build(e,"v4")),d.push(this.colorB.build(e,"v4")),d.push(this.colorC.build(e,"v4")),d.push(this.colorD.build(e,"v4")),d.push(this.voronoiStyle.build(e,"i")),d.push(this.highCut.build(e,"f")),d.push(this.lowCut.build(e,"f")),d.push(this.smoothness.build(e,"f")),d.push(this.seed.build(e,"f")),d.push(this.quality.build(e,"i")),d.push(this.isMask.build(e,"b")),d.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),d.push(this.alpha.build(e,"f")),d.push(this.calpha),e.format(p+"("+d.join(",")+")",this.getType(e),t)}};Ua.numOctaves=5;var zf=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,f,h,m,y,b){super("v3");this.nodeType="Outline";this.firstTime=!0,this.outlineColor=e,this.contourColor=t,this.outlineWidth=o,this.contourWidth=i,this.contourThreshold=a,this.outlineThreshold=s,this.contourFrequency=l,this.outlineSmoothing=c,this.contourDirection=u,this.positionalLines=p,this.compensation=d,this.resolution=f,this.normalMap=h,this.depthMap=m,this.pixelRatio=y,this.alpha=b,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){let o=`g${this.uuid.toString().replace(/-/g,"")}`;if(e.require("vWorldViewDir"),e.require("worldNormal"),e.extensions.derivatives=!0,this.compensation.value&&e.define("OUTLINE_COMPENSATION",`${o}_offset`),this.firstTime){let i=this.outlineWidth.build(e,"f"),a=this.resolution.build(e,"v2"),s=this.compensation.build(e,"b"),l=this.pixelRatio.build(e,"f");e.addVertexParsVariable("randomColor","attribute vec3"),e.addVertexParsVariable("extrudeNormal","attribute vec3"),e.addVertexParsVariable(i,"uniform float"),e.addVertexParsVariable(a,"uniform vec2"),e.addVertexParsVariable(s,"uniform bool"),e.addVertexParsVariable(l,"uniform float"),e.addVertexParsVariable("vID","flat out float"),e.addFragmentParsVariable("vID","flat in float"),e.addVertexFinalCode(`
958
990
  vID = randomColor.r;
959
991
  vec2 ${o}_offset = vec2(0.0);
960
992
  if (${s}) {
@@ -969,7 +1001,7 @@ vec3 sphericalTexture(vec3 normal, sampler2D tex, vec2 textureSize, float crop,
969
1001
  // if this offset is the biggest of all the potential offsets
970
1002
  gl_Position = ${o}_clipPosition;
971
1003
  }
972
- `)}if(e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let i=e.include(jf.Nodes.outline),a=[];return a.push(this.outlineColor.build(e,"c")),a.push(this.contourColor.build(e,"c")),a.push(this.outlineWidth.build(e,"f")),a.push(this.contourWidth.build(e,"f")),a.push(this.contourThreshold.build(e,"f")),a.push(this.outlineThreshold.build(e,"f")),a.push(this.contourFrequency.build(e,"f")),a.push(this.outlineSmoothing.build(e,"f")),a.push(this.contourDirection.build(e,"v3")),a.push(this.positionalLines.build(e,"b")),a.push(this.resolution.build(e,"v2")),a.push(this.normalMap.getTexture(e,"t")),a.push(this.depthMap.getTexture(e,"t")),a.push(this.pixelRatio.build(e,"f")),a.push(this.compensation.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.calpha),this.firstTime=!this.firstTime,e.format(i+"("+a.join(",")+")",this.getType(e),t)}else return console.warn("OutlineNode is not compatible with "+e.shader+" shader."),""}},Wa=jf;Wa.Nodes=function(){let e=new J(`
1004
+ `)}if(e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let i=e.include(zf.Nodes.outline),a=[];return a.push(this.outlineColor.build(e,"c")),a.push(this.contourColor.build(e,"c")),a.push(this.outlineWidth.build(e,"f")),a.push(this.contourWidth.build(e,"f")),a.push(this.contourThreshold.build(e,"f")),a.push(this.outlineThreshold.build(e,"f")),a.push(this.contourFrequency.build(e,"f")),a.push(this.outlineSmoothing.build(e,"f")),a.push(this.contourDirection.build(e,"v3")),a.push(this.positionalLines.build(e,"b")),a.push(this.resolution.build(e,"v2")),a.push(this.normalMap.getTexture(e,"t")),a.push(this.depthMap.getTexture(e,"t")),a.push(this.pixelRatio.build(e,"f")),a.push(this.compensation.build(e,"b")),a.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),a.push(this.alpha.build(e,"f")),a.push(this.calpha),this.firstTime=!this.firstTime,e.format(i+"("+a.join(",")+")",this.getType(e),t)}else return console.warn("OutlineNode is not compatible with "+e.shader+" shader."),""}},Ha=zf;Ha.Nodes=function(){let e=new J(`
973
1005
  float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outlineWidth, float pixelRatio)
974
1006
  {
975
1007
  vec2 halton = haltonSequence[frameIndex];
@@ -1118,7 +1150,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1118
1150
  accumAlpha += ( 1.0 - accumAlpha ) * lalpha;
1119
1151
 
1120
1152
  return result;
1121
- }`,[e])}}();var uo=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,h,f,m,y,g,v,w){super("v3");this.nodeType="Pattern";this.style=e,this.projection=t,this.axis=o,this.blending=i,this.offset=a,this.colorA=s,this.colorB=l,this.frequency=c,this.size=u,this.variation=p,this.smoothness=d,this.zigzag=h,this.rotation=f,this.vertical=m,this.horizontal=y,this.sides=g,this.isMask=w,this.alpha=v,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){e.require("position"),e.require("uv"),e.requires.uv=[!0],e.require("normal"),e.requires.normal=!0,e.addFragmentVariable(this.calpha,"float");let o;switch(this.style.value){case 0:o="circle";break;case 1:o="ring";break;case 2:o="polygon";break;case 3:o="xcross";break;case 4:o="diamond";break;case 5:o="checkerboard";break;case 6:o="line";break;case 7:o="wave";break;default:o="circle";break}let i=`g${this.uuid.toString().replace(/-/g,"")}`,a=new J(`float hashwithoutsine12(vec2 p)
1153
+ }`,[e])}}();var uo=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d,f,h,m,y,b,S,P){super("v3");this.nodeType="Pattern";this.style=e,this.projection=t,this.axis=o,this.blending=i,this.offset=a,this.colorA=s,this.colorB=l,this.frequency=c,this.size=u,this.variation=p,this.smoothness=d,this.zigzag=f,this.rotation=h,this.vertical=m,this.horizontal=y,this.sides=b,this.isMask=P,this.alpha=S,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.isShader("fragment")){e.require("position"),e.require("uv"),e.requires.uv=[!0],e.require("normal"),e.requires.normal=!0,e.addFragmentVariable(this.calpha,"float");let o;switch(this.style.value){case 0:o="circle";break;case 1:o="ring";break;case 2:o="polygon";break;case 3:o="xcross";break;case 4:o="diamond";break;case 5:o="checkerboard";break;case 6:o="line";break;case 7:o="wave";break;default:o="circle";break}let i=`g${this.uuid.toString().replace(/-/g,"")}`,a=new J(`float hashwithoutsine12(vec2 p)
1122
1154
  {
1123
1155
  vec3 p3 = fract(vec3(p.xyx) * .1031);
1124
1156
  p3 += dot(p3, p3.yzx + 33.33);
@@ -1132,7 +1164,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1132
1164
  cos(radians) * (uv.y - mid) - sin(radians) * (uv.x - mid) + mid
1133
1165
  );
1134
1166
  return repeat ? fract(rotated): rotated;
1135
- }`),l="";if(this.projection.value===4){let d=this.style.value===2?`${o}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,h=this.style.value===2?`${o}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,f=this.style.value===2?`${o}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation)`;l=`
1167
+ }`),l="";if(this.projection.value===4){let d=this.style.value===2?`${o}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv0, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,f=this.style.value===2?`${o}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv1, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,h=this.style.value===2?`${o}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(uv2, frequency, size, variation, smoothness_remapped, zigzag, rotation)`;l=`
1136
1168
  vec3 p = position;
1137
1169
  float factor = 0.0125;
1138
1170
  vec2 uv0 = fract(p.xy * factor);
@@ -1144,8 +1176,8 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1144
1176
  uv2 = rotate_uv(uv2 + offset, rotation, true);
1145
1177
 
1146
1178
  float d0 = ${d};
1147
- float d1 = ${h};
1148
- float d2 = ${f};
1179
+ float d1 = ${f};
1180
+ float d2 = ${h};
1149
1181
 
1150
1182
  // Range from 3 to 128 seems to be good
1151
1183
  float exponent = (1.0 - blending) * 125.0 + 3.0;
@@ -1160,20 +1192,20 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1160
1192
  float draw = d0 + d1 + d2;
1161
1193
 
1162
1194
  vec2 custom_uv = uv0 * weights.z + uv1 * weights.x + uv2 * weights.y;
1163
- `}else{let d=this.style.value===2?`${o}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,h="";this.axis.value===0?h=`float radius = length(p);
1195
+ `}else{let d=this.style.value===2?`${o}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation, sides)`:`${o}(custom_uv, frequency, size, variation, smoothness_remapped, zigzag, rotation)`,f="";this.axis.value===0?f=`float radius = length(p);
1164
1196
  float theta = atan(p.y, p.z);
1165
- float phi = acos(p.x / radius);`:this.axis.value===1?h=`float radius = length(p);
1197
+ float phi = acos(p.x / radius);`:this.axis.value===1?f=`float radius = length(p);
1166
1198
  float theta = atan(p.x, p.z);
1167
- float phi = acos(p.y / radius);`:(this.axis.value,h=`float radius = length(p);
1199
+ float phi = acos(p.y / radius);`:(this.axis.value,f=`float radius = length(p);
1168
1200
  float theta = atan(p.y, p.x);
1169
- float phi = acos(p.z / radius);`);let f="";switch(this.projection.value){case 0:f="custom_uv = vUv.st;";break;case 1:break;case 2:f=`
1201
+ float phi = acos(p.z / radius);`);let h="";switch(this.projection.value){case 0:h="custom_uv = vUv.st;";break;case 1:break;case 2:h=`
1170
1202
  vec3 p = position;
1171
- ${h}
1203
+ ${f}
1172
1204
  custom_uv = vec2(theta, phi);
1173
1205
  custom_uv /= PI;
1174
1206
  `;break;case 3:break;default:break}l=`
1175
1207
  vec2 custom_uv;
1176
- ${f}
1208
+ ${h}
1177
1209
 
1178
1210
  custom_uv += offset;
1179
1211
  custom_uv = fract(custom_uv);
@@ -1204,7 +1236,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1204
1236
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
1205
1237
 
1206
1238
  return clamp(color, 0.0, 1.0).rgb;
1207
- }`,[s,a,uo.DrawFunctions.circle,uo.DrawFunctions.ring,uo.DrawFunctions.polygon,uo.DrawFunctions.cross,uo.DrawFunctions.diamond,uo.DrawFunctions.checkerboard,uo.DrawFunctions.line,uo.DrawFunctions.wave]),u=e.include(c),p=[];return p.push("normal"),p.push(this.blending.build(e,"f")),p.push(this.style.build(e,"i")),p.push(this.offset.build(e,"v2")),p.push(this.colorA.build(e,"v4")),p.push(this.colorB.build(e,"v4")),p.push(this.frequency.build(e,"v2")),p.push(this.size.build(e,"f")),p.push(this.variation.build(e,"f")),p.push(this.smoothness.build(e,"f")),p.push(this.zigzag.build(e,"f")),p.push(this.rotation.build(e,"f")),p.push(this.vertical.build(e,"v2")),p.push(this.horizontal.build(e,"v2")),p.push(this.sides.build(e,"i")),p.push(this.isMask.build(e,"b")),p.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),p.push(this.alpha.build(e,"f")),p.push(this.calpha),e.format(u+"("+p.join(",")+")",this.getType(e),t)}else return console.warn("PatterNode is not compatible with "+e.shader+" shader."),e.format("vec3(0.0)",this.getType(e),t)}},qa=uo;qa.DrawFunctions=function(){let e=new J(`float hashwithoutsine12(vec2 p) {
1239
+ }`,[s,a,uo.DrawFunctions.circle,uo.DrawFunctions.ring,uo.DrawFunctions.polygon,uo.DrawFunctions.cross,uo.DrawFunctions.diamond,uo.DrawFunctions.checkerboard,uo.DrawFunctions.line,uo.DrawFunctions.wave]),u=e.include(c),p=[];return p.push("normal"),p.push(this.blending.build(e,"f")),p.push(this.style.build(e,"i")),p.push(this.offset.build(e,"v2")),p.push(this.colorA.build(e,"v4")),p.push(this.colorB.build(e,"v4")),p.push(this.frequency.build(e,"v2")),p.push(this.size.build(e,"f")),p.push(this.variation.build(e,"f")),p.push(this.smoothness.build(e,"f")),p.push(this.zigzag.build(e,"f")),p.push(this.rotation.build(e,"f")),p.push(this.vertical.build(e,"v2")),p.push(this.horizontal.build(e,"v2")),p.push(this.sides.build(e,"i")),p.push(this.isMask.build(e,"b")),p.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),p.push(this.alpha.build(e,"f")),p.push(this.calpha),e.format(u+"("+p.join(",")+")",this.getType(e),t)}else return console.warn("PatterNode is not compatible with "+e.shader+" shader."),e.format("vec3(0.0)",this.getType(e),t)}},Wa=uo;Wa.DrawFunctions=function(){let e=new J(`float hashwithoutsine12(vec2 p) {
1208
1240
  vec3 p3 = fract(vec3(p.xyx) * 0.1031);
1209
1241
  p3 += dot(p3, p3.yzx + 33.33);
1210
1242
  return fract((p3.x + p3.y) * p3.z);
@@ -1369,21 +1401,22 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1369
1401
  float s = mix(size, size * rand, variation);
1370
1402
 
1371
1403
  return smoothstep(-smoothness, smoothness, distance_estimate - s * 0.5);
1372
- }`);return{tileAndCenter:t,circle:o,ring:i,polygon:a,cross:s,diamond:l,checkerboard:c,line:u,wave:p}}();var kf=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Rainbow";this.filmThickness=e,this.movement=t,this.wavelengths=o,this.noiseStrength=i,this.noiseScale=a,this.offset=s,this.isMask=c,this.alpha=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let o=e.include(kf.Nodes.rainbow),i=[];return i.push(this.filmThickness.build(e,"f")),i.push(this.movement.build(e,"f")),i.push(this.wavelengths.build(e,"v3")),i.push(this.noiseStrength.build(e,"f")),i.push(this.noiseScale.build(e,"f")),i.push(this.offset.build(e,"v3")),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("RainbowNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},$a=kf;$a.Nodes=function(){let e=new J(`vec3 attenuation(vec3 wavelengths, float filmThickness, float movement, float noiseStrength, float noiseScale, vec3 offset) {
1373
- vec3 st = position / noiseScale;
1374
- vec3 q = vec3(simplex3d(st),
1375
- simplex3d(st + vec3(1.0)),
1376
- simplex3d(st + vec3(1.0)));
1377
-
1378
- vec3 r = vec3(simplex3d(st + vec3(1.4, 1.3, 1.0) * q + vec3(1.7, 9.2, 1.0)),
1379
- simplex3d(st + vec3(2.0, 1.2, 1.0) * q + vec3(8.3, 2.8, 1.0)),
1380
- simplex3d(st * q));
1404
+ }`);return{tileAndCenter:t,circle:o,ring:i,polygon:a,cross:s,diamond:l,checkerboard:c,line:u,wave:p}}();var Gf=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Rainbow";this.filmThickness=e,this.movement=t,this.wavelengths=o,this.noiseStrength=i,this.noiseScale=a,this.offset=s,this.isMask=c,this.alpha=l,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("vWorldViewDir"),e.require("worldNormal"),e.isShader("fragment")){e.require("uv"),e.requires.uv=[!0],e.addFragmentVariable(this.calpha,"float");let o=e.include(Gf.Nodes.rainbow),i=[];return i.push(this.filmThickness.build(e,"f")),i.push(this.movement.build(e,"f")),i.push(this.wavelengths.build(e,"v3")),i.push(this.noiseStrength.build(e,"f")),i.push(this.noiseScale.build(e,"f")),i.push(this.offset.build(e,"v3")),i.push(this.isMask.build(e,"b")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("RainbowNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},qa=Gf;qa.Nodes=function(){let e=new J(`vec3 attenuation(vec3 wavelengths, float filmThickness, float movement, float noiseStrength, float noiseScale, vec3 offset) {
1405
+ float f = 0.0;
1406
+
1407
+ if (noiseStrength != 0.0) {
1408
+ vec3 st = position / noiseScale;
1409
+ float noise = simplexFast(1.6 * st + vec3(1.8, 1.5, 1.9) * simplexFast(st) + vec3(1.7, 9.2, 1.0));
1410
+ f = noise * noiseStrength;
1411
+ }
1381
1412
 
1382
- float noise = simplex3d(st + r);
1413
+ vec3 waves = wavelengths * vec3(1.0, 0.8, 0.6) + 1.0;
1414
+ float angle = dot(normalize(vWorldViewDir + (offset * -0.001)), normalize(vWNormal));
1383
1415
 
1384
- return .5 + .5 * cos((((filmThickness + (noise * noiseStrength)) / (vec3(wavelengths.r * 1.0, wavelengths.g * 0.8, wavelengths.b * 0.6) + 1.0)) * dot(normalize(vWorldViewDir + (offset * -0.001)), normalize(vWNormal))) + movement);
1385
- }`,[Rt.simplex]);return{rainbow:new J(`vec3 rainbow(float filmThickness, float movement, vec3 wavelengths, float noiseStrength, float noiseScale, vec3 offset, bool isMask, float mask, float alpha, out float calpha) {
1386
- vec3 res = clamp(attenuation(wavelengths, filmThickness, movement, noiseStrength, noiseScale, offset), 0.0, 2.0);
1416
+ mediump vec3 color = cos((((filmThickness + f) / waves) * angle) + movement);
1417
+ return .5 + .5 * color;
1418
+ }`,[Rt.simplexFast]);return{rainbow:new J(`vec3 rainbow(float filmThickness, float movement, vec3 wavelengths, float noiseStrength, float noiseScale, vec3 offset, bool isMask, float mask, float alpha, out float calpha) {
1419
+ mediump vec3 res = clamp(attenuation(wavelengths, filmThickness, movement, noiseStrength, noiseScale, offset), 0.0, 2.0);
1387
1420
 
1388
1421
  float rainbowContribution = clamp(res.r + res.g + res.b, 0.0, 1.0);
1389
1422
 
@@ -1392,7 +1425,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1392
1425
  accumAlpha += (1.0 - accumAlpha) * lalpha * (1.0 - float(isMask));
1393
1426
 
1394
1427
  return res;
1395
- }`,[e])}}();var Uf=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p){super("v3");this.nodeType="Toon";this.positioning=e,this.colors=t,this.steps=o,this.source=i,this.isWorldSpace=a,this.noiseStrength=s,this.noiseScale=l,this.shadowColor=c,this.offset=u,this.alpha=p,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("worldNormal"),e.require("worldPosition"),e.isShader("fragment")){e.define("COLORS_MAX",10),e.addFragmentVariable(this.calpha,"float");let o=e.include(Uf.Nodes.toon),i=[];return i.push(this.positioning.build(e,"i")),i.push(this.colors.build(e,"v4[]")),i.push(this.steps.build(e,"f[]")),i.push(this.source.build(e,"v3")),i.push(this.isWorldSpace.build(e,"b")),i.push(this.noiseStrength.build(e,"f")),i.push(this.noiseScale.build(e,"f")),i.push(this.shadowColor.build(e,"v4")),i.push(this.offset.build(e,"v3")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("ToonNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Ya=Uf;Ya.Nodes=function(){let e=new J(`float rand(float n) {
1428
+ }`,[e])}}();var Ff=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p){super("v3");this.nodeType="Toon";this.positioning=e,this.colors=t,this.steps=o,this.source=i,this.isWorldSpace=a,this.noiseStrength=s,this.noiseScale=l,this.shadowColor=c,this.offset=u,this.alpha=p,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.require("worldNormal"),e.require("worldPosition"),e.isShader("fragment")){e.define("COLORS_MAX",10),e.addFragmentVariable(this.calpha,"float");let o=e.include(Ff.Nodes.toon),i=[];return i.push(this.positioning.build(e,"i")),i.push(this.colors.build(e,"v4[]")),i.push(this.steps.build(e,"f[]")),i.push(this.source.build(e,"v3")),i.push(this.isWorldSpace.build(e,"b")),i.push(this.noiseStrength.build(e,"f")),i.push(this.noiseScale.build(e,"f")),i.push(this.shadowColor.build(e,"v4")),i.push(this.offset.build(e,"v3")),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("ToonNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},$a=Ff;$a.Nodes=function(){let e=new J(`float rand(float n) {
1396
1429
  return fract(sin(n) * 43758.5453123);
1397
1430
  }`),t=new J(`float hash1(float p) {
1398
1431
  p = fract(p * 0.011);
@@ -1593,9 +1626,9 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1593
1626
 
1594
1627
  // Position warp noise
1595
1628
  // vec3 offset = vec3(
1596
- // simplex3d(st),
1597
- // simplex3d(st + vec3(111.1, 143.89, 217.19)),
1598
- // simplex3d(st + vec3(171.1, 247.89, 117.23))
1629
+ // simplexFast(st),
1630
+ // simplexFast(st + vec3(111.1, 143.89, 217.19)),
1631
+ // simplexFast(st + vec3(171.1, 247.89, 117.23))
1599
1632
  // );
1600
1633
  // st += offset;
1601
1634
  // float noise = valueNoise(st);
@@ -1628,7 +1661,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1628
1661
 
1629
1662
  return color.xyz;
1630
1663
 
1631
- }`,[Rt.simplex,e,o,a])}}();import{Vector2 as _b}from"three";var Db=function(){return{textureBicubic:new J(`float w0( float a ) {
1664
+ }`,[Rt.simplexFast,e,o,a])}}();import{Vector2 as Db}from"three";var Nb=function(){return{textureBicubic:new J(`float w0( float a ) {
1632
1665
  return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
1633
1666
  }
1634
1667
 
@@ -1692,7 +1725,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1692
1725
  vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
1693
1726
  vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
1694
1727
  return mix( fSample, cSample, fract( lod ) );
1695
- }`)}}();function Bb(n,r){return n>=r?new _b(r/n,1):new _b(1,n/r)}var Hf=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Transmission";this.thickness=e,this.ior=t,this.roughness=o,this.transmissionSamplerSize=i,this.transmissionSamplerMap=a,this.transmissionDepthMap=s,this.aspectRatio=l,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0,e.isShader("fragment")){e.define("NUM_SAMPLES",6),e.define("BLUR_SLOD",Math.pow(2,Te.transmissionLod.value)),e.require("worldPosition"),e.requires.worldNormal=!0,e.requires.modelMatrix=!0,e.requires.projectionMatrix=!0,e.addFragmentVariable(this.calpha,"float");let o=e.include(Hf.Nodes.transmission),i=[];return i.push(this.thickness.build(e,"f")),i.push(this.ior.build(e,"f")),i.push(this.roughness.build(e,"f")),i.push(this.transmissionSamplerSize.build(e,"v2")),i.push(this.transmissionSamplerMap.getTexture(e,"t")),i.push(this.transmissionDepthMap.getTexture(e,"t")),i.push(this.aspectRatio.build(e,"v2")),i.push("normal"),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("TransmissionNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Xa=Hf;Xa.Nodes=function(){let e=new J(`vec3 blur(sampler2D sp, vec2 U, vec2 scale, float lod, sampler2D dm, vec2 unrefractedU, vec2 aspectRatio) {
1728
+ }`)}}();function _b(n,r){return n>=r?new Db(r/n,1):new Db(1,n/r)}var jf=class extends ge{constructor(e,t,o,i,a,s,l,c){super("v3");this.nodeType="Transmission";this.thickness=e,this.ior=t,this.roughness=o,this.transmissionSamplerSize=i,this.transmissionSamplerMap=a,this.transmissionDepthMap=s,this.aspectRatio=l,this.alpha=c,this.calpha=`g${this.uuid.toString().replace(/-/g,"")}_calpha`}generate(e,t){if(e.extensions.shaderTextureLOD=!0,e.extensions.derivatives=!0,e.isShader("fragment")){e.define("NUM_SAMPLES",6),e.define("BLUR_SLOD",Math.pow(2,Te.transmissionLod.value)),e.require("worldPosition"),e.requires.worldNormal=!0,e.requires.modelMatrix=!0,e.requires.projectionMatrix=!0,e.addFragmentVariable(this.calpha,"float");let o=e.include(jf.Nodes.transmission),i=[];return i.push(this.thickness.build(e,"f")),i.push(this.ior.build(e,"f")),i.push(this.roughness.build(e,"f")),i.push(this.transmissionSamplerSize.build(e,"v2")),i.push(this.transmissionSamplerMap.getTexture(e,"t")),i.push(this.transmissionDepthMap.getTexture(e,"t")),i.push(this.aspectRatio.build(e,"v2")),i.push("normal"),i.push(this.mask?`luminance(${this.mask.flow(e,"v3").result})`:"1.0"),i.push(this.alpha.build(e,"f")),i.push(this.calpha),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("TransmissionNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Ya=jf;Ya.Nodes=function(){let e=new J(`vec3 blur(sampler2D sp, vec2 U, vec2 scale, float lod, sampler2D dm, vec2 unrefractedU, vec2 aspectRatio) {
1696
1729
  // Slightly modified version of this:
1697
1730
  // https://www.shadertoy.com/view/ltScRG
1698
1731
 
@@ -1752,7 +1785,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1752
1785
  float lod = applyIorToRoughness(roughness, ior);
1753
1786
  return blur(transmissionSamplerMap, fragCoord, vec2(lod), min(framebufferLod / 5.5, 8.5), transmissionDepthMap, unrefractedCoords, aspectRatio);
1754
1787
  #endif
1755
- }`,[Db.textureBicubic,o,e]),a=new J(`vec3 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness, vec2 transmissionSamplerSize, sampler2D transmissionSamplerMap, sampler2D transmissionDepthMap, vec2 aspectRatio ) {
1788
+ }`,[Nb.textureBicubic,o,e]),a=new J(`vec3 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness, vec2 transmissionSamplerSize, sampler2D transmissionSamplerMap, sampler2D transmissionDepthMap, vec2 aspectRatio ) {
1756
1789
  vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
1757
1790
  vec3 refractedRayExit = position + transmissionRay;
1758
1791
 
@@ -1783,20 +1816,20 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1783
1816
  accumAlpha += ( 1.0 - accumAlpha ) * alpha;
1784
1817
 
1785
1818
  return transmission;
1786
- }`,[a])}}();var Wf=(e=>(e.NOISE="noise",e.MAP="map",e))(Wf||{}),qf=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d){super("v3");this.displacementTypeIndex=new Be(0);this.nodeType="VertexDisplacement";this.intensity=e,this.movementOrTexture=t,Object.values(Wf)[this.displacementTypeIndex.value]==="map"&&(this.mat=new La(this.movementOrTexture.value.matrix)),this.cropOrOffset=o,this.scale=p,this.noiseFunctionIndex=d,this.voronoiStyle=i,this.smoothness=a,this.seed=s,this.highCut=l,this.lowCut=c,this.quality=u}generate(e,t){if(e.isShader("vertex")){e.define("USE_LAYER_DISPLACE");let o,i=[];switch(i.push("displaced_position"),i.push("displaced_normal"),Object.values(Wf)[this.displacementTypeIndex.value]){case"map":{o=e.include(qf.Nodes.map),i.push(this.movementOrTexture.getTexture(e,"t")),i.push("uv"),i.push(this.cropOrOffset.build(e,"f")),this.mat&&i.push(this.mat.build(e,"mat3"));break}case"noise":{let s=Object.values(al)[this.noiseFunctionIndex.value],l=new J(`vec3 orthogonal(vec3 v) {
1819
+ }`,[a])}}();var kf=(e=>(e.NOISE="noise",e.MAP="map",e))(kf||{}),Uf=class extends ge{constructor(e,t,o,i,a,s,l,c,u,p,d){super("v3");this.displacementTypeIndex=new Be(0);this.nodeType="VertexDisplacement";this.intensity=e,this.movementOrTexture=t,Object.values(kf)[this.displacementTypeIndex.value]==="map"&&(this.mat=new Ra(this.movementOrTexture.value.matrix)),this.cropOrOffset=o,this.scale=p,this.noiseFunctionIndex=d,this.voronoiStyle=i,this.smoothness=a,this.seed=s,this.highCut=l,this.lowCut=c,this.quality=u}generate(e,t){if(e.isShader("vertex")){e.define("USE_LAYER_DISPLACE");let o,i=[];switch(i.push("displaced_position"),i.push("displaced_normal"),Object.values(kf)[this.displacementTypeIndex.value]){case"map":{o=e.include(Uf.Nodes.map),i.push(this.movementOrTexture.getTexture(e,"t")),i.push("uv"),i.push(this.cropOrOffset.build(e,"f")),this.mat&&i.push(this.mat.build(e,"mat3"));break}case"noise":{let l=["simplexPrecise","simplexFractal","simplexAshima","fbm","perlin","voronoi"][this.noiseFunctionIndex.value],c=new J(`vec3 orthogonal(vec3 v) {
1787
1820
  return normalize(abs(v.x) > abs(v.z) ? vec3(-v.y, v.x, 0.0) : vec3(0.0, -v.z, v.y));
1788
- }`),c=s=="voronoi"?`
1789
- float v = ${s}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1), voronoiStyle, smoothness, seed, quality);
1821
+ }`),u=l=="voronoi"?`
1822
+ float v = ${l}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1), voronoiStyle, smoothness, seed, quality);
1790
1823
  v = remap(v, lowCut, highCut, 0.0, 1.0);
1791
1824
  v = smax(v, 0.0, smoothness * 0.25);
1792
1825
  v = smin(v, 1.0, smoothness * 0.25);
1793
1826
 
1794
1827
  return p + n * v * intensity;
1795
1828
  `:`
1796
- return p + n * ${s}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1)) * intensity;
1797
- `,u=new J(`vec3 distorted(vec3 p, vec3 n, float scale, float intensity, vec3 offset, float neighbour_offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality) {
1798
- ${c}
1799
- }`,[Rt.simplex,Rt.simplexFractal,Rt.simplexAshima,Rt.fbm,Rt.perlin,Rt.voronoi]),p=new J(`vec3 vertexDisplacementNoise(vec3 position, vec3 normal, float scale, vec3 offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality, float intensity, out vec3 displaced_normal) {
1829
+ return p + n * ${l}((p + offset) * scale * 0.001 + neighbour_offset + (movement * 0.1)) * intensity;
1830
+ `,p=new J(`vec3 distorted(vec3 p, vec3 n, float scale, float intensity, vec3 offset, float neighbour_offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality) {
1831
+ ${u}
1832
+ }`,[Rt.simplexPrecise,Rt.simplexFractal,Rt.simplexAshima,Rt.fbm,Rt.perlin,Rt.voronoi]),d=new J(`vec3 vertexDisplacementNoise(vec3 position, vec3 normal, float scale, vec3 offset, float movement, int voronoiStyle, float smoothness, float seed, float highCut, float lowCut, int quality, float intensity, out vec3 displaced_normal) {
1800
1833
  vec3 displaced_position = distorted(position, normal, scale, intensity, offset, neighbor_offset, movement, voronoiStyle, smoothness, seed, highCut, lowCut, quality);
1801
1834
  vec3 tangent1 = orthogonal(normal);
1802
1835
  vec3 tangent2 = normalize(cross(normal, tangent1));
@@ -1812,7 +1845,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1812
1845
  vec3 distorted2 = distorted(nearby2, normal, scale, intensity, offset, neighbor_offset, movement, voronoiStyle, smoothness, seed, highCut, lowCut, quality);
1813
1846
  displaced_normal = normalize(cross(distorted1 - displaced_position, distorted2 - displaced_position));
1814
1847
  return displaced_position;
1815
- }`,[u,l]);o=e.include(p),i.push(this.scale.build(e,"f")),i.push(this.cropOrOffset.build(e,"v3")),i.push(this.movementOrTexture.build(e,"f")),i.push(this.voronoiStyle.build(e,"i")),i.push(this.smoothness.build(e,"f")),i.push(this.seed.build(e,"f")),i.push(this.highCut.build(e,"f")),i.push(this.lowCut.build(e,"f")),i.push(this.quality.build(e,"i"));break}}return i.push(this.intensity.build(e,"f")),i.push("displaced_normal"),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("VertexDisplacementNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Ka=qf;Ka.Nodes=function(){let e=new J(`vec3 orthogonal(vec3 v) {
1848
+ }`,[p,c]);o=e.include(d),i.push(this.scale.build(e,"f")),i.push(this.cropOrOffset.build(e,"v3")),i.push(this.movementOrTexture.build(e,"f")),i.push(this.voronoiStyle.build(e,"i")),i.push(this.smoothness.build(e,"f")),i.push(this.seed.build(e,"f")),i.push(this.highCut.build(e,"f")),i.push(this.lowCut.build(e,"f")),i.push(this.quality.build(e,"i"));break}}return i.push(this.intensity.build(e,"f")),i.push("displaced_normal"),e.format(o+"("+i.join(",")+")",this.getType(e),t)}else return console.warn("VertexDisplacementNode is not compatible with "+e.shader+" shader."),e.format("vec3( 0.0 )",this.getType(e),t)}},Xa=Uf;Xa.Nodes=function(){let e=new J(`vec3 orthogonal(vec3 v) {
1816
1849
  return normalize(abs(v.x) > abs(v.z) ? vec3(-v.y, v.x, 0.0) : vec3(0.0, -v.z, v.y));
1817
1850
  }`),t=new J(`float displacementMapTexture(sampler2D tex, float crop, vec2 uv, mat3 mat, vec2 offset) {
1818
1851
  vec2 uvs = (mat * vec3(uv * 2.0 - 1.0, 1.0) / 2.0 + 0.5).xy + offset;
@@ -1834,7 +1867,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1834
1867
  vec3 distorted2 = nearby2 + normal * displacementMapTexture(tex, crop, uv, mat, vec2(neighbor_offset)) * intensity;
1835
1868
  displaced_normal = normalize(cross(distorted1 - displaced_position, distorted2 - displaced_position));
1836
1869
  return displaced_position;
1837
- }`,[e,t])}}();var Te={normalRenderTarget:new Yt,normalRenderTargetDepth:new Yt,transmissionRenderTarget:new Yt,aspectRatio:new st,transmissionSize:new st(2048,2048),transmissionRenderTargetDepth:new Yt,aoRenderTarget:new Yt,aoEnabled:new ft,pixelRatioNode:new se(1),resolution:new st,penumbraSize:new jr(5,.5),frameIndex:new Be(0),transmissionLod:new Be(2)};for(let n of Object.values(Te))n.isRenderGlobal=!0;var Rb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.9.44/build/ui.wasm"};var Go=class extends qe{constructor(){super("basic");this.nodeType="Basic";this.color=new He(mt),this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft}get category(){return"phong"}generate(e){let t;if(e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(MN.merge([IN.fog])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>"].join(`
1870
+ }`,[e,t])}}();var Te={normalRenderTarget:new Yt,normalRenderTargetDepth:new Yt,transmissionRenderTarget:new Yt,aspectRatio:new st,transmissionSize:new st(2048,2048),transmissionRenderTargetDepth:new Yt,aoRenderTarget:new Yt,aoEnabled:new ft,pixelRatioNode:new se(1),resolution:new st,penumbraSize:new jr(5,.5),frameIndex:new Be(0),transmissionLod:new Be(2)};for(let n of Object.values(Te))n.isRenderGlobal=!0;var Bb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.9.46/build/ui.wasm"};var Go=class extends qe{constructor(){super("basic");this.nodeType="Basic";this.color=new He(mt),this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft}get category(){return"phong"}generate(e){let t;if(e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(IN.merge([TN.fog])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>"].join(`
1838
1871
  `));let i=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
1839
1872
  #include <skinbase_vertex>
1840
1873
  #include <skinnormal_vertex>
@@ -1856,7 +1889,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1856
1889
  `];o&&i.push(o.code,o.result?"displaced_position = "+o.result+";":""),i.push("transformed = displaced_position;","#include <morphtarget_vertex>","#include <skinning_vertex>","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),i.push("#include <project_vertex>","#include <fog_vertex>","#include <clipping_planes_vertex>"," vViewPosition = - mvPosition.xyz;","#include <worldpos_vertex>"),i.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),t=i.join(`
1857
1890
  `)}else{this.color===void 0&&(this.color=new He(mt)),this.color.analyze(e,{slot:"color"}),this.alpha&&this.alpha.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"});let o=this.color.flow(e,"c",{slot:"color"}),i=this.alpha?this.alpha.flow(e,"f"):void 0,a=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0,s=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0;e.requires.transparent=i!==void 0,e.addParsCode(["varying vec3 vWPosition;","#include <fog_pars_fragment>","#include <dithering_pars_fragment>","varying vec3 vViewPosition;","#include <normal_pars_fragment>"].join(`
1858
1891
  `));let l=["#include <normal_fragment_begin>",o.code];i&&l.push(i.code,"#ifdef ALPHATEST"," if ( "+i.result+" <= ALPHATEST ) discard;","#endif"),s?l.push(s.code,`vec3 outgoingLight = ${o.result};`,`vec3 finalColor = spe_blend(outgoingLight, ${s.result}, 1.0, SPE_BLENDING_NORMAL);`):l.push(`vec3 finalColor = ${o.result};`);let c="1.0";this.mask&&(this.mask.analyze(e),c=`luminance(${this.mask.flow(e,"v3").result})`),i?l.push(`gl_FragColor = vec4( finalColor, accumAlpha * ${i.result} * ${c} );`):l.push("gl_FragColor = vec4("+o.result+", 1.0 );"),a&&l.push(`gl_FragColor.a *= ${a.result};`),l.push("#include <fog_fragment>","#include <dithering_fragment>"),t=l.join(`
1859
- `)}return t}};import{UniformsLib as Lb,UniformsUtils as EN}from"three";var sl=class extends qe{constructor(){super("lambert");this.nodeType="Lambert";this.color=new He(mt),this.emissive=new He(0),this.emissiveIntensity=new se(1),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"lambert"}build(e){let t;if(e.define("LAMBERT"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(EN.merge([Lb.fog,Lb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","varying vec3 vLightFront;","varying vec3 vIndirectFront;","#ifndef DOUBLE_SIDED"," #define DOUBLE_SIDED","#endif","#ifdef DOUBLE_SIDED"," varying vec3 vLightBack;"," varying vec3 vIndirectBack;","#endif","#include <bsdfs>","#include <lights_pars_begin>","#include <color_pars_vertex>","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
1892
+ `)}return t}};import{UniformsLib as Rb,UniformsUtils as MN}from"three";var nl=class extends qe{constructor(){super("lambert");this.nodeType="Lambert";this.color=new He(mt),this.emissive=new He(0),this.emissiveIntensity=new se(1),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"lambert"}build(e){let t;if(e.define("LAMBERT"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(MN.merge([Rb.fog,Rb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","varying vec3 vLightFront;","varying vec3 vIndirectFront;","#ifndef DOUBLE_SIDED"," #define DOUBLE_SIDED","#endif","#ifdef DOUBLE_SIDED"," varying vec3 vLightBack;"," varying vec3 vIndirectBack;","#endif","#include <bsdfs>","#include <lights_pars_begin>","#include <color_pars_vertex>","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
1860
1893
  `));let i=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
1861
1894
  #include <skinbase_vertex>
1862
1895
  #include <skinnormal_vertex>
@@ -1952,22 +1985,22 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1952
1985
  #endif
1953
1986
  `," #include <shadowmap_vertex>"," #include <fog_vertex>"),i.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),t=i.join(`
1954
1987
  `)}else{e.mergeUniform({penumbraSize:Te.penumbraSize}),e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({aoMap:Te.aoRenderTarget}),e.mergeUniform({aoEnabled:Te.aoEnabled}),this.color===void 0&&(this.color=new He(mt)),this.color.analyze(e,{slot:"color"}),this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e);let o=this.color.flow(e,"c",{slot:"color"}),i=this.emissive.flow(e,"c",{slot:"emissive"}),a=this.emissiveIntensity.flow(e,"f",{slot:"emissive"}),s=this.occlusion.flow(e,"b",{slot:"occlusion"}),l=this.shadingAlpha.flow(e,"f"),c=this.shadingBlend.flow(e,"i"),u=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,p=this.alpha?this.alpha.flow(e,"f"):void 0,d=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0;e.requires.transparent=p!==void 0,e.addParsCode([`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","varying vec3 vViewPosition;","varying vec3 vWPosition;","varying vec3 vLightFront;","varying vec3 vIndirectFront;","#ifndef DOUBLE_SIDED"," #define DOUBLE_SIDED","#endif","#include <normal_pars_fragment>","#ifdef DOUBLE_SIDED"," varying vec3 vLightBack;"," varying vec3 vIndirectBack;","#endif","#include <bsdfs>","#include <lights_pars_begin>","#include <fog_pars_fragment>","#include <shadowmap_pars_fragment>","#include <shadowmask_pars_fragment>","#include <clipping_planes_pars_fragment>","#include <dithering_pars_fragment>"].join(`
1955
- `));let h=["#include <normal_fragment_begin>",`
1988
+ `));let f=["#include <normal_fragment_begin>",`
1956
1989
  // NOTE: gl_FrontFacing alternative using face normal estimation.
1957
1990
  vec3 viewdx = dFdx(vViewPosition);
1958
1991
  vec3 viewdy = dFdy(vViewPosition);
1959
1992
  vec3 faceNormal = normalize(cross(viewdx, viewdy));
1960
1993
  bool isFrontFacing = (dot(normal, faceNormal) >= 0.0);
1961
- `,"#include <clipping_planes_fragment>"];h.push(o.code,"vec3 diffuseColor = "+o.result+";","ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"),p&&h.push(p.code,"#ifdef ALPHATEST","if ( "+p.result+" <= ALPHATEST ) discard;","#endif"),h.push("#ifdef DOUBLE_SIDED"," reflectedLight.indirectDiffuse += ( isFrontFacing ) ? vIndirectFront : vIndirectBack;","#else"," reflectedLight.indirectDiffuse += vIndirectFront;","#endif","#include <lightmap_fragment>","reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );","#ifdef DOUBLE_SIDED"," reflectedLight.directDiffuse = ( isFrontFacing ) ? vLightFront : vLightBack;","#else"," reflectedLight.directDiffuse = vLightFront;","#endif","reflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();"),i&&h.push(i.code,"reflectedLight.directDiffuse += "+i.result+" * "+a.result+";"),h.push("vec3 ao = aoEnabled && "+s.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = (reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) ;");let f="1.0";this.mask&&(this.mask.analyze(e),f=`luminance(${this.mask.flow(e,"v3").result})`),h.push(`
1994
+ `,"#include <clipping_planes_fragment>"];f.push(o.code,"vec3 diffuseColor = "+o.result+";","ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"),p&&f.push(p.code,"#ifdef ALPHATEST","if ( "+p.result+" <= ALPHATEST ) discard;","#endif"),f.push("#ifdef DOUBLE_SIDED"," reflectedLight.indirectDiffuse += ( isFrontFacing ) ? vIndirectFront : vIndirectBack;","#else"," reflectedLight.indirectDiffuse += vIndirectFront;","#endif","#include <lightmap_fragment>","reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );","#ifdef DOUBLE_SIDED"," reflectedLight.directDiffuse = ( isFrontFacing ) ? vLightFront : vLightBack;","#else"," reflectedLight.directDiffuse = vLightFront;","#endif","reflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();"),i&&f.push(i.code,"reflectedLight.directDiffuse += "+i.result+" * "+a.result+";"),f.push("vec3 ao = aoEnabled && "+s.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = (reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) ;");let h="1.0";this.mask&&(this.mask.analyze(e),h=`luminance(${this.mask.flow(e,"v3").result})`),f.push(`
1962
1995
  if (outgoingLight != diffuseColor) {
1963
1996
  float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 );
1964
- accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${f} * lightAccu;
1965
- outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${f}, ${c.result} );
1997
+ accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${h} * lightAccu;
1998
+ outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${h}, ${c.result} );
1966
1999
 
1967
2000
  outgoingLight *= ao;
1968
2001
  }
1969
- `),u&&h.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),p?h.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${p.result} );`):h.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&h.push(`gl_FragColor.a *= ${d.result};`),h.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=h.join(`
1970
- `)}return t}};import{UniformsLib as Vb,UniformsUtils as NN}from"three";var Fo=function(){let n=new J(`vec2 dHdxy(sampler2D bumpMap, vec2 bumpMapUv, float bumpScale) {
2002
+ `),u&&f.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),p?f.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${p.result} );`):f.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&f.push(`gl_FragColor.a *= ${d.result};`),f.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=f.join(`
2003
+ `)}return t}};import{UniformsLib as Lb,UniformsUtils as EN}from"three";var Fo=function(){let n=new J(`vec2 dHdxy(sampler2D bumpMap, vec2 bumpMapUv, float bumpScale) {
1971
2004
 
1972
2005
  // Gradient of UVs w.r.t. X coordinate (in screen-space)
1973
2006
  vec2 dSTdx = dFdx(bumpMapUv);
@@ -1998,7 +2031,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
1998
2031
 
1999
2032
  vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
2000
2033
  return normalize( abs( fDet ) * vN - vGrad );
2001
- }`);return{dHdxy:n,perturbNormalArb:r}}();var ll=class extends qe{constructor(){super("phong");this.nodeType="Phong";this.color=new He(mt),this.specular=new He(1118481),this.shininess=new se(30),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"phong"}build(e){let t;if(e.define("PHONG"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(NN.merge([Vb.fog,Vb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2034
+ }`);return{dHdxy:n,perturbNormalArb:r}}();var il=class extends qe{constructor(){super("phong");this.nodeType="Phong";this.color=new He(mt),this.specular=new He(1118481),this.shininess=new se(30),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"phong"}build(e){let t;if(e.define("PHONG"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(EN.merge([Lb.fog,Lb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2002
2035
  `));let i=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
2003
2036
  #include <skinbase_vertex>
2004
2037
  #include <skinnormal_vertex>
@@ -2019,7 +2052,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2019
2052
  #endif
2020
2053
  `];o&&i.push(o.code,o.result?"displaced_position = "+o.result+";":""),i.push("transformed = displaced_position;","#include <morphtarget_vertex>","#include <skinning_vertex>","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),i.push(" #include <project_vertex>"," #include <clipping_planes_vertex>"," vViewPosition = - mvPosition.xyz;"," #include <worldpos_vertex>"," #include <shadowmap_vertex>"," #include <fog_vertex>"),i.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),t=i.join(`
2021
2054
  `)}else{e.mergeUniform({penumbraSize:Te.penumbraSize}),e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({aoMap:Te.aoRenderTarget}),e.mergeUniform({aoEnabled:Te.aoEnabled}),this.color===void 0&&(this.color=new He(mt)),this.color.analyze(e,{slot:"color"}),this.specular.analyze(e),this.shininess.analyze(e);let o=this.occlusion.flow(e,"b",{slot:"occlusion"});this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e);let i=this.color.flow(e,"c",{slot:"color"}),a=this.specular.flow(e,"c"),s=this.shininess.flow(e,"f"),l=this.shadingAlpha.flow(e,"f"),c=this.shadingBlend.flow(e,"i"),u=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,p=this.alpha?this.alpha.flow(e,"f"):void 0,d=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0;e.requires.transparent=p!==void 0,e.addParsCode(["varying vec3 vWPosition;","uniform vec3 emissive;",`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","#include <normal_pars_fragment>","#include <fog_pars_fragment>","#include <bsdfs>","#include <lights_pars_begin>","#include <lights_phong_pars_fragment>","#include <shadowmap_pars_fragment>","#include <dithering_pars_fragment>"].join(`
2022
- `));let h=["#include <normal_fragment_begin>",`
2055
+ `));let f=["#include <normal_fragment_begin>",`
2023
2056
  // NOTE: gl_FrontFacing alternative using face normal estimation.
2024
2057
  vec3 viewdx = dFdx(vViewPosition);
2025
2058
  vec3 viewdy = dFdy(vViewPosition);
@@ -2027,7 +2060,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2027
2060
  if (dot(normal, faceNormal) < 0.0) {
2028
2061
  normal *= -1.0;
2029
2062
  }
2030
- `," BlinnPhongMaterial material;"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let m=this.bumpMap.texture.flow(e,"t"),y=this.bumpMap.flow(e,"v3"),g=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",v="";this.bumpMap.projection.value===4?v=`
2063
+ `," BlinnPhongMaterial material;"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let m=this.bumpMap.texture.flow(e,"t"),y=this.bumpMap.flow(e,"v3"),b=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",S="";this.bumpMap.projection.value===4?S=`
2031
2064
  vec3 bumpNormal = vec3(0.0);
2032
2065
  {
2033
2066
  vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0;
@@ -2035,13 +2068,13 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2035
2068
  vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2;
2036
2069
  vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights;
2037
2070
 
2038
- vec2 grad0 = dHdxy(${m.result}, uv0, ${g});
2071
+ vec2 grad0 = dHdxy(${m.result}, uv0, ${b});
2039
2072
  vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection);
2040
2073
 
2041
- vec2 grad1 = dHdxy(${m.result}, uv1, ${g});
2074
+ vec2 grad1 = dHdxy(${m.result}, uv1, ${b});
2042
2075
  vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection);
2043
2076
 
2044
- vec2 grad2 = dHdxy(${m.result}, uv2, ${g});
2077
+ vec2 grad2 = dHdxy(${m.result}, uv2, ${b});
2045
2078
  vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection);
2046
2079
 
2047
2080
  bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y;
@@ -2049,23 +2082,23 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2049
2082
  }
2050
2083
 
2051
2084
  normal = bumpNormal;
2052
- `:v=`
2085
+ `:S=`
2053
2086
  vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs;
2054
- vec2 grad = dHdxy(${m.result}, bumpMapCachedUv, ${g});
2087
+ vec2 grad = dHdxy(${m.result}, bumpMapCachedUv, ${b});
2055
2088
  normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection );
2056
- `,h.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates
2089
+ `,f.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates
2057
2090
  ${y.result};
2058
- ${v}
2059
- `)}h.push(i.code," vec3 diffuseColor = "+i.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"," vec3 totalEmissiveRadiance = emissive;",a.code," vec3 specular = "+a.result+";",s.code," float shininess = max( 0.0001, "+s.result+" );"," float specularStrength = 1.0;"),p&&h.push(p.code,"#ifdef ALPHATEST","if ( "+p.result+" <= ALPHATEST ) discard;","#endif"),h.push("material.diffuseColor = diffuseColor;"),h.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include <lights_fragment_begin>","#include <lights_fragment_end>"),h.push("vec3 ao = aoEnabled && "+o.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;");let f="1.0";this.mask&&(this.mask.analyze(e),f=`luminance(${this.mask.flow(e,"v3").result})`),h.push(`
2091
+ ${S}
2092
+ `)}f.push(i.code," vec3 diffuseColor = "+i.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );"," vec3 totalEmissiveRadiance = emissive;",a.code," vec3 specular = "+a.result+";",s.code," float shininess = max( 0.0001, "+s.result+" );"," float specularStrength = 1.0;"),p&&f.push(p.code,"#ifdef ALPHATEST","if ( "+p.result+" <= ALPHATEST ) discard;","#endif"),f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include <lights_fragment_begin>","#include <lights_fragment_end>"),f.push("vec3 ao = aoEnabled && "+o.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;");let h="1.0";this.mask&&(this.mask.analyze(e),h=`luminance(${this.mask.flow(e,"v3").result})`),f.push(`
2060
2093
  if (outgoingLight != diffuseColor) {
2061
2094
  float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 );
2062
- accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${f} * lightAccu;
2063
- outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${f}, ${c.result} );
2095
+ accumAlpha += ( 1.0 - accumAlpha ) * ${l.result} * ${h} * lightAccu;
2096
+ outgoingLight = spe_blend( diffuseColor, outgoingLight, ${l.result} * ${h}, ${c.result} );
2064
2097
 
2065
2098
  outgoingLight *= ao;
2066
2099
  }
2067
- `),u&&h.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),p?h.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${p.result});`):h.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&h.push(`gl_FragColor.a *= ${d.result};`),h.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=h.join(`
2068
- `)}return t}};import{UniformsLib as $f,UniformsUtils as DN}from"three";var cl=class extends qe{constructor(){super("standard");this.nodeType="Standard";this.color=new He(mt),this.roughness=new se(.3),this.metalness=new se(0),this.reflectivity=new se(.5),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"physical"}build(e){let t;if(e.define("STANDARD"),e.requires.lights=!0,e.extensions.derivatives=!0,e.extensions.shaderTextureLOD=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(DN.merge([$f.fog,$f.lights])),$f.LTC_1&&(e.uniforms.ltc_1={value:void 0},e.uniforms.ltc_2={value:void 0}),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2100
+ `),u&&f.push(u.code,`outgoingLight = spe_blend(outgoingLight, ${u.result}, 1.0, SPE_BLENDING_NORMAL);`),p?f.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${p.result});`):f.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),d&&f.push(`gl_FragColor.a *= ${d.result};`),f.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=f.join(`
2101
+ `)}return t}};import{UniformsLib as Hf,UniformsUtils as NN}from"three";var al=class extends qe{constructor(){super("standard");this.nodeType="Standard";this.color=new He(mt),this.roughness=new se(.3),this.metalness=new se(0),this.reflectivity=new se(.5),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0),this.occlusion=new ft(!0)}get category(){return"physical"}build(e){let t;if(e.define("STANDARD"),e.requires.lights=!0,e.extensions.derivatives=!0,e.extensions.shaderTextureLOD=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(NN.merge([Hf.fog,Hf.lights])),Hf.LTC_1&&(e.uniforms.ltc_1={value:void 0},e.uniforms.ltc_2={value:void 0}),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2069
2102
  `));let i=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
2070
2103
  #include <skinbase_vertex>
2071
2104
  #include <skinnormal_vertex>
@@ -2085,7 +2118,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2085
2118
  #include <begin_vertex>
2086
2119
  #endif /* !USE_LAYER_DISPLACE */
2087
2120
  `];o&&i.push(o.code,o.result?"displaced_position = "+o.result+";":""),i.push("transformed = displaced_position;","#include <morphtarget_vertex>","#include <skinning_vertex>","transformedNormal = normalMatrix * displaced_normal;","#ifndef FLAT_SHADED"," vNormal = transformedNormal;","#endif"),i.push("#include <project_vertex>","#include <fog_vertex>","#include <clipping_planes_vertex>"," vViewPosition = - mvPosition.xyz;","#include <worldpos_vertex>","#include <shadowmap_vertex>"),i.push("vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;"),t=i.join(`
2088
- `)}else{e.mergeUniform({penumbraSize:Te.penumbraSize}),e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({aoMap:Te.aoRenderTarget}),e.mergeUniform({aoEnabled:Te.aoEnabled});let o={gamma:!0};this.color===void 0&&(this.color=new He(mt)),this.color.analyze(e,{slot:"color",context:o}),this.roughness.analyze(e),this.metalness.analyze(e);let i=this.occlusion.flow(e,"b",{slot:"occlusion"});this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e),this.reflectivity&&this.reflectivity.analyze(e);let a=this.color.flow(e,"c",{slot:"color",context:o}),s=this.roughness.flow(e,"f"),l=this.metalness.flow(e,"f"),c=this.shadingAlpha.flow(e,"f"),u=this.shadingBlend.flow(e,"i"),p=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,d=this.alpha?this.alpha.flow(e,"f"):void 0,h=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0,f=this.reflectivity?this.reflectivity.flow(e,"f"):void 0;e.requires.transparent=d!==void 0,e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;",`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","#include <normal_pars_fragment>","#include <dithering_pars_fragment>","#include <fog_pars_fragment>","#include <bsdfs>","#include <lights_pars_begin>","#include <lights_physical_pars_fragment>","#include <shadowmap_pars_fragment>"].join(`
2121
+ `)}else{e.mergeUniform({penumbraSize:Te.penumbraSize}),e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({aoMap:Te.aoRenderTarget}),e.mergeUniform({aoEnabled:Te.aoEnabled});let o={gamma:!0};this.color===void 0&&(this.color=new He(mt)),this.color.analyze(e,{slot:"color",context:o}),this.roughness.analyze(e),this.metalness.analyze(e);let i=this.occlusion.flow(e,"b",{slot:"occlusion"});this.shadingAlpha.analyze(e),this.shadingBlend.analyze(e),this.afterColor&&this.afterColor.analyze(e,{slot:"afterColor"}),this.alpha&&this.alpha.analyze(e),this.reflectivity&&this.reflectivity.analyze(e);let a=this.color.flow(e,"c",{slot:"color",context:o}),s=this.roughness.flow(e,"f"),l=this.metalness.flow(e,"f"),c=this.shadingAlpha.flow(e,"f"),u=this.shadingBlend.flow(e,"i"),p=this.afterColor?this.afterColor.flow(e,"c",{slot:"afterColor"}):void 0,d=this.alpha?this.alpha.flow(e,"f"):void 0,f=this.alphaOverride?this.alphaOverride.flow(e,"f"):void 0,h=this.reflectivity?this.reflectivity.flow(e,"f"):void 0;e.requires.transparent=d!==void 0,e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;",`uniform float penumbraSize[${5}];`,"uniform sampler2D aoMap;","uniform bool aoEnabled;","#include <normal_pars_fragment>","#include <dithering_pars_fragment>","#include <fog_pars_fragment>","#include <bsdfs>","#include <lights_pars_begin>","#include <lights_physical_pars_fragment>","#include <shadowmap_pars_fragment>"].join(`
2089
2122
  `));let m=["#include <clipping_planes_fragment>"," #include <normal_fragment_begin>",`
2090
2123
  // NOTE: gl_FrontFacing alternative using face normal estimation.
2091
2124
  vec3 viewdx = dFdx(vViewPosition);
@@ -2094,7 +2127,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2094
2127
  if (dot(normal, faceNormal) < 0.0) {
2095
2128
  normal *= -1.0;
2096
2129
  }
2097
- `," PhysicalMaterial material;"," material.diffuseColor = vec3( 1.0 );"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let g=this.bumpMap.texture.flow(e,"t"),v=this.bumpMap.flow(e,"v3"),w=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",O="";this.bumpMap.projection.value===4?O=`
2130
+ `," PhysicalMaterial material;"," material.diffuseColor = vec3( 1.0 );"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let b=this.bumpMap.texture.flow(e,"t"),S=this.bumpMap.flow(e,"v3"),P=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",C="";this.bumpMap.projection.value===4?C=`
2098
2131
  vec3 bumpNormal = vec3(0.0);
2099
2132
  {
2100
2133
  vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0;
@@ -2102,13 +2135,13 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2102
2135
  vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2;
2103
2136
  vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights;
2104
2137
 
2105
- vec2 grad0 = dHdxy(${g.result}, uv0, ${w});
2138
+ vec2 grad0 = dHdxy(${b.result}, uv0, ${P});
2106
2139
  vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection);
2107
2140
 
2108
- vec2 grad1 = dHdxy(${g.result}, uv1, ${w});
2141
+ vec2 grad1 = dHdxy(${b.result}, uv1, ${P});
2109
2142
  vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection);
2110
2143
 
2111
- vec2 grad2 = dHdxy(${g.result}, uv2, ${w});
2144
+ vec2 grad2 = dHdxy(${b.result}, uv2, ${P});
2112
2145
  vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection);
2113
2146
 
2114
2147
  bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y;
@@ -2116,14 +2149,14 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2116
2149
  }
2117
2150
 
2118
2151
  normal = bumpNormal;
2119
- `:O=`
2152
+ `:C=`
2120
2153
  vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs;
2121
- vec2 grad = dHdxy(${g.result}, bumpMapCachedUv, ${w});
2154
+ vec2 grad = dHdxy(${b.result}, bumpMapCachedUv, ${P});
2122
2155
  normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection );
2123
2156
  `,m.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates
2124
- ${v.result};
2125
- ${O}
2126
- `)}if(m.push(a.code," vec3 diffuseColor = "+a.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",l.code," float metalnessFactor = "+l.result+";"),this.roughnessMap){let g=this.roughnessMap.texture.flow(e,"t"),v=this.roughnessMap.flow(e,"v3"),w="";this.roughnessMap.projection.value===4?w=`
2157
+ ${S.result};
2158
+ ${C}
2159
+ `)}if(m.push(a.code," vec3 diffuseColor = "+a.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",l.code," float metalnessFactor = "+l.result+";"),this.roughnessMap){let b=this.roughnessMap.texture.flow(e,"t"),S=this.roughnessMap.flow(e,"v3"),P="";this.roughnessMap.projection.value===4?P=`
2127
2160
  float roughnessChange = 1.0;
2128
2161
  {
2129
2162
  vec2 uv0 = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs0;
@@ -2131,25 +2164,25 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2131
2164
  vec2 uv2 = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs2;
2132
2165
  vec3 weights = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_triplanarWeights;
2133
2166
 
2134
- float r0 = luminance(texture(${g.result}, uv0).rgb) * roughnessScale;
2135
- float r1 = luminance(texture(${g.result}, uv1).rgb) * roughnessScale;
2136
- float r2 = luminance(texture(${g.result}, uv2).rgb) * roughnessScale;
2167
+ float r0 = luminance(texture(${b.result}, uv0).rgb) * roughnessScale;
2168
+ float r1 = luminance(texture(${b.result}, uv1).rgb) * roughnessScale;
2169
+ float r2 = luminance(texture(${b.result}, uv2).rgb) * roughnessScale;
2137
2170
 
2138
2171
  roughnessChange = (r0 * weights.z + r1 * weights.x + r2 * weights.y);
2139
2172
  }
2140
2173
  float roughnessFactor = roughnessChange * ${s.result};
2141
- `:w=`
2174
+ `:P=`
2142
2175
  vec2 roughnessMapCachedUv = g${this.roughnessMap.uuid.toString().replace(/-/g,"")}_writeUvs;
2143
2176
 
2144
- vec4 vals = texture(${g.result}, roughnessMapCachedUv);
2177
+ vec4 vals = texture(${b.result}, roughnessMapCachedUv);
2145
2178
  float roughnessFactor = luminance(vals.rgb) * ${s.result};
2146
2179
  `,m.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates
2147
- ${v.result};
2180
+ ${S.result};
2148
2181
 
2149
2182
  const float roughnessScale = 1.0;
2150
2183
 
2151
- ${w}
2152
- `)}else m.push(s.code," float roughnessFactor = "+s.result+";");d&&m.push(d.code,"#ifdef ALPHATEST"," if ( "+d.result+" <= ALPHATEST ) discard;","#endif"),m.push("vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );"),m.push("material.diffuseColor = diffuseColor * ( 1.0 - metalnessFactor );","material.roughness = max( roughnessFactor, 0.0525 );","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.roughness = clamp( roughnessFactor, 0.04, 1.0 );"),f?m.push(f.code,"material.specularColor = mix( vec3( 0.16 * pow2( "+f.result+" ) ), diffuseColor, metalnessFactor );"):m.push("material.specularColor = mix( vec3( 0.04 ), diffuseColor, metalnessFactor );"),m.push("#include <lights_fragment_begin>"),m.push("#include <lights_fragment_end>"),m.push("vec3 ao = aoEnabled && "+i.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular;");let y="1.0";this.mask&&(this.mask.analyze(e),y=`luminance(${this.mask.flow(e,"v3").result})`),m.push(`
2184
+ ${P}
2185
+ `)}else m.push(s.code," float roughnessFactor = "+s.result+";");d&&m.push(d.code,"#ifdef ALPHATEST"," if ( "+d.result+" <= ALPHATEST ) discard;","#endif"),m.push("vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );"),m.push("material.diffuseColor = diffuseColor * ( 1.0 - metalnessFactor );","material.roughness = max( roughnessFactor, 0.0525 );","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.roughness = clamp( roughnessFactor, 0.04, 1.0 );"),h?m.push(h.code,"material.specularColor = mix( vec3( 0.16 * pow2( "+h.result+" ) ), diffuseColor, metalnessFactor );"):m.push("material.specularColor = mix( vec3( 0.04 ), diffuseColor, metalnessFactor );"),m.push("#include <lights_fragment_begin>"),m.push("#include <lights_fragment_end>"),m.push("vec3 ao = aoEnabled && "+i.result+" ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse)) + reflectedLight.directSpecular + reflectedLight.indirectSpecular;");let y="1.0";this.mask&&(this.mask.analyze(e),y=`luminance(${this.mask.flow(e,"v3").result})`),m.push(`
2153
2186
  if (outgoingLight != diffuseColor) {
2154
2187
  float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 );
2155
2188
  accumAlpha += ( 1.0 - accumAlpha ) * ${c.result} * ${y} * lightAccu;
@@ -2157,8 +2190,8 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2157
2190
 
2158
2191
  outgoingLight *= ao;
2159
2192
  }
2160
- `),p&&m.push(p.code,`outgoingLight = spe_blend(outgoingLight, ${p.result}, 1.0, SPE_BLENDING_NORMAL);`),d?m.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${d.result} );`):m.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),h&&m.push(`gl_FragColor.a *= ${h.result};`),m.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=m.join(`
2161
- `)}return t}};import{UniformsLib as zb,UniformsUtils as _N}from"three";var ul=class extends qe{constructor(){super("toon");this.nodeType="Toon";this.color=new He(mt),this.specular=new He(1118481),this.shininess=new se(30),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0)}get category(){return"toon"}build(e){let t;if(e.define("TOON"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(_N.merge([zb.fog,zb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2193
+ `),p&&m.push(p.code,`outgoingLight = spe_blend(outgoingLight, ${p.result}, 1.0, SPE_BLENDING_NORMAL);`),d?m.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${d.result} );`):m.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),f&&m.push(`gl_FragColor.a *= ${f.result};`),m.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=m.join(`
2194
+ `)}return t}};import{UniformsLib as Vb,UniformsUtils as DN}from"three";var sl=class extends qe{constructor(){super("toon");this.nodeType="Toon";this.color=new He(mt),this.specular=new He(1118481),this.shininess=new se(30),this.previousModelViewMatrix=new Ft,this.previouseProjectionMatrix=new Ft,this.shadingAlpha=new se(1),this.shadingBlend=new Be(0)}get category(){return"toon"}build(e){let t;if(e.define("TOON"),e.requires.lights=!0,e.extensions.derivatives=!0,e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:Te.frameIndex}),e.mergeUniform({resolution:Te.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(DN.merge([Vb.fog,Vb.lights])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>","#include <shadowmap_pars_vertex>","#include <clipping_planes_pars_vertex>"].join(`
2162
2195
  `));let i=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
2163
2196
  #include <skinbase_vertex>
2164
2197
  #include <skinnormal_vertex>
@@ -2207,7 +2240,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2207
2240
  if (dot(normal, faceNormal) < 0.0) {
2208
2241
  normal *= -1.0;
2209
2242
  }
2210
- `," ToonMaterial material;"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let f=this.bumpMap.texture.flow(e,"t"),m=this.bumpMap.flow(e,"v3"),y=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",g="";this.bumpMap.projection.value===4?g=`
2243
+ `," ToonMaterial material;"];if(this.bumpMap){e.include(Fo.dHdxy),e.include(Fo.perturbNormalArb);let h=this.bumpMap.texture.flow(e,"t"),m=this.bumpMap.flow(e,"v3"),y=this.bumpMapIntensity?this.bumpMapIntensity.flow(e,"f").result:"1.0",b="";this.bumpMap.projection.value===4?b=`
2211
2244
  vec3 bumpNormal = vec3(0.0);
2212
2245
  {
2213
2246
  vec2 uv0 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs0;
@@ -2215,13 +2248,13 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2215
2248
  vec2 uv2 = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs2;
2216
2249
  vec3 weights = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_triplanarWeights;
2217
2250
 
2218
- vec2 grad0 = dHdxy(${f.result}, uv0, ${y});
2251
+ vec2 grad0 = dHdxy(${h.result}, uv0, ${y});
2219
2252
  vec3 n0 = perturbNormalArb(-vViewPosition, normal, grad0, faceDirection);
2220
2253
 
2221
- vec2 grad1 = dHdxy(${f.result}, uv1, ${y});
2254
+ vec2 grad1 = dHdxy(${h.result}, uv1, ${y});
2222
2255
  vec3 n1 = perturbNormalArb(-vViewPosition, normal, grad1, faceDirection);
2223
2256
 
2224
- vec2 grad2 = dHdxy(${f.result}, uv2, ${y});
2257
+ vec2 grad2 = dHdxy(${h.result}, uv2, ${y});
2225
2258
  vec3 n2 = perturbNormalArb(-vViewPosition, normal, grad2, faceDirection);
2226
2259
 
2227
2260
  bumpNormal = n0 * weights.z + n1 * weights.x + n2 * weights.y;
@@ -2229,25 +2262,25 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
2229
2262
  }
2230
2263
 
2231
2264
  normal = bumpNormal;
2232
- `:g=`
2265
+ `:b=`
2233
2266
  vec2 bumpMapCachedUv = g${this.bumpMap.uuid.toString().replace(/-/g,"")}_writeUvs;
2234
- vec2 grad = dHdxy(${f.result}, bumpMapCachedUv, ${y});
2267
+ vec2 grad = dHdxy(${h.result}, bumpMapCachedUv, ${y});
2235
2268
  normal = perturbNormalArb( - vViewPosition, normal, grad, faceDirection );
2236
2269
  `,d.push(`// Call the Texture Layer's function once here so that it writes out its procedural UV coordinates
2237
2270
  ${m.result};
2238
- ${g}
2239
- `)}d.push(o.code," vec3 diffuseColor = "+o.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",i.code," vec3 specular = "+i.result+";",a.code," float shininess = max( 0.0001, "+a.result+" );"," float specularStrength = 1.0;"),u&&d.push(u.code,"#ifdef ALPHATEST","if ( "+u.result+" <= ALPHATEST ) discard;","#endif"),d.push("material.diffuseColor = diffuseColor;"),d.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include <lights_fragment_begin>","#include <lights_fragment_end>"),d.push("vec3 ao = aoEnabled ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) * ao) + reflectedLight.directSpecular;");let h="1.0";this.mask&&(this.mask.analyze(e),h=`luminance(${this.mask.flow(e,"v3").result})`),d.push(`
2271
+ ${b}
2272
+ `)}d.push(o.code," vec3 diffuseColor = "+o.result+";"," ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",i.code," vec3 specular = "+i.result+";",a.code," float shininess = max( 0.0001, "+a.result+" );"," float specularStrength = 1.0;"),u&&d.push(u.code,"#ifdef ALPHATEST","if ( "+u.result+" <= ALPHATEST ) discard;","#endif"),d.push("material.diffuseColor = diffuseColor;"),d.push("material.specularColor = specular;","material.specularShininess = shininess;","material.specularStrength = specularStrength;","#include <lights_fragment_begin>","#include <lights_fragment_end>"),d.push("vec3 ao = aoEnabled ? tex2D(aoMap, gl_FragCoord.xy / resolution).rgb : vec3(1.0);","vec3 outgoingLight = ((reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) * ao) + reflectedLight.directSpecular;");let f="1.0";this.mask&&(this.mask.analyze(e),f=`luminance(${this.mask.flow(e,"v3").result})`),d.push(`
2240
2273
  if (outgoingLight != diffuseColor) {
2241
2274
  float lightAccu = clamp( length( reflectedLight.directSpecular + reflectedLight.indirectSpecular ), 0.0, 1.0 );
2242
- accumAlpha += ( 1.0 - accumAlpha ) * ${s.result} * ${h} * lightAccu;
2243
- outgoingLight = spe_blend( diffuseColor, outgoingLight, ${s.result} * ${h}, ${l.result} );
2275
+ accumAlpha += ( 1.0 - accumAlpha ) * ${s.result} * ${f} * lightAccu;
2276
+ outgoingLight = spe_blend( diffuseColor, outgoingLight, ${s.result} * ${f}, ${l.result} );
2244
2277
  }
2245
2278
  `),c&&d.push(c.code,`outgoingLight = spe_blend(outgoingLight, ${c.result}, 1.0, SPE_BLENDING_NORMAL);`),u?d.push(`gl_FragColor = vec4( outgoingLight, accumAlpha * ${u.result} );`):d.push("gl_FragColor = vec4( outgoingLight, 1.0 );"),p&&d.push(`gl_FragColor.a *= ${p.result};`),d.push("#include <encodings_fragment>","#include <fog_fragment>","#include <dithering_fragment>"),t=d.join(`
2246
- `)}return t}};import{VideoTexture as BN,Texture as RN}from"three";var Vu=class{constructor(r=1e3*10){this.timeout=r;this.cache=new Map;this.head={data:null,time:0,src:null,next:null,prev:null};this.tail={data:null,time:1/0,src:null,next:null,prev:null};this.hasClean=!1;this.head.next=this.tail,this.tail.prev=this.head}log(...r){}remove(r){let e=this.cache.get(r);e&&(this.dispose(r,e.data),this.cache.delete(r),e.prev.next=e.next,e.next.prev=e.prev)}scheduleCleanup(){this.hasClean||(this.log("scheduled cleanup"),this.hasClean=!0,setTimeout(()=>{this.hasClean=!1,this.log("cleaning");let r=Date.now(),e=this.head.next;for(;e.time<r-this.timeout;)this.dispose(e.src,e.data),this.cache.delete(e.src),e=e.next,e.prev=this.head,this.head.next=e;this.head.next!==this.tail?this.scheduleCleanup():this.log("no more cleanup")},this.timeout+1e3))}has(r){return this.cache.get(r)?.data}load(r){let e=Date.now(),t=this.cache.get(r);return t===void 0?(t={data:this.create(r),src:r,time:e,next:null,prev:null},this.cache.set(r,t)):(t.time=e,t.prev.next=t.next,t.next.prev=t.prev),t.prev=this.tail.prev,t.next=this.tail,this.tail.prev.next=t,this.tail.prev=t,this.scheduleCleanup(),t.data}};var Xf=class extends Vu{create(r){return URL.createObjectURL(new Blob([r]))}dispose(r,e){URL.revokeObjectURL(e)}},Yf;function Gb(n){return typeof n=="string"?n:(Yf||(Yf=new Xf),Yf.load(n))}var zu=class{constructor(r,e){this.data=r;this.cache=e;this.refCount=0}deref(){if(this.refCount===0&&!1)throw new Error("ref count -1?");this.refCount-=1,this.refCount===0&&(this.cache.remove(this),this.dispose())}dispose(){if(this.refCount!==0&&!1)throw new Error("ref count is not 0")}},Gu=class{constructor(){this.cache=new Map}remove(r){if(this.cache.delete(r.data)===!1&&!1)throw new Error("ref count remove non-exists")}load(r){let e=this.cache.get(r);return e===void 0&&(e=this.create(r),this.cache.set(r,e)),e.refCount+=1,e}};var Qa=class extends zu{constructor(e,t){super(e,t.imageHolderCache);this.data=e;this.shared=t;this.loaded=!1;this.isVideo=!1;this.isBuffer=!1;this._cache={[1e3]:{},[1001]:{},[1002]:{}};this.isVideo=e.type==="video",this.isBuffer=e.isWebGLRenderTarget===!0,this.loadPromise=this.updateSrc(this.isBuffer?e:e.data)}async updateSrc(e){if(typeof document>"u")return;this.disposeTextures(),this.loaded=!1;let t=()=>{this.loaded=!0;for(let i of Object.values(this._cache))for(let a of Object.values(i))for(let s of Object.values(a))s&&(s.image=this.img,s.needsUpdate=!0);this.shared.requestRender()};if(this.isBuffer)this.img=e,this.loaded=!0;else if(this.isVideo){if(this.img=document.createElement("video"),this.img.preload="auto",this.img.playsInline=!0,this.img.currentTime=.01,typeof e!="string"){var o=new FileReader;o.readAsDataURL(new Blob([e],{type:"video/mp4"}));let i;await new Promise(a=>{o.onloadend=s=>{i=s.target?.result,a(null)}}),this.img.src=i}else this.img.src=e;this.img.onloadeddata=()=>{t()}}else this.img=new Image,this.img.src=Gb(e),this.img.onload=t,await new Promise(i=>{this.img.onload=()=>{t(),i(null)}})}getTexture(e,t=1008,o=1006){let i=this._cache[e]?.[t]?.[o];if(i)return i;{let a;return this.isBuffer?a=this.img.texture:this.isVideo?a=new BN(this.img,void 0,e,e):a=new RN(this.img,void 0,e,e,o,t),this.loaded&&(a.needsUpdate=!0),this._cache[e]===void 0&&(this._cache[e]={}),this._cache[e][t]===void 0&&(this._cache[e][t]={}),this._cache[e][t][o]=a,a}}setNeedsUpdate(e){for(let t of Object.values(this._cache))for(let o of Object.values(t))for(let i of Object.values(o))i&&(i.needsUpdate=e)}disposeTextures(){for(let[e,t]of Object.entries(this._cache))for(let[o,i]of Object.entries(t))for(let[a,s]of Object.entries(i))s?.dispose(),this._cache[e]!==void 0&&this._cache[e][o]!==void 0&&(this._cache[e][o][a]=void 0)}dispose(){super.dispose(),this.disposeTextures()}};var dr=class extends Qa{};import{Vector2 as jo,Vector3 as po,Vector4 as Fu}from"three";function jt(n,r){return r.color(n)}function Fb(n,r){switch(n.type){case"fresnel":return zN(n,r);case"gradient":return GN(n,r);case"depth":return FN(n,r);case"normal":return jN(n,r);case"noise":return kN(n,r);case"rainbow":return UN(n,r);case"toon":return HN(n,r);case"outline":return WN(n,r);case"transmission":return qN(n,r);case"color":return VN(n,r);case"pattern":return $N(n,r)}}function LN(n){return{type:n.type}}function Ur(n,r){let{alpha:e,mode:t,isMask:o}=n,i=typeof e=="string"?(Number(r.getVariable(e))??100)/100:e;return{...LN(n),alpha:i,mode:t,isMask:o}}function VN(n,r){return{...Ur(n,r),color:jt(n.color,r)}}function zN(n,r){let{bias:e,scale:t,intensity:o,factor:i,color:a}=n;return{...Ur(n,r),color:jt(a,r),bias:e,scale:t,intensity:o,factor:i}}function GN(n,r){let{gradientType:e,smooth:t,colors:o,steps:i,angle:a,offset:s,morph:l}=n;return{...Ur(n,r),gradientType:e,smooth:t,colors:o.map(c=>new Fu(c[0],c[1],c[2],c[3])),num:o.length,steps:i,offset:new jo(...s),morph:new jo(...l),angle:a}}function FN(n,r){let{gradientType:e,near:t,far:o,isVector:i,isWorldSpace:a,origin:s,direction:l,colors:c,steps:u,smooth:p}=n;return{...Ur(n,r),gradientType:e,near:t,far:o,isVector:i,isWorldSpace:a,origin:new po(...s),direction:l?new po(...l):new po(1,0,0),colors:c.map(d=>d!==void 0?new Fu(d[0],d[1],d[2],d[3]):new Fu(0,0,0,0)),steps:u.slice(0,c.length),smooth:p}}function jN(n,r){let{cnormal:e}=n;return{...Ur(n,r),cnormal:new po(e[0],e[1],e[2])}}function kN(n,r){return{...Ur(n,r),scale:n.scale,move:n.move,fA:new jo(...n.fA),fB:new jo(...n.fB),size:new po(...n.size),distortion:new jo(...n.distortion),colorA:jt(n.colorA,r),colorB:jt(n.colorB,r),colorC:jt(n.colorC,r),colorD:jt(n.colorD,r),noiseType:n.noiseType,voronoiStyle:n.voronoiStyle,highCut:n.highCut,lowCut:n.lowCut,smoothness:n.smoothness,seed:n.seed,quality:n.quality}}function UN(n,r){return{...Ur(n,r),filmThickness:n.filmThickness,movement:n.movement,wavelengths:new po(...n.wavelengths),noiseStrength:n.noiseStrength,noiseScale:n.noiseScale,offset:new po(...n.offset)}}function HN(n,r){return{...Ur(n,r),positioning:n.positioning,colors:n.colors.map(e=>new Fu(e[0],e[1],e[2],e[3])),num:n.colors.length,steps:n.steps,source:new po(...n.source),isWorldSpace:n.isWorldSpace,noiseStrength:n.noiseStrength,noiseScale:n.noiseScale,shadowColor:jt(n.shadowColor,r),offset:new po(...n.offset)}}function WN(n,r){return{...Ur(n,r),outlineColor:jt(n.outlineColor,r),contourColor:jt(n.contourColor,r),outlineWidth:n.outlineWidth,contourWidth:n.contourWidth,outlineThreshold:n.outlineThreshold,contourThreshold:n.contourThreshold,outlineSmoothing:n.outlineSmoothing,contourFrequency:n.contourFrequency,contourDirection:new po(...n.contourDirection),positionalLines:n.positionalLines,compensation:n.compensation}}function qN(n,r){return{...Ur(n,r),thickness:n.thickness,ior:n.ior,roughness:n.roughness}}function $N(n,r){return{...Ur(n,r),style:n.style,projection:n.projection,axis:n.axis,blending:n.blending,offset:new jo(...n.offset),colorA:jt(n.colorA,r),colorB:jt(n.colorB,r),frequency:new jo(...n.frequency),size:n.size,variation:n.variation,smoothness:n.smoothness,zigzag:n.zigzag,rotation:n.rotation,vertical:new jo(...n.vertical),horizontal:new jo(...n.horizontal),sides:n.sides}}var wn=class extends At{};import{MathUtils as YN,Vector4 as XN}from"three";var KN={noise:["noiseType"],texture:["projection","axis","side"],video:["projection","axis","side"],displace:["noiseType"],light:["roughnessMap","bumpMap"],depth:["smooth","isWorldSpace","gradientType","isVector"],pattern:["style","projection","axis"]},QN={depth:["colors"]};function ZN(n,r,e){if(r==="isMask")return!0;let t=KN[n.type],o=QN[n.type];if(o!==void 0){let i=n.color;if(o.includes(r)){let a=i[r]?.value?.length;if(a!==void 0&&a!==e.length)return!0}}return t!==void 0?t.includes(r):!1}function Kf(n,r,e){let t=e.uniforms[`f${e.id}_texture`];if(!t)return!1;let o=!1,i=n;if("image"in i){let a=i.image,s=r.image(a),l=t;l.image instanceof dr||l.image.deref(),l.image=s}if("video"in i){let a=i.video,s=r.video(a),l=t;l.image instanceof dr||l.image.deref(),l.image=s}if("wrapping"in i){let a=t;a.wrap=i.wrapping}if("minFilter"in i){let a=t;a.minFilter=i.minFilter}if("magFilter"in i){let a=t;a.magFilter=i.magFilter}if("rotation"in i&&e.uniforms[`f${e.id}_rotation`])return e.uniforms[`f${e.id}_rotation`].value=(i.rotation??0)*YN.DEG2RAD,o;if("repeat"in i||"offset"in i||"rotation"in i){let a="mat",s=e.uniforms[`f${e.id}_${a}`];"repeat"in i&&(s.repeat=i.repeat),"offset"in i&&(s.offset=i.offset),"rotation"in i&&(s.rotation=i.rotation??0),s.updateMatrix()}return o}function jb(n,r,e,t){let o=!1;for(let[i,a]of Object.entries(n)){if(i==="bumpMap"||i==="roughnessMap"){o=!0;continue}if(!i||a===void 0)continue;if(Qf(i,e,t,r)){i==="visible"&&e.type==="light"&&(o=!0);continue}e.visible=t.visible;let s=e.uniforms[`f${e.id}_${i}`];if(!!s&&!(s instanceof vn))switch(o=o||ZN(e,i,a),s.constructor){case He:if(typeof a=="string"){let l=r.getColor(a);l&&(s.value=l);break}else{let l=a;s.value instanceof wn?s.value=new At(l.r,l.g,l.b,l.a):s.setRGBA(l);break}case er:if(typeof a=="string"){let l=r.getColor(a);l&&(s.value=l);break}else{let l=a;s.value instanceof wn?s.value=new At(l.r,l.g,l.b,l.a):s.value.setRGBA(l.r,l.g,l.b,l.a);break}case st:{let l=a;s.value.setX(l[0]),s.value.setY(l[1]);break}case Gt:{let l=a;s.value.setX(l[0]),s.value.setY(l[1]),s.value.setZ(l[2]);break}case Yt:{Kf(a,r,e);break}case kr:{s.value=a.map(l=>new XN(...l));break}default:{s.value=a;break}}}return o}var Pn=(n,r,e)=>Math.max(0,Math.min(1,Number(r.getVariable(typeof n=="number"?n*100:n,e)??100)/100))??1,Cn=class{constructor(r,e,t,o,i){this.id=r;this.uuid=e;this.data=t;this.uniforms={};for(let a in o)this.uniforms[`f${this.id}_${a}`]=o[a];for(let a in t)Qf(a,this,t,i)}get type(){return this.data.type}static create(r,e,t,o){if(t.type==="light")return Xt.createLightLayer(r,e,t,o);if(t.type==="texture"||t.type==="video"){let i=t.type==="texture"?o.uiBuffer(t.texture.image)??o.image(t.texture.image):o.video(t.texture.video),a=new ri(i,t.texture.wrapping,t.texture.minFilter??1008,t.texture.magFilter??1006),s=new Ru(i),l=new Lu(t.texture.repeat,t.texture.offset,t.texture.rotation??0),c=new se(t.crop?1:0),u=new Be(t.projection??0),p=new Be(["x","y","z"].indexOf(t.axis)??0),d=new Be(t.side??0),h=new st(t.size?new Hr(t.size[0],t.size[1]):new Hr(100,100)),f=new se(t.blending??0),m=new se(Pn(t.alpha,o)),y=new Be(t.mode??0),g=new ft(t.isMask??!1),v=new Sn(a,s,c,u,p,d,h,f,l,m,y,g),w=new ke(v.calpha,"f");return new rt(r,e,t,{texture:a,textureSize:s,crop:c,projection:u,axis:p,side:d,size:h,blending:f,mat:l,alpha:m,mode:y,isMask:g},v,y,w,g,o)}else if(t.type==="matcap"){let i=o.image(t.texture.image),a=new ri(i,t.texture.wrapping,t.texture.minFilter??1008,t.texture.magFilter??1006),s=new se(Pn(t.alpha,o)),l=new Be(t.mode??0),c=new ft(t.isMask??!1),u=new se((t.texture.rotation??0)*JN.DEG2RAD),p=new Ua(a,s,l,c,u),d=new ke(p.calpha,"f");return new rt(r,e,t,{texture:a,alpha:s,mode:l,isMask:c,rotation:u},p,l,d,c,o)}else if(t.type==="displace")if(t.displacementType==="noise"){let i=new Gt(new fo(...t.offset)),a=new se(t.scale??10),s=new se(t.intensity??8),l=new se(t.movement??1),c=new Be(t.noiseType??0),u=new Be(t.voronoiStyle??0),p=new se(t.smoothness??.5),d=new se(t.seed??0),h=new se(t.highCut??1),f=new se(t.lowCut??0),m=new Be(t.quality??1),y=new Ka(s,l,i,u,p,d,h,f,m,a,c);return new dl(r,e,t,{offset:i,scale:a,intensity:s,movement:l,noiseType:c,voronoiStyle:u,smoothness:p,seed:d,highCut:h,lowCut:f,quality:m},y,o)}else throw new Error;else return rD(r,e,t,o)}updateByOp(r,e,t){let o=r;if(o.path[0]===void 0){if(o.type===0)return"type"in o.props||"category"in o.props||"visible"in o.props||"noiseType"in o.props?(t.scene.markNeedsUpdateRendererDirty(),!0):jb(o.props,t.shared,this,e)}else if(o.path[0]==="texture")return"texture"in e||"video"in e?Kf(o.props,t.shared,this):!0;return!1}dispose(){if(eD(this)){let r=this.uniforms[`f${this.id}_texture`];if(!r)return!1;let e=r;e.image instanceof dr||e.image.deref()}}hasValueByKey(r){return this.uniforms[r]!==void 0}hasValue(r){return this.hasValueByKey(`f${this.id}_${r}`)}setValue(r,e){let t=`f${this.id}_${r}`;this.hasValueByKey(t)&&e!==void 0&&(this.uniforms[t].value=e)}getNode(r){let e=`f${this.id}_${r}`;if(this.hasValueByKey(e))return this.uniforms[e]}getValue(r){let e=`f${this.id}_${r}`;if(this.hasValueByKey(e))return this.uniforms[e].value}getName(r){let t=/f\d+_(.*)/.exec(r);if(t&&t.length>1)return t[1];console.log(`Layer.getName: error ${r}`)}getNames(){let r=[];for(let e in this.uniforms){let t=this.getName(e);t&&r.push(t)}return r}},rt=class extends Cn{constructor(e,t,o,i,a,s,l,c,u){super(e,t,o,i,u);this.params=i;this.color=a;this.mode=s;this.alpha=l;this.isMask=c}},dl=class extends Cn{constructor(e,t,o,i,a,s){super(e,t,o,i,s);this.position=a}},Xt=class extends Cn{constructor(e,t,o,i,a,s){super(e,t,o,a,s);this.node=i}static createLightLayer(e,t,o,i){let a,s=new se(Pn(o.alpha,i)),l=new Be(o.mode),c=new se(o.bumpMapIntensity),u=new se(Pn(o.alphaOverride,i)),p;if(!o.visible)a=new Go,p={};else if(o.category==="lambert"){a=new sl;let d=new He(i.color(o.emissive)??0),h=new ft(o.occlusion??!0);p={emissive:d,occlusion:h},a.emissive=d,a.occlusion=h}else if(o.category==="toon"){a=new ul;let d=new se(o.shininess??30),h=new He(i.color(o.specular)??1118481);p={shininess:d,specular:h},a.shininess=d,a.specular=h}else if(o.category==="physical"){a=new cl;let d=new se(o.roughness??.3),h=new se(o.metalness??0),f=new se(o.reflectivity??.5),m=new ft(o.occlusion??!0);p={roughness:d,metalness:h,reflectivity:f,occlusion:m},a.roughness=d,a.metalness=h,a.reflectivity=f,a.occlusion=m}else{a=new ll;let d=new se(o.shininess??30),h=new He(o.specular!==void 0?i.color(o.specular)??1118481:1118481),f=new ft(o.occlusion??!0);p={shininess:d,specular:h,occlusion:f},a.shininess=d,a.specular=h,a.occlusion=f}return a.alpha=new se(1),a.shadingAlpha=s,a.shadingBlend=l,a.bumpMapIntensity=c,a.alphaOverride=u,p.alpha=a.shadingAlpha,p.mode=a.shadingBlend,p.bumpMapIntensity=a.bumpMapIntensity,p.alphaOverride=a.alphaOverride,new Xt(e,t,o,a,p,i)}get category(){return this.node.category}};function eD(n){let r=n instanceof Cn?n.type:n;return r==="texture"||r==="video"||r==="displace_map"||r==="matcap"}function Sr(n){return{alpha:new se(n.alpha??1),mode:new Be(n.mode??0),isMask:new ft(n.isMask??!1)}}function tD(n,r,e,t,o){switch(n.type){case"color":{let i=new He(t.color??mt),a=Sr(t),s=new oi(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{color:i,...a},s,a.mode,l,a.isMask,o)}case"fresnel":{let i=new He(t.color??16777215),a=new se(t.bias??.1),s=new se(t.scale??1),l=new se(t.intensity??2),c=new se(t.factor??1),u=Sr(t),p=new il(i,a,s,l,c,u.alpha,u.mode,u.isMask),d=new ke(p.calpha,"f");return new rt(r,e,n,{color:i,bias:a,scale:s,intensity:l,factor:c,...u},p,u.mode,d,u.isMask,o)}case"rainbow":{let i=new se(t.filmThickness??30),a=new se(t.movement??0),s=new Gt(t.wavelengths??new fo(0,0,0)),l=new se(t.noiseStrength??0),c=new se(t.noiseScale??1),u=new Gt(t.offset??new fo(0,0,0)),p=Sr(t),d=new $a(i,a,s,l,c,u,p.alpha,p.isMask),h=new ke(d.calpha,"f");return new rt(r,e,n,{filmThickness:i,movement:a,wavelengths:s,noiseStrength:l,noiseScale:c,offset:u,...p},d,p.mode,h,p.isMask,o)}case"transmission":{let i=new se(t.thickness??10),a=new se(t.ior??1.5),s=new se(t.roughness??.5),l=Te.transmissionSize,c=Te.transmissionRenderTarget,u=Te.transmissionRenderTargetDepth,p=window.innerWidth,d=window.innerHeight,h=p>=d?new st(d/p,1):new st(1,p/d),f=Sr(t),m=new Xa(i,a,s,l,c,u,h,f.alpha),y=new ke(m.calpha,"f");return new rt(r,e,n,{thickness:i,ior:a,roughness:s,aspectRatio:h,...f},m,f.mode,y,f.isMask,o)}case"toon":{let i=new Be(t.positioning??0),a;t.colors?a=new kr(t.colors.length,t.colors):(a=new kr(10,new Za(0,0,0,1)),a.value[1]=new Za(1,1,1,1));let s;t.steps?s=new jr(t.steps.length,t.steps):(s=new jr(10,1),s.value[0]=0);let l=new Gt(t.source??new fo(0,0,0)),c=new ft(t.isWorldSpace??!0),u=new se(t.noiseStrength??0),p=new se(t.noiseScale??1),d=new er(t.shadowColor),h=new Gt(t.offset??new fo(0,0,0)),f=Sr(t),m=new Ya(i,a,s,l,c,u,p,d,h,f.alpha),y=new ke(m.calpha,"f");return new rt(r,e,n,{positioning:i,colors:a,steps:s,source:l,isWorldSpace:c,noiseStrength:u,noiseScale:p,shadowColor:d,offset:h,...f},m,f.mode,y,f.isMask,o)}case"outline":{let i=new He(t.outlineColor??16777215),a=new He(t.contourColor??16777215),s=new se(t.outlineWidth??.1),l=new se(t.contourWidth??.1),c=new se(t.outlineThreshold??.1),u=new se(t.contourThreshold??.1),p=new se(t.outlineSmoothing??.1),d=new se(t.contourFrequency??.1),h=new Gt(t.contourDirection??new fo(0,1,0)),f=new ft(t.positionalLines??!1),m=new ft(t.compensation??!0),y=Te.normalRenderTarget,g=Te.normalRenderTargetDepth,v=Te.pixelRatioNode,w=Te.resolution,O=Sr(t),S=new Wa(i,a,s,l,c,u,p,d,h,f,m,w,y,g,v,O.alpha),C=new ke(S.calpha,"f");return new rt(r,e,n,{outlineColor:i,contourColor:a,outlineWidth:s,contourWidth:l,outlineThreshold:c,contourThreshold:u,outlineSmoothing:p,contourFrequency:d,contourDirection:h,positionalLines:f,compensation:m,...O},S,O.mode,C,O.isMask,o)}case"depth":{let i=new Be(t.gradientType??0),a=new ft(t.smooth??!1),s=new se(t.near??50),l=new se(t.far??200),c=new se(t.isVector??1),u=new se(t.isWorldSpace??0),p=new Gt(t.origin??new fo),d=new Gt(t.direction??new fo),h;t.colors?h=new kr(t.colors.length,t.colors):(h=new kr(2,new Za(0,0,0,1)),h.value[1]=new Za(1,1,1,1));let f;t.steps?f=new jr(t.steps.length,t.steps):(f=new jr(2,1),f.value[0]=0);let m=Sr(t),y=new ja(i,a,s,l,c,u,p,d,h,f,m.alpha,m.isMask),g=new ke(y.calpha,"f");return new rt(r,e,n,{gradientType:i,smooth:a,near:s,far:l,isVector:c,isWorldSpace:u,origin:p,direction:d,colors:h,steps:f,...m},y,m.mode,g,m.isMask,o)}case"noise":{let i=new se(t.scale??1),a=new Gt(t.size??new fo(100,100,100)),s=new se(t.move??1),l=new st(t.fA??new Hr(1.7,9.2)),c=new st(t.fB??new Hr(8.3,2.8)),u=new st(t.distortion??new Hr(1,1)),p=new er(t.colorA),d=new er(t.colorB),h=new er(t.colorC),f=new er(t.colorD),m=new Be(t.noiseType??0),y=new Be(t.voronoiStyle??0),g=new se(t.highCut??1),v=new se(t.lowCut??0),w=new se(t.smoothness??.5),O=new se(t.seed??.5),S=new Be(t.quality??1),C=Sr(t),T=new Ha(i,a,s,l,c,u,p,d,h,f,C.alpha,m,C.isMask,y,g,v,w,O,S),x=new ke(T.calpha,"f");return new rt(r,e,n,{scale:i,size:a,move:s,fA:l,fB:c,distortion:u,colorA:p,colorB:d,colorC:h,colorD:f,noiseType:m,...C,voronoiStyle:y,highCut:g,lowCut:v,smoothness:w,seed:O,quality:S},T,C.mode,x,C.isMask,o)}case"normal":{let i=new Gt(t.cnormal??new fo(1,1,1)),a=Sr(t),s=new za(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{cnormal:i,...a},s,a.mode,l,a.isMask,o)}case"gradient":{let i=new Be(t.gradientType??0),a=new ft(t.smooth??!1),s;t.colors?s=new kr(t.colors.length,t.colors):(s=new kr(10,new Za(0,0,0,1)),s.value[1]=new Za(1,1,1,1));let l;t.steps?l=new jr(t.steps.length,t.steps):(l=new jr(10,1),l.value[0]=0);let c=new st(t.offset??new Hr(0,0)),u=new st(t.morph??new Hr(0,0)),p=new se(t.angle??0),d=Sr(t),h=new ka(i,a,s,l,c,u,p,d.alpha,d.isMask),f=new ke(h.calpha,"f");return new rt(r,e,n,{gradientType:i,smooth:a,colors:s,steps:l,offset:c,morph:u,angle:p,...d},h,d.mode,f,d.isMask,o)}case"pattern":{let i=new Be(t.style??0),a=new Be(t.projection??0),s=new Be(["x","y","z"].indexOf(t.axis)??0),l=new se(t.blending??0),c=new st(t.offset??new Hr(0,0)),u=new er(t.colorA),p=new er(t.colorB),d=new st(t.frequency??new Hr(10,10)),h=new se(t.size??.5),f=new se(t.variation??0),m=new se(t.smoothness??.5),y=new se(t.zigzag??0),g=new se(t.rotation??0),v=new st(t.vertical??new Hr(0,1)),w=new st(t.horizontal??new Hr(0,1)),O=new Be(t.sides??6),S=Sr(t),C=new qa(i,a,s,l,c,u,p,d,h,f,m,y,g,v,w,O,S.alpha,S.isMask),T=new ke(C.calpha,"f");return new rt(r,e,n,{style:i,projection:a,axis:s,blending:l,offset:c,colorA:u,colorB:p,frequency:d,size:h,variation:f,smoothness:m,zigzag:y,rotation:g,vertical:v,horizontal:w,sides:O,...S},C,S.mode,T,S.isMask,o)}default:{let i=new He(1,0,0,1),a=Sr(t),s=new oi(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{color:i,...a},s,a.mode,l,a.isMask,o)}}}function rD(n,r,e,t){let o=Fb(e,t);return tD(e,n,r,o,t)}function Qf(n,r,e,t){if(e.type==="displace"&&(n==="intensity"||n==="visible")){let o=r.uniforms[`f${r.id}_intensity`];return o?(o.value=e.intensity*(e.visible?1:0),o):void 0}if(e.type!=="displace"&&(n==="alpha"||n==="visible")){let o=r.uniforms[`f${r.id}_alpha`];if(!o)return;if(o.value=Pn(e.alpha,t)*(e.visible?1:0),e.type==="outline"&&n==="visible"){let i=r.uniforms[`f${r.id}_compensation`];i&&(i.value=e.compensation&&e.visible)}return o}}function ju(n,r){let e=0,t=n.layers.find(o=>o.data.type==="light");if(t){let o=t.data,i=Number(r.getVariable(o.alphaOverride));if((typeof o.alphaOverride=="string"?i/100:o.alphaOverride)<1)return!0}for(let o of n.layers){if(o.data.type!=="displace"&&o.data.isMask)return!0;if(o.data.type!=="displace"&&"alpha"in o.data&&o.data.type!=="light"&&o.data.type!=="fresnel"&&o.data.type!=="texture"&&o.data.type!=="matcap"&&o.data.type!=="rainbow"&&o.data.type!=="outline"&&o.data.type!=="pattern"){let i=o.data.visible?o.data.alpha:0;if(typeof i=="string"&&(i=Math.max(0,Math.min(1,Number(r.getVariable(i)??100)/100))),i===1&&o.data.type==="depth"||o.data.type==="gradient"){for(let a of o.data.colors)if(a[3]<1){i=a[3];break}}else if(i===1&&o.data.type==="noise"){let a=r.color(o.data.colorA).a,s=r.color(o.data.colorB).a,l=r.color(o.data.colorC).a,c=r.color(o.data.colorD).a,u=Math.min(a,Math.min(s,Math.min(l,c)));u<1&&(i=u)}e+=(1-e)*i}}return e<1}var rr=class extends oD{constructor(){super(void 0);this.flatShading=!1;this.needsJitter=!0;this.nodeContextUuid=0;this.fog=!0,this.dithering=!0,this.vertexColors=!0,this.transparent=!0}customProgramCacheKey(){return""}},ku=class extends rr{constructor(e,t,o,i){super();this.flatShading=e;this.side=t;this.wireframe=o;this.root=i}updateAfterBuild(){let e=this.root;this.lights=e.lights,this.vertexShader=e.vertexShader,this.fragmentShader=e.fragmentShader,this.defines=e.defines,this.uniforms=e.uniforms,this.extensions=e.extensions,this.transparent=e.transparent,this.cacheKey=e.customProgramCacheKey()+"flat"+this.flatShading+this.side}onBeforeCompile(e,t){this.root.onBeforeCompile(e)}get data(){return this.root.data}get category(){return this.root.category}get hasAO(){return this.root.hasAO}getFlavor(e,t,o){return this.root.getFlavor(e,t,o)}get layers(){return this.root.layers}get fragment(){return this.root.fragment}getLayersOfType(e){return this.root.getLayersOfType(e)}getLayerByUuid(e){return this.root.getLayerByUuid(e)}updateByOp(e,t,o){this.root.updateByOp(e,t,o)}nodeMaterialDispose(){this.root.nodeMaterialDispose()}},ii=class extends rr{constructor(e,t,o=!0){super();this.data=e;this.allowVariableSaves=o;this.layerIdGen=0;this.flavors=[];this.masks={};this.type="NodeMaterial";this.updaters=[],this.needsJitter=t.shared.needsJitter,qe.startContext(this),this.reset0(e,t),qe.endContext(this)}get nodeMaterial(){return this}getFlavor(e,t,o){let i=o?6:(e?3:0)+t;if(i===0)return this;this.flavors===void 0&&(this.flavors=[]),i-=1;let a=this.flavors[i];return a===void 0&&(a=new ku(e,t,o,this),a.needsJitter=this.needsJitter,this.flavors[i]=a,a.flatShading=e,a.side=t,a.updateAfterBuild()),a}get fragment(){return this.lightLayer.node}get category(){return this.lightLayer.category}get hasAO(){return this.lightLayer.getNode("occlusion")?.value??!1}reset(e,t,o=!1){qe.startContext(this),(this.data!==e||o)&&this.reset0(e,t),qe.endContext(this)}reset0(e,t){this.data=e;let o=e.layers??Et.defaultTwoLayerData("phong").layers;try{this.layers=o.map(i=>Cn.create(this.layerIdGen++,i.id,i.data,t.shared))}catch{this.layers=[]}this.layers.reverse(),this.name=e.name??"Untitled Material",this.onUpdate(t.shared),this.transparent=ju(e,t.shared),this.saveVariableLocations(t)}onVariableUpdate(e,t,o){if(e[0]==="alphaOverride")this.transparent=ju(this.data,o.shared),this.lightLayer.setValue("alphaOverride",Math.max(0,Math.min(Number(t)/100,1)));else if(e[0]==="layer"){let i=e[1],a=e[2];if(i&&a){let s=this.layers.find(l=>l.uuid===i);s?.hasValue(a)&&(a==="alpha"?(this.transparent=ju(this.data,o.shared),s.setValue(a,Math.max(0,Math.min(Number(t)/100,1)))):s.setValue(a,t))}}}saveVariableLocations(e){if(!this.allowVariableSaves)return;let t=this.data.layers.find(o=>o.data.type==="light");t&&e.shared.getVariable(t.data.alphaOverride,["material",this.uuid,"alphaOverride"]),this.data.layers.forEach(o=>{"alpha"in o.data&&typeof o.data.alpha=="string"&&e.shared.getVariable(o.data.alpha,["material",this.uuid,"layer",o.id,"alpha"])})}getLayersOfType(e){return this.layers.filter(t=>t.type===e)}getLayerByUuid(e){return this.layers.find(t=>t.uuid===e)}onUpdate(e){this.lightLayer=this.layers.find(t=>t instanceof Xt),this.lightLayer===void 0&&(this.lightLayer=new Xt(0,"",{...xt.defaultData("light","phong"),visible:!1},new Go,{},e)),this.dispose();for(let t of this.flavors)t&&t.dispose();this.applyTextureMaps(),this.applyMasks(),this.blendColors(),this.blendAfterColors(),this.blendPositions(),this.build(),this.nodeContextUuid=0}applyTextureMaps(){let e=this.layers.find(a=>a instanceof Xt);if(!e)return;let t=e.data,o=t.bumpMap,i=t.roughnessMap;e.node.bumpMap=void 0,e.node.roughnessMap=void 0;for(let a=0;a<this.layers.length;++a){let s=this.layers[a];s instanceof rt&&s.color instanceof Sn&&(s.uuid===o&&(e.node.bumpMap=s.color),s.uuid===i&&(e.node.roughnessMap=s.color))}}updateByOp(e,t,o){if(qe.startContext(this),t!==void 0?this.data=t:t=this.data,this.transparent=ju(t,o.shared),e.path[0]==="layers"){let i=o.shared,a=e.path[1];if(a===void 0)o.scene.markNeedsUpdateRendererDirty(),this.reset0(t,o);else{e.type===0&&e.props.occlusion!==void 0&&o.scene.markNeedsUpdateRendererDirty();let s=this.layers.find(l=>l.uuid===a);if(s){let l=t.layers.data(a),c;e.type===0&&("alpha"in e.props||"alphaOverride"in e.props)&&("alpha"in e.props?c={...e.props,alpha:Pn(e.props.alpha,i,["material",this.uuid,"layer",a,"alpha"])}:c={...e.props,alphaOverride:Pn(e.props.alphaOverride,i,["material",this.uuid,"alphaOverride"])}),s.updateByOp({...e,...c?{props:c}:{},path:e.path.slice(2)},l,o)&&this.reset0(t,o)}}}else this.reset0(t,o);qe.endContext(this)}applyMasks(){for(let e=0;e<this.layers.length;++e){let t=this.layers[e];t instanceof rt?t.color.mask=void 0:t instanceof Xt&&(t.node.mask=void 0)}for(let e=0;e<this.layers.length;++e){let t=this.layers[e];if(t instanceof rt&&t.isMask.value&&t.data.visible&&e>0){let o=e-1,i=this.layers[o];i instanceof Xt?i.node.mask=new _t(t.color,t.alpha,_t.MUL):i instanceof rt&&(i.isMask.value||(i.color.mask=new _t(t.color,t.alpha,_t.MUL)))}}}blendColors(){let e=this.layers.findIndex(o=>o instanceof rt),t=this.layers.findIndex(o=>o instanceof Xt);if(e!==-1&&e<t){let o=this.layers[e].color;for(let i=e+1;i<t;++i){let a=this.layers[i];if(a instanceof rt){if(a.isMask.value)continue;o=new Va(o,a.color,a.alpha,a.mode)}}this.fragment.color=o}else this.fragment.color=void 0}blendAfterColors(){let e=new ke("outgoingLight","f"),t=this.layers.findIndex(o=>o instanceof Xt);if(this.layers.length>t+1){for(let o=t+1;o<this.layers.length;++o){let i=this.layers[o];if(i instanceof rt){if(i.isMask.value)continue;e=new Va(e,i.color,i.alpha,i.mode)}}this.fragment.afterColor=e}else this.fragment.afterColor=void 0}blendPositions(){let e=this.layers.filter(t=>t instanceof dl);if(e.length>0){let t=e[0].position;for(let o=1;o<e.length;++o)e[o]&&(t=new _t(t,e[o].position,_t.ADD),t=new _t(t,new se(.5).setReadonly(!0),_t.MUL));this.fragment.position=t}else this.fragment.position=void 0}getDefines(){return this.defines}getUniforms(){return this.uniforms}getVertexShader(){return this.vertexShader}getFragmentShader(){return this.fragmentShader}onBeforeCompile(e){e.defines=this.defines,e.uniforms=this.uniforms,e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.extensionDerivatives=this.extensions.derivatives===!0,e.extensionFragDepth=this.extensions.fragDepth===!0,e.extensionDrawBuffers=this.extensions.drawBuffers===!0,e.extensionShaderTextureLOD=this.extensions.shaderTextureLOD===!0}clampUniformsForPreview(e,t){let o=(i,a,s)=>Math.min(Math.max(i,a),s);for(let i of this.layers)if(i.type==="displace"){let a=o(i.uniforms[`f${i.id}_intensity`].value,e,t);i.uniforms[`f${i.id}_intensity`].value=a}}updateFrame(e){for(let t=0;t<this.updaters.length;++t)e.updateNode(this.updaters[t])}build(){let e=new Ra;e.needsJitter=this.needsJitter,this.lights=this.lightLayer.data.visible,e.build(this.fragment,this.fragment),this.vertexShader=e.getCode("vertex"),this.fragmentShader=e.getCode("fragment"),this.defines=e.defines,this.uniforms=e.uniforms,this.extensions=e.extensions,this.updaters=e.updaters;for(let t of this.flavors)t&&t.updateAfterBuild();return this}nodeMaterialDispose(){this.layers.forEach(e=>e.dispose()),super.dispose();for(let e of this.flavors)e&&e.dispose()}assetsLoaded(){for(let e of this.layers)if(e instanceof rt){let t=e.params.texture;if(t instanceof ri&&!t.image.loaded)return!1}return!0}};Object.defineProperties(rr.prototype,{properties:{get:function(){return this.fragment.properties}}});var ai=class extends ii{constructor(r,e,t){super(r,e,!1),this.uuid=t,this.allowVariableSaves=!0,this.saveVariableLocations(e)}};var kb=new Map;function Ub(n){if(typeof n=="string")return n;let r=kb.get(n);return r||(r={url:URL.createObjectURL(new Blob([n]))},kb.set(n,r)),r.url}var nD,Hb=new Promise(n=>{nD=n});var Wb;Hb.then(n=>Wb=n);var si=class{constructor({src:r,volume:e,delay:t,loop:o}){this._volume=1;this.delay=0;this._loop=1;this.loopsRemaining=0;this._status="stopped";this.onEnd=()=>{this.loopsRemaining===1/0?this.replay():this.loopsRemaining>1?(this.replay(),this.loopsRemaining--):(this._status="stopped",this.loopsRemaining=this._loop)};let i;typeof r=="string"?i={src:r}:i={src:Ub(r),format:"wav"},this.sound=new Wb.Howl(i),this.sound.on("end",this.onEnd),this.src=r,e!==void 0&&(this.volume=e),t!==void 0&&(this.delay=t),o!==void 0&&(this.loop=o)}get status(){return this._status}get volume(){return this._volume}set volume(r){this._volume=r,this.sound.volume(r)}get loop(){return this._loop}set loop(r){this._loop=r,this.loopsRemaining=r}replay(){this.clearDelay(),this.delayTimerId=window.setTimeout(()=>{this.sound.play(),this.clearDelay()},this.delay)}fade(r,e=1e3){r?(this.sound.volume(this._volume),this.clearFade(),this.fadeTimerId=window.setTimeout(()=>{this.sound.fade(this._volume,0,e),this.clearFade()},r)):this.sound.fade(this._volume,0,e)}on(r,e,t){this.sound.on(r,e,t)}off(r,e,t){this.sound.off(r,e,t)}play(){this._status==="playing"||this.sound.playing()||(this._status==="paused"?(this.sound.seek()===0?this.replay():this.sound.play(),this._status="playing"):this._status==="stopped"&&(this.replay(),this._status="playing"))}pause(){this._status==="playing"&&(this.sound.pause(),this.clearFade(),this.clearDelay(),this._status="paused")}stop(){this.sound.stop(),this.loopsRemaining=this._loop,this.clearFade(),this.clearDelay(),this._status="stopped"}clearFade(){this.fadeTimerId&&(clearTimeout(this.fadeTimerId),delete this.fadeTimerId)}clearDelay(){this.delayTimerId&&(clearTimeout(this.delayTimerId),delete this.delayTimerId)}dispose(r=!1){this.off(),this.stop(),this.clearFade(),this.clearDelay()}};import{Box2 as iD,Vector2 as li,Path as qb,Shape as aD,ShapeUtils as sD,Color as lD}from"three";var Uu=class{constructor(){this.type="ShapePath";this.color=new lD;this.subPaths=[];this.currentPath=null}moveTo(r,e){return this.currentPath=new qb,this.subPaths.push(this.currentPath),this.currentPath.moveTo(r,e),this}lineTo(r,e){return this.currentPath?.lineTo(r,e),this}quadraticCurveTo(r,e,t,o){return this.currentPath?.quadraticCurveTo(r,e,t,o),this}bezierCurveTo(r,e,t,o,i,a){return this.currentPath?.bezierCurveTo(r,e,t,o,i,a),this}splineThru(r){return this.currentPath?.splineThru(r),this}toShapes(){let e={ORIGIN:0,DESTINATION:1,BETWEEN:2,LEFT:3,RIGHT:4,BEHIND:5,BEYOND:6},t={loc:e.ORIGIN,t:0};function o(m,y,g,v){let w=m.x,O=y.x,S=g.x,C=v.x,T=m.y,x=y.y,N=g.y,E=v.y,M=(C-S)*(T-N)-(E-N)*(w-S),D=(O-w)*(T-N)-(x-T)*(w-S),_=(E-N)*(O-w)-(C-S)*(x-T),B=M/_,V=D/_;if(_===0&&M!==0||B<=0||B>=1||V<0||V>1)return null;if(M===0&&_===0){for(let k=0;k<2;k++)if(i(k===0?g:v,m,y),t.loc===e.ORIGIN){let L=k===0?g:v;return{x:L.x,y:L.y,t:t.t}}else if(t.loc===e.BETWEEN){let L=+(w+t.t*(O-w)).toPrecision(10),W=+(T+t.t*(x-T)).toPrecision(10);return{x:L,y:W,t:t.t}}return null}else{for(let W=0;W<2;W++)if(i(W===0?g:v,m,y),t.loc===e.ORIGIN){let F=W===0?g:v;return{x:F.x,y:F.y,t:t.t}}let k=+(w+B*(O-w)).toPrecision(10),L=+(T+B*(x-T)).toPrecision(10);return{x:k,y:L,t:B}}}function i(m,y,g){let v=g.x-y.x,w=g.y-y.y,O=m.x-y.x,S=m.y-y.y,C=v*S-O*w;if(m.x===y.x&&m.y===y.y){t.loc=e.ORIGIN,t.t=0;return}if(m.x===g.x&&m.y===g.y){t.loc=e.DESTINATION,t.t=1;return}if(C<-Number.EPSILON){t.loc=e.LEFT;return}if(C>Number.EPSILON){t.loc=e.RIGHT;return}if(v*O<0||w*S<0){t.loc=e.BEHIND;return}if(Math.sqrt(v*v+w*w)<Math.sqrt(O*O+S*S)){t.loc=e.BEYOND;return}let T;v!==0?T=O/v:T=S/w,t.loc=e.BETWEEN,t.t=T}function a(m,y){let g=[],v=[];for(let w=1;w<m.length;w++){let O=m[w-1],S=m[w];for(let C=1;C<y.length;C++){let T=y[C-1],x=y[C],N=o(O,S,T,x);N!==null&&g.find(E=>E.t<=N.t+Number.EPSILON&&E.t>=N.t-Number.EPSILON)===void 0&&(g.push(N),v.push(new li(N.x,N.y)))}}return v}function s(m,y,g){let v=new li;y.getCenter(v);let w=[];return g.forEach(O=>{O.boundingBox.containsPoint(v)&&a(m,O.points).forEach(C=>{w.push({identifier:O.identifier,isCW:O.isCW,point:C})})}),w.sort((O,S)=>O.point.x-S.point.x),w}function l(m,y,g,v,w){(w==null||w==="")&&(w="nonzero");let O=new li;m.boundingBox.getCenter(O);let S=[new li(g,O.y),new li(v,O.y)],C=s(S,m.boundingBox,y);C.sort((D,_)=>D.point.x-_.point.x);let T=[],x=[];C.forEach(D=>{D.identifier===m.identifier?T.push(D):x.push(D)});let N=T[0].point.x,E=[],M=0;for(;M<x.length&&x[M].point.x<N;)E.length>0&&E[E.length-1]===x[M].identifier?E.pop():E.push(x[M].identifier),M++;if(E.push(m.identifier),w==="evenodd"){let D=E.length%2===0,_=E[E.length-2];return{identifier:m.identifier,isHole:D,for:_}}else if(w==="nonzero"){let D=!0,_=null,B=null;for(let V=0;V<E.length;V++){let k=E[V];y[k]&&(D?(B=y[k].isCW,D=!1,_=k):B!==y[k].isCW&&(B=y[k].isCW,D=!0))}return{identifier:m.identifier,isHole:D,for:_}}else console.warn('fill-rule: "'+w+'" is currently not implemented.')}let c=0,u=999999999,p=-999999999,d=[];this.subPaths.forEach(m=>{let y=m.getPoints(),g=-999999999,v=999999999,w=-999999999,O=999999999;for(let S=0;S<y.length;S++){let C=y[S];C.y>g&&(g=C.y),C.y<v&&(v=C.y),C.x>w&&(w=C.x),C.x<O&&(O=C.x)}p<=w&&(p=w+1),u>=O&&(u=O-1),y.length&&d.push({curves:m.curves,points:y,isCW:sD.isClockWise(y),identifier:c++,boundingBox:new iD(new li(O,v),new li(w,g))})});let h=d.map(m=>l(m,d,u,p,this.userData?.style.fillRule)),f=[];return d.forEach(m=>{let y=h[m.identifier];if(y&&!y.isHole){let g=new aD;g.curves=m.curves,h.filter(w=>w?.isHole&&w.for===m.identifier).forEach(w=>{if(w){let O=d[w.identifier],S=new qb;S.curves=O.curves,g.holes.push(S)}}),f.push(g)}}),f}};var Zf=!1,Yb,Jf=new Promise(n=>{Yb=n}),$b=!1;var Hu;function Xb(){if(Zf=!0,$b)return;if(Hu)return Hu;async function n(){let e=await import("./opentype.js");Yb(e),$b=!0}return Hu=n(),Hu}var pl=class{async load(r,e,t=()=>{}){let{load:o}=await Jf;o(r,(i,a)=>{i||!a?t(i??"Something went wrong"):e(a)})}async parse(r){let{parse:e,Bidi:t}=await Jf;try{let o=e(r),i=new t,a=s=>o.charToGlyphIndex(s.char);return i.registerModifier("glyphIndex",null,a),i.applyFeatures(o,o.defaultRenderOptions.features),{font:o,bidi:i}}catch(o){console.error(o)}}};async function cD(n){return await(await fetch(n)).arrayBuffer()}var uD=new pl;async function eh(n){let r,e,t=!1;if(n.url?(r=await cD(n.url),e=n.url,t=n.url.startsWith("/")):n.data&&(r=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength)),r)if(Zf){let o=await uD.parse(r);if(o)return{font:o.font,url:e,intercepted:t,arr:r,bidi:o.bidi}}else return{font:void 0,url:e,intercepted:t,arr:r,bidi:null}}import{CubicBezierCurve as dD,LineCurve as pD,QuadraticBezierCurve as fD}from"three";function hD(n,r){return r.state.glyphIndex===n||r.state.fina===n||r.state.medi===n||r.state.init===n}var Wu=class{constructor(r){this._arrayBuffer=new ArrayBuffer(1);this._isLoaded=!1;this._intercepted=!1;this._isUserFont=r.isUserFont??!1,this._loadingPromise=eh(r).then(e=>{e&&(this._arrayBuffer=e.arr,this._url=e.url,this.font=e.font,this._intercepted=e.intercepted,this._isLoaded=!0,this._bidi=e.bidi)})}update(r){this._isLoaded=!1,this._isUserFont=r.isUserFont??!1,this._loadingPromise=eh(r).then(e=>{e&&(this._arrayBuffer=e.arr,this._url=e.url,this.font=e.font,this._intercepted=e.intercepted,this._isLoaded=!0,this._bidi=e.bidi)})}get url(){return this._url}get intercepted(){return this._intercepted}get isLoaded(){return this._isLoaded}get loadingPromise(){return this._loadingPromise}reverseLigaturesTable(r,e,t){if(!this._bidi)return[];let o=this._bidi;o.getTextGlyphs(e);let i=o.tokenizer.tokens,a=[],s=0,l=t.length===i.length;for(let c=0;c<t.length;c++){let u=t[c].index,p=String.fromCharCode(t[c].unicode),d=i[s];if(hD(u,d)||l)a.push({char:p,index:u,replacements:[d.state.glyphIndex],replacementChars:[d.char]}),s++;else{let h=d.char,f="",m=[d.state.glyphIndex],y=[],g=!1;for(;!g;)s++,f=e.charAt(s),h+=f,m.push(r.charToGlyphIndex(f)),y=r.stringToGlyphs(h),y.length===1&&y[0].index===u&&(g=!0),s>e.length&&(g=!0);a.push({char:p,index:u,replacements:m,replacementChars:Array.from(h)}),s++}}return a}generateShapes(r,e){if(!this._isLoaded)return;let t=this.font,o=e.fontSize/this.unitsPerEm,i=e.fontSize*e.lineHeight,a=r.map(v=>this.getTextWidth(v,e)),s=e.width,l=this.getCharWidth(`
2247
- `,e),c=e.horizontalAlign===1?l:0,u=this.computeSpaceWidthForLine(r,0,e),p=this.getLineInitialOffsetX(a[0],s,e.horizontalAlign,r[0],l),d=this.getLineInitialOffsetY(i,r.length,e.height,o,e.verticalAlign),h=[],f=r.map(v=>[]),m=r.map(v=>[]),y;for(let v=0;v<r.length;v++){let w=r[v],O={features:{liga:!0}},S=[];try{S=t.stringToGlyphs(w,O)}catch(T){console.warn(T)}p=this.getLineInitialOffsetX(a[v],s,e.horizontalAlign,w,l);let C=[];try{C=this.reverseLigaturesTable(t,w,S)}catch(T){console.warn(T)}u=this.computeSpaceWidthForLine(r,v,e);for(let T=0;T<S.length;T++){let x=S[T],N=x.index===0?`
2248
- `:x.unicode?String.fromCharCode(x.unicode):void 0,E=C[T],M=0,D=0;T===0&&e.horizontalAlign===2&&x.leftSideBearing!==void 0&&(D=-x.leftSideBearing*o),y&&(M=t.getKerningValue(x,y)*o),p+=D+M;let _=0;if(N===`
2249
- `)_=c;else if(N===" ")_=u;else{let B=this.createPath(x,o,p,d,e);B&&(_=B.offsetX-(M+D),h.push(B.path))}if(E.replacements.length===1)m[v].push([p,d]),f[v].push(_);else{let B=E.replacements.map(W=>(t.glyphs.get(W).advanceWidth??0)*o),V=B.reduce((W,F)=>W+=F,0),k=B.map(W=>W/V),L=p;for(let W=0;W<k.length;W++){let F=_*k[W];m[v].push([L,d]),f[v].push(F),L+=F}}p+=_,y=x}d-=i}let g=[];for(let v=0,w=h.length;v<w;v++)g.push(...h[v].toShapes());return{shapes:g,charWidths:f,lineWidths:a,charCoords:m}}get isUserFont(){return this._isUserFont}get arrayBuffer(){return this._arrayBuffer}get ascender(){return this.font?.ascender??0}get descender(){return this.font?.descender??0}get familyName(){return this.font?.names.fontFamily??""}get subfamilyName(){return this.font?.names.fontSubfamily??""}get unitsPerEm(){return this.font?.unitsPerEm??1}getLineInitialOffsetX(r,e,t,o,i){return(t===3||t===2)&&o.indexOf(`
2250
- `)>=0&&(r-=i),t===3?e*.5-r*.5:t===2?e-r:0}getLineInitialOffsetY(r,e,t,o,i){let a=e*r,s=Math.abs(this.ascender-this.descender)*o,l=r-s,c=-this.ascender*o-l/2;return i===3?-(t-a-c):i===2?-(t*.5-a*.5-c):c}createPath(r,e,t,o,i){let a=r.getPath(t,-o,i.fontSize,{kerning:!1,letterSpacing:i.letterSpacing});if(!a){console.error('THREE.Font: character "'+r+'" does not exists in font family '+this.familyName+".");return}let s=new Uu,l=(r.advanceWidth??1)*e;if(r)for(let c of a.commands){let u=s.currentPath?.currentPoint;if(!(u&&c.type!=="Z"&&u.x===c.x&&-u.y===c.y))switch(c.type){case"M":s.moveTo(c.x,-c.y);break;case"L":s.lineTo(c.x,-c.y);break;case"Q":s.quadraticCurveTo(c.x1,-c.y1,c.x,-c.y);break;case"C":s.bezierCurveTo(c.x1,-c.y1,c.x2,-c.y2,c.x,-c.y);break}}return s.subPaths.forEach(c=>{let u=mD(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l+i.fontSize*i.letterSpacing,path:s}}getCharWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(r,e,t){let o=this.getCharWidth(" ",t),i=r[e];if(i){let a=this.countSpaces(i.trimEnd());if(t.horizontalAlign===4&&e<r.length-1&&a){let s=t.width,l=this.getTextWidth(i,t);return(s-(l-a*o))/a}}return o}countSpaces(r){return(r.match(/ /g)||[]).length}};function mD(n){if(n.length){let r=n[0];if(r instanceof pD)return r.v1;if(r instanceof dD||r instanceof fD)return r.v0}}var th=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(r){return this.objects.get(r)}get size(){return this.objects.size}get(r,e,t){let o=this.objects.get(r);return o===void 0?(o=this.createObject(r,e,t),this.objects.set(r,o)):o.isShared=!0,o}forceDelete(r){let e=this.objects.get(r);e&&(this.disposeObject(e),this.objects.delete(r))}mutateIfUnique(r,e){let t=this.objects.get(r);if(t&&t.isShared!==!0)return this.objects.delete(r),this.objects.set(e,t),t}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(r,e){let t=this.objects.get(r);e===t?this.unreachable.delete(r):!1&&console.warn("Reachable but deleted",r)}endGc(){this.unreachable.forEach(r=>{this.disposeObject(this.objects.get(r)),this.objects.delete(r)}),this.unreachable.clear()}dispose(){this.objects.forEach(r=>{this.disposeObject(r)}),this.objects.clear()}},fl=class extends th{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,t,o){let i=Vo(e,t,this.flatShading,o);return i.computeBoundingSphere(),i}};var Kb={markNeedsUpdateRendererDirty:()=>{}};import{MathUtils as nv}from"three";var qu=1e3,Qb=512*qu;function yD(n,r){let e=typeof n;return!!((r==="string"||r==="number")&&e===r||r==="boolean"&&(n==="true"||n==="false"||n===!0||n===!1)||r==="image"&&e==="string"&&n.startsWith("http"))}var Zb="https://hooks.spline.design",gD=`${Zb}/events?hashFile=`,Qte=`${Zb}/`,$u=class{constructor(r,e){this.id=r;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=Lo();this.reconnectWaitFor=qu;this._onError=r=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=r=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=qu,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=qu,this._connected=!1};this._onMessage=r=>{let e=r.data,t;try{t=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(t){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:i})=>{t[i.name]!==void 0&&yD(t[i.name],i.type)&&(this.result===void 0&&(this.result={}),this.result[i.name]=t[i.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(gD+this.userWebhook.url),this.eventSource.addEventListener("message",this._onMessage),this.eventSource.addEventListener("error",this._onError),this.eventSource.addEventListener("open",this._onConnected))}disconnect(){this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this.eventSource?.close(),this._onDisconnected(),clearTimeout(this.scheduledReconnectHandle)}_scheduleReconnect(){this.reconnectWaitFor*=2,this.reconnectWaitFor>Qb&&(this.reconnectWaitFor=Qb),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(r){this.userWebhook=r}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(r=>r.data.name)}getParameterValue(r){if(this.getParametersKeys().includes(r)){if(this.result)return this.result?.[r];for(let t of this.userWebhook.parametersSchemas)if(t.data.name===r)return qc.defaultParameterValueByType(t.data.type)}}};var xD=globalThis.atob,bD=globalThis.btoa,wr=class{static floatTo16BitPCM(r){let e=new ArrayBuffer(r.length*2),t=new DataView(e),o=0;for(let i=0;i<r.length;i++,o+=2){let a=Math.max(-1,Math.min(1,r[i]));t.setInt16(o,a<0?a*32768:a*32767,!0)}return e}static base64ToArrayBuffer(r){let e=xD(r),t=e.length,o=new Uint8Array(t);for(let i=0;i<t;i++)o[i]=e.charCodeAt(i);return o.buffer}static arrayBufferToBase64(r){r instanceof Float32Array?r=this.floatTo16BitPCM(r):r instanceof Int16Array&&(r=r.buffer);let e="",t=new Uint8Array(r),o=32768;for(let i=0;i<t.length;i+=o){let a=t.subarray(i,i+o);e+=String.fromCharCode.apply(null,a)}return bD(e)}static mergeInt16Arrays(r,e){if(r instanceof ArrayBuffer&&(r=new Int16Array(r)),e instanceof ArrayBuffer&&(e=new Int16Array(e)),!(r instanceof Int16Array)||!(e instanceof Int16Array))throw new Error("Both items must be Int16Array");let t=new Int16Array(r.length+e.length);for(let o=0;o<r.length;o++)t[o]=r[o];for(let o=0;o<e.length;o++)t[r.length+o]=e[o];return t}static generateId(r,e=21){let t="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=Array(e-r.length).fill(0).map(i=>t[Math.floor(Math.random()*t.length)]).join("");return`${r}${o}`}};var vD=n=>new Promise(r=>setTimeout(()=>r(),n)),Ja=class{constructor(){this.eventHandlers={},this.nextEventHandlers={}}clearEventHandlers(){return this.eventHandlers={},this.nextEventHandlers={},!0}on(r,e){return this.eventHandlers[r]=this.eventHandlers[r]||[],this.eventHandlers[r].push(e),e}onNext(r,e){return this.nextEventHandlers[r]=this.nextEventHandlers[r]||[],this.nextEventHandlers[r].push(e),e}off(r,e){let t=this.eventHandlers[r]||[];if(e){let o=t.indexOf(e);if(o===-1)throw new Error(`Could not turn off specified event listener for "${r}": not found as a listener`);t.splice(o,1)}else delete this.eventHandlers[r];return!0}offNext(r,e){let t=this.nextEventHandlers[r]||[];if(e){let o=t.indexOf(e);if(o===-1)throw new Error(`Could not turn off specified next event listener for "${r}": not found as a listener`);t.splice(o,1)}else delete this.nextEventHandlers[r];return!0}async waitForNext(r,e=null){let t=Date.now(),o;for(this.onNext(r,i=>o=i);!o;){if(e&&Date.now()-t>e)return null;await vD(1)}return o}dispatch(r,e){let t=[].concat(this.eventHandlers[r]||[]);for(let i of t)i(e);let o=[].concat(this.nextEventHandlers[r]||[]);for(let i of o)i(e);return delete this.nextEventHandlers[r],!0}};var hl=class extends Ja{constructor({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}={}){if(super(),this.defaultUrl="wss://api.openai.com/v1/realtime",this.url=r||this.defaultUrl,this.apiKey=e||null,this.debug=!!o,this.ws=null,globalThis.document&&this.apiKey&&!t)throw new Error('Can not provide API key in the browser without "dangerouslyAllowAPIKeyInBrowser" set to true')}isConnected(){return!!this.ws}log(...r){let t=[`[Websocket/${new Date().toISOString()}]`].concat(r).map(o=>typeof o=="object"&&o!==null?JSON.stringify(o,null,2):o);return this.debug&&console.log(...t),!0}async connect({model:r}={model:"gpt-4o-realtime-preview-2024-10-01"}){if(!this.apiKey&&this.url===this.defaultUrl&&console.warn(`No apiKey provided for connection to "${this.url}"`),this.isConnected())throw new Error("Already connected");if(globalThis.document){this.apiKey&&console.warn("Warning: Connecting using API key in the browser, this is not recommended");let e=globalThis.WebSocket,t=new e(`${this.url}${r?`?model=${r}`:""}`,["realtime",`openai-insecure-api-key.${this.apiKey}`,"openai-beta.realtime-v1"]);return t.addEventListener("message",o=>{let i=JSON.parse(o.data);this.receive(i.type,i)}),new Promise((o,i)=>{let a=()=>{this.disconnect(t),i(new Error(`Could not connect to "${this.url}"`))};t.addEventListener("error",a),t.addEventListener("open",()=>{this.log(`Connected to "${this.url}"`),t.removeEventListener("error",a),t.addEventListener("error",()=>{this.disconnect(t),this.log(`Error, disconnected from "${this.url}"`),this.dispatch("close",{error:!0})}),t.addEventListener("close",()=>{this.disconnect(t),this.log(`Disconnected from "${this.url}"`),this.dispatch("close",{error:!1})}),this.ws=t,o(!0)})})}}disconnect(r){if(!r||this.ws===r)return this.ws&&this.ws.close(),this.ws=null,!0}receive(r,e){return this.log("received:",r,e),this.dispatch(`server.${r}`,e),this.dispatch("server.*",e),!0}send(r,e){if(!this.isConnected())throw new Error("RealtimeAPI is not connected");if(e=e||{},typeof e!="object")throw new Error("data must be an object");let t={event_id:wr.generateId("evt_"),type:r,...e};return this.dispatch(`client.${r}`,t),this.dispatch("client.*",t),this.log("sent:",r,t),this.ws.send(JSON.stringify(t)),!0}};var ml=class{constructor(){$r(this,"defaultFrequency",24e3);$r(this,"EventProcessors",{"conversation.item.created":r=>{let{item:e}=r,t=JSON.parse(JSON.stringify(e));if(this.itemLookup[t.id]||(this.itemLookup[t.id]=t,this.items.push(t)),t.formatted={},t.formatted.audio=new Int16Array(0),t.formatted.text="",t.formatted.transcript="",this.queuedSpeechItems[t.id]&&(t.formatted.audio=this.queuedSpeechItems[t.id].audio,delete this.queuedSpeechItems[t.id]),t.content){let o=t.content.filter(i=>["text","input_text"].includes(i.type));for(let i of o)t.formatted.text+=i.text}return this.queuedTranscriptItems[t.id]&&(t.formatted.transcript=this.queuedTranscriptItems.transcript,delete this.queuedTranscriptItems[t.id]),t.type==="message"?t.role==="user"?(t.status="completed",this.queuedInputAudio&&(t.formatted.audio=this.queuedInputAudio,this.queuedInputAudio=null)):t.status="in_progress":t.type==="function_call"?(t.formatted.tool={type:"function",name:t.name,call_id:t.call_id,arguments:""},t.status="in_progress"):t.type==="function_call_output"&&(t.status="completed",t.formatted.output=t.output),{item:t,delta:null}},"conversation.item.truncated":r=>{let{item_id:e,audio_end_ms:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`item.truncated: Item "${e}" not found`);let i=Math.floor(t*this.defaultFrequency/1e3);return o.formatted.transcript="",o.formatted.audio=o.formatted.audio.slice(0,i),{item:o,delta:null}},"conversation.item.deleted":r=>{let{item_id:e}=r,t=this.itemLookup[e];if(!t)throw new Error(`item.deleted: Item "${e}" not found`);delete this.itemLookup[t.id];let o=this.items.indexOf(t);return o>-1&&this.items.splice(o,1),{item:t,delta:null}},"conversation.item.input_audio_transcription.completed":r=>{let{item_id:e,content_index:t,transcript:o}=r,i=this.itemLookup[e],a=o||" ";return i?(i.content[t].transcript=o,i.formatted.transcript=a,{item:i,delta:{transcript:o}}):(this.queuedTranscriptItems[e]={transcript:a},{item:null,delta:null})},"input_audio_buffer.speech_started":r=>{let{item_id:e,audio_start_ms:t}=r;return this.queuedSpeechItems[e]={audio_start_ms:t},{item:null,delta:null}},"input_audio_buffer.speech_stopped":(r,e)=>{let{item_id:t,audio_end_ms:o}=r;this.queuedSpeechItems[t]||(this.queuedSpeechItems[t]={audio_start_ms:o});let i=this.queuedSpeechItems[t];if(i.audio_end_ms=o,e){let a=Math.floor(i.audio_start_ms*this.defaultFrequency/1e3),s=Math.floor(i.audio_end_ms*this.defaultFrequency/1e3);i.audio=e.slice(a,s)}return{item:null,delta:null}},"response.created":r=>{let{response:e}=r;return this.responseLookup[e.id]||(this.responseLookup[e.id]=e,this.responses.push(e)),{item:null,delta:null}},"response.output_item.added":r=>{let{response_id:e,item:t}=r,o=this.responseLookup[e];if(!o)throw new Error(`response.output_item.added: Response "${e}" not found`);return o.output.push(t.id),{item:null,delta:null}},"response.output_item.done":r=>{let{item:e}=r;if(!e)throw new Error('response.output_item.done: Missing "item"');let t=this.itemLookup[e.id];if(!t)throw new Error(`response.output_item.done: Item "${e.id}" not found`);return t.status=e.status,{item:t,delta:null}},"response.content_part.added":r=>{let{item_id:e,part:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`response.content_part.added: Item "${e}" not found`);return o.content.push(t),{item:o,delta:null}},"response.audio_transcript.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.audio_transcript.delta: Item "${e}" not found`);return i.content[t].transcript+=o,i.formatted.transcript+=o,{item:i,delta:{transcript:o}}},"response.audio.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.audio.delta: Item "${e}" not found`);let a=wr.base64ToArrayBuffer(o),s=new Int16Array(a);return i.formatted.audio=wr.mergeInt16Arrays(i.formatted.audio,s),{item:i,delta:{audio:s}}},"response.text.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.text.delta: Item "${e}" not found`);return i.content[t].text+=o,i.formatted.text+=o,{item:i,delta:{text:o}}},"response.function_call_arguments.delta":r=>{let{item_id:e,delta:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`response.function_call_arguments.delta: Item "${e}" not found`);return o.arguments+=t,o.formatted.tool.arguments+=t,{item:o,delta:{arguments:t}}}});this.clear()}clear(){return this.itemLookup={},this.items=[],this.responseLookup={},this.responses=[],this.queuedSpeechItems={},this.queuedTranscriptItems={},this.queuedInputAudio=null,!0}queueInputAudio(r){return this.queuedInputAudio=r,r}processEvent(r,...e){if(!r.event_id)throw console.error(r),new Error('Missing "event_id" on event');if(!r.type)throw console.error(r),new Error('Missing "type" on event');let t=this.EventProcessors[r.type];if(!t)throw new Error(`Missing conversation event processor for "${r.type}"`);return t.call(this,r,...e)}getItem(r){return this.itemLookup[r]||null}getItems(){return this.items.slice()}};var es=class extends Ja{constructor({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}={}){super(),this.defaultSessionConfig={modalities:["text","audio"],instructions:"",voice:"alloy",input_audio_format:"pcm16",output_audio_format:"pcm16",input_audio_transcription:null,turn_detection:null,tools:[],tool_choice:"auto",temperature:.8,max_response_output_tokens:4096},this.sessionConfig={},this.transcriptionModels=[{model:"whisper-1"}],this.defaultServerVadConfig={type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:200},this.realtime=new hl({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}),this.conversation=new ml,this._resetConfig(),this._addAPIEventHandlers()}_resetConfig(){return this.sessionCreated=!1,this.tools={},this.sessionConfig=JSON.parse(JSON.stringify(this.defaultSessionConfig)),this.inputAudioBuffer=new Int16Array(0),!0}_addAPIEventHandlers(){this.realtime.on("client.*",o=>{let i={time:new Date().toISOString(),source:"client",event:o};this.dispatch("realtime.event",i)}),this.realtime.on("server.*",o=>{let i={time:new Date().toISOString(),source:"server",event:o};this.dispatch("realtime.event",i)}),this.realtime.on("server.session.created",()=>this.sessionCreated=!0);let r=(o,...i)=>{let{item:a,delta:s}=this.conversation.processEvent(o,...i);return{item:a,delta:s}},e=(o,...i)=>{let{item:a,delta:s}=r(o,...i);return a&&this.dispatch("conversation.updated",{item:a,delta:s}),{item:a,delta:s}},t=async o=>{try{let i=JSON.parse(o.arguments),a=this.tools[o.name];if(!a)throw new Error(`Tool "${o.name}" has not been added`);let s=await a.handler(i);this.realtime.send("conversation.item.create",{item:{type:"function_call_output",call_id:o.call_id,output:JSON.stringify(s)}})}catch(i){this.realtime.send("conversation.item.create",{item:{type:"function_call_output",call_id:o.call_id,output:JSON.stringify({error:i.message})}})}this.createResponse()};return this.realtime.on("server.response.created",r),this.realtime.on("server.response.output_item.added",r),this.realtime.on("server.response.content_part.added",r),this.realtime.on("server.input_audio_buffer.speech_started",o=>{r(o),this.dispatch("conversation.interrupted")}),this.realtime.on("server.input_audio_buffer.speech_stopped",o=>r(o,this.inputAudioBuffer)),this.realtime.on("server.conversation.item.created",o=>{let{item:i}=e(o);this.dispatch("conversation.item.appended",{item:i}),i.status==="completed"&&this.dispatch("conversation.item.completed",{item:i})}),this.realtime.on("server.conversation.item.truncated",e),this.realtime.on("server.conversation.item.deleted",e),this.realtime.on("server.conversation.item.input_audio_transcription.completed",e),this.realtime.on("server.response.audio_transcript.delta",e),this.realtime.on("server.response.audio.delta",e),this.realtime.on("server.response.text.delta",e),this.realtime.on("server.response.function_call_arguments.delta",e),this.realtime.on("server.response.output_item.done",async o=>{let{item:i}=e(o);i.status==="completed"&&this.dispatch("conversation.item.completed",{item:i}),i.formatted.tool&&t(i.formatted.tool)}),!0}isConnected(){return this.realtime.isConnected()}reset(){return this.disconnect(),this.clearEventHandlers(),this.realtime.clearEventHandlers(),this._resetConfig(),this._addAPIEventHandlers(),!0}async connect(){if(this.isConnected())throw new Error("Already connected, use .disconnect() first");return await this.realtime.connect(),this.updateSession(),!0}async waitForSessionCreated(){if(!this.isConnected())throw new Error("Not connected, use .connect() first");for(;!this.sessionCreated;)await new Promise(r=>setTimeout(()=>r(),1));return!0}disconnect(){this.sessionCreated=!1,this.realtime.isConnected()&&this.realtime.disconnect(),this.conversation.clear()}getTurnDetectionType(){return this.sessionConfig.turn_detection?.type||null}addTool(r,e){if(!r?.name)throw new Error("Missing tool name in definition");let t=r?.name;if(this.tools[t])throw new Error(`Tool "${t}" already added. Please use .removeTool("${t}") before trying to add again.`);if(typeof e!="function")throw new Error(`Tool "${t}" handler must be a function`);return this.tools[t]={definition:r,handler:e},this.updateSession(),this.tools[t]}removeTool(r){if(!this.tools[r])throw new Error(`Tool "${r}" does not exist, can not be removed.`);return delete this.tools[r],!0}deleteItem(r){return this.realtime.send("conversation.item.delete",{item_id:r}),!0}updateSession({modalities:r=void 0,instructions:e=void 0,voice:t=void 0,input_audio_format:o=void 0,output_audio_format:i=void 0,input_audio_transcription:a=void 0,turn_detection:s=void 0,tools:l=void 0,tool_choice:c=void 0,temperature:u=void 0,max_response_output_tokens:p=void 0}={}){r!==void 0&&(this.sessionConfig.modalities=r),e!==void 0&&(this.sessionConfig.instructions=e),t!==void 0&&(this.sessionConfig.voice=t),o!==void 0&&(this.sessionConfig.input_audio_format=o),i!==void 0&&(this.sessionConfig.output_audio_format=i),a!==void 0&&(this.sessionConfig.input_audio_transcription=a),s!==void 0&&(this.sessionConfig.turn_detection=s),l!==void 0&&(this.sessionConfig.tools=l),c!==void 0&&(this.sessionConfig.tool_choice=c),u!==void 0&&(this.sessionConfig.temperature=u),p!==void 0&&(this.sessionConfig.max_response_output_tokens=p);let d=[].concat((l||[]).map(f=>{let m={type:"function",...f};if(this.tools[m?.name])throw new Error(`Tool "${m?.name}" has already been defined`);return m}),Object.keys(this.tools).map(f=>({type:"function",...this.tools[f].definition}))),h={...this.sessionConfig};return h.tools=d,this.realtime.isConnected()&&this.realtime.send("session.update",{session:h}),!0}sendUserMessageContent(r=[]){if(r.length){for(let e of r)e.type==="input_audio"&&(e.audio instanceof ArrayBuffer||e.audio instanceof Int16Array)&&(e.audio=wr.arrayBufferToBase64(e.audio));this.realtime.send("conversation.item.create",{item:{type:"message",role:"user",content:r}})}return this.createResponse(),!0}appendInputAudio(r){return r.byteLength>0&&(this.realtime.send("input_audio_buffer.append",{audio:wr.arrayBufferToBase64(r)}),this.inputAudioBuffer=wr.mergeInt16Arrays(this.inputAudioBuffer,r)),!0}createResponse(){return this.getTurnDetectionType()===null&&this.inputAudioBuffer.byteLength>0&&(this.realtime.send("input_audio_buffer.commit"),this.conversation.queueInputAudio(this.inputAudioBuffer),this.inputAudioBuffer=new Int16Array(0)),this.realtime.send("response.create"),!0}cancelResponse(r,e=0){if(r){if(r){let t=this.conversation.getItem(r);if(!t)throw new Error(`Could not find item "${r}"`);if(t.type!=="message")throw new Error('Can only cancelResponse messages with type "message"');if(t.role!=="assistant")throw new Error('Can only cancelResponse messages with role "assistant"');this.realtime.send("response.cancel");let o=t.content.findIndex(i=>i.type==="audio");if(o===-1)throw new Error("Could not find audio on item to cancel");return this.realtime.send("conversation.item.truncate",{item_id:r,content_index:o,audio_end_ms:Math.floor(e/this.conversation.defaultFrequency*1e3)}),{item:t}}}else return this.realtime.send("response.cancel"),{item:null}}async waitForNextItem(){let r=await this.waitForNext("conversation.item.appended"),{item:e}=r;return{item:e}}async waitForNextCompletedItem(){let r=await this.waitForNext("conversation.item.completed"),{item:e}=r;return{item:e}}};var SD=`
2279
+ `)}return t}};import{VideoTexture as _N,Texture as BN}from"three";var _u=class{constructor(r=1e3*10){this.timeout=r;this.cache=new Map;this.head={data:null,time:0,src:null,next:null,prev:null};this.tail={data:null,time:1/0,src:null,next:null,prev:null};this.hasClean=!1;this.head.next=this.tail,this.tail.prev=this.head}log(...r){}remove(r){let e=this.cache.get(r);e&&(this.dispose(r,e.data),this.cache.delete(r),e.prev.next=e.next,e.next.prev=e.prev)}scheduleCleanup(){this.hasClean||(this.log("scheduled cleanup"),this.hasClean=!0,setTimeout(()=>{this.hasClean=!1,this.log("cleaning");let r=Date.now(),e=this.head.next;for(;e.time<r-this.timeout;)this.dispose(e.src,e.data),this.cache.delete(e.src),e=e.next,e.prev=this.head,this.head.next=e;this.head.next!==this.tail?this.scheduleCleanup():this.log("no more cleanup")},this.timeout+1e3))}has(r){return this.cache.get(r)?.data}load(r){let e=Date.now(),t=this.cache.get(r);return t===void 0?(t={data:this.create(r),src:r,time:e,next:null,prev:null},this.cache.set(r,t)):(t.time=e,t.prev.next=t.next,t.next.prev=t.prev),t.prev=this.tail.prev,t.next=this.tail,this.tail.prev.next=t,this.tail.prev=t,this.scheduleCleanup(),t.data}};var qf=class extends _u{create(r){return URL.createObjectURL(new Blob([r]))}dispose(r,e){URL.revokeObjectURL(e)}},Wf;function zb(n){return typeof n=="string"?n:(Wf||(Wf=new qf),Wf.load(n))}var Bu=class{constructor(r,e){this.data=r;this.cache=e;this.refCount=0}deref(){if(this.refCount===0&&!1)throw new Error("ref count -1?");this.refCount-=1,this.refCount===0&&(this.cache.remove(this),this.dispose())}dispose(){if(this.refCount!==0&&!1)throw new Error("ref count is not 0")}},Ru=class{constructor(){this.cache=new Map}remove(r){if(this.cache.delete(r.data)===!1&&!1)throw new Error("ref count remove non-exists")}load(r){let e=this.cache.get(r);return e===void 0&&(e=this.create(r),this.cache.set(r,e)),e.refCount+=1,e}};var Ka=class extends Bu{constructor(e,t){super(e,t.imageHolderCache);this.data=e;this.shared=t;this.loaded=!1;this.isVideo=!1;this.isBuffer=!1;this._cache={[1e3]:{},[1001]:{},[1002]:{}};this.isVideo=e.type==="video",this.isBuffer=e.isWebGLRenderTarget===!0,this.loadPromise=this.updateSrc(this.isBuffer?e:e.data)}async updateSrc(e){if(typeof document>"u")return;this.disposeTextures(),this.loaded=!1;let t=()=>{this.loaded=!0;for(let i of Object.values(this._cache))for(let a of Object.values(i))for(let s of Object.values(a))s&&(s.image=this.img,s.needsUpdate=!0);this.shared.requestRender()};if(this.isBuffer)this.img=e,this.loaded=!0;else if(this.isVideo){if(this.img=document.createElement("video"),this.img.preload="auto",this.img.playsInline=!0,this.img.currentTime=.01,typeof e!="string"){var o=new FileReader;o.readAsDataURL(new Blob([e],{type:"video/mp4"}));let i;await new Promise(a=>{o.onloadend=s=>{i=s.target?.result,a(null)}}),this.img.src=i}else this.img.src=e;this.img.onloadeddata=()=>{t()}}else this.img=new Image,this.img.src=zb(e),this.img.onload=t,await new Promise(i=>{this.img.onload=()=>{t(),i(null)}})}getTexture(e,t=1008,o=1006){let i=this._cache[e]?.[t]?.[o];if(i)return i;{let a;return this.isBuffer?a=this.img.texture:this.isVideo?a=new _N(this.img,void 0,e,e):a=new BN(this.img,void 0,e,e,o,t),this.loaded&&(a.needsUpdate=!0),this._cache[e]===void 0&&(this._cache[e]={}),this._cache[e][t]===void 0&&(this._cache[e][t]={}),this._cache[e][t][o]=a,a}}setNeedsUpdate(e){for(let t of Object.values(this._cache))for(let o of Object.values(t))for(let i of Object.values(o))i&&(i.needsUpdate=e)}disposeTextures(){for(let[e,t]of Object.entries(this._cache))for(let[o,i]of Object.entries(t))for(let[a,s]of Object.entries(i))s?.dispose(),this._cache[e]!==void 0&&this._cache[e][o]!==void 0&&(this._cache[e][o][a]=void 0)}dispose(){super.dispose(),this.disposeTextures()}};var dr=class extends Ka{};import{Vector2 as jo,Vector3 as po,Vector4 as Lu}from"three";function jt(n,r){return r.color(n)}function Gb(n,r){switch(n.type){case"fresnel":return VN(n,r);case"gradient":return zN(n,r);case"depth":return GN(n,r);case"normal":return FN(n,r);case"noise":return jN(n,r);case"rainbow":return kN(n,r);case"toon":return UN(n,r);case"outline":return HN(n,r);case"transmission":return WN(n,r);case"color":return LN(n,r);case"pattern":return qN(n,r)}}function RN(n){return{type:n.type}}function Ur(n,r){let{alpha:e,mode:t,isMask:o}=n,i=typeof e=="string"?(Number(r.getVariable(e))??100)/100:e;return{...RN(n),alpha:i,mode:t,isMask:o}}function LN(n,r){return{...Ur(n,r),color:jt(n.color,r)}}function VN(n,r){let{bias:e,scale:t,intensity:o,factor:i,color:a}=n;return{...Ur(n,r),color:jt(a,r),bias:e,scale:t,intensity:o,factor:i}}function zN(n,r){let{gradientType:e,smooth:t,colors:o,steps:i,angle:a,offset:s,morph:l}=n;return{...Ur(n,r),gradientType:e,smooth:t,colors:o.map(c=>new Lu(c[0],c[1],c[2],c[3])),num:o.length,steps:i,offset:new jo(...s),morph:new jo(...l),angle:a}}function GN(n,r){let{gradientType:e,near:t,far:o,isVector:i,isWorldSpace:a,origin:s,direction:l,colors:c,steps:u,smooth:p}=n;return{...Ur(n,r),gradientType:e,near:t,far:o,isVector:i,isWorldSpace:a,origin:new po(...s),direction:l?new po(...l):new po(1,0,0),colors:c.map(d=>d!==void 0?new Lu(d[0],d[1],d[2],d[3]):new Lu(0,0,0,0)),steps:u.slice(0,c.length),smooth:p}}function FN(n,r){let{cnormal:e}=n;return{...Ur(n,r),cnormal:new po(e[0],e[1],e[2])}}function jN(n,r){return{...Ur(n,r),scale:n.scale,move:n.move,fA:new jo(...n.fA),fB:new jo(...n.fB),size:new po(...n.size),distortion:new jo(...n.distortion),colorA:jt(n.colorA,r),colorB:jt(n.colorB,r),colorC:jt(n.colorC,r),colorD:jt(n.colorD,r),noiseType:n.noiseType,voronoiStyle:n.voronoiStyle,highCut:n.highCut,lowCut:n.lowCut,smoothness:n.smoothness,seed:n.seed,quality:n.quality}}function kN(n,r){return{...Ur(n,r),filmThickness:n.filmThickness,movement:n.movement,wavelengths:new po(...n.wavelengths),noiseStrength:n.noiseStrength,noiseScale:n.noiseScale,offset:new po(...n.offset)}}function UN(n,r){return{...Ur(n,r),positioning:n.positioning,colors:n.colors.map(e=>new Lu(e[0],e[1],e[2],e[3])),num:n.colors.length,steps:n.steps,source:new po(...n.source),isWorldSpace:n.isWorldSpace,noiseStrength:n.noiseStrength,noiseScale:n.noiseScale,shadowColor:jt(n.shadowColor,r),offset:new po(...n.offset)}}function HN(n,r){return{...Ur(n,r),outlineColor:jt(n.outlineColor,r),contourColor:jt(n.contourColor,r),outlineWidth:n.outlineWidth,contourWidth:n.contourWidth,outlineThreshold:n.outlineThreshold,contourThreshold:n.contourThreshold,outlineSmoothing:n.outlineSmoothing,contourFrequency:n.contourFrequency,contourDirection:new po(...n.contourDirection),positionalLines:n.positionalLines,compensation:n.compensation}}function WN(n,r){return{...Ur(n,r),thickness:n.thickness,ior:n.ior,roughness:n.roughness}}function qN(n,r){return{...Ur(n,r),style:n.style,projection:n.projection,axis:n.axis,blending:n.blending,offset:new jo(...n.offset),colorA:jt(n.colorA,r),colorB:jt(n.colorB,r),frequency:new jo(...n.frequency),size:n.size,variation:n.variation,smoothness:n.smoothness,zigzag:n.zigzag,rotation:n.rotation,vertical:new jo(...n.vertical),horizontal:new jo(...n.horizontal),sides:n.sides}}var Sn=class extends At{};import{MathUtils as $N,Vector4 as YN}from"three";var XN={noise:["noiseType"],texture:["projection","axis","side"],video:["projection","axis","side"],displace:["noiseType"],light:["roughnessMap","bumpMap"],depth:["smooth","isWorldSpace","gradientType","isVector"],pattern:["style","projection","axis"]},KN={depth:["colors"]};function QN(n,r,e){if(r==="isMask")return!0;let t=XN[n.type],o=KN[n.type];if(o!==void 0){let i=n.color;if(o.includes(r)){let a=i[r]?.value?.length;if(a!==void 0&&a!==e.length)return!0}}return t!==void 0?t.includes(r):!1}function $f(n,r,e){let t=e.uniforms[`f${e.id}_texture`];if(!t)return!1;let o=!1,i=n;if("image"in i){let a=i.image,s=r.image(a),l=t;l.image instanceof dr||l.image.deref(),l.image=s}if("video"in i){let a=i.video,s=r.video(a),l=t;l.image instanceof dr||l.image.deref(),l.image=s}if("wrapping"in i){let a=t;a.wrap=i.wrapping}if("minFilter"in i){let a=t;a.minFilter=i.minFilter}if("magFilter"in i){let a=t;a.magFilter=i.magFilter}if("rotation"in i&&e.uniforms[`f${e.id}_rotation`])return e.uniforms[`f${e.id}_rotation`].value=(i.rotation??0)*$N.DEG2RAD,o;if("repeat"in i||"offset"in i||"rotation"in i){let a="mat",s=e.uniforms[`f${e.id}_${a}`];"repeat"in i&&(s.repeat=i.repeat),"offset"in i&&(s.offset=i.offset),"rotation"in i&&(s.rotation=i.rotation??0),s.updateMatrix()}return o}function Fb(n,r,e,t){let o=!1;for(let[i,a]of Object.entries(n)){if(i==="bumpMap"||i==="roughnessMap"){o=!0;continue}if(!i||a===void 0)continue;if(Yf(i,e,t,r)){i==="visible"&&e.type==="light"&&(o=!0);continue}e.visible=t.visible;let s=e.uniforms[`f${e.id}_${i}`];if(!!s&&!(s instanceof bn))switch(o=o||QN(e,i,a),s.constructor){case He:if(typeof a=="string"){let l=r.getColor(a);l&&(s.value=l);break}else{let l=a;s.value instanceof Sn?s.value=new At(l.r,l.g,l.b,l.a):s.setRGBA(l);break}case er:if(typeof a=="string"){let l=r.getColor(a);l&&(s.value=l);break}else{let l=a;s.value instanceof Sn?s.value=new At(l.r,l.g,l.b,l.a):s.value.setRGBA(l.r,l.g,l.b,l.a);break}case st:{let l=a;s.value.setX(l[0]),s.value.setY(l[1]);break}case Gt:{let l=a;s.value.setX(l[0]),s.value.setY(l[1]),s.value.setZ(l[2]);break}case Yt:{$f(a,r,e);break}case kr:{s.value=a.map(l=>new YN(...l));break}default:{s.value=a;break}}}return o}var wn=(n,r,e)=>Math.max(0,Math.min(1,Number(r.getVariable(typeof n=="number"?n*100:n,e)??100)/100))??1,Pn=class{constructor(r,e,t,o,i){this.id=r;this.uuid=e;this.data=t;this.uniforms={};for(let a in o)this.uniforms[`f${this.id}_${a}`]=o[a];for(let a in t)Yf(a,this,t,i)}get type(){return this.data.type}static create(r,e,t,o){if(t.type==="light")return Xt.createLightLayer(r,e,t,o);if(t.type==="texture"||t.type==="video"){let i=t.type==="texture"?o.uiBuffer(t.texture.image)??o.image(t.texture.image):o.video(t.texture.video),a=new ti(i,t.texture.wrapping,t.texture.minFilter??1008,t.texture.magFilter??1006),s=new Nu(i),l=new Du(t.texture.repeat,t.texture.offset,t.texture.rotation??0),c=new se(t.crop?1:0),u=new Be(t.projection??0),p=new Be(["x","y","z"].indexOf(t.axis)??0),d=new Be(t.side??0),f=new st(t.size?new Hr(t.size[0],t.size[1]):new Hr(100,100)),h=new se(t.blending??0),m=new se(wn(t.alpha,o)),y=new Be(t.mode??0),b=new ft(t.isMask??!1),S=new vn(a,s,c,u,p,d,f,h,l,m,y,b),P=new ke(S.calpha,"f");return new rt(r,e,t,{texture:a,textureSize:s,crop:c,projection:u,axis:p,side:d,size:f,blending:h,mat:l,alpha:m,mode:y,isMask:b},S,y,P,b,o)}else if(t.type==="matcap"){let i=o.image(t.texture.image),a=new ti(i,t.texture.wrapping,t.texture.minFilter??1008,t.texture.magFilter??1006),s=new se(wn(t.alpha,o)),l=new Be(t.mode??0),c=new ft(t.isMask??!1),u=new se((t.texture.rotation??0)*ZN.DEG2RAD),p=new ka(a,s,l,c,u),d=new ke(p.calpha,"f");return new rt(r,e,t,{texture:a,alpha:s,mode:l,isMask:c,rotation:u},p,l,d,c,o)}else if(t.type==="displace")if(t.displacementType==="noise"){let i=new Gt(new fo(...t.offset)),a=new se(t.scale??10),s=new se(t.intensity??8),l=new se(t.movement??1),c=new Be(t.noiseType??0),u=new Be(t.voronoiStyle??0),p=new se(t.smoothness??.5),d=new se(t.seed??0),f=new se(t.highCut??1),h=new se(t.lowCut??0),m=new Be(t.quality??1),y=new Xa(s,l,i,u,p,d,f,h,m,a,c);return new ll(r,e,t,{offset:i,scale:a,intensity:s,movement:l,noiseType:c,voronoiStyle:u,smoothness:p,seed:d,highCut:f,lowCut:h,quality:m},y,o)}else throw new Error;else return t3(r,e,t,o)}updateByOp(r,e,t){let o=r;if(o.path[0]===void 0){if(o.type===0)return"type"in o.props||"category"in o.props||"visible"in o.props||"noiseType"in o.props?(t.scene.markNeedsUpdateRendererDirty(),!0):Fb(o.props,t.shared,this,e)}else if(o.path[0]==="texture")return"texture"in e||"video"in e?$f(o.props,t.shared,this):!0;return!1}dispose(){if(JN(this)){let r=this.uniforms[`f${this.id}_texture`];if(!r)return!1;let e=r;e.image instanceof dr||e.image.deref()}}hasValueByKey(r){return this.uniforms[r]!==void 0}hasValue(r){return this.hasValueByKey(`f${this.id}_${r}`)}setValue(r,e){let t=`f${this.id}_${r}`;this.hasValueByKey(t)&&e!==void 0&&(this.uniforms[t].value=e)}getNode(r){let e=`f${this.id}_${r}`;if(this.hasValueByKey(e))return this.uniforms[e]}getValue(r){let e=`f${this.id}_${r}`;if(this.hasValueByKey(e))return this.uniforms[e].value}getName(r){let t=/f\d+_(.*)/.exec(r);if(t&&t.length>1)return t[1];console.log(`Layer.getName: error ${r}`)}getNames(){let r=[];for(let e in this.uniforms){let t=this.getName(e);t&&r.push(t)}return r}},rt=class extends Pn{constructor(e,t,o,i,a,s,l,c,u){super(e,t,o,i,u);this.params=i;this.color=a;this.mode=s;this.alpha=l;this.isMask=c}},ll=class extends Pn{constructor(e,t,o,i,a,s){super(e,t,o,i,s);this.position=a}},Xt=class extends Pn{constructor(e,t,o,i,a,s){super(e,t,o,a,s);this.node=i}static createLightLayer(e,t,o,i){let a,s=new se(wn(o.alpha,i)),l=new Be(o.mode),c=new se(o.bumpMapIntensity),u=new se(wn(o.alphaOverride,i)),p;if(!o.visible)a=new Go,p={};else if(o.category==="lambert"){a=new nl;let d=new He(i.color(o.emissive)??0),f=new ft(o.occlusion??!0);p={emissive:d,occlusion:f},a.emissive=d,a.occlusion=f}else if(o.category==="toon"){a=new sl;let d=new se(o.shininess??30),f=new He(i.color(o.specular)??1118481);p={shininess:d,specular:f},a.shininess=d,a.specular=f}else if(o.category==="physical"){a=new al;let d=new se(o.roughness??.3),f=new se(o.metalness??0),h=new se(o.reflectivity??.5),m=new ft(o.occlusion??!0);p={roughness:d,metalness:f,reflectivity:h,occlusion:m},a.roughness=d,a.metalness=f,a.reflectivity=h,a.occlusion=m}else{a=new il;let d=new se(o.shininess??30),f=new He(o.specular!==void 0?i.color(o.specular)??1118481:1118481),h=new ft(o.occlusion??!0);p={shininess:d,specular:f,occlusion:h},a.shininess=d,a.specular=f,a.occlusion=h}return a.alpha=new se(1),a.shadingAlpha=s,a.shadingBlend=l,a.bumpMapIntensity=c,a.alphaOverride=u,p.alpha=a.shadingAlpha,p.mode=a.shadingBlend,p.bumpMapIntensity=a.bumpMapIntensity,p.alphaOverride=a.alphaOverride,new Xt(e,t,o,a,p,i)}get category(){return this.node.category}};function JN(n){let r=n instanceof Pn?n.type:n;return r==="texture"||r==="video"||r==="displace_map"||r==="matcap"}function Sr(n){return{alpha:new se(n.alpha??1),mode:new Be(n.mode??0),isMask:new ft(n.isMask??!1)}}function e3(n,r,e,t,o){switch(n.type){case"color":{let i=new He(t.color??mt),a=Sr(t),s=new ri(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{color:i,...a},s,a.mode,l,a.isMask,o)}case"fresnel":{let i=new He(t.color??16777215),a=new se(t.bias??.1),s=new se(t.scale??1),l=new se(t.intensity??2),c=new se(t.factor??1),u=Sr(t),p=new ol(i,a,s,l,c,u.alpha,u.mode,u.isMask),d=new ke(p.calpha,"f");return new rt(r,e,n,{color:i,bias:a,scale:s,intensity:l,factor:c,...u},p,u.mode,d,u.isMask,o)}case"rainbow":{let i=new se(t.filmThickness??30),a=new se(t.movement??0),s=new Gt(t.wavelengths??new fo(0,0,0)),l=new se(t.noiseStrength??0),c=new se(t.noiseScale??1),u=new Gt(t.offset??new fo(0,0,0)),p=Sr(t),d=new qa(i,a,s,l,c,u,p.alpha,p.isMask),f=new ke(d.calpha,"f");return new rt(r,e,n,{filmThickness:i,movement:a,wavelengths:s,noiseStrength:l,noiseScale:c,offset:u,...p},d,p.mode,f,p.isMask,o)}case"transmission":{let i=new se(t.thickness??10),a=new se(t.ior??1.5),s=new se(t.roughness??.5),l=Te.transmissionSize,c=Te.transmissionRenderTarget,u=Te.transmissionRenderTargetDepth,p=window.innerWidth,d=window.innerHeight,f=p>=d?new st(d/p,1):new st(1,p/d),h=Sr(t),m=new Ya(i,a,s,l,c,u,f,h.alpha),y=new ke(m.calpha,"f");return new rt(r,e,n,{thickness:i,ior:a,roughness:s,aspectRatio:f,...h},m,h.mode,y,h.isMask,o)}case"toon":{let i=new Be(t.positioning??0),a;t.colors?a=new kr(t.colors.length,t.colors):(a=new kr(10,new Qa(0,0,0,1)),a.value[1]=new Qa(1,1,1,1));let s;t.steps?s=new jr(t.steps.length,t.steps):(s=new jr(10,1),s.value[0]=0);let l=new Gt(t.source??new fo(0,0,0)),c=new ft(t.isWorldSpace??!0),u=new se(t.noiseStrength??0),p=new se(t.noiseScale??1),d=new er(t.shadowColor),f=new Gt(t.offset??new fo(0,0,0)),h=Sr(t),m=new $a(i,a,s,l,c,u,p,d,f,h.alpha),y=new ke(m.calpha,"f");return new rt(r,e,n,{positioning:i,colors:a,steps:s,source:l,isWorldSpace:c,noiseStrength:u,noiseScale:p,shadowColor:d,offset:f,...h},m,h.mode,y,h.isMask,o)}case"outline":{let i=new He(t.outlineColor??16777215),a=new He(t.contourColor??16777215),s=new se(t.outlineWidth??.1),l=new se(t.contourWidth??.1),c=new se(t.outlineThreshold??.1),u=new se(t.contourThreshold??.1),p=new se(t.outlineSmoothing??.1),d=new se(t.contourFrequency??.1),f=new Gt(t.contourDirection??new fo(0,1,0)),h=new ft(t.positionalLines??!1),m=new ft(t.compensation??!0),y=Te.normalRenderTarget,b=Te.normalRenderTargetDepth,S=Te.pixelRatioNode,P=Te.resolution,C=Sr(t),v=new Ha(i,a,s,l,c,u,p,d,f,h,m,P,y,b,S,C.alpha),A=new ke(v.calpha,"f");return new rt(r,e,n,{outlineColor:i,contourColor:a,outlineWidth:s,contourWidth:l,outlineThreshold:c,contourThreshold:u,outlineSmoothing:p,contourFrequency:d,contourDirection:f,positionalLines:h,compensation:m,...C},v,C.mode,A,C.isMask,o)}case"depth":{let i=new Be(t.gradientType??0),a=new ft(t.smooth??!1),s=new se(t.near??50),l=new se(t.far??200),c=new se(t.isVector??1),u=new se(t.isWorldSpace??0),p=new Gt(t.origin??new fo),d=new Gt(t.direction??new fo),f;t.colors?f=new kr(t.colors.length,t.colors):(f=new kr(2,new Qa(0,0,0,1)),f.value[1]=new Qa(1,1,1,1));let h;t.steps?h=new jr(t.steps.length,t.steps):(h=new jr(2,1),h.value[0]=0);let m=Sr(t),y=new Fa(i,a,s,l,c,u,p,d,f,h,m.alpha,m.isMask),b=new ke(y.calpha,"f");return new rt(r,e,n,{gradientType:i,smooth:a,near:s,far:l,isVector:c,isWorldSpace:u,origin:p,direction:d,colors:f,steps:h,...m},y,m.mode,b,m.isMask,o)}case"noise":{let i=new se(t.scale??1),a=new Gt(t.size??new fo(100,100,100)),s=new se(t.move??1),l=new st(t.fA??new Hr(1.7,9.2)),c=new st(t.fB??new Hr(8.3,2.8)),u=new st(t.distortion??new Hr(1,1)),p=new er(t.colorA),d=new er(t.colorB),f=new er(t.colorC),h=new er(t.colorD),m=new Be(t.noiseType??0),y=new Be(t.voronoiStyle??0),b=new se(t.highCut??1),S=new se(t.lowCut??0),P=new se(t.smoothness??.5),C=new se(t.seed??.5),v=new Be(t.quality??1),A=Sr(t),T=new Ua(i,a,s,l,c,u,p,d,f,h,A.alpha,m,A.isMask,y,b,S,P,C,v),g=new ke(T.calpha,"f");return new rt(r,e,n,{scale:i,size:a,move:s,fA:l,fB:c,distortion:u,colorA:p,colorB:d,colorC:f,colorD:h,noiseType:m,...A,voronoiStyle:y,highCut:b,lowCut:S,smoothness:P,seed:C,quality:v},T,A.mode,g,A.isMask,o)}case"normal":{let i=new Gt(t.cnormal??new fo(1,1,1)),a=Sr(t),s=new Va(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{cnormal:i,...a},s,a.mode,l,a.isMask,o)}case"gradient":{let i=new Be(t.gradientType??0),a=new ft(t.smooth??!1),s;t.colors?s=new kr(t.colors.length,t.colors):(s=new kr(10,new Qa(0,0,0,1)),s.value[1]=new Qa(1,1,1,1));let l;t.steps?l=new jr(t.steps.length,t.steps):(l=new jr(10,1),l.value[0]=0);let c=new st(t.offset??new Hr(0,0)),u=new st(t.morph??new Hr(0,0)),p=new se(t.angle??0),d=Sr(t),f=new ja(i,a,s,l,c,u,p,d.alpha,d.isMask),h=new ke(f.calpha,"f");return new rt(r,e,n,{gradientType:i,smooth:a,colors:s,steps:l,offset:c,morph:u,angle:p,...d},f,d.mode,h,d.isMask,o)}case"pattern":{let i=new Be(t.style??0),a=new Be(t.projection??0),s=new Be(["x","y","z"].indexOf(t.axis)??0),l=new se(t.blending??0),c=new st(t.offset??new Hr(0,0)),u=new er(t.colorA),p=new er(t.colorB),d=new st(t.frequency??new Hr(10,10)),f=new se(t.size??.5),h=new se(t.variation??0),m=new se(t.smoothness??.5),y=new se(t.zigzag??0),b=new se(t.rotation??0),S=new st(t.vertical??new Hr(0,1)),P=new st(t.horizontal??new Hr(0,1)),C=new Be(t.sides??6),v=Sr(t),A=new Wa(i,a,s,l,c,u,p,d,f,h,m,y,b,S,P,C,v.alpha,v.isMask),T=new ke(A.calpha,"f");return new rt(r,e,n,{style:i,projection:a,axis:s,blending:l,offset:c,colorA:u,colorB:p,frequency:d,size:f,variation:h,smoothness:m,zigzag:y,rotation:b,vertical:S,horizontal:P,sides:C,...v},A,v.mode,T,v.isMask,o)}default:{let i=new He(1,0,0,1),a=Sr(t),s=new ri(i,a.alpha),l=new ke(s.calpha,"f");return new rt(r,e,n,{color:i,...a},s,a.mode,l,a.isMask,o)}}}function t3(n,r,e,t){let o=Gb(e,t);return e3(e,n,r,o,t)}function Yf(n,r,e,t){if(e.type==="displace"&&(n==="intensity"||n==="visible")){let o=r.uniforms[`f${r.id}_intensity`];return o?(o.value=e.intensity*(e.visible?1:0),o):void 0}if(e.type!=="displace"&&(n==="alpha"||n==="visible")){let o=r.uniforms[`f${r.id}_alpha`];if(!o)return;if(o.value=wn(e.alpha,t)*(e.visible?1:0),e.type==="outline"&&n==="visible"){let i=r.uniforms[`f${r.id}_compensation`];i&&(i.value=e.compensation&&e.visible)}return o}}function Vu(n,r){let e=0,t=n.layers.find(o=>o.data.type==="light");if(t){let o=t.data,i=Number(r.getVariable(o.alphaOverride));if((typeof o.alphaOverride=="string"?i/100:o.alphaOverride)<1)return!0}for(let o of n.layers){if(o.data.type!=="displace"&&o.data.isMask)return!0;if(o.data.type!=="displace"&&"alpha"in o.data&&o.data.type!=="light"&&o.data.type!=="fresnel"&&o.data.type!=="texture"&&o.data.type!=="matcap"&&o.data.type!=="rainbow"&&o.data.type!=="outline"&&o.data.type!=="pattern"){let i=o.data.visible?o.data.alpha:0;if(typeof i=="string"&&(i=Math.max(0,Math.min(1,Number(r.getVariable(i)??100)/100))),i===1&&o.data.type==="depth"||o.data.type==="gradient"){for(let a of o.data.colors)if(a[3]<1){i=a[3];break}}else if(i===1&&o.data.type==="noise"){let a=r.color(o.data.colorA).a,s=r.color(o.data.colorB).a,l=r.color(o.data.colorC).a,c=r.color(o.data.colorD).a,u=Math.min(a,Math.min(s,Math.min(l,c)));u<1&&(i=u)}e+=(1-e)*i}}return e<1}var rr=class extends r3{constructor(){super(void 0);this.flatShading=!1;this.needsJitter=!0;this.nodeContextUuid=0;this.fog=!0,this.dithering=!0,this.vertexColors=!0,this.transparent=!0}customProgramCacheKey(){return""}},zu=class extends rr{constructor(e,t,o,i){super();this.flatShading=e;this.side=t;this.wireframe=o;this.root=i}updateAfterBuild(){let e=this.root;this.lights=e.lights,this.vertexShader=e.vertexShader,this.fragmentShader=e.fragmentShader,this.defines=e.defines,this.uniforms=e.uniforms,this.extensions=e.extensions,this.transparent=e.transparent,this.cacheKey=e.customProgramCacheKey()+"flat"+this.flatShading+this.side}onBeforeCompile(e,t){this.root.onBeforeCompile(e)}get data(){return this.root.data}get category(){return this.root.category}get hasAO(){return this.root.hasAO}getFlavor(e,t,o){return this.root.getFlavor(e,t,o)}get layers(){return this.root.layers}get fragment(){return this.root.fragment}getLayersOfType(e){return this.root.getLayersOfType(e)}getLayerByUuid(e){return this.root.getLayerByUuid(e)}updateByOp(e,t,o){this.root.updateByOp(e,t,o)}nodeMaterialDispose(){this.root.nodeMaterialDispose()}},ni=class extends rr{constructor(e,t,o=!0){super();this.data=e;this.allowVariableSaves=o;this.layerIdGen=0;this.flavors=[];this.masks={};this.type="NodeMaterial";this.updaters=[],this.needsJitter=t.shared.needsJitter,qe.startContext(this),this.reset0(e,t),qe.endContext(this)}get nodeMaterial(){return this}getFlavor(e,t,o){let i=o?6:(e?3:0)+t;if(i===0)return this;this.flavors===void 0&&(this.flavors=[]),i-=1;let a=this.flavors[i];return a===void 0&&(a=new zu(e,t,o,this),a.needsJitter=this.needsJitter,this.flavors[i]=a,a.flatShading=e,a.side=t,a.updateAfterBuild()),a}get fragment(){return this.lightLayer.node}get category(){return this.lightLayer.category}get hasAO(){return this.lightLayer.getNode("occlusion")?.value??!1}reset(e,t,o=!1){qe.startContext(this),(this.data!==e||o)&&this.reset0(e,t),qe.endContext(this)}reset0(e,t){this.data=e;let o=e.layers??Et.defaultTwoLayerData("phong").layers;try{this.layers=o.map(i=>Pn.create(this.layerIdGen++,i.id,i.data,t.shared))}catch{this.layers=[]}this.layers.reverse(),this.name=e.name??"Untitled Material",this.onUpdate(t.shared),this.transparent=Vu(e,t.shared),this.saveVariableLocations(t)}onVariableUpdate(e,t,o){if(e[0]==="alphaOverride")this.transparent=Vu(this.data,o.shared),this.lightLayer.setValue("alphaOverride",Math.max(0,Math.min(Number(t)/100,1)));else if(e[0]==="layer"){let i=e[1],a=e[2];if(i&&a){let s=this.layers.find(l=>l.uuid===i);s?.hasValue(a)&&(a==="alpha"?(this.transparent=Vu(this.data,o.shared),s.setValue(a,Math.max(0,Math.min(Number(t)/100,1)))):s.setValue(a,t))}}}saveVariableLocations(e){if(!this.allowVariableSaves)return;let t=this.data.layers.find(o=>o.data.type==="light");t&&e.shared.getVariable(t.data.alphaOverride,["material",this.uuid,"alphaOverride"]),this.data.layers.forEach(o=>{"alpha"in o.data&&typeof o.data.alpha=="string"&&e.shared.getVariable(o.data.alpha,["material",this.uuid,"layer",o.id,"alpha"])})}getLayersOfType(e){return this.layers.filter(t=>t.type===e)}getLayerByUuid(e){return this.layers.find(t=>t.uuid===e)}onUpdate(e){this.lightLayer=this.layers.find(t=>t instanceof Xt),this.lightLayer===void 0&&(this.lightLayer=new Xt(0,"",{...xt.defaultData("light","phong"),visible:!1},new Go,{},e)),this.dispose();for(let t of this.flavors)t&&t.dispose();this.applyTextureMaps(),this.applyMasks(),this.blendColors(),this.blendAfterColors(),this.blendPositions(),this.build(),this.nodeContextUuid=0}applyTextureMaps(){let e=this.layers.find(a=>a instanceof Xt);if(!e)return;let t=e.data,o=t.bumpMap,i=t.roughnessMap;e.node.bumpMap=void 0,e.node.roughnessMap=void 0;for(let a=0;a<this.layers.length;++a){let s=this.layers[a];s instanceof rt&&s.color instanceof vn&&(s.uuid===o&&(e.node.bumpMap=s.color),s.uuid===i&&(e.node.roughnessMap=s.color))}}updateByOp(e,t,o){if(qe.startContext(this),t!==void 0?this.data=t:t=this.data,this.transparent=Vu(t,o.shared),e.path[0]==="layers"){let i=o.shared,a=e.path[1];if(a===void 0)o.scene.markNeedsUpdateRendererDirty(),this.reset0(t,o);else{e.type===0&&e.props.occlusion!==void 0&&o.scene.markNeedsUpdateRendererDirty();let s=this.layers.find(l=>l.uuid===a);if(s){let l=t.layers.data(a),c;e.type===0&&("alpha"in e.props||"alphaOverride"in e.props)&&("alpha"in e.props?c={...e.props,alpha:wn(e.props.alpha,i,["material",this.uuid,"layer",a,"alpha"])}:c={...e.props,alphaOverride:wn(e.props.alphaOverride,i,["material",this.uuid,"alphaOverride"])}),s.updateByOp({...e,...c?{props:c}:{},path:e.path.slice(2)},l,o)&&this.reset0(t,o)}}}else this.reset0(t,o);qe.endContext(this)}applyMasks(){for(let e=0;e<this.layers.length;++e){let t=this.layers[e];t instanceof rt?t.color.mask=void 0:t instanceof Xt&&(t.node.mask=void 0)}for(let e=0;e<this.layers.length;++e){let t=this.layers[e];if(t instanceof rt&&t.isMask.value&&t.data.visible&&e>0){let o=e-1,i=this.layers[o];i instanceof Xt?i.node.mask=new _t(t.color,t.alpha,_t.MUL):i instanceof rt&&(i.isMask.value||(i.color.mask=new _t(t.color,t.alpha,_t.MUL)))}}}blendColors(){let e=this.layers.findIndex(o=>o instanceof rt),t=this.layers.findIndex(o=>o instanceof Xt);if(e!==-1&&e<t){let o=this.layers[e].color;for(let i=e+1;i<t;++i){let a=this.layers[i];if(a instanceof rt){if(a.isMask.value)continue;o=new La(o,a.color,a.alpha,a.mode)}}this.fragment.color=o}else this.fragment.color=void 0}blendAfterColors(){let e=new ke("outgoingLight","f"),t=this.layers.findIndex(o=>o instanceof Xt);if(this.layers.length>t+1){for(let o=t+1;o<this.layers.length;++o){let i=this.layers[o];if(i instanceof rt){if(i.isMask.value)continue;e=new La(e,i.color,i.alpha,i.mode)}}this.fragment.afterColor=e}else this.fragment.afterColor=void 0}blendPositions(){let e=this.layers.filter(t=>t instanceof ll);if(e.length>0){let t=e[0].position;for(let o=1;o<e.length;++o)e[o]&&(t=new _t(t,e[o].position,_t.ADD),t=new _t(t,new se(.5).setReadonly(!0),_t.MUL));this.fragment.position=t}else this.fragment.position=void 0}getDefines(){return this.defines}getUniforms(){return this.uniforms}getVertexShader(){return this.vertexShader}getFragmentShader(){return this.fragmentShader}onBeforeCompile(e){e.defines=this.defines,e.uniforms=this.uniforms,e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.extensionDerivatives=this.extensions.derivatives===!0,e.extensionFragDepth=this.extensions.fragDepth===!0,e.extensionDrawBuffers=this.extensions.drawBuffers===!0,e.extensionShaderTextureLOD=this.extensions.shaderTextureLOD===!0}clampUniformsForPreview(e,t){let o=(i,a,s)=>Math.min(Math.max(i,a),s);for(let i of this.layers)if(i.type==="displace"){let a=o(i.uniforms[`f${i.id}_intensity`].value,e,t);i.uniforms[`f${i.id}_intensity`].value=a}}updateFrame(e){for(let t=0;t<this.updaters.length;++t)e.updateNode(this.updaters[t])}build(){let e=new Ba;e.needsJitter=this.needsJitter,this.lights=this.lightLayer.data.visible,e.build(this.fragment,this.fragment),this.vertexShader=e.getCode("vertex"),this.fragmentShader=e.getCode("fragment"),this.defines=e.defines,this.uniforms=e.uniforms,this.extensions=e.extensions,this.updaters=e.updaters;for(let t of this.flavors)t&&t.updateAfterBuild();return this}nodeMaterialDispose(){this.layers.forEach(e=>e.dispose()),super.dispose();for(let e of this.flavors)e&&e.dispose()}assetsLoaded(){for(let e of this.layers)if(e instanceof rt){let t=e.params.texture;if(t instanceof ti&&!t.image.loaded)return!1}return!0}};Object.defineProperties(rr.prototype,{properties:{get:function(){return this.fragment.properties}}});var ii=class extends ni{constructor(r,e,t){super(r,e,!1),this.uuid=t,this.allowVariableSaves=!0,this.saveVariableLocations(e)}};var jb=new Map;function kb(n){if(typeof n=="string")return n;let r=jb.get(n);return r||(r={url:URL.createObjectURL(new Blob([n]))},jb.set(n,r)),r.url}var o3,Ub=new Promise(n=>{o3=n});var Hb;Ub.then(n=>Hb=n);var ai=class{constructor({src:r,volume:e,delay:t,loop:o}){this._volume=1;this.delay=0;this._loop=1;this.loopsRemaining=0;this._status="stopped";this.onEnd=()=>{this.loopsRemaining===1/0?this.replay():this.loopsRemaining>1?(this.replay(),this.loopsRemaining--):(this._status="stopped",this.loopsRemaining=this._loop)};let i;typeof r=="string"?i={src:r}:i={src:kb(r),format:"wav"},this.sound=new Hb.Howl(i),this.sound.on("end",this.onEnd),this.src=r,e!==void 0&&(this.volume=e),t!==void 0&&(this.delay=t),o!==void 0&&(this.loop=o)}get status(){return this._status}get volume(){return this._volume}set volume(r){this._volume=r,this.sound.volume(r)}get loop(){return this._loop}set loop(r){this._loop=r,this.loopsRemaining=r}replay(){this.clearDelay(),this.delayTimerId=window.setTimeout(()=>{this.sound.play(),this.clearDelay()},this.delay)}fade(r,e=1e3){r?(this.sound.volume(this._volume),this.clearFade(),this.fadeTimerId=window.setTimeout(()=>{this.sound.fade(this._volume,0,e),this.clearFade()},r)):this.sound.fade(this._volume,0,e)}on(r,e,t){this.sound.on(r,e,t)}off(r,e,t){this.sound.off(r,e,t)}play(){this._status==="playing"||this.sound.playing()||(this._status==="paused"?(this.sound.seek()===0?this.replay():this.sound.play(),this._status="playing"):this._status==="stopped"&&(this.replay(),this._status="playing"))}pause(){this._status==="playing"&&(this.sound.pause(),this.clearFade(),this.clearDelay(),this._status="paused")}stop(){this.sound.stop(),this.loopsRemaining=this._loop,this.clearFade(),this.clearDelay(),this._status="stopped"}clearFade(){this.fadeTimerId&&(clearTimeout(this.fadeTimerId),delete this.fadeTimerId)}clearDelay(){this.delayTimerId&&(clearTimeout(this.delayTimerId),delete this.delayTimerId)}dispose(r=!1){this.off(),this.stop(),this.clearFade(),this.clearDelay()}};import{Box2 as n3,Vector2 as si,Path as Wb,Shape as i3,ShapeUtils as a3,Color as s3}from"three";var Gu=class{constructor(){this.type="ShapePath";this.color=new s3;this.subPaths=[];this.currentPath=null}moveTo(r,e){return this.currentPath=new Wb,this.subPaths.push(this.currentPath),this.currentPath.moveTo(r,e),this}lineTo(r,e){return this.currentPath?.lineTo(r,e),this}quadraticCurveTo(r,e,t,o){return this.currentPath?.quadraticCurveTo(r,e,t,o),this}bezierCurveTo(r,e,t,o,i,a){return this.currentPath?.bezierCurveTo(r,e,t,o,i,a),this}splineThru(r){return this.currentPath?.splineThru(r),this}toShapes(){let e={ORIGIN:0,DESTINATION:1,BETWEEN:2,LEFT:3,RIGHT:4,BEHIND:5,BEYOND:6},t={loc:e.ORIGIN,t:0};function o(m,y,b,S){let P=m.x,C=y.x,v=b.x,A=S.x,T=m.y,g=y.y,D=b.y,E=S.y,M=(A-v)*(T-D)-(E-D)*(P-v),N=(C-P)*(T-D)-(g-T)*(P-v),_=(E-D)*(C-P)-(A-v)*(g-T),B=M/_,V=N/_;if(_===0&&M!==0||B<=0||B>=1||V<0||V>1)return null;if(M===0&&_===0){for(let k=0;k<2;k++)if(i(k===0?b:S,m,y),t.loc===e.ORIGIN){let L=k===0?b:S;return{x:L.x,y:L.y,t:t.t}}else if(t.loc===e.BETWEEN){let L=+(P+t.t*(C-P)).toPrecision(10),W=+(T+t.t*(g-T)).toPrecision(10);return{x:L,y:W,t:t.t}}return null}else{for(let W=0;W<2;W++)if(i(W===0?b:S,m,y),t.loc===e.ORIGIN){let F=W===0?b:S;return{x:F.x,y:F.y,t:t.t}}let k=+(P+B*(C-P)).toPrecision(10),L=+(T+B*(g-T)).toPrecision(10);return{x:k,y:L,t:B}}}function i(m,y,b){let S=b.x-y.x,P=b.y-y.y,C=m.x-y.x,v=m.y-y.y,A=S*v-C*P;if(m.x===y.x&&m.y===y.y){t.loc=e.ORIGIN,t.t=0;return}if(m.x===b.x&&m.y===b.y){t.loc=e.DESTINATION,t.t=1;return}if(A<-Number.EPSILON){t.loc=e.LEFT;return}if(A>Number.EPSILON){t.loc=e.RIGHT;return}if(S*C<0||P*v<0){t.loc=e.BEHIND;return}if(Math.sqrt(S*S+P*P)<Math.sqrt(C*C+v*v)){t.loc=e.BEYOND;return}let T;S!==0?T=C/S:T=v/P,t.loc=e.BETWEEN,t.t=T}function a(m,y){let b=[],S=[];for(let P=1;P<m.length;P++){let C=m[P-1],v=m[P];for(let A=1;A<y.length;A++){let T=y[A-1],g=y[A],D=o(C,v,T,g);D!==null&&b.find(E=>E.t<=D.t+Number.EPSILON&&E.t>=D.t-Number.EPSILON)===void 0&&(b.push(D),S.push(new si(D.x,D.y)))}}return S}function s(m,y,b){let S=new si;y.getCenter(S);let P=[];return b.forEach(C=>{C.boundingBox.containsPoint(S)&&a(m,C.points).forEach(A=>{P.push({identifier:C.identifier,isCW:C.isCW,point:A})})}),P.sort((C,v)=>C.point.x-v.point.x),P}function l(m,y,b,S,P){(P==null||P==="")&&(P="nonzero");let C=new si;m.boundingBox.getCenter(C);let v=[new si(b,C.y),new si(S,C.y)],A=s(v,m.boundingBox,y);A.sort((N,_)=>N.point.x-_.point.x);let T=[],g=[];A.forEach(N=>{N.identifier===m.identifier?T.push(N):g.push(N)});let D=T[0].point.x,E=[],M=0;for(;M<g.length&&g[M].point.x<D;)E.length>0&&E[E.length-1]===g[M].identifier?E.pop():E.push(g[M].identifier),M++;if(E.push(m.identifier),P==="evenodd"){let N=E.length%2===0,_=E[E.length-2];return{identifier:m.identifier,isHole:N,for:_}}else if(P==="nonzero"){let N=!0,_=null,B=null;for(let V=0;V<E.length;V++){let k=E[V];y[k]&&(N?(B=y[k].isCW,N=!1,_=k):B!==y[k].isCW&&(B=y[k].isCW,N=!0))}return{identifier:m.identifier,isHole:N,for:_}}else console.warn('fill-rule: "'+P+'" is currently not implemented.')}let c=0,u=999999999,p=-999999999,d=[];this.subPaths.forEach(m=>{let y=m.getPoints(),b=-999999999,S=999999999,P=-999999999,C=999999999;for(let v=0;v<y.length;v++){let A=y[v];A.y>b&&(b=A.y),A.y<S&&(S=A.y),A.x>P&&(P=A.x),A.x<C&&(C=A.x)}p<=P&&(p=P+1),u>=C&&(u=C-1),y.length&&d.push({curves:m.curves,points:y,isCW:a3.isClockWise(y),identifier:c++,boundingBox:new n3(new si(C,S),new si(P,b))})});let f=d.map(m=>l(m,d,u,p,this.userData?.style.fillRule)),h=[];return d.forEach(m=>{let y=f[m.identifier];if(y&&!y.isHole){let b=new i3;b.curves=m.curves,f.filter(P=>P?.isHole&&P.for===m.identifier).forEach(P=>{if(P){let C=d[P.identifier],v=new Wb;v.curves=C.curves,b.holes.push(v)}}),h.push(b)}}),h}};var Xf=!1,$b,Kf=new Promise(n=>{$b=n}),qb=!1;var Fu;function Yb(){if(Xf=!0,qb)return;if(Fu)return Fu;async function n(){let e=await import("./opentype.js");$b(e),qb=!0}return Fu=n(),Fu}var cl=class{async load(r,e,t=()=>{}){let{load:o}=await Kf;o(r,(i,a)=>{i||!a?t(i??"Something went wrong"):e(a)})}async parse(r){let{parse:e,Bidi:t}=await Kf;try{let o=e(r),i=new t,a=s=>o.charToGlyphIndex(s.char);return i.registerModifier("glyphIndex",null,a),i.applyFeatures(o,o.defaultRenderOptions.features),{font:o,bidi:i}}catch(o){console.error(o)}}};async function l3(n){return await(await fetch(n)).arrayBuffer()}var c3=new cl;async function Qf(n){let r,e,t=!1;if(n.url?(r=await l3(n.url),e=n.url,t=n.url.startsWith("/")):n.data&&(r=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength)),r)if(Xf){let o=await c3.parse(r);if(o)return{font:o.font,url:e,intercepted:t,arr:r,bidi:o.bidi}}else return{font:void 0,url:e,intercepted:t,arr:r,bidi:null}}import{CubicBezierCurve as u3,LineCurve as d3,QuadraticBezierCurve as p3}from"three";function f3(n,r){return r.state.glyphIndex===n||r.state.fina===n||r.state.medi===n||r.state.init===n}var ju=class{constructor(r){this._arrayBuffer=new ArrayBuffer(1);this._isLoaded=!1;this._intercepted=!1;this._isUserFont=r.isUserFont??!1,this._loadingPromise=Qf(r).then(e=>{e&&(this._arrayBuffer=e.arr,this._url=e.url,this.font=e.font,this._intercepted=e.intercepted,this._isLoaded=!0,this._bidi=e.bidi)})}update(r){this._isLoaded=!1,this._isUserFont=r.isUserFont??!1,this._loadingPromise=Qf(r).then(e=>{e&&(this._arrayBuffer=e.arr,this._url=e.url,this.font=e.font,this._intercepted=e.intercepted,this._isLoaded=!0,this._bidi=e.bidi)})}get url(){return this._url}get intercepted(){return this._intercepted}get isLoaded(){return this._isLoaded}get loadingPromise(){return this._loadingPromise}reverseLigaturesTable(r,e,t){if(!this._bidi)return[];let o=this._bidi;o.getTextGlyphs(e);let i=o.tokenizer.tokens,a=[],s=0,l=t.length===i.length;for(let c=0;c<t.length;c++){let u=t[c].index,p=String.fromCharCode(t[c].unicode),d=i[s];if(f3(u,d)||l)a.push({char:p,index:u,replacements:[d.state.glyphIndex],replacementChars:[d.char]}),s++;else{let f=d.char,h="",m=[d.state.glyphIndex],y=[],b=!1;for(;!b;)s++,h=e.charAt(s),f+=h,m.push(r.charToGlyphIndex(h)),y=r.stringToGlyphs(f),y.length===1&&y[0].index===u&&(b=!0),s>e.length&&(b=!0);a.push({char:p,index:u,replacements:m,replacementChars:Array.from(f)}),s++}}return a}generateShapes(r,e){if(!this._isLoaded)return;let t=this.font,o=e.fontSize/this.unitsPerEm,i=e.fontSize*e.lineHeight,a=r.map(S=>this.getTextWidth(S,e)),s=e.width,l=this.getCharWidth(`
2280
+ `,e),c=e.horizontalAlign===1?l:0,u=this.computeSpaceWidthForLine(r,0,e),p=this.getLineInitialOffsetX(a[0],s,e.horizontalAlign,r[0],l),d=this.getLineInitialOffsetY(i,r.length,e.height,o,e.verticalAlign),f=[],h=r.map(S=>[]),m=r.map(S=>[]),y;for(let S=0;S<r.length;S++){let P=r[S],C={features:{liga:!0}},v=[];try{v=t.stringToGlyphs(P,C)}catch(T){console.warn(T)}p=this.getLineInitialOffsetX(a[S],s,e.horizontalAlign,P,l);let A=[];try{A=this.reverseLigaturesTable(t,P,v)}catch(T){console.warn(T)}u=this.computeSpaceWidthForLine(r,S,e);for(let T=0;T<v.length;T++){let g=v[T],D=g.index===0?`
2281
+ `:g.unicode?String.fromCharCode(g.unicode):void 0,E=A[T],M=0,N=0;T===0&&e.horizontalAlign===2&&g.leftSideBearing!==void 0&&(N=-g.leftSideBearing*o),y&&(M=t.getKerningValue(g,y)*o),p+=N+M;let _=0;if(D===`
2282
+ `)_=c;else if(D===" ")_=u;else{let B=this.createPath(g,o,p,d,e);B&&(_=B.offsetX-(M+N),f.push(B.path))}if(E.replacements.length===1)m[S].push([p,d]),h[S].push(_);else{let B=E.replacements.map(W=>(t.glyphs.get(W).advanceWidth??0)*o),V=B.reduce((W,F)=>W+=F,0),k=B.map(W=>W/V),L=p;for(let W=0;W<k.length;W++){let F=_*k[W];m[S].push([L,d]),h[S].push(F),L+=F}}p+=_,y=g}d-=i}let b=[];for(let S=0,P=f.length;S<P;S++)b.push(...f[S].toShapes());return{shapes:b,charWidths:h,lineWidths:a,charCoords:m}}get isUserFont(){return this._isUserFont}get arrayBuffer(){return this._arrayBuffer}get ascender(){return this.font?.ascender??0}get descender(){return this.font?.descender??0}get familyName(){return this.font?.names.fontFamily??""}get subfamilyName(){return this.font?.names.fontSubfamily??""}get unitsPerEm(){return this.font?.unitsPerEm??1}getLineInitialOffsetX(r,e,t,o,i){return(t===3||t===2)&&o.indexOf(`
2283
+ `)>=0&&(r-=i),t===3?e*.5-r*.5:t===2?e-r:0}getLineInitialOffsetY(r,e,t,o,i){let a=e*r,s=Math.abs(this.ascender-this.descender)*o,l=r-s,c=-this.ascender*o-l/2;return i===3?-(t-a-c):i===2?-(t*.5-a*.5-c):c}createPath(r,e,t,o,i){let a=r.getPath(t,-o,i.fontSize,{kerning:!1,letterSpacing:i.letterSpacing});if(!a){console.error('THREE.Font: character "'+r+'" does not exists in font family '+this.familyName+".");return}let s=new Gu,l=(r.advanceWidth??1)*e;if(r)for(let c of a.commands){let u=s.currentPath?.currentPoint;if(!(u&&c.type!=="Z"&&u.x===c.x&&-u.y===c.y))switch(c.type){case"M":s.moveTo(c.x,-c.y);break;case"L":s.lineTo(c.x,-c.y);break;case"Q":s.quadraticCurveTo(c.x1,-c.y1,c.x,-c.y);break;case"C":s.bezierCurveTo(c.x1,-c.y1,c.x2,-c.y2,c.x,-c.y);break}}return s.subPaths.forEach(c=>{let u=h3(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l+i.fontSize*i.letterSpacing,path:s}}getCharWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(r,e,t){let o=this.getCharWidth(" ",t),i=r[e];if(i){let a=this.countSpaces(i.trimEnd());if(t.horizontalAlign===4&&e<r.length-1&&a){let s=t.width,l=this.getTextWidth(i,t);return(s-(l-a*o))/a}}return o}countSpaces(r){return(r.match(/ /g)||[]).length}};function h3(n){if(n.length){let r=n[0];if(r instanceof d3)return r.v1;if(r instanceof u3||r instanceof p3)return r.v0}}var Zf=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(r){return this.objects.get(r)}get size(){return this.objects.size}get(r,e,t){let o=this.objects.get(r);return o===void 0?(o=this.createObject(r,e,t),this.objects.set(r,o)):o.isShared=!0,o}forceDelete(r){let e=this.objects.get(r);e&&(this.disposeObject(e),this.objects.delete(r))}mutateIfUnique(r,e){let t=this.objects.get(r);if(t&&t.isShared!==!0)return this.objects.delete(r),this.objects.set(e,t),t}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(r,e){let t=this.objects.get(r);e===t?this.unreachable.delete(r):!1&&console.warn("Reachable but deleted",r)}endGc(){this.unreachable.forEach(r=>{this.disposeObject(this.objects.get(r)),this.objects.delete(r)}),this.unreachable.clear()}dispose(){this.objects.forEach(r=>{this.disposeObject(r)}),this.objects.clear()}},ul=class extends Zf{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,t,o){let i=Vo(e,t,this.flatShading,o);return i.computeBoundingSphere(),i}};var Xb={markNeedsUpdateRendererDirty:()=>{}};import{MathUtils as ov}from"three";var ku=1e3,Kb=512*ku;function m3(n,r){let e=typeof n;return!!((r==="string"||r==="number")&&e===r||r==="boolean"&&(n==="true"||n==="false"||n===!0||n===!1)||r==="image"&&e==="string"&&n.startsWith("http"))}var Qb="https://hooks.spline.design",y3=`${Qb}/events?hashFile=`,Kte=`${Qb}/`,Uu=class{constructor(r,e){this.id=r;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=Lo();this.reconnectWaitFor=ku;this._onError=r=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=r=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=ku,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=ku,this._connected=!1};this._onMessage=r=>{let e=r.data,t;try{t=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(t){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:i})=>{t[i.name]!==void 0&&m3(t[i.name],i.type)&&(this.result===void 0&&(this.result={}),this.result[i.name]=t[i.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(y3+this.userWebhook.url),this.eventSource.addEventListener("message",this._onMessage),this.eventSource.addEventListener("error",this._onError),this.eventSource.addEventListener("open",this._onConnected))}disconnect(){this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this.eventSource?.close(),this._onDisconnected(),clearTimeout(this.scheduledReconnectHandle)}_scheduleReconnect(){this.reconnectWaitFor*=2,this.reconnectWaitFor>Kb&&(this.reconnectWaitFor=Kb),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(r){this.userWebhook=r}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(r=>r.data.name)}getParameterValue(r){if(this.getParametersKeys().includes(r)){if(this.result)return this.result?.[r];for(let t of this.userWebhook.parametersSchemas)if(t.data.name===r)return Uc.defaultParameterValueByType(t.data.type)}}};var g3=globalThis.atob,x3=globalThis.btoa,wr=class{static floatTo16BitPCM(r){let e=new ArrayBuffer(r.length*2),t=new DataView(e),o=0;for(let i=0;i<r.length;i++,o+=2){let a=Math.max(-1,Math.min(1,r[i]));t.setInt16(o,a<0?a*32768:a*32767,!0)}return e}static base64ToArrayBuffer(r){let e=g3(r),t=e.length,o=new Uint8Array(t);for(let i=0;i<t;i++)o[i]=e.charCodeAt(i);return o.buffer}static arrayBufferToBase64(r){r instanceof Float32Array?r=this.floatTo16BitPCM(r):r instanceof Int16Array&&(r=r.buffer);let e="",t=new Uint8Array(r),o=32768;for(let i=0;i<t.length;i+=o){let a=t.subarray(i,i+o);e+=String.fromCharCode.apply(null,a)}return x3(e)}static mergeInt16Arrays(r,e){if(r instanceof ArrayBuffer&&(r=new Int16Array(r)),e instanceof ArrayBuffer&&(e=new Int16Array(e)),!(r instanceof Int16Array)||!(e instanceof Int16Array))throw new Error("Both items must be Int16Array");let t=new Int16Array(r.length+e.length);for(let o=0;o<r.length;o++)t[o]=r[o];for(let o=0;o<e.length;o++)t[r.length+o]=e[o];return t}static generateId(r,e=21){let t="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=Array(e-r.length).fill(0).map(i=>t[Math.floor(Math.random()*t.length)]).join("");return`${r}${o}`}};var b3=n=>new Promise(r=>setTimeout(()=>r(),n)),Za=class{constructor(){this.eventHandlers={},this.nextEventHandlers={}}clearEventHandlers(){return this.eventHandlers={},this.nextEventHandlers={},!0}on(r,e){return this.eventHandlers[r]=this.eventHandlers[r]||[],this.eventHandlers[r].push(e),e}onNext(r,e){return this.nextEventHandlers[r]=this.nextEventHandlers[r]||[],this.nextEventHandlers[r].push(e),e}off(r,e){let t=this.eventHandlers[r]||[];if(e){let o=t.indexOf(e);if(o===-1)throw new Error(`Could not turn off specified event listener for "${r}": not found as a listener`);t.splice(o,1)}else delete this.eventHandlers[r];return!0}offNext(r,e){let t=this.nextEventHandlers[r]||[];if(e){let o=t.indexOf(e);if(o===-1)throw new Error(`Could not turn off specified next event listener for "${r}": not found as a listener`);t.splice(o,1)}else delete this.nextEventHandlers[r];return!0}async waitForNext(r,e=null){let t=Date.now(),o;for(this.onNext(r,i=>o=i);!o;){if(e&&Date.now()-t>e)return null;await b3(1)}return o}dispatch(r,e){let t=[].concat(this.eventHandlers[r]||[]);for(let i of t)i(e);let o=[].concat(this.nextEventHandlers[r]||[]);for(let i of o)i(e);return delete this.nextEventHandlers[r],!0}};var dl=class extends Za{constructor({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}={}){if(super(),this.defaultUrl="wss://api.openai.com/v1/realtime",this.url=r||this.defaultUrl,this.apiKey=e||null,this.debug=!!o,this.ws=null,globalThis.document&&this.apiKey&&!t)throw new Error('Can not provide API key in the browser without "dangerouslyAllowAPIKeyInBrowser" set to true')}isConnected(){return!!this.ws}log(...r){let t=[`[Websocket/${new Date().toISOString()}]`].concat(r).map(o=>typeof o=="object"&&o!==null?JSON.stringify(o,null,2):o);return this.debug&&console.log(...t),!0}async connect({model:r}={model:"gpt-4o-realtime-preview-2024-10-01"}){if(!this.apiKey&&this.url===this.defaultUrl&&console.warn(`No apiKey provided for connection to "${this.url}"`),this.isConnected())throw new Error("Already connected");if(globalThis.document){this.apiKey&&console.warn("Warning: Connecting using API key in the browser, this is not recommended");let e=globalThis.WebSocket,t=new e(`${this.url}${r?`?model=${r}`:""}`,["realtime",`openai-insecure-api-key.${this.apiKey}`,"openai-beta.realtime-v1"]);return t.addEventListener("message",o=>{let i=JSON.parse(o.data);this.receive(i.type,i)}),new Promise((o,i)=>{let a=()=>{this.disconnect(t),i(new Error(`Could not connect to "${this.url}"`))};t.addEventListener("error",a),t.addEventListener("open",()=>{this.log(`Connected to "${this.url}"`),t.removeEventListener("error",a),t.addEventListener("error",()=>{this.disconnect(t),this.log(`Error, disconnected from "${this.url}"`),this.dispatch("close",{error:!0})}),t.addEventListener("close",()=>{this.disconnect(t),this.log(`Disconnected from "${this.url}"`),this.dispatch("close",{error:!1})}),this.ws=t,o(!0)})})}}disconnect(r){if(!r||this.ws===r)return this.ws&&this.ws.close(),this.ws=null,!0}receive(r,e){return this.log("received:",r,e),this.dispatch(`server.${r}`,e),this.dispatch("server.*",e),!0}send(r,e){if(!this.isConnected())throw new Error("RealtimeAPI is not connected");if(e=e||{},typeof e!="object")throw new Error("data must be an object");let t={event_id:wr.generateId("evt_"),type:r,...e};return this.dispatch(`client.${r}`,t),this.dispatch("client.*",t),this.log("sent:",r,t),this.ws.send(JSON.stringify(t)),!0}};var pl=class{constructor(){$r(this,"defaultFrequency",24e3);$r(this,"EventProcessors",{"conversation.item.created":r=>{let{item:e}=r,t=JSON.parse(JSON.stringify(e));if(this.itemLookup[t.id]||(this.itemLookup[t.id]=t,this.items.push(t)),t.formatted={},t.formatted.audio=new Int16Array(0),t.formatted.text="",t.formatted.transcript="",this.queuedSpeechItems[t.id]&&(t.formatted.audio=this.queuedSpeechItems[t.id].audio,delete this.queuedSpeechItems[t.id]),t.content){let o=t.content.filter(i=>["text","input_text"].includes(i.type));for(let i of o)t.formatted.text+=i.text}return this.queuedTranscriptItems[t.id]&&(t.formatted.transcript=this.queuedTranscriptItems.transcript,delete this.queuedTranscriptItems[t.id]),t.type==="message"?t.role==="user"?(t.status="completed",this.queuedInputAudio&&(t.formatted.audio=this.queuedInputAudio,this.queuedInputAudio=null)):t.status="in_progress":t.type==="function_call"?(t.formatted.tool={type:"function",name:t.name,call_id:t.call_id,arguments:""},t.status="in_progress"):t.type==="function_call_output"&&(t.status="completed",t.formatted.output=t.output),{item:t,delta:null}},"conversation.item.truncated":r=>{let{item_id:e,audio_end_ms:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`item.truncated: Item "${e}" not found`);let i=Math.floor(t*this.defaultFrequency/1e3);return o.formatted.transcript="",o.formatted.audio=o.formatted.audio.slice(0,i),{item:o,delta:null}},"conversation.item.deleted":r=>{let{item_id:e}=r,t=this.itemLookup[e];if(!t)throw new Error(`item.deleted: Item "${e}" not found`);delete this.itemLookup[t.id];let o=this.items.indexOf(t);return o>-1&&this.items.splice(o,1),{item:t,delta:null}},"conversation.item.input_audio_transcription.completed":r=>{let{item_id:e,content_index:t,transcript:o}=r,i=this.itemLookup[e],a=o||" ";return i?(i.content[t].transcript=o,i.formatted.transcript=a,{item:i,delta:{transcript:o}}):(this.queuedTranscriptItems[e]={transcript:a},{item:null,delta:null})},"input_audio_buffer.speech_started":r=>{let{item_id:e,audio_start_ms:t}=r;return this.queuedSpeechItems[e]={audio_start_ms:t},{item:null,delta:null}},"input_audio_buffer.speech_stopped":(r,e)=>{let{item_id:t,audio_end_ms:o}=r;this.queuedSpeechItems[t]||(this.queuedSpeechItems[t]={audio_start_ms:o});let i=this.queuedSpeechItems[t];if(i.audio_end_ms=o,e){let a=Math.floor(i.audio_start_ms*this.defaultFrequency/1e3),s=Math.floor(i.audio_end_ms*this.defaultFrequency/1e3);i.audio=e.slice(a,s)}return{item:null,delta:null}},"response.created":r=>{let{response:e}=r;return this.responseLookup[e.id]||(this.responseLookup[e.id]=e,this.responses.push(e)),{item:null,delta:null}},"response.output_item.added":r=>{let{response_id:e,item:t}=r,o=this.responseLookup[e];if(!o)throw new Error(`response.output_item.added: Response "${e}" not found`);return o.output.push(t.id),{item:null,delta:null}},"response.output_item.done":r=>{let{item:e}=r;if(!e)throw new Error('response.output_item.done: Missing "item"');let t=this.itemLookup[e.id];if(!t)throw new Error(`response.output_item.done: Item "${e.id}" not found`);return t.status=e.status,{item:t,delta:null}},"response.content_part.added":r=>{let{item_id:e,part:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`response.content_part.added: Item "${e}" not found`);return o.content.push(t),{item:o,delta:null}},"response.audio_transcript.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.audio_transcript.delta: Item "${e}" not found`);return i.content[t].transcript+=o,i.formatted.transcript+=o,{item:i,delta:{transcript:o}}},"response.audio.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.audio.delta: Item "${e}" not found`);let a=wr.base64ToArrayBuffer(o),s=new Int16Array(a);return i.formatted.audio=wr.mergeInt16Arrays(i.formatted.audio,s),{item:i,delta:{audio:s}}},"response.text.delta":r=>{let{item_id:e,content_index:t,delta:o}=r,i=this.itemLookup[e];if(!i)throw new Error(`response.text.delta: Item "${e}" not found`);return i.content[t].text+=o,i.formatted.text+=o,{item:i,delta:{text:o}}},"response.function_call_arguments.delta":r=>{let{item_id:e,delta:t}=r,o=this.itemLookup[e];if(!o)throw new Error(`response.function_call_arguments.delta: Item "${e}" not found`);return o.arguments+=t,o.formatted.tool.arguments+=t,{item:o,delta:{arguments:t}}}});this.clear()}clear(){return this.itemLookup={},this.items=[],this.responseLookup={},this.responses=[],this.queuedSpeechItems={},this.queuedTranscriptItems={},this.queuedInputAudio=null,!0}queueInputAudio(r){return this.queuedInputAudio=r,r}processEvent(r,...e){if(!r.event_id)throw console.error(r),new Error('Missing "event_id" on event');if(!r.type)throw console.error(r),new Error('Missing "type" on event');let t=this.EventProcessors[r.type];if(!t)throw new Error(`Missing conversation event processor for "${r.type}"`);return t.call(this,r,...e)}getItem(r){return this.itemLookup[r]||null}getItems(){return this.items.slice()}};var Ja=class extends Za{constructor({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}={}){super(),this.defaultSessionConfig={modalities:["text","audio"],instructions:"",voice:"alloy",input_audio_format:"pcm16",output_audio_format:"pcm16",input_audio_transcription:null,turn_detection:null,tools:[],tool_choice:"auto",temperature:.8,max_response_output_tokens:4096},this.sessionConfig={},this.transcriptionModels=[{model:"whisper-1"}],this.defaultServerVadConfig={type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:200},this.realtime=new dl({url:r,apiKey:e,dangerouslyAllowAPIKeyInBrowser:t,debug:o}),this.conversation=new pl,this._resetConfig(),this._addAPIEventHandlers()}_resetConfig(){return this.sessionCreated=!1,this.tools={},this.sessionConfig=JSON.parse(JSON.stringify(this.defaultSessionConfig)),this.inputAudioBuffer=new Int16Array(0),!0}_addAPIEventHandlers(){this.realtime.on("client.*",o=>{let i={time:new Date().toISOString(),source:"client",event:o};this.dispatch("realtime.event",i)}),this.realtime.on("server.*",o=>{let i={time:new Date().toISOString(),source:"server",event:o};this.dispatch("realtime.event",i)}),this.realtime.on("server.session.created",()=>this.sessionCreated=!0);let r=(o,...i)=>{let{item:a,delta:s}=this.conversation.processEvent(o,...i);return{item:a,delta:s}},e=(o,...i)=>{let{item:a,delta:s}=r(o,...i);return a&&this.dispatch("conversation.updated",{item:a,delta:s}),{item:a,delta:s}},t=async o=>{try{let i=JSON.parse(o.arguments),a=this.tools[o.name];if(!a)throw new Error(`Tool "${o.name}" has not been added`);let s=await a.handler(i);this.realtime.send("conversation.item.create",{item:{type:"function_call_output",call_id:o.call_id,output:JSON.stringify(s)}})}catch(i){this.realtime.send("conversation.item.create",{item:{type:"function_call_output",call_id:o.call_id,output:JSON.stringify({error:i.message})}})}this.createResponse()};return this.realtime.on("server.response.created",r),this.realtime.on("server.response.output_item.added",r),this.realtime.on("server.response.content_part.added",r),this.realtime.on("server.input_audio_buffer.speech_started",o=>{r(o),this.dispatch("conversation.interrupted")}),this.realtime.on("server.input_audio_buffer.speech_stopped",o=>r(o,this.inputAudioBuffer)),this.realtime.on("server.conversation.item.created",o=>{let{item:i}=e(o);this.dispatch("conversation.item.appended",{item:i}),i.status==="completed"&&this.dispatch("conversation.item.completed",{item:i})}),this.realtime.on("server.conversation.item.truncated",e),this.realtime.on("server.conversation.item.deleted",e),this.realtime.on("server.conversation.item.input_audio_transcription.completed",e),this.realtime.on("server.response.audio_transcript.delta",e),this.realtime.on("server.response.audio.delta",e),this.realtime.on("server.response.text.delta",e),this.realtime.on("server.response.function_call_arguments.delta",e),this.realtime.on("server.response.output_item.done",async o=>{let{item:i}=e(o);i.status==="completed"&&this.dispatch("conversation.item.completed",{item:i}),i.formatted.tool&&t(i.formatted.tool)}),!0}isConnected(){return this.realtime.isConnected()}reset(){return this.disconnect(),this.clearEventHandlers(),this.realtime.clearEventHandlers(),this._resetConfig(),this._addAPIEventHandlers(),!0}async connect(){if(this.isConnected())throw new Error("Already connected, use .disconnect() first");return await this.realtime.connect(),this.updateSession(),!0}async waitForSessionCreated(){if(!this.isConnected())throw new Error("Not connected, use .connect() first");for(;!this.sessionCreated;)await new Promise(r=>setTimeout(()=>r(),1));return!0}disconnect(){this.sessionCreated=!1,this.realtime.isConnected()&&this.realtime.disconnect(),this.conversation.clear()}getTurnDetectionType(){return this.sessionConfig.turn_detection?.type||null}addTool(r,e){if(!r?.name)throw new Error("Missing tool name in definition");let t=r?.name;if(this.tools[t])throw new Error(`Tool "${t}" already added. Please use .removeTool("${t}") before trying to add again.`);if(typeof e!="function")throw new Error(`Tool "${t}" handler must be a function`);return this.tools[t]={definition:r,handler:e},this.updateSession(),this.tools[t]}removeTool(r){if(!this.tools[r])throw new Error(`Tool "${r}" does not exist, can not be removed.`);return delete this.tools[r],!0}deleteItem(r){return this.realtime.send("conversation.item.delete",{item_id:r}),!0}updateSession({modalities:r=void 0,instructions:e=void 0,voice:t=void 0,input_audio_format:o=void 0,output_audio_format:i=void 0,input_audio_transcription:a=void 0,turn_detection:s=void 0,tools:l=void 0,tool_choice:c=void 0,temperature:u=void 0,max_response_output_tokens:p=void 0}={}){r!==void 0&&(this.sessionConfig.modalities=r),e!==void 0&&(this.sessionConfig.instructions=e),t!==void 0&&(this.sessionConfig.voice=t),o!==void 0&&(this.sessionConfig.input_audio_format=o),i!==void 0&&(this.sessionConfig.output_audio_format=i),a!==void 0&&(this.sessionConfig.input_audio_transcription=a),s!==void 0&&(this.sessionConfig.turn_detection=s),l!==void 0&&(this.sessionConfig.tools=l),c!==void 0&&(this.sessionConfig.tool_choice=c),u!==void 0&&(this.sessionConfig.temperature=u),p!==void 0&&(this.sessionConfig.max_response_output_tokens=p);let d=[].concat((l||[]).map(h=>{let m={type:"function",...h};if(this.tools[m?.name])throw new Error(`Tool "${m?.name}" has already been defined`);return m}),Object.keys(this.tools).map(h=>({type:"function",...this.tools[h].definition}))),f={...this.sessionConfig};return f.tools=d,this.realtime.isConnected()&&this.realtime.send("session.update",{session:f}),!0}sendUserMessageContent(r=[]){if(r.length){for(let e of r)e.type==="input_audio"&&(e.audio instanceof ArrayBuffer||e.audio instanceof Int16Array)&&(e.audio=wr.arrayBufferToBase64(e.audio));this.realtime.send("conversation.item.create",{item:{type:"message",role:"user",content:r}})}return this.createResponse(),!0}appendInputAudio(r){return r.byteLength>0&&(this.realtime.send("input_audio_buffer.append",{audio:wr.arrayBufferToBase64(r)}),this.inputAudioBuffer=wr.mergeInt16Arrays(this.inputAudioBuffer,r)),!0}createResponse(){return this.getTurnDetectionType()===null&&this.inputAudioBuffer.byteLength>0&&(this.realtime.send("input_audio_buffer.commit"),this.conversation.queueInputAudio(this.inputAudioBuffer),this.inputAudioBuffer=new Int16Array(0)),this.realtime.send("response.create"),!0}cancelResponse(r,e=0){if(r){if(r){let t=this.conversation.getItem(r);if(!t)throw new Error(`Could not find item "${r}"`);if(t.type!=="message")throw new Error('Can only cancelResponse messages with type "message"');if(t.role!=="assistant")throw new Error('Can only cancelResponse messages with role "assistant"');this.realtime.send("response.cancel");let o=t.content.findIndex(i=>i.type==="audio");if(o===-1)throw new Error("Could not find audio on item to cancel");return this.realtime.send("conversation.item.truncate",{item_id:r,content_index:o,audio_end_ms:Math.floor(e/this.conversation.defaultFrequency*1e3)}),{item:t}}}else return this.realtime.send("response.cancel"),{item:null}}async waitForNextItem(){let r=await this.waitForNext("conversation.item.appended"),{item:e}=r;return{item:e}}async waitForNextCompletedItem(){let r=await this.waitForNext("conversation.item.completed"),{item:e}=r;return{item:e}}};var v3=`
2251
2284
  class AudioProcessor extends AudioWorkletProcessor {
2252
2285
 
2253
2286
  constructor() {
@@ -2454,9 +2487,9 @@ class AudioProcessor extends AudioWorkletProcessor {
2454
2487
  }
2455
2488
 
2456
2489
  registerProcessor('audio_processor', AudioProcessor);
2457
- `,wD=new Blob([SD],{type:"application/javascript"}),PD=URL.createObjectURL(wD),Jb=PD;var ev=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],CD=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],ko=[],Xu=[];for(let n=1;n<=8;n++)for(let r=0;r<ev.length;r++){let e=ev[r];ko.push(e/Math.pow(2,8-n)),Xu.push(CD[r]+n)}var Yu=[32,2e3],rh=ko.filter((n,r)=>ko[r]>Yu[0]&&ko[r]<Yu[1]),tv=Xu.filter((n,r)=>ko[r]>Yu[0]&&ko[r]<Yu[1]);var On=class{static getFrequencies(r,e,t,o="frequency",i=-100,a=-30){t||(t=new Float32Array(r.frequencyBinCount),r.getFloatFrequencyData(t));let s=e/2,l=1/t.length*s,c,u,p;if(o==="music"||o==="voice"){let f=o==="voice"?rh:ko,m=Array(f.length).fill(i);for(let y=0;y<t.length;y++){let g=y*l,v=t[y];for(let w=f.length-1;w>=0;w--)if(g>f[w]){m[w]=Math.max(m[w],v);break}}c=m,u=o==="voice"?rh:ko,p=o==="voice"?tv:Xu}else c=Array.from(t),u=c.map((f,m)=>l*m),p=u.map(f=>`${f.toFixed(2)} Hz`);let d=c.map(f=>Math.max(0,Math.min((f-i)/(a-i),1)));return{values:new Float32Array(d),frequencies:u,labels:p}}constructor(r,e=null){if(this.fftResults=[],e){let{length:t,sampleRate:o}=e,i=new OfflineAudioContext({length:t,sampleRate:o}),a=i.createBufferSource();a.buffer=e;let s=i.createAnalyser();s.fftSize=8192,s.smoothingTimeConstant=.1,a.connect(s);let l=1/60,c=t/o,u=p=>{let d=l*p;d<c&&i.suspend(d).then(()=>{let h=new Float32Array(s.frequencyBinCount);s.getFloatFrequencyData(h),this.fftResults.push(h),u(p+1)}),p===1?i.startRendering():i.resume()};a.start(0),u(1),this.audio=r,this.context=i,this.analyser=s,this.sampleRate=o,this.audioBuffer=e}else{let t=new AudioContext,o=t.createMediaElementSource(r),i=t.createAnalyser();i.fftSize=8192,i.smoothingTimeConstant=.1,o.connect(i),i.connect(t.destination),this.audio=r,this.context=t,this.analyser=i,this.sampleRate=this.context.sampleRate,this.audioBuffer=null}}getFrequencies(r="frequency",e=-100,t=-30){let o=null;if(this.audioBuffer&&this.fftResults.length){let i=this.audio.currentTime/this.audio.duration,a=Math.min(i*this.fftResults.length|0,this.fftResults.length-1);o=this.fftResults[a]}return On.getFrequencies(this.analyser,this.sampleRate,o,r,e,t)}async resumeIfSuspended(){return this.context.state==="suspended"&&await this.context.resume(),!0}};var Uo=class{static floatTo16BitPCM(r){let e=new ArrayBuffer(r.length*2),t=new DataView(e),o=0;for(let i=0;i<r.length;i++,o+=2){let a=Math.max(-1,Math.min(1,r[i]));t.setInt16(o,a<0?a*32768:a*32767,!0)}return e}static mergeBuffers(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(new Uint8Array(r),0),t.set(new Uint8Array(e),r.byteLength),t.buffer}_packData(r,e){return[new Uint8Array([e,e>>8]),new Uint8Array([e,e>>8,e>>16,e>>24])][r]}pack(r,e){if(e?.bitsPerSample)if(e?.channels){if(!e?.data)throw new Error('Missing "data"')}else throw new Error('Missing "channels"');else throw new Error('Missing "bitsPerSample"');let{bitsPerSample:t,channels:o,data:i}=e,a=["RIFF",this._packData(1,4+(8+24)+(8+8)),"WAVE","fmt ",this._packData(1,16),this._packData(0,1),this._packData(0,o.length),this._packData(1,r),this._packData(1,r*o.length*t/8),this._packData(0,o.length*t/8),this._packData(0,t),"data",this._packData(1,o[0].length*o.length*t/8),i],s=new Blob(a,{type:"audio/mpeg"}),l=URL.createObjectURL(s);return{blob:s,url:l,channelCount:o.length,sampleRate:r,duration:i.byteLength/(o.length*r*2)}}};var yl=class{constructor({sampleRate:r=44100,outputToSpeakers:e=!1,debug:t=!1}={}){this.scriptSrc=Jb,this.sampleRate=r,this.outputToSpeakers=e,this.debug=!!t,this._deviceChangeCallback=null,this._devices=[],this.stream=null,this.processor=null,this.source=null,this.node=null,this.recording=!1,this._lastEventId=0,this.eventReceipts={},this.eventTimeout=5e3,this._chunkProcessor=()=>{},this._chunkProcessorSize=void 0,this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)}}static async decode(r,e=44100,t=-1){let o=new AudioContext({sampleRate:e}),i,a;if(r instanceof Blob){if(t!==-1)throw new Error('Can not specify "fromSampleRate" when reading from Blob');a=r,i=await a.arrayBuffer()}else if(r instanceof ArrayBuffer){if(t!==-1)throw new Error('Can not specify "fromSampleRate" when reading from ArrayBuffer');i=r,a=new Blob([i],{type:"audio/wav"})}else{let u,p;if(r instanceof Int16Array){p=r,u=new Float32Array(r.length);for(let m=0;m<r.length;m++)u[m]=r[m]/32768}else if(r instanceof Float32Array)u=r;else if(r instanceof Array)u=new Float32Array(r);else throw new Error('"audioData" must be one of: Blob, Float32Arrray, Int16Array, ArrayBuffer, Array<number>');if(t===-1)throw new Error('Must specify "fromSampleRate" when reading from Float32Array, In16Array or Array');if(t<3e3)throw new Error('Minimum "fromSampleRate" is 3000 (3kHz)');p||(p=Uo.floatTo16BitPCM(u));let d={bitsPerSample:16,channels:[u],data:p};a=new Uo().pack(t,d).blob,i=await a.arrayBuffer()}let s=await o.decodeAudioData(i),l=s.getChannelData(0),c=URL.createObjectURL(a);return{blob:a,url:c,values:l,audioBuffer:s}}log(){return this.debug&&this.log(...arguments),!0}getSampleRate(){return this.sampleRate}getStatus(){return this.processor?this.recording?"recording":"paused":"ended"}async _event(r,e={},t=null){if(t=t||this.processor,!t)throw new Error("Can not send events without recording first");let o={event:r,id:this._lastEventId++,data:e};t.port.postMessage(o);let i=new Date().valueOf();for(;!this.eventReceipts[o.id];){if(new Date().valueOf()-i>this.eventTimeout)throw new Error(`Timeout waiting for "${r}" event`);await new Promise(s=>setTimeout(()=>s(!0),1))}let a=this.eventReceipts[o.id];return delete this.eventReceipts[o.id],a}listenForDeviceChange(r){if(r===null&&this._deviceChangeCallback)navigator.mediaDevices.removeEventListener("devicechange",this._deviceChangeCallback),this._deviceChangeCallback=null;else if(r!==null){let e=0,t=[],o=a=>a.map(s=>s.deviceId).sort().join(","),i=async()=>{let a=++e,s=await this.listDevices();a===e&&o(t)!==o(s)&&(t=s,r(s.slice()))};navigator.mediaDevices.addEventListener("devicechange",i),i(),this._deviceChangeCallback=i}return!0}async requestPermission(){let r=await navigator.permissions.query({name:"microphone"});if(r.state==="denied")window.alert("You must grant microphone access to use this feature.");else if(r.state==="prompt")try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(o=>o.stop())}catch{window.alert("You must grant microphone access to use this feature.")}return!0}async listDevices(){if(!navigator.mediaDevices||!("enumerateDevices"in navigator.mediaDevices))throw new Error("Could not request user devices");await this.requestPermission();let e=(await navigator.mediaDevices.enumerateDevices()).filter(i=>i.kind==="audioinput"),t=e.findIndex(i=>i.deviceId==="default"),o=[];if(t!==-1){let i=e.splice(t,1)[0],a=e.findIndex(s=>s.groupId===i.groupId);a!==-1&&(i=e.splice(a,1)[0]),i.default=!0,o.push(i)}return o.concat(e)}async begin(r){if(this.processor)throw new Error("Already connected: please call .end() to start a new session");if(!navigator.mediaDevices||!("getUserMedia"in navigator.mediaDevices))throw new Error("Could not request user media");try{let s={audio:!0};r&&(s.audio={deviceId:{exact:r}}),this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{throw new Error("Could not start media stream")}let e=new AudioContext({sampleRate:this.sampleRate}),t=e.createMediaStreamSource(this.stream);try{await e.audioWorklet.addModule(this.scriptSrc)}catch(s){throw console.error(s),new Error(`Could not add audioWorklet module: ${this.scriptSrc}`)}let o=new AudioWorkletNode(e,"audio_processor");o.port.onmessage=s=>{let{event:l,id:c,data:u}=s.data;if(l==="receipt")this.eventReceipts[c]=u;else if(l==="chunk")if(this._chunkProcessorSize){let p=this._chunkProcessorBuffer;this._chunkProcessorBuffer={raw:Uo.mergeBuffers(p.raw,u.raw),mono:Uo.mergeBuffers(p.mono,u.mono)},this._chunkProcessorBuffer.mono.byteLength>=this._chunkProcessorSize&&(this._chunkProcessor(this._chunkProcessorBuffer),this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)})}else this._chunkProcessor(u)};let i=t.connect(o),a=e.createAnalyser();return a.fftSize=8192,a.smoothingTimeConstant=.1,i.connect(a),this.outputToSpeakers&&(console.warn(`Warning: Output to speakers may affect sound quality,
2490
+ `,S3=new Blob([v3],{type:"application/javascript"}),w3=URL.createObjectURL(S3),Zb=w3;var Jb=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],P3=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],ko=[],Wu=[];for(let n=1;n<=8;n++)for(let r=0;r<Jb.length;r++){let e=Jb[r];ko.push(e/Math.pow(2,8-n)),Wu.push(P3[r]+n)}var Hu=[32,2e3],Jf=ko.filter((n,r)=>ko[r]>Hu[0]&&ko[r]<Hu[1]),ev=Wu.filter((n,r)=>ko[r]>Hu[0]&&ko[r]<Hu[1]);var Cn=class{static getFrequencies(r,e,t,o="frequency",i=-100,a=-30){t||(t=new Float32Array(r.frequencyBinCount),r.getFloatFrequencyData(t));let s=e/2,l=1/t.length*s,c,u,p;if(o==="music"||o==="voice"){let h=o==="voice"?Jf:ko,m=Array(h.length).fill(i);for(let y=0;y<t.length;y++){let b=y*l,S=t[y];for(let P=h.length-1;P>=0;P--)if(b>h[P]){m[P]=Math.max(m[P],S);break}}c=m,u=o==="voice"?Jf:ko,p=o==="voice"?ev:Wu}else c=Array.from(t),u=c.map((h,m)=>l*m),p=u.map(h=>`${h.toFixed(2)} Hz`);let d=c.map(h=>Math.max(0,Math.min((h-i)/(a-i),1)));return{values:new Float32Array(d),frequencies:u,labels:p}}constructor(r,e=null){if(this.fftResults=[],e){let{length:t,sampleRate:o}=e,i=new OfflineAudioContext({length:t,sampleRate:o}),a=i.createBufferSource();a.buffer=e;let s=i.createAnalyser();s.fftSize=8192,s.smoothingTimeConstant=.1,a.connect(s);let l=1/60,c=t/o,u=p=>{let d=l*p;d<c&&i.suspend(d).then(()=>{let f=new Float32Array(s.frequencyBinCount);s.getFloatFrequencyData(f),this.fftResults.push(f),u(p+1)}),p===1?i.startRendering():i.resume()};a.start(0),u(1),this.audio=r,this.context=i,this.analyser=s,this.sampleRate=o,this.audioBuffer=e}else{let t=new AudioContext,o=t.createMediaElementSource(r),i=t.createAnalyser();i.fftSize=8192,i.smoothingTimeConstant=.1,o.connect(i),i.connect(t.destination),this.audio=r,this.context=t,this.analyser=i,this.sampleRate=this.context.sampleRate,this.audioBuffer=null}}getFrequencies(r="frequency",e=-100,t=-30){let o=null;if(this.audioBuffer&&this.fftResults.length){let i=this.audio.currentTime/this.audio.duration,a=Math.min(i*this.fftResults.length|0,this.fftResults.length-1);o=this.fftResults[a]}return Cn.getFrequencies(this.analyser,this.sampleRate,o,r,e,t)}async resumeIfSuspended(){return this.context.state==="suspended"&&await this.context.resume(),!0}};var Uo=class{static floatTo16BitPCM(r){let e=new ArrayBuffer(r.length*2),t=new DataView(e),o=0;for(let i=0;i<r.length;i++,o+=2){let a=Math.max(-1,Math.min(1,r[i]));t.setInt16(o,a<0?a*32768:a*32767,!0)}return e}static mergeBuffers(r,e){let t=new Uint8Array(r.byteLength+e.byteLength);return t.set(new Uint8Array(r),0),t.set(new Uint8Array(e),r.byteLength),t.buffer}_packData(r,e){return[new Uint8Array([e,e>>8]),new Uint8Array([e,e>>8,e>>16,e>>24])][r]}pack(r,e){if(e?.bitsPerSample)if(e?.channels){if(!e?.data)throw new Error('Missing "data"')}else throw new Error('Missing "channels"');else throw new Error('Missing "bitsPerSample"');let{bitsPerSample:t,channels:o,data:i}=e,a=["RIFF",this._packData(1,4+(8+24)+(8+8)),"WAVE","fmt ",this._packData(1,16),this._packData(0,1),this._packData(0,o.length),this._packData(1,r),this._packData(1,r*o.length*t/8),this._packData(0,o.length*t/8),this._packData(0,t),"data",this._packData(1,o[0].length*o.length*t/8),i],s=new Blob(a,{type:"audio/mpeg"}),l=URL.createObjectURL(s);return{blob:s,url:l,channelCount:o.length,sampleRate:r,duration:i.byteLength/(o.length*r*2)}}};var fl=class{constructor({sampleRate:r=44100,outputToSpeakers:e=!1,debug:t=!1}={}){this.scriptSrc=Zb,this.sampleRate=r,this.outputToSpeakers=e,this.debug=!!t,this._deviceChangeCallback=null,this._devices=[],this.stream=null,this.processor=null,this.source=null,this.node=null,this.recording=!1,this._lastEventId=0,this.eventReceipts={},this.eventTimeout=5e3,this._chunkProcessor=()=>{},this._chunkProcessorSize=void 0,this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)}}static async decode(r,e=44100,t=-1){let o=new AudioContext({sampleRate:e}),i,a;if(r instanceof Blob){if(t!==-1)throw new Error('Can not specify "fromSampleRate" when reading from Blob');a=r,i=await a.arrayBuffer()}else if(r instanceof ArrayBuffer){if(t!==-1)throw new Error('Can not specify "fromSampleRate" when reading from ArrayBuffer');i=r,a=new Blob([i],{type:"audio/wav"})}else{let u,p;if(r instanceof Int16Array){p=r,u=new Float32Array(r.length);for(let m=0;m<r.length;m++)u[m]=r[m]/32768}else if(r instanceof Float32Array)u=r;else if(r instanceof Array)u=new Float32Array(r);else throw new Error('"audioData" must be one of: Blob, Float32Arrray, Int16Array, ArrayBuffer, Array<number>');if(t===-1)throw new Error('Must specify "fromSampleRate" when reading from Float32Array, In16Array or Array');if(t<3e3)throw new Error('Minimum "fromSampleRate" is 3000 (3kHz)');p||(p=Uo.floatTo16BitPCM(u));let d={bitsPerSample:16,channels:[u],data:p};a=new Uo().pack(t,d).blob,i=await a.arrayBuffer()}let s=await o.decodeAudioData(i),l=s.getChannelData(0),c=URL.createObjectURL(a);return{blob:a,url:c,values:l,audioBuffer:s}}log(){return this.debug&&this.log(...arguments),!0}getSampleRate(){return this.sampleRate}getStatus(){return this.processor?this.recording?"recording":"paused":"ended"}async _event(r,e={},t=null){if(t=t||this.processor,!t)throw new Error("Can not send events without recording first");let o={event:r,id:this._lastEventId++,data:e};t.port.postMessage(o);let i=new Date().valueOf();for(;!this.eventReceipts[o.id];){if(new Date().valueOf()-i>this.eventTimeout)throw new Error(`Timeout waiting for "${r}" event`);await new Promise(s=>setTimeout(()=>s(!0),1))}let a=this.eventReceipts[o.id];return delete this.eventReceipts[o.id],a}listenForDeviceChange(r){if(r===null&&this._deviceChangeCallback)navigator.mediaDevices.removeEventListener("devicechange",this._deviceChangeCallback),this._deviceChangeCallback=null;else if(r!==null){let e=0,t=[],o=a=>a.map(s=>s.deviceId).sort().join(","),i=async()=>{let a=++e,s=await this.listDevices();a===e&&o(t)!==o(s)&&(t=s,r(s.slice()))};navigator.mediaDevices.addEventListener("devicechange",i),i(),this._deviceChangeCallback=i}return!0}async requestPermission(){let r=await navigator.permissions.query({name:"microphone"});if(r.state==="denied")window.alert("You must grant microphone access to use this feature.");else if(r.state==="prompt")try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(o=>o.stop())}catch{window.alert("You must grant microphone access to use this feature.")}return!0}async listDevices(){if(!navigator.mediaDevices||!("enumerateDevices"in navigator.mediaDevices))throw new Error("Could not request user devices");await this.requestPermission();let e=(await navigator.mediaDevices.enumerateDevices()).filter(i=>i.kind==="audioinput"),t=e.findIndex(i=>i.deviceId==="default"),o=[];if(t!==-1){let i=e.splice(t,1)[0],a=e.findIndex(s=>s.groupId===i.groupId);a!==-1&&(i=e.splice(a,1)[0]),i.default=!0,o.push(i)}return o.concat(e)}async begin(r){if(this.processor)throw new Error("Already connected: please call .end() to start a new session");if(!navigator.mediaDevices||!("getUserMedia"in navigator.mediaDevices))throw new Error("Could not request user media");try{let s={audio:!0};r&&(s.audio={deviceId:{exact:r}}),this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{throw new Error("Could not start media stream")}let e=new AudioContext({sampleRate:this.sampleRate}),t=e.createMediaStreamSource(this.stream);try{await e.audioWorklet.addModule(this.scriptSrc)}catch(s){throw console.error(s),new Error(`Could not add audioWorklet module: ${this.scriptSrc}`)}let o=new AudioWorkletNode(e,"audio_processor");o.port.onmessage=s=>{let{event:l,id:c,data:u}=s.data;if(l==="receipt")this.eventReceipts[c]=u;else if(l==="chunk")if(this._chunkProcessorSize){let p=this._chunkProcessorBuffer;this._chunkProcessorBuffer={raw:Uo.mergeBuffers(p.raw,u.raw),mono:Uo.mergeBuffers(p.mono,u.mono)},this._chunkProcessorBuffer.mono.byteLength>=this._chunkProcessorSize&&(this._chunkProcessor(this._chunkProcessorBuffer),this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)})}else this._chunkProcessor(u)};let i=t.connect(o),a=e.createAnalyser();return a.fftSize=8192,a.smoothingTimeConstant=.1,i.connect(a),this.outputToSpeakers&&(console.warn(`Warning: Output to speakers may affect sound quality,
2458
2491
  especially due to system audio feedback preventative measures.
2459
- use only for debugging`),a.connect(e.destination)),this.source=t,this.node=i,this.analyser=a,this.processor=o,!0}getFrequencies(r="frequency",e=-100,t=-30){if(!this.processor)throw new Error("Session ended: please call .begin() first");return On.getFrequencies(this.analyser,this.sampleRate,null,r,e,t)}async pause(){if(this.processor){if(!this.recording)throw new Error("Already paused: please call .record() first")}else throw new Error("Session ended: please call .begin() first");return this._chunkProcessorBuffer.raw.byteLength&&this._chunkProcessor(this._chunkProcessorBuffer),this.log("Pausing ..."),await this._event("stop"),this.recording=!1,!0}async record(r=()=>{},e=8192){if(this.processor){if(this.recording)throw new Error("Already recording: please call .pause() first");if(typeof r!="function")throw new Error("chunkProcessor must be a function")}else throw new Error("Session ended: please call .begin() first");return this._chunkProcessor=r,this._chunkProcessorSize=e,this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)},this.log("Recording ..."),await this._event("start"),this.recording=!0,!0}async clear(){if(!this.processor)throw new Error("Session ended: please call .begin() first");return await this._event("clear"),!0}async read(){if(!this.processor)throw new Error("Session ended: please call .begin() first");return this.log("Reading ..."),await this._event("read")}async save(r=!1){if(!this.processor)throw new Error("Session ended: please call .begin() first");if(!r&&this.recording)throw new Error("Currently recording: please call .pause() first, or call .save(true) to force");this.log("Exporting ...");let e=await this._event("export");return new Uo().pack(this.sampleRate,e.audio)}async end(){if(!this.processor)throw new Error("Session ended: please call .begin() first");let r=this.processor;this.log("Stopping ..."),await this._event("stop"),this.recording=!1,this.stream.getTracks().forEach(a=>a.stop()),this.log("Exporting ...");let t=await this._event("export",{},r);return this.processor.disconnect(),this.source.disconnect(),this.node.disconnect(),this.analyser.disconnect(),this.stream=null,this.processor=null,this.source=null,this.node=null,new Uo().pack(this.sampleRate,t.audio)}async quit(){return this.listenForDeviceChange(null),this.processor&&await this.end(),!0}};var OD=`
2492
+ use only for debugging`),a.connect(e.destination)),this.source=t,this.node=i,this.analyser=a,this.processor=o,!0}getFrequencies(r="frequency",e=-100,t=-30){if(!this.processor)throw new Error("Session ended: please call .begin() first");return Cn.getFrequencies(this.analyser,this.sampleRate,null,r,e,t)}async pause(){if(this.processor){if(!this.recording)throw new Error("Already paused: please call .record() first")}else throw new Error("Session ended: please call .begin() first");return this._chunkProcessorBuffer.raw.byteLength&&this._chunkProcessor(this._chunkProcessorBuffer),this.log("Pausing ..."),await this._event("stop"),this.recording=!1,!0}async record(r=()=>{},e=8192){if(this.processor){if(this.recording)throw new Error("Already recording: please call .pause() first");if(typeof r!="function")throw new Error("chunkProcessor must be a function")}else throw new Error("Session ended: please call .begin() first");return this._chunkProcessor=r,this._chunkProcessorSize=e,this._chunkProcessorBuffer={raw:new ArrayBuffer(0),mono:new ArrayBuffer(0)},this.log("Recording ..."),await this._event("start"),this.recording=!0,!0}async clear(){if(!this.processor)throw new Error("Session ended: please call .begin() first");return await this._event("clear"),!0}async read(){if(!this.processor)throw new Error("Session ended: please call .begin() first");return this.log("Reading ..."),await this._event("read")}async save(r=!1){if(!this.processor)throw new Error("Session ended: please call .begin() first");if(!r&&this.recording)throw new Error("Currently recording: please call .pause() first, or call .save(true) to force");this.log("Exporting ...");let e=await this._event("export");return new Uo().pack(this.sampleRate,e.audio)}async end(){if(!this.processor)throw new Error("Session ended: please call .begin() first");let r=this.processor;this.log("Stopping ..."),await this._event("stop"),this.recording=!1,this.stream.getTracks().forEach(a=>a.stop()),this.log("Exporting ...");let t=await this._event("export",{},r);return this.processor.disconnect(),this.source.disconnect(),this.node.disconnect(),this.analyser.disconnect(),this.stream=null,this.processor=null,this.source=null,this.node=null,new Uo().pack(this.sampleRate,t.audio)}async quit(){return this.listenForDeviceChange(null),this.processor&&await this.end(),!0}};var C3=`
2460
2493
  class StreamProcessor extends AudioWorkletProcessor {
2461
2494
  constructor() {
2462
2495
  super();
@@ -2545,7 +2578,7 @@ class StreamProcessor extends AudioWorkletProcessor {
2545
2578
  }
2546
2579
 
2547
2580
  registerProcessor('stream_processor', StreamProcessor);
2548
- `,AD=new Blob([OD],{type:"application/javascript"}),TD=URL.createObjectURL(AD),rv=TD;var Ku=class{constructor({sampleRate:r=44100}={}){this.scriptSrc=rv,this.sampleRate=r,this.context=null,this.stream=null,this.analyser=null,this.trackSampleOffsets={},this.interruptedTrackIds={}}async connect(){this.context=new AudioContext({sampleRate:this.sampleRate}),this.context.state==="suspended"&&await this.context.resume();try{await this.context.audioWorklet.addModule(this.scriptSrc)}catch(e){throw console.error(e),new Error(`Could not add audioWorklet module: ${this.scriptSrc}`)}let r=this.context.createAnalyser();return r.fftSize=8192,r.smoothingTimeConstant=.1,this.analyser=r,!0}getFrequencies(r="frequency",e=-100,t=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return On.getFrequencies(this.analyser,this.sampleRate,null,r,e,t)}_start(){let r=new AudioWorkletNode(this.context,"stream_processor");return r.connect(this.context.destination),r.port.onmessage=e=>{let{event:t}=e.data;if(t==="stop")r.disconnect(),this.stream=null;else if(t==="offset"){let{requestId:o,trackId:i,offset:a}=e.data,s=a/this.sampleRate;this.trackSampleOffsets[o]={trackId:i,offset:a,currentTime:s}}},this.analyser.disconnect(),r.connect(this.analyser),this.stream=r,!0}add16BitPCM(r,e="default"){if(typeof e!="string")throw new Error("trackId must be a string");if(this.interruptedTrackIds[e])return;this.stream||this._start();let t;if(r instanceof Int16Array)t=r;else if(r instanceof ArrayBuffer)t=new Int16Array(r);else throw new Error("argument must be Int16Array or ArrayBuffer");return this.stream.port.postMessage({event:"write",buffer:t,trackId:e}),t}async getTrackSampleOffset(r=!1){if(!this.stream)return null;let e=crypto.randomUUID();this.stream.port.postMessage({event:r?"interrupt":"offset",requestId:e});let t;for(;!t;)t=this.trackSampleOffsets[e],await new Promise(i=>setTimeout(()=>i(),1));let{trackId:o}=t;return r&&o&&(this.interruptedTrackIds[o]=!0),t}async interrupt(){return this.getTrackSampleOffset(!0)}};var ov=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/",gl=class{constructor(r,e,t){this.data=r;this.id=e;this.shared=t;this.items=[];this.isConnected=!1;this.rafId=0;this.emitter=Lo();this.voice=0;this.frequencies=new Float32Array([0]);this.onRealTimeEvent=({time:r,source:e,event:t})=>{e==="server"&&t.type==="spline.ready"?this.onSessionCreated(t):e==="server"&&t.type==="session.created"&&(this.client.createResponse(),this.client.on("realtime.event",this.onRealTimeEvent))};this.onSessionCreated=async r=>{let e=Object.values(this.client.tools).map(t=>({type:"function",...t.definition}));this.client.realtime.send("spline.tools",{tools:e}),this.client.realtime.send("spline.connect",{}),await this.wavRecorder.record(t=>this.client.isConnected()&&this.client.appendInputAudio(t.mono))};this.animate=()=>{if(this.rafId=requestAnimationFrame(this.animate),this.isConnected){let r=this.wavStreamPlayer.analyser?this.wavStreamPlayer.getFrequencies("voice"):{values:new Float32Array([0])},e=r.values.reduce((t,o)=>t+o,0)/r.values.length;this.voice=e,this.frequencies=r.values,this.emitter.emit("voice",{value:e,frequencies:r.values})}};this.client=new es({url:ov()+"?uuidfile="+r.integration.hash}),this.wavRecorder=new yl({sampleRate:24e3}),this.wavStreamPlayer=new Ku({sampleRate:24e3})}update(r){this.data=r,this.client=new es({url:ov()+"?uuidfile="+r.integration.hash})}setColorByName(r,e){let t=this.shared.getColorByName(r);if(t){let{id:o}=t,{r:i,g:a,b:s}=J0.hexStringToRgb(e)??{r:0,g:0,b:0};this.shared.updateColor(o,{r:i/255,g:a/255,b:s/255})}}connect(){if(this.isConnected)return;this.isConnected=!0,this.client.updateSession({turn_detection:{type:"server_vad"}}),this.client.addTool({name:"set_personality_color",description:"returns a color based on the voice personality of the ai assistant. This should be called by the voice assistant each time it is asks to speak differently. If a color cannot be associated to the personality, the color should be a neutral color.",parameters:{type:"object",properties:{color:{type:"string",description:"css hex color string, reflecting the personality"},personality:{type:"string",description:"the personality of the voice assistant"}},required:["color","personality"]}},({color:i})=>{this.setColorByName("Voice Assistant Color",i)});let r=this.shared.getVariablesNames().join(", ");this.client.addTool({name:"set_variable",description:"Sets a Spline variable value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the variable that needs to be set. Here's a list of available variables: ${r}. It the variable does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"The new value for this variable, should always be a string even for number and boolean variables, assume that the value will be cast to the proper type afterwards."}},required:["name","value","type"]}},({name:i,value:a})=>{let s=this.shared.getVariableByName(i);if(s){let l=this.shared.getVariable(s.id),c;typeof l=="number"?c=parseFloat(a):typeof l=="boolean"?c=a.toLowerCase()==="true":c={textValue:a},this.shared.updateVariable(s.id,c)}});let e=this.shared.getColorNames().join(", ");this.client.addTool({name:"set_color",description:"Sets a Spline color asset value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the color asset that needs to be set. Here's a list of available color assets: ${e}. It the color asset does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"css hex color string"}},required:["name","value"]}},({name:i,value:a})=>{this.setColorByName(i,a)});let t=this.shared.scene,o=[];t.traverseEntity(i=>{i.data.events.forEach(a=>{if(a.data.type==="AIAssistantTrigger"){let{description:s}=a.data;o.push(s)}})}),this.client.addTool({name:"trigger_event",description:"Trigger an event by name, here are the available events, please match what the user is asking for to one of these if it applies, otherwise don't call the function and warn the user.",parameters:{type:"object",properties:{description:{type:"string",description:`The name of the event that needs to be triggered. Here's a list of available events: ${JSON.stringify(o)}.`},direction:{type:"string",description:"default is forward, but can be forward or backward. Always set to forward unless the user ask to reverse or cancel the event, then set to backward."}},required:["description","direction"]}},({description:i,direction:a})=>{this.emitter.emit("trigger_event",{description:i,direction:a})}),this.client.on("error",i=>console.error(i)),this.client.on("conversation.interrupted",async()=>{let i=await this.wavStreamPlayer.interrupt();if(i?.trackId){let{trackId:a,offset:s}=i;await this.client.cancelResponse(a,s)}}),this.client.on("conversation.updated",async({item:i,delta:a})=>{let s=this.client.conversation.getItems();if(a?.audio&&this.wavStreamPlayer.add16BitPCM(a.audio,i.id),i.status==="completed"&&i.formatted.audio?.length){let l=await yl.decode(i.formatted.audio,24e3,24e3);i.formatted.file=l}this.items=s}),this.animate()}disconnect(){cancelAnimationFrame(this.rafId),this.voice=0,this.isConnected=!1}async start(){try{await this.wavRecorder.end()}catch{}await this.wavRecorder.begin(),this.client.on("realtime.event",this.onRealTimeEvent),await this.wavStreamPlayer.connect(),await this.client.connect()}async stop(){try{this.client.off("realtime.event",this.onRealTimeEvent)}catch(r){console.error(r)}this.client.disconnect(),await this.wavRecorder.end(),await this.wavStreamPlayer.interrupt()}computeAnalysisForListenerEvent(r){if(r.analysis==="range"){let e=this.frequencies.slice(...r.analysisRange);return e.reduce((t,o)=>t+o,0)/e.length}return r.analysis==="single"?this.frequencies[r.analysisSingle]:this.voice}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}};function iv(n){return"variable_"+n}var oh=class extends Gu{constructor(e){super();this.shared=e}create(e){return new Qa(e,this.shared)}},ci=class{constructor(r,e={},t=!0,o=!1){this.data=r;this.needsJitter=t;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new fl(!0);this.geometryCache2=new fl(!1);this.imageHolderCache=new oh(this);this.thisContext={scene:Kb,shared:this};this.deletedMaterial=new ai(Et.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new dr(Qc.emptyImage,this);this.deletedVideo=new dr(Zi.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.variables={};this.userAPIs={};this.userWebhooks={};this.mouseProperty=null;this.raycastProperty=null;this.requestRender=()=>{this._requestRender&&this._requestRender()};if(e.images)for(let[i,a]of Object.entries(e.images))this.addImage(i,a);if(e.videos)for(let[i,a]of Object.entries(e.videos))this.addVideo(i,a);if(e.audios)for(let[i,a]of Object.entries(e.audios))this.addAudio(i,a);if(e.particles)for(let[i,a]of Object.entries(e.particles))this.addParticle(i,a);this.reset(r)}setRequestRender(r){this._requestRender=r}getImageLoadPromises(){return Object.values(this.images).map(r=>r.loadPromise)}setEntityOpContext(r){this.entityOpContext=r}reset(r,e=!1){this.data=r,this.resetLib(r.lib);for(let{id:t,data:o}of r.variables)this.addVariableHolder(t,o),e&&this.updateVariableHolder(t,o);for(let[t,o]of Object.entries(r.userAPIs))this.addUserAPI(t,o);for(let[t,o]of Object.entries(r.userWebhooks))this.addUserWebhook(t,o);for(let[t,o]of Object.entries(r.images))this.addImage(t,o);for(let[t,o]of Object.entries(r.videos))this.addVideo(t,o);for(let[t,o]of Object.entries(r.colors))this.addColor(t,o);for(let[t,o]of Object.entries(r.materials))this.addMaterial(t,o);for(let[t,o]of Object.entries(r.audios))this.addAudio(t,o);for(let[t,o]of Object.entries(r.particles))this.addParticle(t,o);for(let[t,o]of Object.entries(r.fonts))this.addFont(t,o)}addMaterial(r,e){if(this.materials[r]){let t=this.materials[r];t.reset(e,this.thisContext),t.dispose()}else{let t=new ai(e,this.thisContext,r);this.materials[r]=t}}deleteMaterial(r){this.materials[r]&&(this.materials[r].nodeMaterialDispose(),delete this.materials[r])}getMaterial(r){let e=this.materials[r];return e}getMaterialOrDeletedPlaceholder(r){return this.materials[r]??this.deletedMaterial}material(r){return typeof r=="string"?this.getMaterialOrDeletedPlaceholder(r):r==null?(console.error("material is undefined or null"),this.deletedMaterial):new ii(r,this.thisContext)}getMaterials(){return this.materials}addImage(r,e){return this.images[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[r].updateSrc(e.data),!0):(this.images[r]=new dr(e,this),!1)}deleteImage(r){let e=this.images[r];e&&(e.dispose(),delete this.images[r])}getDefaultImage(){return this.images.image_0}getImage(r){return this.images[r]??this.deletedImage}image(r){return typeof r=="string"?this.getImage(r):this.imageHolderCache.load(r)}addUIBuffer(r,e){return this.uiBuffers[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[r].updateSrc(e),!0):(this.uiBuffers[r]=new dr(e,this),!1)}uiBuffer(r){return this.uiBuffers[r]}addVideo(r,e){return this.videos[r]?(this.videos[r].updateSrc(e.data),!0):(this.videos[r]=new dr(e,this),!1)}deleteVideo(r){let e=this.videos[r];e&&(e.dispose(),delete this.videos[r])}getVideo(r){return this.videos[r]??this.deletedVideo}video(r){return typeof r=="string"?this.getVideo(r):this.imageHolderCache.load(r)}addColor(r,e){return this.colors[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[r].setRGBA(e.r,e.g,e.b,e.a):this.colors[r].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[r]=new wn(e.r,e.g,e.b,e.a):this.colors[r]=new wn(e.r,e.g,e.b,1),!1)}updateColor(r,e){if(this.colors[r]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let t=this.colors[r];return this.colors[r].r=e.r??t.r,this.colors[r].g=e.g??t.g,this.colors[r].b=e.b??t.b,this.colors[r].a=e.a??t.a,!0}return!1}deleteColor(r){this.colors[r]&&delete this.colors[r]}getColor(r){return this.colors[r]}getColorNames(){return Object.values(this.data.colors).map(r=>r.name)}getColorByName(r){for(let e in this.data.colors)if(this.data.colors[e].name===r)return{color:this.colors[e],id:e}}color(r){let e;if(typeof r=="string"){let t=this.getColor(r);t?e=t:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new At(0,0,0,0))}else return"a"in r?new At(r.r,r.g,r.b,r.a):new At(r.r,r.g,r.b,1);return e}addAudio(r,e){this.audios[r]=e}getAudio(r){let e=this.audios[r];if(e instanceof si)return e;{let t=new si({src:e.data});return this.audios[r]=t,t}}addParticle(r,e){this.particles[r]=e}getParticle(r){return this.particles[r]}deleteParticle(r){this.particles[r]&&delete this.particles[r]}deleteAudio(r){let e=this.audios[r];e&&(e instanceof si&&e.dispose(),delete this.audios[r])}addFont(r,e){this.fonts[r]=new Wu(e),this.fonts[r].loadingPromise.then(()=>this.requestRender())}getFont(r){return this.fonts[r]}deleteFont(r){this.fonts[r]&&delete this.fonts[r]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof si&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(r,e){if(this.variables[r]===void 0){let t=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(iv(r));t=o!==null?JSON.parse(o):e.value}return this.variables[r]={value:t,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0),!0}return this.variables[r].value=e.value,!1}resetDynamicVariablePlayState(){for(let r in this.variables)this.variables[r].dynamicVariablePlayState!==void 0&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(r,e){this.updateVariable(r,e.value)}updateVariable(r,e){if(this.variables[r]===void 0)return!1;this.variables[r].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[r].persistent&&localStorage.setItem(iv(r),JSON.stringify(e));let t=e;for(;typeof t=="string";)t=this.variables[t].value;let o=this.entityOpContext.scene;for(let i=this.variables[r].locations.length-1;i>=0;i--){let a=this.variables[r].locations[i];if(a[0]==="material"){let s=a[1],l=t,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(d=>{let h=d.root??d;h.uuid===s&&h.onVariableUpdate(u,l,c)});let p=this.materials[s];p&&p.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[r].locations.splice(i,1);continue}if(a[1]!=="geometry"&&a[1]!=="particles"){for(let l=1;l<a.length-1;l++)s=s[a[l]];a[1]==="rotation"?s[a[a.length-1]]=t*nv.DEG2RAD:s[a[a.length-1]]=t}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(t,a),Le.is(s))if(a[1]==="position"||a[1]==="rotation"||a[1]==="scale")s.onVariableUpdate();else if(a[1]==="geometry"){let l=s;s.component&&(l=s.component);let c=l.dataPatched;l.chooseGeoemtryCache(this).forceDelete(c.geometry),l.createGeometryDelayed(this.entityOpContext),l.onVariableUpdate(!0),l.invalidateDownstreamBooleanData(),l.instances.forEach(u=>{let p=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(p.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],t)}}return this.requestRender(),!0}deleteVariable(r){this.variables[r]&&delete this.variables[r]}getVariable(r,e){if(Array.isArray(r)){if(r[0]==="mouse")return this.mouseProperty?.[r[1]]??0;if(r[0]==="raycast")return this.raycastProperty?.[r[1]]??0;let t=this.entityOpContext.scene.find(r[0]);if(r[1]==="width"||r[1]==="height"||r[1]==="depth")return t.geometry.userData.parameters[r[1]];for(let o=1;o<r.length;o++)t=t[r[o]];return r[1]==="rotation"&&(t*=nv.RAD2DEG),t}for(let t in this.variables){if(e===void 0)break;let o=this.variables[t],i=o.locations?.findIndex(a=>Ze.equal(a,e));i!==void 0&&i!==-1&&o.locations.splice(i,1)}if(typeof r=="string"){let t=r,o=r;do{if(o=t,this.variables[t]===void 0)break;let i=this.variables[t].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),t=i}while(typeof t=="string");return t}else return r}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(r=>r.data.name)}getVariableByName(r){for(let e of this.data.variables)if(e.data.name===r)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(r){return this.variables[r]?.dynamicVariablePlayState}setDynamicVariablePlayState(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(r){return this.variables[r]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariableToggleIsForward=e)}resetLib(r){for(let[e,t]of Object.entries(r.images))this.addImage(e,t.asset);for(let[e,t]of Object.entries(r.audios))this.addAudio(e,t.asset);for(let[e,t]of Object.entries(r.particles))this.addParticle(e,t.asset);for(let[e,t]of Object.entries(r.colors))this.addColor(e,t.asset);for(let[e,t]of Object.entries(r.fonts))this.addFont(e,t.asset);for(let[e,t]of Object.entries(r.materials))this.addMaterial(e,t.asset);for(let[e,t]of Object.entries(r.videos))this.addVideo(e,t.asset);for(let[e,t]of Object.entries(r.variables))this.addVariableHolder(e,t.asset)}updateLibByOp(r,e){r.path[0]==="images"?r.path.length===1&&r.type===1?this.addImage(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteImage(r.id):r.path[0]==="videos"?r.path.length===1&&r.type===1?this.addVideo(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVideo(r.id):r.path[0]==="audios"?r.path.length===1&&r.type===1?this.addAudio(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteAudio(r.id):r.path[0]==="particles"?r.path.length===1&&r.type===1?this.addParticle(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteParticle(r.id):r.path[0]==="colors"?r.path.length===1&&r.type===1?this.addColor(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteColor(r.id):r.path[0]==="materials"?r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteMaterial(r.id):r.path[0]==="fonts"?r.path.length===1&&r.type===1?this.addFont(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteFont(r.id):r.path[0]==="variables"?r.path.length===1&&r.type===1?this.addVariableHolder(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVariable(r.id):r.path[0]==="components"&&e.updateByLibOp(r,this)}updateByOp(r,e,t){if(this.data=e,r.path[0]==="images")r.path.length===2&&r.type===0?r.props.data&&this.getImage(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addImage(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteImage(r.id);else if(r.path[0]==="videos")r.path.length===2&&r.type===0?r.props.data&&this.getVideo(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addVideo(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteVideo(r.id);else if(r.path[0]==="audios")r.path.length===2&&r.type===0?r.props.data&&this.addAudio(r.path[1],e.audios[r.path[1]]):r.path.length===1&&r.type===1?this.addAudio(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteAudio(r.id);else if(r.path[0]==="particles")r.path.length===2&&r.type===0?r.props.data&&this.addParticle(r.path[1],e.particles[r.path[1]]):r.path.length===1&&r.type===1?this.addParticle(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteParticle(r.id);else if(r.path[0]==="colors")r.path.length===2&&r.type===0?this.updateColor(r.path[1],r.props):r.path.length===1&&r.type===1?this.addColor(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteColor(r.id);else if(r.path[0]==="materials")r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data):r.path.length===1&&r.type===2?this.deleteMaterial(r.id):r.path.length>1&&this.getMaterial(r.path[1]).updateByOp(nt.drop(r,2),e.materials[r.path[1]],{shared:this,scene:t});else if(r.path[0]==="fonts")r.path.length===2&&r.type===0?this.updateFont(r.path[1],r,t):r.path.length===1&&r.type===1?this.addFont(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteFont(r.id);else if(r.path[0]==="variables")r.path.length===2&&r.type===0?"value"in r.props?this.updateVariable(r.path[1],r.props.value):"persistent"in r.props&&(this.variables[r.path[1]].persistent=r.props.persistent):r.path.length===1&&r.type===4?this.addVariableHolder(r.id,r.data):r.path.length===1&&r.type===5&&this.deleteVariable(r.id);else if(r.path[0]==="userAPIs"){if(r.path.length===1&&r.type===1)this.addUserAPI(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserAPI(r.id);else if(typeof r.path[1]=="string"){let o=e.userAPIs[r.path[1]];if(o){let i=r.type===0&&r.props.debounce===void 0,a=this.getUserAPI(r.path[1]);a instanceof gl?a.update(o):a?.update(o,this,i)}}}else if(r.path[0]==="userWebhooks"){if(r.path.length===1&&r.type===1)this.addUserWebhook(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserWebhook(r.id);else if(typeof r.path[1]=="string"){let o=e.userWebhooks[r.path[1]];o&&this.getUserWebhook(r.path[1])?.update(o)}}else r.path[0]==="lib"&&this.updateLibByOp(nt.drop(r,1),t)}updateFont(r,e,t){if(e.props.url){let o=this.getFont(r),i={...this.data.fonts[r],url:e.props.url};o.update(i),o.loadingPromise.then(()=>this.requestRender()),t.updateFont(r,this)}}addUserAPI(r,e){return this.userAPIs[r]?(this.userAPIs[r].update(e,this),!0):this.openAIRealtime?.id===r?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new gl(e,r,this),!1):(this.userAPIs[r]=new Au(r,e,this),!1)}getUserAPI(r){return this.openAIRealtime?.id===r?this.openAIRealtime:this.userAPIs[r]}getUserAPIs(){return this.userAPIs}deleteUserAPI(r){let e=this.userAPIs[r];e&&(e.dispose(),delete this.userAPIs[r])}addUserWebhook(r,e){return this.userWebhooks[r]?(this.userWebhooks[r].update(e),!0):(this.userWebhooks[r]=new $u(r,e),!1)}getUserWebhook(r){return this.userWebhooks[r]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(r){let e=this.userWebhooks[r];e&&(e.dispose(),delete this.userWebhooks[r])}get scene(){return this.entityOpContext.scene}},av=new ci(xr.emptyData());var or=class extends Ct{updateByPatchedOp(e,t,o){if(super.updateByPatchedOp(e,t,o),_g(e.path,["materials"])!==null&&e.type===0&&Array.isArray(this.material))for(let[i,a]of Object.entries(e.props)){let s=o.shared.material(a);this.material[Number(i)]=s}else if(Re(e.path,["material"])&&this.material instanceof rr)"material"in t&&typeof t.material!="string"&&this.material.updateByOp(nt.drop(e,1),t.material,o);else if(Re(e.path,["materials","*"])&&Array.isArray(this.material)){let i=e.path[1];if("materials"in t&&i<this.material.length){let a=t.materials[i];typeof a!="string"&&this.material[i].updateByOp(nt.drop(e,2),a,o)}}}get needsAO(){return this.material!==void 0?(Array.isArray(this.material)?this.material[0]:this.material).hasAO:!1}updateState(e,t){super.updateState(e,t),e.castShadow!==void 0&&(this.castShadow=e.castShadow),e.receiveShadow!==void 0&&(this.receiveShadow=e.receiveShadow);let o=this.dataPatched;if(e.geometry?.type!=="NonParametricGeometry"&&"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe),t.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(i=>t.shared.material(i).getFlavor(o.flatShading,o.side,o.wireframe)),t.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],t.scene.markNeedsUpdateRendererDirty())),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let i=0;i<this.material.length;i++)this.material[i]=this.material[i].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe)}disposeMaterial(){this.material&&Fl(this.material).forEach(e=>{e instanceof rr&&(e instanceof ai||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};import{BufferGeometry as MD,Matrix4 as nh,Vector3 as dv,Vector4 as ih}from"three";var sv=new dv,lv=new ih,cv=new ih,ED=new dv,uv=new nh,lt=class extends or{constructor(e,t,o){super(e,t);this.data=t;this.isSkinnedMesh=!1;this.localGeometry=void 0,t.bindMode&&t.bindMatrix&&(this.bindMode=t.bindMode,this.bindMatrix=new nh().fromArray(t.bindMatrix),this.bindMatrixInverse=new nh)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof MD&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof ci){let e=this.geometryCreateDeleyed,t=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=t.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return Ds.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return Ds.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),Re(e.path,["geometry"])&&this.updateByPatchedOpGeometry(nt.drop(e,1),t.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,t){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let i=e;if(this.localGeometry===void 0){let u={...this.data.geometry,...i};this.localGeometry=Vo(u,t,this.data.flatShading,this)}let a,s,l;i.scaleBaked?[a,s,l]=i.scaleBaked:{width:a,height:s,depth:l}=i;let c=this.localGeometry.userData;c.sxPrev!==void 0&&el(this.localGeometry.attributes,a/c.sxPrev,s/c.syPrev,l/c.szPrev),c.sxPrev=a,c.syPrev=s,c.szPrev=l}else{let i={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=Vo(i,t,this.data.flatShading,this)}}refreshAttachedClonersInteractions(){for(let e of this.attachedSurfaceCloners)e.update()}refreshAttachedCloners(e){for(let t of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(t.object)}refreshAttachedPaths(e){for(let t of this.attachedPaths)e.scene.addPendingCommand(()=>t.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,t,o){let i=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof yt&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,t)===this.geometryCreateDeleyed&&(i=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(t,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),i||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,t){this.createGeometryDelayed(t)}updateState(e,t){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,t);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:i,value:a}}of o)this.updateMorphInfluences(i,t.shared.getVariable(a,[this.uuid,"morphTargetInfluences",i]))}super.updateState(e,t)}updateMorphInfluences(e,t){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=t)}updateGeometryGroupsIfNeeded(){Array.isArray(this.material)&&this.geometry.groups.length===0&&this.geometry.addGroup(0,Math.max(this.geometry.getIndex()?.count??0,this.geometry.getAttribute("position").count),0)}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;this.is2DType?e.set(0,0,o.depth*.5):this.isNonParametric?(e.setScalar(0),this.geometry.boundingSphere&&e.copy(this.geometry.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):e.setScalar(0),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode==="attached"?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode==="detached"&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}bind(e,t){this.skeleton=e,this.isSkinnedMesh=!0,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let t=new ih,o=this.geometry.attributes.skinWeight;for(let i=0,a=o.count;i<a;i++){t.fromBufferAttribute(o,i);let s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),o.setXYZW(i,t.x,t.y,t.z,t.w)}}boneTransform(e,t){let o=this.skeleton;if(o===void 0)return;let i=this.geometry;lv.fromBufferAttribute(i.attributes.skinIndex,e),cv.fromBufferAttribute(i.attributes.skinWeight,e),sv.copy(t).applyMatrix4(this.bindMatrix),t.set(0,0,0);for(let a=0;a<4;a++){let s=cv.getComponent(a);if(s!==0){let l=lv.getComponent(a);uv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),t.addScaledVector(ED.copy(sv).applyMatrix4(uv),s)}}return t.applyMatrix4(this.bindMatrixInverse)}};function DD(n){if(n.geometry.attributes.extrudeNormal||!n.geometry.attributes.position||!n.geometry.attributes.normal)return;let r=new Map,e=n.geometry.attributes,t=e.position.array,o=e.normal.array,i=new Float32Array(t.length);for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=new sh(o[a],o[a+1],o[a+2]);r.has(s)?r.get(s)?.normals.push(l):r.set(s,{normals:[l],result:new sh})}r.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=r.get(s)?.result;l&&(i[a]=l.x,i[a+1]=l.y,i[a+2]=l.z)}n.geometry.setAttribute("extrudeNormal",new pv(i,3))}function _D(n){if(n.geometry.attributes.extrudeNormals||!n.geometry.attributes.position)return;let e=n.geometry.attributes.position.array,t=new Float32Array(e.length),o=new sh;for(let i=0;i<e.length;i+=3)o.set(e[i],e[i+1],e[i+2]).normalize(),t[i]=o.x,t[i+1]=o.y,t[i+2]=o.z;n.geometry.setAttribute("extrudeNormal",new pv(t,3))}function ts(n){if(Array.isArray(n.material)){for(let r of n.material)if(r.getLayersOfType("outline").length===0)return}else if(!(n.material instanceof rr)||n.material.getLayersOfType("outline").length===0)return;n instanceof lt&&n.is2DAndNoDepth?_D(n):DD(n)}function rs(n){if(!n.geometry.attributes.position)return;let e=n.geometry.attributes.position.array,t=new Float32Array(e.length),o=parseInt(n.uuid.replace(/\D/g,"")),i=[ah.seededRandom(o),ah.seededRandom(o+1e4),ah.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)t[a]=i[a%3];n.geometry.setAttribute("randomColor",new ND(t,3))}var ho=new BD,xl=new LD;function hv(n){let r=!1;return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="SubdivGeometry"&&(r=!0)}),r}var ui=class extends lt{constructor(e,t,o){super(e,t,o);this.data=t;this.hiddenMatrixOld=new RD;this.smoothShading=!0;this.skipReactionUpdate=!1}chooseGeoemtryCache(e){return this.dataPatched.flatShading?e.geometryCache:e.geometryCache2}get subdivPointerNew(){return this.localGeometry!==void 0?this.subdivPointer:this.geometry.ensureSubdivPointer()}get originalGeometryNew(){return this.localGeometry!==void 0?this.originalGeometry:this.geometry.originalGeometry}get phongAngle(){return this.data.geometry.phongAngle??45}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let t=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:i,subdivPointer:a}=yt.build(e,this.subdivPointer,this.smoothShading,this.hasNonUniformScale?this.shearScale:void 0);this.subdivPointer=a,o!==void 0&&(this.originalGeometry?.dispose(),this.originalGeometry=o),i!==void 0&&(this.subdividedGeometry?.dispose(),this.subdividedGeometry=i??void 0),this.localGeometry=this.subdividedGeometry??this.originalGeometry,ts(this),rs(this),this.calcBoundingBox(),t&&(this.localGeometry.uuid=t)}updateState(e,t){if(super.updateState(e,t),e.flatShading!==void 0){let o=this.material;this.material=Array.isArray(o)?o.map(i=>i.getFlavor(!1,i.side,i.wireframe)):o.getFlavor(!1,o.side,o.wireframe),this.smoothShading=!e.flatShading,this.createGeometryDelayed(t)}}updateMesh(e=!1){yt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&yt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=yt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=yt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,t){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Ct.prototype.raycast.call(this,e,t),this.localGeometry=o}activateSVDCompensation(){!this.hasNonUniformScale||(this.matrix.copy(this.matrixWorldRigid),this.hiddenMatrixOld.copy(this.hiddenMatrix),this.hiddenMatrix.copy(this.parent.matrixWorld).invert())}deactivateSVDCompensation(){!this.hasNonUniformScale||(this.updateMatrix(),this.hasNonUniformScale=void 0,this.hiddenMatrix.copy(this.hiddenMatrixOld))}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new fv,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;ho.setFromBufferAttribute(t),ho.getCenter(o),e.boundingSphere.radius=o.distanceTo(ho.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),ho.getSize(xl),this.hasNonUniformScale&&xl.divide(this.scale);let i={width:xl.x,height:xl.y,depth:xl.z};return this.geometry.userData.parameters=i,i}updateBoundingSphere(e){let t=this.originalGeometry;ho.min.set(e[0],e[2],e[4]),ho.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(ho.min.applyMatrix4(this.shearScaleInv),ho.max.applyMatrix4(this.shearScaleInv)),t.boundingSphere===null&&(t.boundingSphere=new fv);let o=t.boundingSphere.center;ho.getCenter(o),t.boundingSphere.radius=o.distanceTo(ho.max)}freeSubdivPointer(){this.subdivPointer&&(yt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),this.localGeometry&&this.createGeometryByControls(t)}};import{Triangle as VD,Vector3 as pi}from"three";var mv=-1,zD=1,yv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},gv={polygon_center:0,edge:1,vertex:2},bl=(n,r)=>(e,t)=>!r||e===0||n===0?0:n*t/100,Ae=(n,r)=>{let e=Math.abs(r),t=e*-1;return(n-mv)*(e-t)/(zD-mv)+t};function xv(n){let r=[],e={};for(var t=0,o=n.length;t<o;t++){var i=JSON.stringify(n[t].pos.map(a=>Math.round(a*1e4)/1e4));e[i]||(r.push(n[t]),e[i]=!0)}return r}var GD=new pi,Qu=new pi,FD=new pi,jD=new pi;function os(n,r){let e=FD.fromArray(n),t=jD.fromArray(r);Qu.copy(t).sub(e);let o=Qu.length();return Qu.normalize().multiplyScalar(o*.5),GD.copy(e).add(Qu).toArray()}var Pr=new VD,Zu=new pi,Ju=new pi,di=new pi;function bv(n){let r=[];for(let e=0;e<=n.index.count;e++)if(Zu.fromArray(n.index.array,e*3),Pr.setFromAttributeAndIndices(n.attributes.position,Zu.x,Zu.y,Zu.z),Pr.getNormal(Ju),Pr.getMidpoint(di),!(isNaN(di.x)||isNaN(di.y)||isNaN(di.z))){let{a:t,b:o,c:i}=Pr,a=t.toArray(),s=o.toArray(),l=i.toArray(),c=t.distanceTo(o),u=o.distanceTo(i),p=i.distanceTo(t),d=os(a,s),h=os(s,l),f=os(l,a),m=[c,u,p],y=Math.max(...m),g=m.filter(O=>Math.round(O)===Math.round(y)).length>1,v=[],w=Pr.getMidpoint(di).toArray();y===c&&!g&&(v=[h,f,f],w=d),y===u&&!g&&(v=[d,f,f],w=h),y===p&&!g&&(v=[d,h,h],w=f),g&&(v=[d,h,f]),r.push({vertices:[a,s,l],faceCenters:v,midpoint:w,norm:Pr.getNormal(Ju).toArray()})}return r}function vv(n){let r=[],{position:e}=n.attributes;for(let t=0;t<e.count;t++){Pr.setFromAttributeAndIndices(e,t*3,t*3+1,t*3+2),Pr.getNormal(Ju),Pr.getMidpoint(di);let o=Pr.a.toArray(),i=Pr.b.toArray(),a=Pr.c.toArray();r.push({vertices:[o,i,a],faceCenters:[os(o,i),os(i,a),os(a,o)],midpoint:di.toArray(),norm:Ju.toArray()})}return r}var kD=4,UD=.5,lh=n=>.5*(1-Math.cos(n*Math.PI)),ch=class{constructor(){this.perlin=new Array(4095+1)}noise(r,e=0,t=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let g=0;g<4095+1;g++)this.perlin[g]=Math.random()}r<0&&(r=-r),e<0&&(e=-e),t<0&&(t=-t);let o=Math.floor(r),i=Math.floor(e),a=Math.floor(t),s=r-o,l=e-i,c=t-a,u,p,d=0,h=.5,f,m,y;for(let g=0;g<kD;g++){let v=o+(i<<4)+(a<<8);u=lh(s),p=lh(l),f=this.perlin[v&4095],f+=u*(this.perlin[v+1&4095]-f),m=this.perlin[v+16&4095],m+=u*(this.perlin[v+16+1&4095]-m),f+=p*(m-f),v+=256,m=this.perlin[v&4095],m+=u*(this.perlin[v+1&4095]-m),y=this.perlin[v+16&4095],y+=u*(this.perlin[v+16+1&4095]-y),m+=p*(y-m),f+=lh(c)*(m-f),d+=f*h,h*=UD,o<<=1,s*=2,i<<=1,l*=2,a<<=1,c*=2,s>=1&&(o++,s--),l>=1&&(i++,l--),c>=1&&(a++,c--)}return d}noiseSeed(r){let e=(()=>{let a,s;return{setSeed(l){s=a=(l??Math.random()*4294967296)>>>0},getSeed(){return a},rand(){return s=(1664525*s+1013904223)%4294967296,s/4294967296}}})();e.setSeed(r),this.perlin=new Array(4095+1);for(let t=0;t<4095+1;t++)this.perlin[t]=e.rand()}},Sv=ch;import{Vector3 as HD,Matrix4 as WD,Ray as qD}from"three";var wv=new HD,Pv=new WD,Cv=new qD;function Ov(n){let r=!1;return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&(t.geometry.type==="TextGeometry"||t.geometry.type==="InputGeometry")&&(r=!0)}),r}var An=class extends lt{constructor(e,t,o){super(e,t,o);this.data=t}get textGeometry(){return this.geometry}get charWidths(){return this.textGeometry.charWidths}get charCoords(){return this.textGeometry.charCoords}get wrappedText(){return this.textGeometry.wrappedText}get font(){return this.textGeometry.font}get initialOffsetY(){let e=this.dataPatched;return this.font?.getLineInitialOffsetY(this.lineHeight,this.wrappedText.length,e.geometry.height,this.fontScale,e.geometry.verticalAlign)??0}get fontScale(){let e=this.dataPatched;return this.font?e.geometry.fontSize/this.font.unitsPerEm:1}get AD(){return Math.abs(this.ascender-this.descender)}get ascender(){return(this.font?.ascender??1)*this.fontScale}get descender(){return(this.font?.descender??1)*this.fontScale}get lineHeight(){let e=this.dataPatched;return e.geometry.fontSize*e.geometry.lineHeight}raycast(e,t){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(Pv.copy(o).invert(),Cv.copy(e.ray).applyMatrix4(Pv),Cv.intersectBox(this.singleBBox,wv))){let i=wv.applyMatrix4(o),a=e.ray.origin.distanceTo(i);t.push({distance:a,point:i.clone(),object:this})}}};var Kt=1e-4,mo,Mv,Ev,Nv,Tv=new pr,Iv=new pr;Mu.then(n=>{mo=n,Mv=[mo.get_face_center,mo.get_edge_midpoint,mo.get_vertex_position],Ev=[mo.get_face_normal,mo.get_edge_normal,mo.get_vertex_normal],Nv=[mo.face_count,mo.edge_count,mo.vertex_count]});var YD=new fi,XD=new fi,Tn=new pr,ed=new pr,vl=new pr,dh=new pr,KD=new pr,QD=new pr;var Ho=new Sv,is=class extends ua($D){constructor(e,t){super();this.parameters=t;this.objectForSample=void 0;this._pendingMediaLoad=!1;this.object=e}resetOnMove(){this.removeFromParent(),this.parent=null}expandClones(e){if(this.parent===null)this.updateState(this.parameters,e);else for(let t of this.children)t instanceof _o&&t.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(t=>{t instanceof _o&&t.object===e&&(t.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(){switch(this._updateCount(),this.parameters.type){case"radial":this._updateRadial(this.parameters);break;case"linear":this._updateLinear(this.parameters);break;case"grid":this._updateGrid(this.parameters);break;case"toObject":this._updateToObject(this.parameters)}for(let e of this.children)e.updateMatrix(),e.hasNonUniformScale&&(e.updateMatrixWorld(),e.updateMatrixWorldSVD())}_updateCount(e){let t;if(e!==void 0?t=e:t=this.parameters.type==="grid"?Math.round(this.parameters.grid.count[0])*Math.round(this.parameters.grid.count[1])*Math.round(this.parameters.grid.count[2]):this.parameters.count,this.parameters.type==="toObject"&&!this.parameters.toObject.object&&(t=0),this.parameters.type==="toObject"&&this.objectForSample){for(let i=0,a=this.children.length;i<a;++i)this.remove(this.children[0]);let o=this.children;if(o.length===t)return;if(o.length<t)for(let i=0,a=t-o.length;i<a;++i){let s=new _o(this.object);s.expand(),this.add(s)}else for(let i=0,a=o.length-t;i<a;++i)this.remove(o[i])}else{if(this.children.length===t)return;if(this.children.length<t)for(let o=0,i=t-this.children.length;o<i;++o){let a=new _o(this.object);a.expand(),this.add(a)}else for(let o=0,i=this.children.length-t;o<i;++o)this.remove(this.children[0])}}_updateRadial(e){let t=e.radial,o=t.start*Av.DEG2RAD,i=t.end*Av.DEG2RAD,a=o-i,s=new uh(t.rotation[0],t.rotation[1],t.rotation[2]),l;switch(t.axis){case"z":l=new pr(0,0,1);break;case"y":l=new pr(0,1,0);break;default:case"x":l=new pr(1,0,0);break}let c=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,u=c.noiseType==="perlin";Ho.noiseSeed(c.seed);let p=ru((0,ns.default)(c.seed)),d=bl(c.strength,this.parameters.randomness);for(let[h,f]of this.children.entries()){let m=h*(c.freqScale/10)+c.movement,y=u?Ho.noise(m):p(m,m),g=h+1;f.scale.x=t.scale[0]+d(g,Ae(y,c.scale[0]))||Kt,f.scale.y=t.scale[1]+d(g,Ae(y,c.scale[1]))||Kt,f.scale.z=t.scale[2]+d(g,Ae(y,c.scale[2]))||Kt,f.position.setScalar(0);let v=a/e.count*h-o;switch(t.axis){case"x":f.rotation.set(0,v,0);break;case"y":f.rotation.set(0,0,v);break;case"z":f.rotation.set(v,0,0);break}f.translateOnAxis(l,t.radius),f.position.x+=t.position[0]+d(g,Ae(y,c.position[0])),f.position.y+=t.position[1]+d(g,Ae(y,c.position[1])),f.position.z+=t.position[2]+d(g,Ae(y,c.position[2]));let w=d(g,Ae(y,c.rotation[0])),O=d(g,Ae(y,c.rotation[1])),S=d(g,Ae(y,c.rotation[2]));t.alignment===!0?(f.rotation.x+=s.x+w,f.rotation.y+=s.y+O,f.rotation.z+=s.z+S):f.rotation.set(s.x+w,s.y+O,s.z+S)}}_updateLinear(e){if(e.type!=="linear")throw new Error;let t=e.linear,o=new uh(t.rotation[0],t.rotation[1],t.rotation[2]),i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=i.noiseType==="perlin";Ho.noiseSeed(i.seed);let s=ru((0,ns.default)(i.seed)),l=bl(i.strength,this.parameters.randomness);for(let[c,u]of this.children.entries()){let p=c*(i.freqScale/10)+i.movement,d=a?Ho.noise(p):s(p,p),h=c+1,f=l(h,Ae(d,i.rotation[0])),m=l(h,Ae(d,i.rotation[1])),y=l(h,Ae(d,i.rotation[2]));u.scale.x=1+(t.scale[0]-1)*c+l(h,Ae(d,i.scale[0]))||Kt,u.scale.y=1+(t.scale[1]-1)*c+l(h,Ae(d,i.scale[1]))||Kt,u.scale.z=1+(t.scale[2]-1)*c+l(h,Ae(d,i.scale[2]))||Kt,u.rotation.x=o.x*c+f,u.rotation.y=o.y*c+m,u.rotation.z=o.z*c+y,u.position.x=t.position[0]*c+l(h,Ae(d,i.position[0])),u.position.y=t.position[1]*c+l(h,Ae(d,i.position[1])),u.position.z=t.position[2]*c+l(h,Ae(d,i.position[2]))}}_updateGrid(e){let t=0,o=e.grid,i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=bl(i.strength,this.parameters.randomness),s=i.noiseType==="perlin";Ho.noiseSeed(i.seed);let l=jx((0,ns.default)(i.seed));if(o.useCenter===!0){let c={x:o.count[0]%2===0?2:1,y:o.count[1]%2===0?2:1,z:o.count[2]%2===0?2:1},u=new pr(o.size[0]*(o.count[0]-c.x)*.5,o.size[1]*(o.count[1]-c.y)*.5,o.size[2]*(o.count[2]-c.z)*.5);for(let p=0;p<o.count[0];p++)for(let d=0;d<o.count[1];d++)for(let h=0;h<o.count[2];h++){let f=[(p+1)*(i.freqScale/10)+i.movement,(d+1)*(i.freqScale/10)+i.movement,(h+1)*(i.freqScale/10)+i.movement],m=s?Ho.noise(...f):l(...f),y=this.children[t++];y.scale.x=1+a(t,Ae(m,i.scale[0]))||Kt,y.scale.y=1+a(t,Ae(m,i.scale[1]))||Kt,y.scale.z=1+a(t,Ae(m,i.scale[2]))||Kt;let g=a(t,Ae(m,i.rotation[0])),v=a(t,Ae(m,i.rotation[1])),w=a(t,Ae(m,i.rotation[2]));y.rotation.set(g,v,w),y.position.x=o.size[0]*p-u.x+a(t,Ae(m,i.position[0])),y.position.y=o.size[1]*d-u.y+a(t,Ae(m,i.position[1])),y.position.z=o.size[2]*h-u.z+a(t,Ae(m,i.position[2]))}}else for(let c=0;c<o.count[0];c++)for(let u=0;u<o.count[1];u++)for(let p=0;p<o.count[2];p++){let d=[(c+1)*(i.freqScale/10)+i.movement,(u+1)*(i.freqScale/10)+i.movement,(p+1)*(i.freqScale/10)+i.movement],h=s?Ho.noise(...d):l(...d),f=this.children[t++];f.scale.x=1+a(t,Ae(h,i.scale[0]))||Kt,f.scale.y=1+a(t,Ae(h,i.scale[1]))||Kt,f.scale.z=1+a(t,Ae(h,i.scale[2]))||Kt;let m=a(t,Ae(h,i.rotation[0])),y=a(t,Ae(h,i.rotation[1])),g=a(t,Ae(h,i.rotation[2]));f.rotation.set(m,y,g),f.position.x=o.size[0]*c+a(t,Ae(h,i.position[0])),f.position.y=-o.size[1]*u+a(t,Ae(h,i.position[1])),f.position.z=-o.size[2]*p+a(t,Ae(h,i.position[2]))}}_updateToObject(e){if(e.type!=="toObject")throw new Error;let{toObject:t}=e,o=new uh(t.rotation[0],t.rotation[1],t.rotation[2]),i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=i.noiseType==="perlin";Ho.noiseSeed(i.seed);let s=ru((0,ns.default)(i.seed)),l=bl(i.strength,this.parameters.randomness);if(!t.object){for(let[,g]of this.children.entries())g.position.set(0,0,0),g.scale.setScalar(1),g.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof An)if(!this.objectForSample.font?.isLoaded||this.objectForSample.geometry.attributes.position===void 0){this._pendingMediaLoad=!0;return}else this._pendingMediaLoad=!1;if(this.objectForSample.geometry===void 0&&this.objectForSample.isAncestorOf(this.object.uuid)){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) seem to be a child/descendant of the object it's being cloned to. Please re-parent it so that they are siblings instead.`);return}let c=this.getSubdivData(),u=[],p=g=>{let v=g.length,w=g.map(C=>C[0]).reduce((C,T)=>C+T,0),O=g.map(C=>C[1]).reduce((C,T)=>C+T,0),S=g.map(C=>C[2]).reduce((C,T)=>C+T,0);return[w/v,O/v,S/v]},d=g=>Math.round(g*1e6)/1e6;c.forEach(g=>{let v=c.filter(w=>d(g.pos[0])===d(w.pos[0])&&d(g.pos[1])===d(w.pos[1])&&d(g.pos[2])===d(w.pos[2]));v.length>1?u.push({pos:g.pos,norm:p(v.map(w=>w.norm))}):u.push(g)});let h=xv(u);if(h.length>0){let g=Math.round(h.length*t.count/100);this._updateCount(g)}else{let g=this.objectForSample.geometry.getAttribute("position");if(!g||isNaN(g.count)||g.count===0){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) cannot be cloned on the surface of "${this.objectForSample.name}" (${this.objectForSample.uuid}) because the latter does not have a valid geometry.`);return}}this.objectForSample.updateMatrixWorld();let f=new ou(this.objectForSample).build(),m=yv[t.axis],y=this.children;f.setRandomGenerator((0,ns.default)(this.object.uuid+t.seed));for(let[g,v]of y.entries()){let w=g*(i.freqScale/10)+i.movement,O=a?Ho.noise(w):s(w,w),S=g+1,C=l(S,Ae(O,i.rotation[0])),T=l(S,Ae(O,i.rotation[1])),x=l(S,Ae(O,i.rotation[2]));t.spreadType==="random"?f.sample(vl,dh):(h.length&&(vl.fromArray(h[g].pos),dh.fromArray(h[g].norm)),this.objectForSample instanceof ui&&vl.applyMatrix4(YD.copy(this.objectForSample.matrixWorld).invert())),vl.applyMatrix4(this.object.hiddenMatrix.clone().invert()),v.position.copy(vl),Tn.fromArray(m);let N=t.align==="normal"?dh:this.object.getWorldDirection(QD),E=ed.fromArray(t.position);ed.x+=l(S,Ae(O,i.position[0])),ed.y+=l(S,Ae(O,i.position[1])),ed.z+=l(S,Ae(O,i.position[2]));let M=Math.acos(N.dot(Tn)),D=KD.crossVectors(Tn,N).normalize(),_=XD.makeRotationAxis(D,M),B=N.clone().cross(this.object.up).normalize(),V=B.clone().cross(N).normalize(),k=new fi().makeBasis(B,N,V),L=new pr(Tn.y,Tn.z,Tn.x).normalize(),W=L.clone().cross(Tn).normalize(),F=new fi().makeBasis(L,Tn,W).invert(),j=new fi().multiplyMatrices(k,F);v.rotation.setFromRotationMatrix(j),E.applyMatrix4(_),v.position.add(E),v.rotation.x=v.rotation.x+o.x+C,v.rotation.y=v.rotation.y+o.y+T,v.rotation.z=v.rotation.z+o.z+x,v.scale.setScalar(1),v.scale.x=v.scale.x+t.scale[0]+l(S,Ae(O,i.scale[0]))||Kt,v.scale.y=v.scale.y+t.scale[1]+l(S,Ae(O,i.scale[1]))||Kt,v.scale.z=v.scale.z+t.scale[2]+l(S,Ae(O,i.scale[2]))||Kt,v.scale.multiply(this.object.scale),v.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType;if(e==="random")return[];if(this.objectForSample instanceof ui){let t=this.objectForSample,o=gv[e],i=Nv[o],a=Mv[o],s=Ev[o],l=[],c=i(t.subdivPointerNew);for(let u=0;u<=c-1;u++){let p=a(t.subdivPointerNew,u),d=s(t.subdivPointerNew,u);Tv.fromArray(p).applyMatrix4(t.matrixWorld),Iv.fromArray(d),l.push({pos:Tv.toArray(),norm:Iv.toArray()})}return l}else return(this.objectForSample.geometry.index?bv(this.objectForSample.geometry):vv(this.objectForSample.geometry)).map((o,i)=>e==="polygon_center"?{pos:o.midpoint,norm:o.norm}:e==="vertex"?[{pos:o.vertices[0],norm:o.norm},{pos:o.vertices[1],norm:o.norm},{pos:o.vertices[2],norm:o.norm}]:e==="edge"?[{pos:o.faceCenters[0],norm:o.norm},{pos:o.faceCenters[1],norm:o.norm},{pos:o.faceCenters[2],norm:o.norm}]:[]).flat()}updateState(e,t){if(this.parameters=Co(e),this.parameters.type!=="toObject")(this.parent===null||this.parent!==this.object)&&(this.removeFromParent(),this.object.parent?.add(this),this.matrix=this.object.matrix,this.hiddenMatrix=this.object.hiddenMatrix,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1);else if(this.parent===null||this.parent.uuid!==this.parameters.toObject.object){this.removeFromParent();let o=t.find(this.parameters.toObject.object);o instanceof Ct?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new fi,this.hiddenMatrix=new fi,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update()}get pendingMediaLoad(){return this._pendingMediaLoad}};import{Scene as yB,Vector3 as gB,Matrix4 as xB,Box3 as bB,MeshBasicMaterial as vB,Skeleton as SB}from"three";import{Camera as c3,OrthographicCamera as u3,PerspectiveCamera as d3,Vector3 as qr,Object3D as Rv,Quaternion as p3,Matrix4 as f3}from"three";import{Camera as o3,LineSegments as n3,BufferGeometry as i3,LineBasicMaterial as a3,Color as fh,Vector3 as s3,Float32BufferAttribute as _v}from"three";import{BoxGeometry as ZD}from"three";var yo=n=>{var r;return r=class extends n{},r.geometryHelper=new ZD(30,30,30),r};import{Ray as JD,Sphere as e3,Matrix4 as t3,Vector3 as Wo}from"three";var td=new JD,ph=new e3,Dv=new t3,go=(n,r,e,t,o=!1,i=n)=>{let a=r,s=i.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),ph.copy(a.boundingSphere),ph.applyMatrix4(s),e.ray.intersectsSphere(ph)===!1||(Dv.copy(s).invert(),td.copy(e.ray).applyMatrix4(Dv),a.boundingBox!==null&&td.intersectsBox(a.boundingBox)===!1))return;let l,c,u,p,d=a.index,h=a.attributes.position,f=a.drawRange,m,y;if(o===!1){let v=Math.max(0,f.start),w=Math.min(d.count,f.start+f.count);for(m=v,y=w;m<y;m+=3)if(c=d.getX(m),u=d.getX(m+1),p=d.getX(m+2),l=g(n,e,td,h,c,u,p),l){l.faceIndex=Math.floor(m/3),t.push(l);return}}else{let w=a.attributes.position,O=new Wo,S=new Wo,C=new Wo,T=new Wo,x=2,E=1/((i.scale.x+i.scale.y+i.scale.z)/3),M=E*E,D=Math.max(0,f.start),_=Math.min(w.count,f.start+f.count);for(let B=D,V=_-1;B<V;B+=x){if(O.fromBufferAttribute(w,B),S.fromBufferAttribute(w,B+1),td.distanceSqToSegment(O,S,T,C)>M)continue;T.applyMatrix4(i.matrixWorld);let L=e.ray.origin.distanceTo(T);L<e.near||L>e.far||t.push({distance:L,point:C.clone().applyMatrix4(i.matrixWorld),object:n})}}function g(v,w,O,S,C,T,x){let N=new Wo,E=new Wo,M=new Wo,D=new Wo,_=new Wo;if(N.fromBufferAttribute(S,C),E.fromBufferAttribute(S,T),M.fromBufferAttribute(S,x),O.intersectTriangle(N,E,M,!1,D)===null)return null;_.copy(D),_.applyMatrix4(v.matrixWorld);let V=w.ray.origin.distanceTo(_);return V<w.near||V>w.far?null:{faceIndex:1,distance:V,point:_.clone(),object:v}}};var rd=new s3,Cr=new o3,hh=class extends n3{constructor(e){let t=new i3,o=new a3({color:16777215,vertexColors:!0,toneMapped:!1}),i=[],a=[],s={},l=new fh(15711266),c=new fh(15711266),u=new fh(2857471);p("n1","n2",l),p("n2","n4",l),p("n4","n3",l),p("n3","n1",l),p("f1","f2",l),p("f2","f4",l),p("f4","f3",l),p("f3","f1",l),p("n1","f1",l),p("n2","f2",l),p("n3","f3",l),p("n4","f4",l),p("p","n1",c),p("p","n2",c),p("p","n3",c),p("p","n4",c),p("u1","u2",u),p("u2","u3",u),p("u3","u1",u);function p(h,f,m){d(h,m),d(f,m)}function d(h,f){i.push(0,0,0),a.push(f.r,f.g,f.b),s[h]===void 0&&(s[h]=[]),s[h].push(i.length/3-1)}t.setAttribute("position",new _v(i,3)),t.setAttribute("color",new _v(a,3));super(t,o);this.type="CameraHelper",this.camera=e,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=s,this.update()}update(){let e=this.geometry,t=this.pointMap,o=!0;Cr.projectionMatrixInverse.elements=[.5112609807824982,-0,-0,-0,-0,.41421356237309503,-0,-0,-0,-0,-0,-.099999,-0,-0,-1.0000000000000002,.100001];let i=1,a=1,s=o?.8:1e-4;Wr("n1",t,e,Cr,-i,-a,s),Wr("n2",t,e,Cr,i,-a,s),Wr("n3",t,e,Cr,-i,a,s),Wr("n4",t,e,Cr,i,a,s);let l=s;Wr("f1",t,e,Cr,-i,-a,l),Wr("f2",t,e,Cr,i,-a,l),Wr("f3",t,e,Cr,-i,a,l),Wr("f4",t,e,Cr,i,a,l);let c=l,u=.5;Wr("u1",t,e,Cr,i*.7*u,a*1.1,c),Wr("u2",t,e,Cr,-i*.7*u,a*1.1,c),Wr("u3",t,e,Cr,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function Wr(n,r,e,t,o,i,a){rd.set(o,i,a).unproject(t);let s=r[n];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],rd.x,rd.y,rd.z)}}var od=class extends yo(hh){constructor(e){super(e);this.object=e;this.object=e,this.name=`CombinedCameraHelper: ${e.uuid}`}updateMatrixWorld(e){super.updateMatrixWorld(e),this.updateTarget()}updateTarget(){let e=this.object.getTarget();this.updateWorldMatrix(!0,!1),this.worldToLocal(e)}raycast(e,t){go(this.object,this.geometry,e,t,!0)}};import{Box3Helper as Bv,BoxGeometry as l3}from"three";var nd;(r=>r.is=e=>"objectHelper"in e)(nd||(nd={}));var Or=(n,r)=>class extends fa(n){constructor(){super(...arguments);this.objectHelper=new r(this);this.gizmos={}}get geometryHelper(){return r.geometryHelper}raycast(o,i){this.objectHelper.raycast(o,i)}showGizmos(){for(let o in this.gizmos){let i=this.gizmos[o];i instanceof Bv&&(i.visible=!0)}}updateEntityBoxSize(o,i){this.objectHelper.visible&&this.geometryHelper instanceof l3?(o.setScalar(0),i.set(this.geometryHelper.parameters.width,this.geometryHelper.parameters.height,this.geometryHelper.parameters.height).multiplyScalar(.5)):super.updateEntityBoxSize(o,i)}hideGizmos(){for(let o in this.gizmos){let i=this.gizmos[o];i instanceof Bv&&(i.visible=!1)}}};var id=790,as=new qr,mh=new qr,yh=new p3,gh=new qr,Sl=new qr,xh=new qr,qo=class extends Or(c3,od){constructor(e="",t={...$n.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=dn.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,t),this.previousProjectionMatrix=new f3,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,i=this.height;this.orthoCamera=new u3(o*-.5,o*.5,i*.5,i*-.5,-5e4,1e4),this.perspCamera=new d3(45,o/i,50,1e4),this.left=this.orthoCamera.left,this.right=this.orthoCamera.right,this.top=this.orthoCamera.top,this.bottom=this.orthoCamera.bottom,this.far=this.orthoCamera.far,this.view=this.orthoCamera.view,this.aspect=this.perspCamera.aspect,this.focus=this.perspCamera.focus,this.filmGauge=this.perspCamera.filmGauge,this.filmOffset=this.perspCamera.filmOffset,this.objectHelper.update()}get isPerspectiveCamera(){return this.cameraType==="PerspectiveCamera"}get isOrthographicCamera(){return!this.isPerspectiveCamera}get cameraType(){return this._cameraType}set fov(e){this.perspCamera.fov=e}get fov(){return this.perspCamera.fov}setNear(e,t){e==="PerspectiveCamera"?this.perspCamera.near=t:this.orthoCamera.near=t}setZoom(e,t){t>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=t:this.orthoCamera.zoom=t)}set cameraType(e){e==="PerspectiveCamera"?this.toPerspective():e==="OrthographicCamera"&&this.toOrthographic()}get near(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.near:this.orthoCamera.near}set near(e){this._cameraType==="PerspectiveCamera"?this.perspCamera.near=e:this.orthoCamera.near=e}get zoom(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom:this.orthoCamera.zoom}set zoom(e){e>=0&&(this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom=e:this.orthoCamera.zoom=e)}lookAt(e,t,o){typeof e=="number"&&(e=new qr(e,t,o)),super.lookAt(e),this.getWorldPosition(as),this.targetOffset=as.distanceTo(e)}getTarget(e=new qr){return this.getWorldDirection(mh),this.getWorldPosition(as),mh.multiplyScalar(this.targetOffset),e.copy(as).add(mh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(as),as.distanceTo(e)}updateUp(){this.getWorldQuaternion(yh),gh.set(0,0,1).applyQuaternion(yh),Sl.copy(Rv.DEFAULT_UP),this.isUpVectorFlipped&&Sl.negate(),Sl.applyQuaternion(yh),xh.copy(Rv.DEFAULT_UP).projectOnPlane(gh),this.angleOffsetFromUp=xh.angleTo(Sl),this.angleOffsetFromUp*=xh.cross(Sl).dot(gh)>=0?1:-1}updateTransformState(e,t){let o=super.updateTransformState(e,t);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let t=e.getWorldPosition(new qr),i=e.getWorldDirection(new qr).multiplyScalar(this.targetOffset);return{position:t.clone().add(i),target:t}}getViewToTarget(e){let o=this.getWorldDirection(new qr).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let t=new qr,o=e.getWorldPosition(t);return this.getViewToTarget(t)}setViewplaneSize(e,t,o=!1){if(this.aspect=e/t,o){let i=e>t?this.aspect:1,a=e>t?1:this.aspect;this.left=-id*.5*i,this.right=id*.5*i,this.top=id*.5*(1/a),this.bottom=-id*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=t*.5,this.bottom=-t*.5;this.updateProjectionMatrix()}copyViewPlaneSize(e){this.aspect=e.aspect,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.updateProjectionMatrix()}toOrthographic(){this.orthoCamera.left=this.left,this.orthoCamera.right=this.right,this.orthoCamera.top=this.top,this.orthoCamera.bottom=this.bottom,this.orthoCamera.view=this.view,this.orthoCamera.far=this.far,this.orthoCamera.updateProjectionMatrix(),this.projectionMatrix=this.orthoCamera.projectionMatrix,this.projectionMatrixInverse=this.orthoCamera.projectionMatrixInverse,this._cameraType="OrthographicCamera",this.objectHelper&&this.objectHelper.update()}toPerspective(){this.perspCamera.aspect=this.aspect,this.perspCamera.fov=this.fov,this.perspCamera.view=this.view,this.perspCamera.far=this.far,this.perspCamera.updateProjectionMatrix(),this.projectionMatrix=this.perspCamera.projectionMatrix,this.projectionMatrixInverse=this.perspCamera.projectionMatrixInverse,this._cameraType="PerspectiveCamera",this.objectHelper&&this.objectHelper.update()}setFocalLength(e){this.perspCamera.setFocalLength(e),this.toPerspective()}getFocalLength(){return this.perspCamera.getFocalLength()}getEffectiveFOV(){return this.perspCamera.getEffectiveFOV()}getFilmWidth(){return this.perspCamera.getFilmWidth()}getFilmHeight(){return this.perspCamera.getFilmHeight()}setViewOffset(e,t,o,i,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,t,o,i,a,s):this.orthoCamera.setViewOffset(e,t,o,i,a,s)}clearViewOffset(){this._cameraType==="PerspectiveCamera"?(this.perspCamera.clearViewOffset(),this.toPerspective()):(this.orthoCamera.clearViewOffset(),this.toOrthographic())}copyHistory(){this.previousProjectionMatrix&&this.previousProjectionMatrix.copy(this.projectionMatrix)}updateProjectionMatrix(){this._cameraType==="PerspectiveCamera"?this.toPerspective():this._cameraType==="OrthographicCamera"&&this.toOrthographic()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,t){return super.copy(e,t),this.parent=e.parent,this.orthoCamera.copy(e.orthoCamera),this.perspCamera.copy(e.perspCamera),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.far=e.far,this.view=e.view===null?null:Object.assign({},e.view),this._cameraType=e._cameraType,this.aspect=e.aspect,this.fov=e.fov,this.focus=e.focus,this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this.targetOffset=e.targetOffset,this.updateProjectionMatrix(),this}toCameraState(e=[]){let t={type:this.cameraType,far:this.far,orthographic:{near:this.orthoCamera.near,zoom:this.orthoCamera.zoom},perspective:{near:this.perspCamera.near,fov:this.perspCamera.fov,zoom:this.perspCamera.zoom},up:this.up.toArray(),targetOffset:this.targetOffset,isUpVectorFlipped:this.isUpVectorFlipped};return ji(t,e)}updateCameraSubtype(e,t){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";t.zoom!==void 0&&this.setZoom(o,t.zoom),t.near!==void 0&&this.setNear(o,t.near),t.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=t.fov)}updateState(e,t){this.updateCameraState(e,t)}updateCameraState(e,t){this.updateState_Entity(e,t),e.far!==void 0&&(this.far=e.far),e.orthographic!==void 0&&this.updateCameraSubtype("orthographic",e.orthographic),e.perspective!==void 0&&this.updateCameraSubtype("perspective",e.perspective),e.type!==void 0&&(this.cameraType=e.type),e.up!==void 0&&this.up.fromArray(e.up),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.type===0&&this.updateCameraSubtype(e.path[0],e.props)}toState(e){return{...super.toState(e),...this.toCameraState(e),type:this.cameraType}}};import{MathUtils as Hie}from"three";import{BufferGeometry as Lv,Matrix4 as Vv,Float32BufferAttribute as h3}from"three";var ss=new Vv,m3=new Vv;var nr=class extends or{constructor(e,t,o){super(e,t);this.data=t;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new Lv;this.onAfterRender=(e,t,o,i,a,s)=>{super.onAfterRender(e,t,o,i,a,s),this.recomputeBoolean()};this.geometry.userData.parameters={width:0,height:0,depth:0}}get booleanOp(){return this.data.geometry.operation}get phongAngle(){return this.data.geometry.phongAngle??45}get isLOD(){return this.recomputeBoolean(),!1}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.path[0]==="geometry"&&e.type===0&&e.props.operation!==void 0&&(this.freeBooleanPointer(),this.resetBBoxNeedsUpdate())}freeBooleanPointer(){super.freeBooleanPointer(),this.geometry.dispose()}recomputeBoolean(e,t=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let i=0;i<this.children.length;i++){let a=this.children[i];a instanceof nr&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,t)}this.meshSetAddresses=[];for(let i=0;i<this.children.length;i++){let a=this.children[i];if(a instanceof Ct&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){ss.multiplyMatrices(a.hiddenMatrix,a.matrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=vr.getMeshSet(a.geometry,e===!0,t)),a.booleanMeshSetAddress===-1)return;vr.transformMeshSet(a.booleanMeshSetAddress,ss),a.booleanMatrixInvOld.copy(ss).invert(),a.booleanWasTransformed=!1}else a instanceof nr&&a.needsTransformForDownstream===!0?(vr.transformMeshSet(a.booleanMeshSetAddress,ss),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(vr.transformMeshSet(a.booleanMeshSetAddress,m3.multiplyMatrices(ss,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(ss).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}vr.hasOpenEdges(a.booleanMeshSetAddress)===!1||i===this.children.length-1&&this.booleanOp===2?(this.meshSetAddresses.push(a.booleanMeshSetAddress),a.geometry.userData.booleanOperationDidFail=!1):a.geometry.userData.booleanOperationDidFail="openEdges"}}if(this.meshSetAddresses.length===0){this.geometry.setAttribute("position",new h3([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return vr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new Lv,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=vr.calcBoolean(this.meshSetAddresses,this.booleanOp,this.geometry,this.phongAngle)}catch(i){this.booleanMeshSetAddress=0,this.geometry.userData.booleanOperationDidFail=!0,console.error(i)}this.booleanMatrixInvOld.copy(this.matrix).invert(),this.needsTransformForDownstream=!0,ts(this),rs(this)}dispose(){super.dispose(),this.geometry.dispose()}};import{Light as y3}from"three";var zv;(r=>{function n(e){return Le.is(e)&&e instanceof y3}r.is=n})(zv||(zv={}));var ls=(n,r)=>class extends Or(n,r){updateState_Light(t,o){this.updateState_Entity(t,o),t.color!==void 0&&(this.color=o.shared.color(t.color)),t.intensity!==void 0&&(this.intensity=t.intensity),t.depth!==void 0&&(this.shadow.camera.far=t.depth,this.shadow.needsUpdate=!0),t.shadows!==void 0&&(this.castShadow=t.shadows)}};var In=n=>n instanceof Ct,wl=n=>n!==null&&n instanceof nr;var Pl=n=>nd.is(n);import{Group as w3}from"three";import{AxesHelper as g3,Group as x3,Quaternion as b3,Vector3 as bh}from"three";var v3=new bh(1,1,1),Gv=new bh,S3=new bh,Fv=new b3,Ar=class extends yo(g3){constructor(e,t=15){super(t);this.object=e;this.dummy=new x3;this.object.updateMatrixWorld(),this.name=`EmptyObjectHelper: ${e.uuid}`,this.matrix=this.dummy.matrixWorld,this.matrixAutoUpdate=!1,this.object.isBone&&(this.visible=!1)}raycast(e,t){go(this.object,Ar.geometryHelper,e,t,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(Gv,Fv,S3),this.matrix.compose(Gv,Fv,v3),super.updateMatrixWorld(e)}updateWorldMatrix(e,t){}};var Mn=class extends Or(w3,Ar){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update()}updateState(r,e){this.updateState_Entity(r,e),"buffer"in r&&Object.keys(r).length===1&&e.scene.reloadSplats()}};import{Group as P3}from"three";var ad=class extends Or(P3,Ar){constructor(e,t,o){super();this.super_Entity(e,t),this.context=o,this.objectHelper.update()}updateState(e,t){this.updateState_Entity(e,t)}};import{Color as d_,Fog as p_,HemisphereLight as f_}from"three";import{ShaderChunk as Cl}from"three";var C3=n=>`
2581
+ `,O3=new Blob([C3],{type:"application/javascript"}),A3=URL.createObjectURL(O3),tv=A3;var qu=class{constructor({sampleRate:r=44100}={}){this.scriptSrc=tv,this.sampleRate=r,this.context=null,this.stream=null,this.analyser=null,this.trackSampleOffsets={},this.interruptedTrackIds={}}async connect(){this.context=new AudioContext({sampleRate:this.sampleRate}),this.context.state==="suspended"&&await this.context.resume();try{await this.context.audioWorklet.addModule(this.scriptSrc)}catch(e){throw console.error(e),new Error(`Could not add audioWorklet module: ${this.scriptSrc}`)}let r=this.context.createAnalyser();return r.fftSize=8192,r.smoothingTimeConstant=.1,this.analyser=r,!0}getFrequencies(r="frequency",e=-100,t=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return Cn.getFrequencies(this.analyser,this.sampleRate,null,r,e,t)}_start(){let r=new AudioWorkletNode(this.context,"stream_processor");return r.connect(this.context.destination),r.port.onmessage=e=>{let{event:t}=e.data;if(t==="stop")r.disconnect(),this.stream=null;else if(t==="offset"){let{requestId:o,trackId:i,offset:a}=e.data,s=a/this.sampleRate;this.trackSampleOffsets[o]={trackId:i,offset:a,currentTime:s}}},this.analyser.disconnect(),r.connect(this.analyser),this.stream=r,!0}add16BitPCM(r,e="default"){if(typeof e!="string")throw new Error("trackId must be a string");if(this.interruptedTrackIds[e])return;this.stream||this._start();let t;if(r instanceof Int16Array)t=r;else if(r instanceof ArrayBuffer)t=new Int16Array(r);else throw new Error("argument must be Int16Array or ArrayBuffer");return this.stream.port.postMessage({event:"write",buffer:t,trackId:e}),t}async getTrackSampleOffset(r=!1){if(!this.stream)return null;let e=crypto.randomUUID();this.stream.port.postMessage({event:r?"interrupt":"offset",requestId:e});let t;for(;!t;)t=this.trackSampleOffsets[e],await new Promise(i=>setTimeout(()=>i(),1));let{trackId:o}=t;return r&&o&&(this.interruptedTrackIds[o]=!0),t}async interrupt(){return this.getTrackSampleOffset(!0)}};var rv=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/",hl=class{constructor(r,e,t){this.data=r;this.id=e;this.shared=t;this.items=[];this.isConnected=!1;this.rafId=0;this.emitter=Lo();this.voice=0;this.frequencies=new Float32Array([0]);this.onRealTimeEvent=({time:r,source:e,event:t})=>{e==="server"&&t.type==="spline.ready"?this.onSessionCreated(t):e==="server"&&t.type==="session.created"&&(this.client.createResponse(),this.client.on("realtime.event",this.onRealTimeEvent))};this.onSessionCreated=async r=>{let e=Object.values(this.client.tools).map(t=>({type:"function",...t.definition}));this.client.realtime.send("spline.tools",{tools:e}),this.client.realtime.send("spline.connect",{}),await this.wavRecorder.record(t=>this.client.isConnected()&&this.client.appendInputAudio(t.mono))};this.animate=()=>{if(this.rafId=requestAnimationFrame(this.animate),this.isConnected){let r=this.wavStreamPlayer.analyser?this.wavStreamPlayer.getFrequencies("voice"):{values:new Float32Array([0])},e=r.values.reduce((t,o)=>t+o,0)/r.values.length;this.voice=e,this.frequencies=r.values,this.emitter.emit("voice",{value:e,frequencies:r.values})}};this.client=new Ja({url:rv()+"?uuidfile="+r.integration.hash}),this.wavRecorder=new fl({sampleRate:24e3}),this.wavStreamPlayer=new qu({sampleRate:24e3})}update(r){this.data=r,this.client=new Ja({url:rv()+"?uuidfile="+r.integration.hash})}setColorByName(r,e){let t=this.shared.getColorByName(r);if(t){let{id:o}=t,{r:i,g:a,b:s}=Z0.hexStringToRgb(e)??{r:0,g:0,b:0};this.shared.updateColor(o,{r:i/255,g:a/255,b:s/255})}}connect(){if(this.isConnected)return;this.isConnected=!0,this.client.updateSession({turn_detection:{type:"server_vad"}}),this.client.addTool({name:"set_personality_color",description:"returns a color based on the voice personality of the ai assistant. This should be called by the voice assistant each time it is asks to speak differently. If a color cannot be associated to the personality, the color should be a neutral color.",parameters:{type:"object",properties:{color:{type:"string",description:"css hex color string, reflecting the personality"},personality:{type:"string",description:"the personality of the voice assistant"}},required:["color","personality"]}},({color:i})=>{this.setColorByName("Voice Assistant Color",i)});let r=this.shared.getVariablesNames().join(", ");this.client.addTool({name:"set_variable",description:"Sets a Spline variable value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the variable that needs to be set. Here's a list of available variables: ${r}. It the variable does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"The new value for this variable, should always be a string even for number and boolean variables, assume that the value will be cast to the proper type afterwards."}},required:["name","value","type"]}},({name:i,value:a})=>{let s=this.shared.getVariableByName(i);if(s){let l=this.shared.getVariable(s.id),c;typeof l=="number"?c=parseFloat(a):typeof l=="boolean"?c=a.toLowerCase()==="true":c={textValue:a},this.shared.updateVariable(s.id,c)}});let e=this.shared.getColorNames().join(", ");this.client.addTool({name:"set_color",description:"Sets a Spline color asset value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the color asset that needs to be set. Here's a list of available color assets: ${e}. It the color asset does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"css hex color string"}},required:["name","value"]}},({name:i,value:a})=>{this.setColorByName(i,a)});let t=this.shared.scene,o=[];t.traverseEntity(i=>{i.data.events.forEach(a=>{if(a.data.type==="AIAssistantTrigger"){let{description:s}=a.data;o.push(s)}})}),this.client.addTool({name:"trigger_event",description:"Trigger an event by name, here are the available events, please match what the user is asking for to one of these if it applies, otherwise don't call the function and warn the user.",parameters:{type:"object",properties:{description:{type:"string",description:`The name of the event that needs to be triggered. Here's a list of available events: ${JSON.stringify(o)}.`},direction:{type:"string",description:"default is forward, but can be forward or backward. Always set to forward unless the user ask to reverse or cancel the event, then set to backward."}},required:["description","direction"]}},({description:i,direction:a})=>{this.emitter.emit("trigger_event",{description:i,direction:a})}),this.client.on("error",i=>console.error(i)),this.client.on("conversation.interrupted",async()=>{let i=await this.wavStreamPlayer.interrupt();if(i?.trackId){let{trackId:a,offset:s}=i;await this.client.cancelResponse(a,s)}}),this.client.on("conversation.updated",async({item:i,delta:a})=>{let s=this.client.conversation.getItems();if(a?.audio&&this.wavStreamPlayer.add16BitPCM(a.audio,i.id),i.status==="completed"&&i.formatted.audio?.length){let l=await fl.decode(i.formatted.audio,24e3,24e3);i.formatted.file=l}this.items=s}),this.animate()}disconnect(){cancelAnimationFrame(this.rafId),this.voice=0,this.isConnected=!1}async start(){try{await this.wavRecorder.end()}catch{}await this.wavRecorder.begin(),this.client.on("realtime.event",this.onRealTimeEvent),await this.wavStreamPlayer.connect(),await this.client.connect()}async stop(){try{this.client.off("realtime.event",this.onRealTimeEvent)}catch(r){console.error(r)}this.client.disconnect(),await this.wavRecorder.end(),await this.wavStreamPlayer.interrupt()}computeAnalysisForListenerEvent(r){if(r.analysis==="range"){let e=this.frequencies.slice(...r.analysisRange);return e.reduce((t,o)=>t+o,0)/e.length}return r.analysis==="single"?this.frequencies[r.analysisSingle]:this.voice}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}};function nv(n){return"variable_"+n}var eh=class extends Ru{constructor(e){super();this.shared=e}create(e){return new Ka(e,this.shared)}},li=class{constructor(r,e={},t=!0,o=!1){this.data=r;this.needsJitter=t;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new ul(!0);this.geometryCache2=new ul(!1);this.imageHolderCache=new eh(this);this.thisContext={scene:Xb,shared:this};this.deletedMaterial=new ii(Et.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new dr(Yc.emptyImage,this);this.deletedVideo=new dr(Qi.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.variables={};this.userAPIs={};this.userWebhooks={};this.mouseProperty=null;this.raycastProperty=null;this.requestRender=()=>{this._requestRender&&this._requestRender()};if(e.images)for(let[i,a]of Object.entries(e.images))this.addImage(i,a);if(e.videos)for(let[i,a]of Object.entries(e.videos))this.addVideo(i,a);if(e.audios)for(let[i,a]of Object.entries(e.audios))this.addAudio(i,a);if(e.particles)for(let[i,a]of Object.entries(e.particles))this.addParticle(i,a);this.reset(r)}setRequestRender(r){this._requestRender=r}getImageLoadPromises(){return Object.values(this.images).map(r=>r.loadPromise)}setEntityOpContext(r){this.entityOpContext=r}reset(r,e=!1){this.data=r,this.resetLib(r.lib);for(let{id:t,data:o}of r.variables)this.addVariableHolder(t,o),e&&this.updateVariableHolder(t,o);for(let[t,o]of Object.entries(r.userAPIs))this.addUserAPI(t,o);for(let[t,o]of Object.entries(r.userWebhooks))this.addUserWebhook(t,o);for(let[t,o]of Object.entries(r.images))this.addImage(t,o);for(let[t,o]of Object.entries(r.videos))this.addVideo(t,o);for(let[t,o]of Object.entries(r.colors))this.addColor(t,o);for(let[t,o]of Object.entries(r.materials))this.addMaterial(t,o);for(let[t,o]of Object.entries(r.audios))this.addAudio(t,o);for(let[t,o]of Object.entries(r.particles))this.addParticle(t,o);for(let[t,o]of Object.entries(r.fonts))this.addFont(t,o)}addMaterial(r,e){if(this.materials[r]){let t=this.materials[r];t.reset(e,this.thisContext),t.dispose()}else{let t=new ii(e,this.thisContext,r);this.materials[r]=t}}deleteMaterial(r){this.materials[r]&&(this.materials[r].nodeMaterialDispose(),delete this.materials[r])}getMaterial(r){let e=this.materials[r];return e}getMaterialOrDeletedPlaceholder(r){return this.materials[r]??this.deletedMaterial}material(r){return typeof r=="string"?this.getMaterialOrDeletedPlaceholder(r):r==null?(console.error("material is undefined or null"),this.deletedMaterial):new ni(r,this.thisContext)}getMaterials(){return this.materials}addImage(r,e){return this.images[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[r].updateSrc(e.data),!0):(this.images[r]=new dr(e,this),!1)}deleteImage(r){let e=this.images[r];e&&(e.dispose(),delete this.images[r])}getDefaultImage(){return this.images.image_0}getImage(r){return this.images[r]??this.deletedImage}image(r){return typeof r=="string"?this.getImage(r):this.imageHolderCache.load(r)}addUIBuffer(r,e){return this.uiBuffers[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[r].updateSrc(e),!0):(this.uiBuffers[r]=new dr(e,this),!1)}uiBuffer(r){return this.uiBuffers[r]}addVideo(r,e){return this.videos[r]?(this.videos[r].updateSrc(e.data),!0):(this.videos[r]=new dr(e,this),!1)}deleteVideo(r){let e=this.videos[r];e&&(e.dispose(),delete this.videos[r])}getVideo(r){return this.videos[r]??this.deletedVideo}video(r){return typeof r=="string"?this.getVideo(r):this.imageHolderCache.load(r)}addColor(r,e){return this.colors[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[r].setRGBA(e.r,e.g,e.b,e.a):this.colors[r].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[r]=new Sn(e.r,e.g,e.b,e.a):this.colors[r]=new Sn(e.r,e.g,e.b,1),!1)}updateColor(r,e){if(this.colors[r]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let t=this.colors[r];return this.colors[r].r=e.r??t.r,this.colors[r].g=e.g??t.g,this.colors[r].b=e.b??t.b,this.colors[r].a=e.a??t.a,!0}return!1}deleteColor(r){this.colors[r]&&delete this.colors[r]}getColor(r){return this.colors[r]}getColorNames(){return Object.values(this.data.colors).map(r=>r.name)}getColorByName(r){for(let e in this.data.colors)if(this.data.colors[e].name===r)return{color:this.colors[e],id:e}}color(r){let e;if(typeof r=="string"){let t=this.getColor(r);t?e=t:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new At(0,0,0,0))}else return"a"in r?new At(r.r,r.g,r.b,r.a):new At(r.r,r.g,r.b,1);return e}addAudio(r,e){this.audios[r]=e}getAudio(r){let e=this.audios[r];if(e instanceof ai)return e;{let t=new ai({src:e.data});return this.audios[r]=t,t}}addParticle(r,e){this.particles[r]=e}getParticle(r){return this.particles[r]}deleteParticle(r){this.particles[r]&&delete this.particles[r]}deleteAudio(r){let e=this.audios[r];e&&(e instanceof ai&&e.dispose(),delete this.audios[r])}addFont(r,e){this.fonts[r]=new ju(e),this.fonts[r].loadingPromise.then(()=>this.requestRender())}getFont(r){return this.fonts[r]}deleteFont(r){this.fonts[r]&&delete this.fonts[r]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof ai&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(r,e){if(this.variables[r]===void 0){let t=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(nv(r));t=o!==null?JSON.parse(o):e.value}return this.variables[r]={value:t,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0),!0}return this.variables[r].value=e.value,!1}resetDynamicVariablePlayState(){for(let r in this.variables)this.variables[r].dynamicVariablePlayState!==void 0&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(r,e){this.updateVariable(r,e.value)}updateVariable(r,e){if(this.variables[r]===void 0)return!1;this.variables[r].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[r].persistent&&localStorage.setItem(nv(r),JSON.stringify(e));let t=e;for(;typeof t=="string";)t=this.variables[t].value;let o=this.entityOpContext.scene;for(let i=this.variables[r].locations.length-1;i>=0;i--){let a=this.variables[r].locations[i];if(a[0]==="material"){let s=a[1],l=t,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(d=>{let f=d.root??d;f.uuid===s&&f.onVariableUpdate(u,l,c)});let p=this.materials[s];p&&p.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[r].locations.splice(i,1);continue}if(a[1]!=="geometry"&&a[1]!=="particles"){for(let l=1;l<a.length-1;l++)s=s[a[l]];a[1]==="rotation"?s[a[a.length-1]]=t*ov.DEG2RAD:s[a[a.length-1]]=t}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(t,a),Le.is(s))if(a[1]==="position"||a[1]==="rotation"||a[1]==="scale")s.onVariableUpdate();else if(a[1]==="geometry"){let l=s;s.component&&(l=s.component);let c=l.dataPatched;l.chooseGeoemtryCache(this).forceDelete(c.geometry),l.createGeometryDelayed(this.entityOpContext),l.onVariableUpdate(!0),l.invalidateDownstreamBooleanData(),l.instances.forEach(u=>{let p=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(p.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],t)}}return this.requestRender(),!0}deleteVariable(r){this.variables[r]&&delete this.variables[r]}getVariable(r,e){if(Array.isArray(r)){if(r[0]==="mouse")return this.mouseProperty?.[r[1]]??0;if(r[0]==="raycast")return this.raycastProperty?.[r[1]]??0;let t=this.entityOpContext.scene.find(r[0]);if(r[1]==="width"||r[1]==="height"||r[1]==="depth")return t.geometry.userData.parameters[r[1]];for(let o=1;o<r.length;o++)t=t[r[o]];return r[1]==="rotation"&&(t*=ov.RAD2DEG),t}for(let t in this.variables){if(e===void 0)break;let o=this.variables[t],i=o.locations?.findIndex(a=>Ze.equal(a,e));i!==void 0&&i!==-1&&o.locations.splice(i,1)}if(typeof r=="string"){let t=r,o=r;do{if(o=t,this.variables[t]===void 0)break;let i=this.variables[t].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),t=i}while(typeof t=="string");return t}else return r}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(r=>r.data.name)}getVariableByName(r){for(let e of this.data.variables)if(e.data.name===r)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(r){return this.variables[r]?.dynamicVariablePlayState}setDynamicVariablePlayState(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(r){return this.variables[r]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariableToggleIsForward=e)}resetLib(r){for(let[e,t]of Object.entries(r.images))this.addImage(e,t.asset);for(let[e,t]of Object.entries(r.audios))this.addAudio(e,t.asset);for(let[e,t]of Object.entries(r.particles))this.addParticle(e,t.asset);for(let[e,t]of Object.entries(r.colors))this.addColor(e,t.asset);for(let[e,t]of Object.entries(r.fonts))this.addFont(e,t.asset);for(let[e,t]of Object.entries(r.materials))this.addMaterial(e,t.asset);for(let[e,t]of Object.entries(r.videos))this.addVideo(e,t.asset);for(let[e,t]of Object.entries(r.variables))this.addVariableHolder(e,t.asset)}updateLibByOp(r,e){r.path[0]==="images"?r.path.length===1&&r.type===1?this.addImage(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteImage(r.id):r.path[0]==="videos"?r.path.length===1&&r.type===1?this.addVideo(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVideo(r.id):r.path[0]==="audios"?r.path.length===1&&r.type===1?this.addAudio(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteAudio(r.id):r.path[0]==="particles"?r.path.length===1&&r.type===1?this.addParticle(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteParticle(r.id):r.path[0]==="colors"?r.path.length===1&&r.type===1?this.addColor(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteColor(r.id):r.path[0]==="materials"?r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteMaterial(r.id):r.path[0]==="fonts"?r.path.length===1&&r.type===1?this.addFont(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteFont(r.id):r.path[0]==="variables"?r.path.length===1&&r.type===1?this.addVariableHolder(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVariable(r.id):r.path[0]==="components"&&e.updateByLibOp(r,this)}updateByOp(r,e,t){if(this.data=e,r.path[0]==="images")r.path.length===2&&r.type===0?r.props.data&&this.getImage(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addImage(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteImage(r.id);else if(r.path[0]==="videos")r.path.length===2&&r.type===0?r.props.data&&this.getVideo(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addVideo(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteVideo(r.id);else if(r.path[0]==="audios")r.path.length===2&&r.type===0?r.props.data&&this.addAudio(r.path[1],e.audios[r.path[1]]):r.path.length===1&&r.type===1?this.addAudio(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteAudio(r.id);else if(r.path[0]==="particles")r.path.length===2&&r.type===0?r.props.data&&this.addParticle(r.path[1],e.particles[r.path[1]]):r.path.length===1&&r.type===1?this.addParticle(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteParticle(r.id);else if(r.path[0]==="colors")r.path.length===2&&r.type===0?this.updateColor(r.path[1],r.props):r.path.length===1&&r.type===1?this.addColor(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteColor(r.id);else if(r.path[0]==="materials")r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data):r.path.length===1&&r.type===2?this.deleteMaterial(r.id):r.path.length>1&&this.getMaterial(r.path[1]).updateByOp(nt.drop(r,2),e.materials[r.path[1]],{shared:this,scene:t});else if(r.path[0]==="fonts")r.path.length===2&&r.type===0?this.updateFont(r.path[1],r,t):r.path.length===1&&r.type===1?this.addFont(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteFont(r.id);else if(r.path[0]==="variables")r.path.length===2&&r.type===0?"value"in r.props?this.updateVariable(r.path[1],r.props.value):"persistent"in r.props&&(this.variables[r.path[1]].persistent=r.props.persistent):r.path.length===1&&r.type===4?this.addVariableHolder(r.id,r.data):r.path.length===1&&r.type===5&&this.deleteVariable(r.id);else if(r.path[0]==="userAPIs"){if(r.path.length===1&&r.type===1)this.addUserAPI(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserAPI(r.id);else if(typeof r.path[1]=="string"){let o=e.userAPIs[r.path[1]];if(o){let i=r.type===0&&r.props.debounce===void 0,a=this.getUserAPI(r.path[1]);a instanceof hl?a.update(o):a?.update(o,this,i)}}}else if(r.path[0]==="userWebhooks"){if(r.path.length===1&&r.type===1)this.addUserWebhook(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserWebhook(r.id);else if(typeof r.path[1]=="string"){let o=e.userWebhooks[r.path[1]];o&&this.getUserWebhook(r.path[1])?.update(o)}}else r.path[0]==="lib"&&this.updateLibByOp(nt.drop(r,1),t)}updateFont(r,e,t){if(e.props.url){let o=this.getFont(r),i={...this.data.fonts[r],url:e.props.url};o.update(i),o.loadingPromise.then(()=>this.requestRender()),t.updateFont(r,this)}}addUserAPI(r,e){return this.userAPIs[r]?(this.userAPIs[r].update(e,this),!0):this.openAIRealtime?.id===r?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new hl(e,r,this),!1):(this.userAPIs[r]=new wu(r,e,this),!1)}getUserAPI(r){return this.openAIRealtime?.id===r?this.openAIRealtime:this.userAPIs[r]}getUserAPIs(){return this.userAPIs}deleteUserAPI(r){let e=this.userAPIs[r];e&&(e.dispose(),delete this.userAPIs[r])}addUserWebhook(r,e){return this.userWebhooks[r]?(this.userWebhooks[r].update(e),!0):(this.userWebhooks[r]=new Uu(r,e),!1)}getUserWebhook(r){return this.userWebhooks[r]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(r){let e=this.userWebhooks[r];e&&(e.dispose(),delete this.userWebhooks[r])}get scene(){return this.entityOpContext.scene}},iv=new li(xr.emptyData());var or=class extends Ct{updateByPatchedOp(e,t,o){if(super.updateByPatchedOp(e,t,o),Ng(e.path,["materials"])!==null&&e.type===0&&Array.isArray(this.material))for(let[i,a]of Object.entries(e.props)){let s=o.shared.material(a);this.material[Number(i)]=s}else if(Re(e.path,["material"])&&this.material instanceof rr)"material"in t&&typeof t.material!="string"&&this.material.updateByOp(nt.drop(e,1),t.material,o);else if(Re(e.path,["materials","*"])&&Array.isArray(this.material)){let i=e.path[1];if("materials"in t&&i<this.material.length){let a=t.materials[i];typeof a!="string"&&this.material[i].updateByOp(nt.drop(e,2),a,o)}}}get needsAO(){return this.material!==void 0?(Array.isArray(this.material)?this.material[0]:this.material).hasAO:!1}updateState(e,t){super.updateState(e,t),e.castShadow!==void 0&&(this.castShadow=e.castShadow),e.receiveShadow!==void 0&&(this.receiveShadow=e.receiveShadow);let o=this.dataPatched;if(e.geometry?.type!=="NonParametricGeometry"&&"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe),t.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(i=>t.shared.material(i).getFlavor(o.flatShading,o.side,o.wireframe)),t.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],t.scene.markNeedsUpdateRendererDirty())),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let i=0;i<this.material.length;i++)this.material[i]=this.material[i].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe)}disposeMaterial(){this.material&&Vl(this.material).forEach(e=>{e instanceof rr&&(e instanceof ii||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};import{BufferGeometry as I3,Matrix4 as th,Vector3 as uv,Vector4 as rh}from"three";var av=new uv,sv=new rh,lv=new rh,M3=new uv,cv=new th,lt=class extends or{constructor(e,t,o){super(e,t);this.data=t;this.isSkinnedMesh=!1;this.localGeometry=void 0,t.bindMode&&t.bindMatrix&&(this.bindMode=t.bindMode,this.bindMatrix=new th().fromArray(t.bindMatrix),this.bindMatrixInverse=new th)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof I3&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof li){let e=this.geometryCreateDeleyed,t=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=t.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return Es.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return Es.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),Re(e.path,["geometry"])&&this.updateByPatchedOpGeometry(nt.drop(e,1),t.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,t){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let i=e;if(this.localGeometry===void 0){let u={...this.data.geometry,...i};this.localGeometry=Vo(u,t,this.data.flatShading,this)}let a,s,l;i.scaleBaked?[a,s,l]=i.scaleBaked:{width:a,height:s,depth:l}=i;let c=this.localGeometry.userData;c.sxPrev!==void 0&&Zs(this.localGeometry.attributes,a/c.sxPrev,s/c.syPrev,l/c.szPrev),c.sxPrev=a,c.syPrev=s,c.szPrev=l}else{let i={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=Vo(i,t,this.data.flatShading,this)}}refreshAttachedClonersInteractions(){for(let e of this.attachedSurfaceCloners)e.update()}refreshAttachedCloners(e){for(let t of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(t.object)}refreshAttachedPaths(e){for(let t of this.attachedPaths)e.scene.addPendingCommand(()=>t.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,t,o){let i=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof yt&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,t)===this.geometryCreateDeleyed&&(i=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(t,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),i||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,t){this.createGeometryDelayed(t)}updateState(e,t){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,t);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:i,value:a}}of o)this.updateMorphInfluences(i,t.shared.getVariable(a,[this.uuid,"morphTargetInfluences",i]))}super.updateState(e,t)}updateMorphInfluences(e,t){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=t)}updateGeometryGroupsIfNeeded(){Array.isArray(this.material)&&this.geometry.groups.length===0&&this.geometry.addGroup(0,Math.max(this.geometry.getIndex()?.count??0,this.geometry.getAttribute("position").count),0)}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;this.is2DType?e.set(0,0,o.depth*.5):this.isNonParametric?(e.setScalar(0),this.geometry.boundingSphere&&e.copy(this.geometry.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):e.setScalar(0),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode==="attached"?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode==="detached"&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}bind(e,t){this.skeleton=e,this.isSkinnedMesh=!0,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let t=new rh,o=this.geometry.attributes.skinWeight;for(let i=0,a=o.count;i<a;i++){t.fromBufferAttribute(o,i);let s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),o.setXYZW(i,t.x,t.y,t.z,t.w)}}boneTransform(e,t){let o=this.skeleton;if(o===void 0)return;let i=this.geometry;sv.fromBufferAttribute(i.attributes.skinIndex,e),lv.fromBufferAttribute(i.attributes.skinWeight,e),av.copy(t).applyMatrix4(this.bindMatrix),t.set(0,0,0);for(let a=0;a<4;a++){let s=lv.getComponent(a);if(s!==0){let l=sv.getComponent(a);cv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),t.addScaledVector(M3.copy(av).applyMatrix4(cv),s)}}return t.applyMatrix4(this.bindMatrixInverse)}};function N3(n){if(n.geometry.attributes.extrudeNormal||!n.geometry.attributes.position||!n.geometry.attributes.normal)return;let r=new Map,e=n.geometry.attributes,t=e.position.array,o=e.normal.array,i=new Float32Array(t.length);for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=new nh(o[a],o[a+1],o[a+2]);r.has(s)?r.get(s)?.normals.push(l):r.set(s,{normals:[l],result:new nh})}r.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=r.get(s)?.result;l&&(i[a]=l.x,i[a+1]=l.y,i[a+2]=l.z)}n.geometry.setAttribute("extrudeNormal",new dv(i,3))}function D3(n){if(n.geometry.attributes.extrudeNormals||!n.geometry.attributes.position)return;let e=n.geometry.attributes.position.array,t=new Float32Array(e.length),o=new nh;for(let i=0;i<e.length;i+=3)o.set(e[i],e[i+1],e[i+2]).normalize(),t[i]=o.x,t[i+1]=o.y,t[i+2]=o.z;n.geometry.setAttribute("extrudeNormal",new dv(t,3))}function es(n){if(Array.isArray(n.material)){for(let r of n.material)if(r.getLayersOfType("outline").length===0)return}else if(!(n.material instanceof rr)||n.material.getLayersOfType("outline").length===0)return;n instanceof lt&&n.is2DAndNoDepth?D3(n):N3(n)}function ts(n){if(!n.geometry.attributes.position)return;let e=n.geometry.attributes.position.array,t=new Float32Array(e.length),o=parseInt(n.uuid.replace(/\D/g,"")),i=[oh.seededRandom(o),oh.seededRandom(o+1e4),oh.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)t[a]=i[a%3];n.geometry.setAttribute("randomColor",new E3(t,3))}var ho=new _3,ml=new R3;function fv(n){let r=!1;return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="SubdivGeometry"&&(r=!0)}),r}var ci=class extends lt{constructor(e,t,o){super(e,t,o);this.data=t;this.hiddenMatrixOld=new B3;this.smoothShading=!0;this.skipReactionUpdate=!1}chooseGeoemtryCache(e){return this.dataPatched.flatShading?e.geometryCache:e.geometryCache2}get subdivPointerNew(){return this.localGeometry!==void 0?this.subdivPointer:this.geometry.ensureSubdivPointer()}get originalGeometryNew(){return this.localGeometry!==void 0?this.originalGeometry:this.geometry.originalGeometry}get phongAngle(){return this.data.geometry.phongAngle??45}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let t=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:i,subdivPointer:a}=yt.build(e,this.subdivPointer,this.smoothShading,this.hasNonUniformScale?this.shearScale:void 0);this.subdivPointer=a,o!==void 0&&(this.originalGeometry?.dispose(),this.originalGeometry=o),i!==void 0&&(this.subdividedGeometry?.dispose(),this.subdividedGeometry=i??void 0),this.localGeometry=this.subdividedGeometry??this.originalGeometry,es(this),ts(this),this.calcBoundingBox(),t&&(this.localGeometry.uuid=t)}updateState(e,t){if(super.updateState(e,t),e.flatShading!==void 0){let o=this.material;this.material=Array.isArray(o)?o.map(i=>i.getFlavor(!1,i.side,i.wireframe)):o.getFlavor(!1,o.side,o.wireframe),this.smoothShading=!e.flatShading,this.createGeometryDelayed(t)}}updateMesh(e=!1){yt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&yt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=yt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=yt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,t){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Ct.prototype.raycast.call(this,e,t),this.localGeometry=o}activateSVDCompensation(){!this.hasNonUniformScale||(this.matrix.copy(this.matrixWorldRigid),this.hiddenMatrixOld.copy(this.hiddenMatrix),this.hiddenMatrix.copy(this.parent.matrixWorld).invert())}deactivateSVDCompensation(){!this.hasNonUniformScale||(this.updateMatrix(),this.hasNonUniformScale=void 0,this.hiddenMatrix.copy(this.hiddenMatrixOld))}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new pv,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;ho.setFromBufferAttribute(t),ho.getCenter(o),e.boundingSphere.radius=o.distanceTo(ho.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),ho.getSize(ml),this.hasNonUniformScale&&ml.divide(this.scale);let i={width:ml.x,height:ml.y,depth:ml.z};return this.geometry.userData.parameters=i,i}updateBoundingSphere(e){let t=this.originalGeometry;ho.min.set(e[0],e[2],e[4]),ho.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(ho.min.applyMatrix4(this.shearScaleInv),ho.max.applyMatrix4(this.shearScaleInv)),t.boundingSphere===null&&(t.boundingSphere=new pv);let o=t.boundingSphere.center;ho.getCenter(o),t.boundingSphere.radius=o.distanceTo(ho.max)}freeSubdivPointer(){this.subdivPointer&&(yt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),this.localGeometry&&this.createGeometryByControls(t)}};import{Triangle as L3,Vector3 as di}from"three";var hv=-1,V3=1,mv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},yv={polygon_center:0,edge:1,vertex:2},yl=(n,r)=>(e,t)=>!r||e===0||n===0?0:n*t/100,Ae=(n,r)=>{let e=Math.abs(r),t=e*-1;return(n-hv)*(e-t)/(V3-hv)+t},z3=new di,$u=new di,G3=new di,F3=new di;function rs(n,r){let e=G3.fromArray(n),t=F3.fromArray(r);$u.copy(t).sub(e);let o=$u.length();return $u.normalize().multiplyScalar(o*.5),z3.copy(e).add($u).toArray()}var Pr=new L3,Yu=new di,Xu=new di,ui=new di;function gv(n){let r=[];for(let e=0;e<=n.index.count;e++)if(Yu.fromArray(n.index.array,e*3),Pr.setFromAttributeAndIndices(n.attributes.position,Yu.x,Yu.y,Yu.z),Pr.getNormal(Xu),Pr.getMidpoint(ui),!(isNaN(ui.x)||isNaN(ui.y)||isNaN(ui.z))){let{a:t,b:o,c:i}=Pr,a=t.toArray(),s=o.toArray(),l=i.toArray(),c=t.distanceTo(o),u=o.distanceTo(i),p=i.distanceTo(t),d=rs(a,s),f=rs(s,l),h=rs(l,a),m=[c,u,p],y=Math.max(...m),b=m.filter(C=>Math.round(C)===Math.round(y)).length>1,S=[],P=Pr.getMidpoint(ui).toArray();y===c&&!b&&(S=[f,h,h],P=d),y===u&&!b&&(S=[d,h,h],P=f),y===p&&!b&&(S=[d,f,f],P=h),b&&(S=[d,f,h]),r.push({vertices:[a,s,l],faceCenters:S,midpoint:P,norm:Pr.getNormal(Xu).toArray()})}return r}function xv(n){let r=[],{position:e}=n.attributes;for(let t=0;t<e.count;t++){Pr.setFromAttributeAndIndices(e,t*3,t*3+1,t*3+2),Pr.getNormal(Xu),Pr.getMidpoint(ui);let o=Pr.a.toArray(),i=Pr.b.toArray(),a=Pr.c.toArray();r.push({vertices:[o,i,a],faceCenters:[rs(o,i),rs(i,a),rs(a,o)],midpoint:ui.toArray(),norm:Xu.toArray()})}return r}var j3=4,k3=.5,ih=n=>.5*(1-Math.cos(n*Math.PI)),ah=class{constructor(){this.perlin=new Array(4095+1)}noise(r,e=0,t=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let b=0;b<4095+1;b++)this.perlin[b]=Math.random()}r<0&&(r=-r),e<0&&(e=-e),t<0&&(t=-t);let o=Math.floor(r),i=Math.floor(e),a=Math.floor(t),s=r-o,l=e-i,c=t-a,u,p,d=0,f=.5,h,m,y;for(let b=0;b<j3;b++){let S=o+(i<<4)+(a<<8);u=ih(s),p=ih(l),h=this.perlin[S&4095],h+=u*(this.perlin[S+1&4095]-h),m=this.perlin[S+16&4095],m+=u*(this.perlin[S+16+1&4095]-m),h+=p*(m-h),S+=256,m=this.perlin[S&4095],m+=u*(this.perlin[S+1&4095]-m),y=this.perlin[S+16&4095],y+=u*(this.perlin[S+16+1&4095]-y),m+=p*(y-m),h+=ih(c)*(m-h),d+=h*f,f*=k3,o<<=1,s*=2,i<<=1,l*=2,a<<=1,c*=2,s>=1&&(o++,s--),l>=1&&(i++,l--),c>=1&&(a++,c--)}return d}noiseSeed(r){let e=(()=>{let a,s;return{setSeed(l){s=a=(l??Math.random()*4294967296)>>>0},getSeed(){return a},rand(){return s=(1664525*s+1013904223)%4294967296,s/4294967296}}})();e.setSeed(r),this.perlin=new Array(4095+1);for(let t=0;t<4095+1;t++)this.perlin[t]=e.rand()}},bv=ah;import{Vector3 as U3,Matrix4 as H3,Ray as W3}from"three";var vv=new U3,Sv=new H3,wv=new W3;function Pv(n){let r=!1;return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&(t.geometry.type==="TextGeometry"||t.geometry.type==="InputGeometry")&&(r=!0)}),r}var On=class extends lt{constructor(e,t,o){super(e,t,o);this.data=t}get textGeometry(){return this.geometry}get charWidths(){return this.textGeometry.charWidths}get charCoords(){return this.textGeometry.charCoords}get wrappedText(){return this.textGeometry.wrappedText}get font(){return this.textGeometry.font}get initialOffsetY(){let e=this.dataPatched;return this.font?.getLineInitialOffsetY(this.lineHeight,this.wrappedText.length,e.geometry.height,this.fontScale,e.geometry.verticalAlign)??0}get fontScale(){let e=this.dataPatched;return this.font?e.geometry.fontSize/this.font.unitsPerEm:1}get AD(){return Math.abs(this.ascender-this.descender)}get ascender(){return(this.font?.ascender??1)*this.fontScale}get descender(){return(this.font?.descender??1)*this.fontScale}get lineHeight(){let e=this.dataPatched;return e.geometry.fontSize*e.geometry.lineHeight}raycast(e,t){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(Sv.copy(o).invert(),wv.copy(e.ray).applyMatrix4(Sv),wv.intersectBox(this.singleBBox,vv))){let i=vv.applyMatrix4(o),a=e.ray.origin.distanceTo(i);t.push({distance:a,point:i.clone(),object:this})}}};var Kt=1e-4,mo,Tv,Iv,Mv,Ov=new pr,Av=new pr;Ou.then(n=>{mo=n,Tv=[mo.get_face_center,mo.get_edge_midpoint,mo.get_vertex_position],Iv=[mo.get_face_normal,mo.get_edge_normal,mo.get_vertex_normal],Mv=[mo.face_count,mo.edge_count,mo.vertex_count]});var $3=new pi,Y3=new pi,An=new pr,Ku=new pr,gl=new pr,lh=new pr,X3=new pr,K3=new pr;var ch=class{constructor(r,e){this.data=r;this.is3D=e;this.perlin=new bv;r.noiseType==="perlin"?(this.perlin.noiseSeed(r.seed),e?this.noise=(o,i,a)=>this.perlin.noise(o,i,a):this.noise=o=>this.perlin.noise(o)):e?this.noise=Fx((0,Qu.default)(r.seed)):this.noise=Gx((0,Qu.default)(r.seed))}},os=class extends ca(q3){constructor(e,t){super();this.parameters=t;this.objectForSample=void 0;this._pendingMediaLoad=!1;this.random=null;this.object=e}resetOnMove(){this.removeFromParent(),this.parent=null}expandClones(e){if(this.parent===null)this.updateState(this.parameters,e);else for(let t of this.children)t instanceof _o&&t.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(t=>{t instanceof _o&&t.object===e&&(t.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(){switch(this._updateCount(),this.parameters.type){case"radial":this._updateRadial(this.parameters);break;case"linear":this._updateLinear(this.parameters);break;case"grid":this._updateGrid(this.parameters);break;case"toObject":this._updateToObject(this.parameters)}for(let e of this.children)e.updateMatrix(),e.hasNonUniformScale&&(e.updateMatrixWorld(),e.updateMatrixWorldSVD())}_updateCount(e){let t;if(e!==void 0?t=e:t=this.parameters.type==="grid"?Math.round(this.parameters.grid.count[0])*Math.round(this.parameters.grid.count[1])*Math.round(this.parameters.grid.count[2]):this.parameters.count,this.parameters.type==="toObject"&&!this.parameters.toObject.object&&(t=0),this.parameters.type==="toObject"&&this.objectForSample){let o=this.children;if(o.length===t)return;if(o.length<t)for(let i=0,a=t-o.length;i<a;++i){let s=new _o(this.object);s.expand(),this.add(s)}else for(let i=0,a=o.length-t;i<a;++i)this.remove(o[i])}else{if(this.children.length===t)return;if(this.children.length<t)for(let o=0,i=t-this.children.length;o<i;++o){let a=new _o(this.object);a.expand(),this.add(a)}else for(let o=0,i=this.children.length-t;o<i;++o)this.remove(this.children[o])}}getRandom(e,t=!1){return(this.random===null||this.random.data.seed!==e.seed||this.random.is3D!==t)&&(this.random=new ch(e,t)),this.random}_updateRadial(e){let t=e.radial,o=t.start*Cv.DEG2RAD,i=t.end*Cv.DEG2RAD,a=o-i,s=new sh(t.rotation[0],t.rotation[1],t.rotation[2]),l;switch(t.axis){case"z":l=new pr(0,0,1);break;case"y":l=new pr(0,1,0);break;default:case"x":l=new pr(1,0,0);break}let c=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,u=this.getRandom(c),p=yl(c.strength,this.parameters.randomness);for(let[d,f]of this.children.entries()){let h=d*(c.freqScale/10)+c.movement,m=u.noise(h,h,h),y=d+1;f.scale.x=t.scale[0]+p(y,Ae(m,c.scale[0]))||Kt,f.scale.y=t.scale[1]+p(y,Ae(m,c.scale[1]))||Kt,f.scale.z=t.scale[2]+p(y,Ae(m,c.scale[2]))||Kt,f.position.setScalar(0);let b=a/e.count*d-o;switch(t.axis){case"x":f.rotation.set(0,b,0);break;case"y":f.rotation.set(0,0,b);break;case"z":f.rotation.set(b,0,0);break}f.translateOnAxis(l,t.radius),f.position.x+=t.position[0]+p(y,Ae(m,c.position[0])),f.position.y+=t.position[1]+p(y,Ae(m,c.position[1])),f.position.z+=t.position[2]+p(y,Ae(m,c.position[2]));let S=p(y,Ae(m,c.rotation[0])),P=p(y,Ae(m,c.rotation[1])),C=p(y,Ae(m,c.rotation[2]));t.alignment===!0?(f.rotation.x+=s.x+S,f.rotation.y+=s.y+P,f.rotation.z+=s.z+C):f.rotation.set(s.x+S,s.y+P,s.z+C)}}_updateLinear(e){if(e.type!=="linear")throw new Error;let t=e.linear,o=new sh(t.rotation[0],t.rotation[1],t.rotation[2]),i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=this.getRandom(i),s=yl(i.strength,this.parameters.randomness);for(let[l,c]of this.children.entries()){let u=l*(i.freqScale/10)+i.movement,p=a.noise(u,u,u),d=l+1,f=s(d,Ae(p,i.rotation[0])),h=s(d,Ae(p,i.rotation[1])),m=s(d,Ae(p,i.rotation[2]));c.scale.x=1+(t.scale[0]-1)*l+s(d,Ae(p,i.scale[0]))||Kt,c.scale.y=1+(t.scale[1]-1)*l+s(d,Ae(p,i.scale[1]))||Kt,c.scale.z=1+(t.scale[2]-1)*l+s(d,Ae(p,i.scale[2]))||Kt,c.rotation.x=o.x*l+f,c.rotation.y=o.y*l+h,c.rotation.z=o.z*l+m,c.position.x=t.position[0]*l+s(d,Ae(p,i.position[0])),c.position.y=t.position[1]*l+s(d,Ae(p,i.position[1])),c.position.z=t.position[2]*l+s(d,Ae(p,i.position[2]))}}_updateGrid(e){let t=0,o=e.grid,i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=this.getRandom(i,!0),s=yl(i.strength,this.parameters.randomness);if(o.useCenter===!0){let l={x:o.count[0]%2===0?2:1,y:o.count[1]%2===0?2:1,z:o.count[2]%2===0?2:1},c=new pr(o.size[0]*(o.count[0]-l.x)*.5,o.size[1]*(o.count[1]-l.y)*.5,o.size[2]*(o.count[2]-l.z)*.5);for(let u=0;u<o.count[0];u++)for(let p=0;p<o.count[1];p++)for(let d=0;d<o.count[2];d++){let f=a.noise((u+1)*(i.freqScale/10)+i.movement,(p+1)*(i.freqScale/10)+i.movement,(d+1)*(i.freqScale/10)+i.movement),h=this.children[t++];h.scale.x=1+s(t,Ae(f,i.scale[0]))||Kt,h.scale.y=1+s(t,Ae(f,i.scale[1]))||Kt,h.scale.z=1+s(t,Ae(f,i.scale[2]))||Kt;let m=s(t,Ae(f,i.rotation[0])),y=s(t,Ae(f,i.rotation[1])),b=s(t,Ae(f,i.rotation[2]));h.rotation.set(m,y,b),h.position.x=o.size[0]*u-c.x+s(t,Ae(f,i.position[0])),h.position.y=o.size[1]*p-c.y+s(t,Ae(f,i.position[1])),h.position.z=o.size[2]*d-c.z+s(t,Ae(f,i.position[2]))}}else for(let l=0;l<o.count[0];l++)for(let c=0;c<o.count[1];c++)for(let u=0;u<o.count[2];u++){let p=a.noise((l+1)*(i.freqScale/10)+i.movement,(c+1)*(i.freqScale/10)+i.movement,(u+1)*(i.freqScale/10)+i.movement),d=this.children[t++];d.scale.x=1+s(t,Ae(p,i.scale[0]))||Kt,d.scale.y=1+s(t,Ae(p,i.scale[1]))||Kt,d.scale.z=1+s(t,Ae(p,i.scale[2]))||Kt;let f=s(t,Ae(p,i.rotation[0])),h=s(t,Ae(p,i.rotation[1])),m=s(t,Ae(p,i.rotation[2]));d.rotation.set(f,h,m),d.position.x=o.size[0]*l+s(t,Ae(p,i.position[0])),d.position.y=-o.size[1]*c+s(t,Ae(p,i.position[1])),d.position.z=-o.size[2]*u+s(t,Ae(p,i.position[2]))}}_updateToObject(e){if(e.type!=="toObject")throw new Error;let{toObject:t}=e,o=new sh(t.rotation[0],t.rotation[1],t.rotation[2]),i=e.randomnessObject??to.defaultData([1,1,1]).randomnessObject,a=this.getRandom(i),s=yl(i.strength,this.parameters.randomness);if(!t.object){for(let[,d]of this.children.entries())d.position.set(0,0,0),d.scale.setScalar(1),d.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof On)if(!this.objectForSample.font?.isLoaded||this.objectForSample.geometry.attributes.position===void 0){this._pendingMediaLoad=!0;return}else this._pendingMediaLoad=!1;if(this.objectForSample.geometry===void 0&&this.objectForSample.isAncestorOf(this.object.uuid)){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) seem to be a child/descendant of the object it's being cloned to. Please re-parent it so that they are siblings instead.`);return}let l=this.getSubdivData();if(l.length>0){let d=Math.round(l.length*t.count/100);this._updateCount(d)}else{let d=this.objectForSample.geometry.getAttribute("position");if(!d||isNaN(d.count)||d.count===0){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) cannot be cloned on the surface of "${this.objectForSample.name}" (${this.objectForSample.uuid}) because the latter does not have a valid geometry.`);return}}this.objectForSample.updateMatrixWorld();let c=new Jc(this.objectForSample).build(),u=mv[t.axis],p=this.children;c.setRandomGenerator((0,Qu.default)(this.object.uuid+t.seed));for(let[d,f]of p.entries()){let h=d*(i.freqScale/10)+i.movement,m=a.noise(h,h,h),y=d+1,b=s(y,Ae(m,i.rotation[0])),S=s(y,Ae(m,i.rotation[1])),P=s(y,Ae(m,i.rotation[2]));t.spreadType==="random"?c.sample(gl,lh):(l.length&&(gl.fromArray(l[d].pos),lh.fromArray(l[d].norm)),this.objectForSample instanceof ci&&gl.applyMatrix4($3.copy(this.objectForSample.matrixWorld).invert())),gl.applyMatrix4(this.object.hiddenMatrix.clone().invert()),f.position.copy(gl),An.fromArray(u);let C=t.align==="normal"?lh:this.object.getWorldDirection(K3),v=Ku.fromArray(t.position);Ku.x+=s(y,Ae(m,i.position[0])),Ku.y+=s(y,Ae(m,i.position[1])),Ku.z+=s(y,Ae(m,i.position[2]));let A=Math.acos(C.dot(An)),T=X3.crossVectors(An,C).normalize(),g=Y3.makeRotationAxis(T,A),D=C.clone().cross(this.object.up).normalize(),E=D.clone().cross(C).normalize(),M=new pi().makeBasis(D,C,E),N=new pr(An.y,An.z,An.x).normalize(),_=N.clone().cross(An).normalize(),B=new pi().makeBasis(N,An,_).invert(),V=new pi().multiplyMatrices(M,B);f.rotation.setFromRotationMatrix(V),v.applyMatrix4(g),f.position.add(v),f.rotation.x=f.rotation.x+o.x+b,f.rotation.y=f.rotation.y+o.y+S,f.rotation.z=f.rotation.z+o.z+P,f.scale.setScalar(1),f.scale.x=f.scale.x+t.scale[0]+s(y,Ae(m,i.scale[0]))||Kt,f.scale.y=f.scale.y+t.scale[1]+s(y,Ae(m,i.scale[1]))||Kt,f.scale.z=f.scale.z+t.scale[2]+s(y,Ae(m,i.scale[2]))||Kt,f.scale.multiply(this.object.scale),f.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType,t=new Map,o=(a,s)=>{let l=Math.round(a[0]*1e4)+"_"+Math.round(a[1]*1e4)+"_"+Math.round(a[2]*1e4),c=t.get(l);c?(c.pos[0]+=a[0],c.pos[1]+=a[1],c.pos[2]+=a[2],c.norm[0]+=s[0],c.norm[1]+=s[1],c.norm[2]+=s[2],c.count+=1):t.set(l,{pos:[...a],norm:[...s],count:1})};if(e==="random")return[];if(this.objectForSample instanceof ci){let a=this.objectForSample,s=yv[e],l=Mv[s],c=Tv[s],u=Iv[s],p=l(a.subdivPointerNew);for(let d=0;d<=p-1;d++){let f=c(a.subdivPointerNew,d),h=u(a.subdivPointerNew,d);Ov.fromArray(f).applyMatrix4(a.matrixWorld),Av.fromArray(h),o(Ov.toArray(),Av.toArray())}}else(this.objectForSample.geometry.index?gv(this.objectForSample.geometry):xv(this.objectForSample.geometry)).forEach((s,l)=>{e==="polygon_center"&&o(s.midpoint,s.norm),e==="vertex"&&(o(s.vertices[0],s.norm),o(s.vertices[1],s.norm),o(s.vertices[2],s.norm)),e==="edge"&&(o(s.faceCenters[0],s.norm),o(s.faceCenters[1],s.norm),o(s.faceCenters[2],s.norm))});let i=Array.from(t.values());for(let a of i)a.pos[0]/=a.count,a.pos[1]/=a.count,a.pos[2]/=a.count,a.norm[0]/=a.count,a.norm[1]/=a.count,a.norm[2]/=a.count;return i}updateState(e,t){if(this.parameters=Co(e),this.parameters.type!=="toObject")(this.parent===null||this.parent!==this.object)&&(this.removeFromParent(),this.object.parent?.add(this),this.matrix=this.object.matrix,this.hiddenMatrix=this.object.hiddenMatrix,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1);else if(this.parent===null||this.parent.uuid!==this.parameters.toObject.object){this.removeFromParent();let o=t.find(this.parameters.toObject.object);o instanceof Ct?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new pi,this.hiddenMatrix=new pi,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update()}get pendingMediaLoad(){return this._pendingMediaLoad}};import{Scene as mB,Vector3 as yB,Matrix4 as gB,Box3 as xB,MeshBasicMaterial as bB,Skeleton as vB}from"three";import{Camera as lD,OrthographicCamera as cD,PerspectiveCamera as uD,Vector3 as qr,Object3D as _v,Quaternion as dD,Matrix4 as pD}from"three";import{Camera as rD,LineSegments as oD,BufferGeometry as nD,LineBasicMaterial as iD,Color as dh,Vector3 as aD,Float32BufferAttribute as Nv}from"three";import{BoxGeometry as Q3}from"three";var yo=n=>{var r;return r=class extends n{},r.geometryHelper=new Q3(30,30,30),r};import{Ray as Z3,Sphere as J3,Matrix4 as eD,Vector3 as Ho}from"three";var Zu=new Z3,uh=new J3,Ev=new eD,go=(n,r,e,t,o=!1,i=n)=>{let a=r,s=i.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),uh.copy(a.boundingSphere),uh.applyMatrix4(s),e.ray.intersectsSphere(uh)===!1||(Ev.copy(s).invert(),Zu.copy(e.ray).applyMatrix4(Ev),a.boundingBox!==null&&Zu.intersectsBox(a.boundingBox)===!1))return;let l,c,u,p,d=a.index,f=a.attributes.position,h=a.drawRange,m,y;if(o===!1){let S=Math.max(0,h.start),P=Math.min(d.count,h.start+h.count);for(m=S,y=P;m<y;m+=3)if(c=d.getX(m),u=d.getX(m+1),p=d.getX(m+2),l=b(n,e,Zu,f,c,u,p),l){l.faceIndex=Math.floor(m/3),t.push(l);return}}else{let P=a.attributes.position,C=new Ho,v=new Ho,A=new Ho,T=new Ho,g=2,E=1/((i.scale.x+i.scale.y+i.scale.z)/3),M=E*E,N=Math.max(0,h.start),_=Math.min(P.count,h.start+h.count);for(let B=N,V=_-1;B<V;B+=g){if(C.fromBufferAttribute(P,B),v.fromBufferAttribute(P,B+1),Zu.distanceSqToSegment(C,v,T,A)>M)continue;T.applyMatrix4(i.matrixWorld);let L=e.ray.origin.distanceTo(T);L<e.near||L>e.far||t.push({distance:L,point:A.clone().applyMatrix4(i.matrixWorld),object:n})}}function b(S,P,C,v,A,T,g){let D=new Ho,E=new Ho,M=new Ho,N=new Ho,_=new Ho;if(D.fromBufferAttribute(v,A),E.fromBufferAttribute(v,T),M.fromBufferAttribute(v,g),C.intersectTriangle(D,E,M,!1,N)===null)return null;_.copy(N),_.applyMatrix4(S.matrixWorld);let V=P.ray.origin.distanceTo(_);return V<P.near||V>P.far?null:{faceIndex:1,distance:V,point:_.clone(),object:S}}};var Ju=new aD,Cr=new rD,ph=class extends oD{constructor(e){let t=new nD,o=new iD({color:16777215,vertexColors:!0,toneMapped:!1}),i=[],a=[],s={},l=new dh(15711266),c=new dh(15711266),u=new dh(2857471);p("n1","n2",l),p("n2","n4",l),p("n4","n3",l),p("n3","n1",l),p("f1","f2",l),p("f2","f4",l),p("f4","f3",l),p("f3","f1",l),p("n1","f1",l),p("n2","f2",l),p("n3","f3",l),p("n4","f4",l),p("p","n1",c),p("p","n2",c),p("p","n3",c),p("p","n4",c),p("u1","u2",u),p("u2","u3",u),p("u3","u1",u);function p(f,h,m){d(f,m),d(h,m)}function d(f,h){i.push(0,0,0),a.push(h.r,h.g,h.b),s[f]===void 0&&(s[f]=[]),s[f].push(i.length/3-1)}t.setAttribute("position",new Nv(i,3)),t.setAttribute("color",new Nv(a,3));super(t,o);this.type="CameraHelper",this.camera=e,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=s,this.update()}update(){let e=this.geometry,t=this.pointMap,o=!0;Cr.projectionMatrixInverse.elements=[.5112609807824982,-0,-0,-0,-0,.41421356237309503,-0,-0,-0,-0,-0,-.099999,-0,-0,-1.0000000000000002,.100001];let i=1,a=1,s=o?.8:1e-4;Wr("n1",t,e,Cr,-i,-a,s),Wr("n2",t,e,Cr,i,-a,s),Wr("n3",t,e,Cr,-i,a,s),Wr("n4",t,e,Cr,i,a,s);let l=s;Wr("f1",t,e,Cr,-i,-a,l),Wr("f2",t,e,Cr,i,-a,l),Wr("f3",t,e,Cr,-i,a,l),Wr("f4",t,e,Cr,i,a,l);let c=l,u=.5;Wr("u1",t,e,Cr,i*.7*u,a*1.1,c),Wr("u2",t,e,Cr,-i*.7*u,a*1.1,c),Wr("u3",t,e,Cr,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function Wr(n,r,e,t,o,i,a){Ju.set(o,i,a).unproject(t);let s=r[n];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],Ju.x,Ju.y,Ju.z)}}var ed=class extends yo(ph){constructor(e){super(e);this.object=e;this.object=e,this.name=`CombinedCameraHelper: ${e.uuid}`}updateMatrixWorld(e){super.updateMatrixWorld(e),this.updateTarget()}updateTarget(){let e=this.object.getTarget();this.updateWorldMatrix(!0,!1),this.worldToLocal(e)}raycast(e,t){go(this.object,this.geometry,e,t,!0)}};import{Box3Helper as Dv,BoxGeometry as sD}from"three";var td;(r=>r.is=e=>"objectHelper"in e)(td||(td={}));var Or=(n,r)=>class extends pa(n){constructor(){super(...arguments);this.objectHelper=new r(this);this.gizmos={}}get geometryHelper(){return r.geometryHelper}raycast(o,i){this.objectHelper.raycast(o,i)}showGizmos(){for(let o in this.gizmos){let i=this.gizmos[o];i instanceof Dv&&(i.visible=!0)}}updateEntityBoxSize(o,i){this.objectHelper.visible&&this.geometryHelper instanceof sD?(o.setScalar(0),i.set(this.geometryHelper.parameters.width,this.geometryHelper.parameters.height,this.geometryHelper.parameters.height).multiplyScalar(.5)):super.updateEntityBoxSize(o,i)}hideGizmos(){for(let o in this.gizmos){let i=this.gizmos[o];i instanceof Dv&&(i.visible=!1)}}};var rd=790,ns=new qr,fh=new qr,hh=new dD,mh=new qr,xl=new qr,yh=new qr,Wo=class extends Or(lD,ed){constructor(e="",t={...qn.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=un.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,t),this.previousProjectionMatrix=new pD,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,i=this.height;this.orthoCamera=new cD(o*-.5,o*.5,i*.5,i*-.5,-5e4,1e4),this.perspCamera=new uD(45,o/i,50,1e4),this.left=this.orthoCamera.left,this.right=this.orthoCamera.right,this.top=this.orthoCamera.top,this.bottom=this.orthoCamera.bottom,this.far=this.orthoCamera.far,this.view=this.orthoCamera.view,this.aspect=this.perspCamera.aspect,this.focus=this.perspCamera.focus,this.filmGauge=this.perspCamera.filmGauge,this.filmOffset=this.perspCamera.filmOffset,this.objectHelper.update()}get isPerspectiveCamera(){return this.cameraType==="PerspectiveCamera"}get isOrthographicCamera(){return!this.isPerspectiveCamera}get cameraType(){return this._cameraType}set fov(e){this.perspCamera.fov=e}get fov(){return this.perspCamera.fov}setNear(e,t){e==="PerspectiveCamera"?this.perspCamera.near=t:this.orthoCamera.near=t}setZoom(e,t){t>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=t:this.orthoCamera.zoom=t)}set cameraType(e){e==="PerspectiveCamera"?this.toPerspective():e==="OrthographicCamera"&&this.toOrthographic()}get near(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.near:this.orthoCamera.near}set near(e){this._cameraType==="PerspectiveCamera"?this.perspCamera.near=e:this.orthoCamera.near=e}get zoom(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom:this.orthoCamera.zoom}set zoom(e){e>=0&&(this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom=e:this.orthoCamera.zoom=e)}lookAt(e,t,o){typeof e=="number"&&(e=new qr(e,t,o)),super.lookAt(e),this.getWorldPosition(ns),this.targetOffset=ns.distanceTo(e)}getTarget(e=new qr){return this.getWorldDirection(fh),this.getWorldPosition(ns),fh.multiplyScalar(this.targetOffset),e.copy(ns).add(fh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(ns),ns.distanceTo(e)}updateUp(){this.getWorldQuaternion(hh),mh.set(0,0,1).applyQuaternion(hh),xl.copy(_v.DEFAULT_UP),this.isUpVectorFlipped&&xl.negate(),xl.applyQuaternion(hh),yh.copy(_v.DEFAULT_UP).projectOnPlane(mh),this.angleOffsetFromUp=yh.angleTo(xl),this.angleOffsetFromUp*=yh.cross(xl).dot(mh)>=0?1:-1}updateTransformState(e,t){let o=super.updateTransformState(e,t);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let t=e.getWorldPosition(new qr),i=e.getWorldDirection(new qr).multiplyScalar(this.targetOffset);return{position:t.clone().add(i),target:t}}getViewToTarget(e){let o=this.getWorldDirection(new qr).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let t=new qr,o=e.getWorldPosition(t);return this.getViewToTarget(t)}setViewplaneSize(e,t,o=!1){if(this.aspect=e/t,o){let i=e>t?this.aspect:1,a=e>t?1:this.aspect;this.left=-rd*.5*i,this.right=rd*.5*i,this.top=rd*.5*(1/a),this.bottom=-rd*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=t*.5,this.bottom=-t*.5;this.updateProjectionMatrix()}copyViewPlaneSize(e){this.aspect=e.aspect,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.updateProjectionMatrix()}toOrthographic(){this.orthoCamera.left=this.left,this.orthoCamera.right=this.right,this.orthoCamera.top=this.top,this.orthoCamera.bottom=this.bottom,this.orthoCamera.view=this.view,this.orthoCamera.far=this.far,this.orthoCamera.updateProjectionMatrix(),this.projectionMatrix=this.orthoCamera.projectionMatrix,this.projectionMatrixInverse=this.orthoCamera.projectionMatrixInverse,this._cameraType="OrthographicCamera",this.objectHelper&&this.objectHelper.update()}toPerspective(){this.perspCamera.aspect=this.aspect,this.perspCamera.fov=this.fov,this.perspCamera.view=this.view,this.perspCamera.far=this.far,this.perspCamera.updateProjectionMatrix(),this.projectionMatrix=this.perspCamera.projectionMatrix,this.projectionMatrixInverse=this.perspCamera.projectionMatrixInverse,this._cameraType="PerspectiveCamera",this.objectHelper&&this.objectHelper.update()}setFocalLength(e){this.perspCamera.setFocalLength(e),this.toPerspective()}getFocalLength(){return this.perspCamera.getFocalLength()}getEffectiveFOV(){return this.perspCamera.getEffectiveFOV()}getFilmWidth(){return this.perspCamera.getFilmWidth()}getFilmHeight(){return this.perspCamera.getFilmHeight()}setViewOffset(e,t,o,i,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,t,o,i,a,s):this.orthoCamera.setViewOffset(e,t,o,i,a,s)}clearViewOffset(){this._cameraType==="PerspectiveCamera"?(this.perspCamera.clearViewOffset(),this.toPerspective()):(this.orthoCamera.clearViewOffset(),this.toOrthographic())}copyHistory(){this.previousProjectionMatrix&&this.previousProjectionMatrix.copy(this.projectionMatrix)}updateProjectionMatrix(){this._cameraType==="PerspectiveCamera"?this.toPerspective():this._cameraType==="OrthographicCamera"&&this.toOrthographic()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,t){return super.copy(e,t),this.parent=e.parent,this.orthoCamera.copy(e.orthoCamera),this.perspCamera.copy(e.perspCamera),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.far=e.far,this.view=e.view===null?null:Object.assign({},e.view),this._cameraType=e._cameraType,this.aspect=e.aspect,this.fov=e.fov,this.focus=e.focus,this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this.targetOffset=e.targetOffset,this.updateProjectionMatrix(),this}toCameraState(e=[]){let t={type:this.cameraType,far:this.far,orthographic:{near:this.orthoCamera.near,zoom:this.orthoCamera.zoom},perspective:{near:this.perspCamera.near,fov:this.perspCamera.fov,zoom:this.perspCamera.zoom},up:this.up.toArray(),targetOffset:this.targetOffset,isUpVectorFlipped:this.isUpVectorFlipped};return Fi(t,e)}updateCameraSubtype(e,t){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";t.zoom!==void 0&&this.setZoom(o,t.zoom),t.near!==void 0&&this.setNear(o,t.near),t.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=t.fov)}updateState(e,t){this.updateCameraState(e,t)}updateCameraState(e,t){this.updateState_Entity(e,t),e.far!==void 0&&(this.far=e.far),e.orthographic!==void 0&&this.updateCameraSubtype("orthographic",e.orthographic),e.perspective!==void 0&&this.updateCameraSubtype("perspective",e.perspective),e.type!==void 0&&(this.cameraType=e.type),e.up!==void 0&&this.up.fromArray(e.up),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.type===0&&this.updateCameraSubtype(e.path[0],e.props)}toState(e){return{...super.toState(e),...this.toCameraState(e),type:this.cameraType}}};import{MathUtils as Hie}from"three";import{BufferGeometry as Bv,Matrix4 as Rv,Float32BufferAttribute as fD}from"three";var is=new Rv,hD=new Rv;var nr=class extends or{constructor(e,t,o){super(e,t);this.data=t;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new Bv;this.onAfterRender=(e,t,o,i,a,s)=>{super.onAfterRender(e,t,o,i,a,s),this.recomputeBoolean()};this.geometry.userData.parameters={width:0,height:0,depth:0}}get booleanOp(){return this.data.geometry.operation}get phongAngle(){return this.data.geometry.phongAngle??45}get isLOD(){return this.recomputeBoolean(),!1}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.path[0]==="geometry"&&e.type===0&&e.props.operation!==void 0&&(this.freeBooleanPointer(),this.resetBBoxNeedsUpdate())}freeBooleanPointer(){super.freeBooleanPointer(),this.geometry.dispose()}recomputeBoolean(e,t=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let i=0;i<this.children.length;i++){let a=this.children[i];a instanceof nr&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,t)}this.meshSetAddresses=[];for(let i=0;i<this.children.length;i++){let a=this.children[i];if(a instanceof Ct&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){is.multiplyMatrices(a.hiddenMatrix,a.matrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=vr.getMeshSet(a.geometry,e===!0,t)),a.booleanMeshSetAddress===-1)return;vr.transformMeshSet(a.booleanMeshSetAddress,is),a.booleanMatrixInvOld.copy(is).invert(),a.booleanWasTransformed=!1}else a instanceof nr&&a.needsTransformForDownstream===!0?(vr.transformMeshSet(a.booleanMeshSetAddress,is),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(vr.transformMeshSet(a.booleanMeshSetAddress,hD.multiplyMatrices(is,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(is).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}vr.hasOpenEdges(a.booleanMeshSetAddress)===!1||i===this.children.length-1&&this.booleanOp===2?(this.meshSetAddresses.push(a.booleanMeshSetAddress),a.geometry.userData.booleanOperationDidFail=!1):a.geometry.userData.booleanOperationDidFail="openEdges"}}if(this.meshSetAddresses.length===0){this.geometry.setAttribute("position",new fD([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return vr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new Bv,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=vr.calcBoolean(this.meshSetAddresses,this.booleanOp,this.geometry,this.phongAngle)}catch(i){this.booleanMeshSetAddress=0,this.geometry.userData.booleanOperationDidFail=!0,console.error(i)}this.booleanMatrixInvOld.copy(this.matrix).invert(),this.needsTransformForDownstream=!0,es(this),ts(this)}dispose(){super.dispose(),this.geometry.dispose()}};import{Light as mD}from"three";var Lv;(r=>{function n(e){return Le.is(e)&&e instanceof mD}r.is=n})(Lv||(Lv={}));var as=(n,r)=>class extends Or(n,r){updateState_Light(t,o){this.updateState_Entity(t,o),t.color!==void 0&&(this.color=o.shared.color(t.color)),t.intensity!==void 0&&(this.intensity=t.intensity),t.depth!==void 0&&(this.shadow.camera.far=t.depth,this.shadow.needsUpdate=!0),t.shadows!==void 0&&(this.castShadow=t.shadows)}};var Tn=n=>n instanceof Ct,bl=n=>n!==null&&n instanceof nr;var vl=n=>td.is(n);import{Group as SD}from"three";import{AxesHelper as yD,Group as gD,Quaternion as xD,Vector3 as gh}from"three";var bD=new gh(1,1,1),Vv=new gh,vD=new gh,zv=new xD,Ar=class extends yo(yD){constructor(e,t=15){super(t);this.object=e;this.dummy=new gD;this.object.updateMatrixWorld(),this.name=`EmptyObjectHelper: ${e.uuid}`,this.matrix=this.dummy.matrixWorld,this.matrixAutoUpdate=!1,this.object.isBone&&(this.visible=!1)}raycast(e,t){go(this.object,Ar.geometryHelper,e,t,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(Vv,zv,vD),this.matrix.compose(Vv,zv,bD),super.updateMatrixWorld(e)}updateWorldMatrix(e,t){}};var In=class extends Or(SD,Ar){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update()}updateState(r,e){this.updateState_Entity(r,e),"buffer"in r&&Object.keys(r).length===1&&e.scene.reloadSplats()}};import{Group as wD}from"three";var od=class extends Or(wD,Ar){constructor(e,t,o){super();this.super_Entity(e,t),this.context=o,this.objectHelper.update()}updateState(e,t){this.updateState_Entity(e,t)}};import{Color as u_,Fog as d_,HemisphereLight as p_}from"three";import{ShaderChunk as Sl}from"three";var PD=n=>`
2549
2582
 
2550
2583
  // PCSS implementation based on:
2551
2584
  // https://www.gamedev.net/articles/programming/graphics/contact-hardening-soft-shadows-made-fast-r4906/
@@ -2919,18 +2952,18 @@ float vogelShadow(int index, sampler2D shadowMap, vec2 uv, float texelSize, floa
2919
2952
  }
2920
2953
 
2921
2954
  #endif
2922
- `,O3=Cl.lights_fragment_begin,A3=Cl.shadowmask_pars_fragment,jv=null,T3=n=>{switch(n){case"low":return 8;case"medium":return 16;case"high":return 32;default:return 16}},kv=(n="medium")=>{if(jv===n)return!1;jv=n;let r=T3(n);Cl.shadowmap_pars_fragment=C3(r);let e=O3.slice();e=e.replace("getShadow( spotShadowMap[ i ]",`getShadow( UNROLLED_LOOP_INDEX + ${3}, spotShadowMap[ i ]`),e=e.replace("getShadow( directionalShadowMap[ i ]","getShadow( UNROLLED_LOOP_INDEX, directionalShadowMap[ i ]"),Cl.lights_fragment_begin=e;let t=A3.slice();return t=t.replaceAll("getShadow(","getShadow( UNROLLED_LOOP_INDEX, "),Cl.shadowmask_pars_fragment=t,!0};import{DirectionalLight as D3,CameraHelper as Uv}from"three";import{DirectionalLightHelper as I3}from"three";var cs=class extends yo(I3){constructor(e,t=15,o=10066329){super(e,t,o);this.object=e;this.added=!1;this.name=`DirectionalLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,cs.geometryHelper,e,t)}};import{PointLightHelper as M3}from"three";var us=class extends yo(M3){constructor(e,t=15,o=6710886){super(e,t,o);this.object=e;this.name=`PointLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,us.geometryHelper,e,t)}};import{SpotLightHelper as E3,Vector3 as N3}from"three";var sd=class extends yo(E3){constructor(e,t=6710886){super(e,t);this.object=e;this.name=`SpotLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,sd.geometryHelper,e,t)}update(){if(this.object!==void 0){let e=sd._vector,t=this.object.distance?this.object.distance:1e3,o=t*Math.tan(this.object.angle);this.cone.scale.set(o,o,t),e.setFromMatrixPosition(this.object.target.matrixWorld),this.cone.lookAt(e);let i=this.color!==void 0?this.color:this.light.color;if(this.cone.material instanceof Array)for(let a=0,s=this.cone.material.length;a<s;a++)this.cone.material[a].color.set(i);else this.cone.material.color.set(i)}}},Ol=sd;Ol._vector=new N3;function _3(n,r){n.shadow.camera.right=r/2,n.shadow.camera.left=-r/2,n.shadow.camera.top=r/2,n.shadow.camera.bottom=-r/2,n.shadow.needsUpdate=!0}var ds=class extends ls(D3,cs){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=2048,this.shadow.mapSize.height=2048,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.top=1250,i.bottom=-1250,i.right=1250,i.left=-1250,i.near=-1e4,i.far=2500;let a=new Uv(this.shadow.camera);a.visible=!1,this.gizmos.shadowmap=a}update(){this.shadow.camera.updateProjectionMatrix();for(let r in this.gizmos){let e=this.gizmos[r];e instanceof Uv&&e.update()}}updateMatrixWorld(r){super.updateMatrixWorld(r),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e);let t=r.depth!==void 0&&r.depth!==this.shadow.camera.far||r.size!==void 0&&r.size/2!==this.shadow.camera.right;r.size!==void 0&&_3(this,r.size),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null)),r.penumbraSize!==void 0&&e.scene.markPenumbraSizeDirty(),t&&this.update()}};import{Scene as h_}from"three";import{SpotLight as B3,CameraHelper as Hv,MathUtils as R3,Vector3 as Yv,Quaternion as L3}from"three";var Wv=new Yv,qv=new Yv,$v=new L3,ps=class extends ls(B3,Ol){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=1024,this.shadow.mapSize.height=1024,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.fov=R3.RAD2DEG*2*this.angle,i.aspect=1,i.near=100,i.far=2500;let a=new Hv(this.shadow.camera);a.visible=!1,this.gizmos.shadowmap=a,this.update()}update(){this.shadow.camera.updateProjectionMatrix();for(let r in this.gizmos){let e=this.gizmos[r];e instanceof Hv&&e.update()}}updateMatrixWorld(r){super.updateMatrixWorld(r),qv.setFromMatrixPosition(this.matrixWorld),$v.setFromRotationMatrix(this.matrixWorld),Wv.copy(this.up).applyQuaternion($v).negate().multiplyScalar(this.distance),this.target.position.copy(qv).add(Wv),this.target.updateMatrixWorld(),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e),r.distance!==void 0&&(this.distance=r.distance),r.decay!==void 0&&(this.decay=r.decay),r.angle!==void 0&&(this.angle=r.angle),r.penumbra!==void 0&&(this.penumbra=r.penumbra),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.penumbraSize!==void 0&&e.scene.markPenumbraSizeDirty(),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null))}};function V3(n){let r=(n[0][0]+n[1][1])/2,e=(n[0][0]-n[1][1])/2,t=(n[1][0]+n[0][1])/2,o=(n[1][0]-n[0][1])/2,i=Math.sqrt(r*r+o*o),a=Math.sqrt(e*e+t*t),s=i+a,l=i-a,c=Math.atan2(t,e),u=Math.atan2(o,r),p=(u-c)/2,d=(u+c)/2,h=[[Math.cos(d),Math.sin(d)],[-Math.sin(d),Math.cos(d)]],f=[[s,0],[0,l]],m=[[Math.cos(p),Math.sin(p)],[-Math.sin(p),Math.cos(p)]];return h[0][0]*=-1,h[0][1]*=-1,m[0][0]*=-1,m[1][0]*=-1,[h,f,m]}function ld(n,r){return[[n[0][0]*r[0][0]+n[0][1]*r[1][0],n[0][0]*r[0][1]+n[0][1]*r[1][1]],[n[1][0]*r[0][0]+n[1][1]*r[1][0],n[1][0]*r[0][1]+n[1][1]*r[1][1]]]}function Xv(n){return[[n[0][0],n[1][0]],[n[0][1],n[1][1]]]}function Kv(n){let[r,e,t]=V3(n),o=ld(r,Xv(t)),i=ld(ld(t,e),Xv(t)),a=Math.atan2(o[1][0],o[0][0]),s=[i[0][0],i[1][1]],l=[i[0][1]/i[1][1],i[1][0]/i[0][0]];return{rotation:a,scale:s,shear:l}}function Qv({rotation:n,scale:r,shear:e}){let t=Math.cos(n),o=Math.sin(n),i=[[t,-o],[o,t]],a=[[r[0],e[0]*r[1]],[e[1]*r[0],r[1]]],s=ld(i,a);return[s[0][0],s[1][0],s[0][1],s[1][1]]}var Ee;(S=>{function n(){return[1,0,0,0,1,0,0,0,1]}S.identity=n;function r(C,T=S.identity()){for(let x=0,N=C.length;x<N;x++)T[x]=C[x];return T}S.copy=r;function e(C,T,x,N,E,M){return S.setAbcdef(S.identity(),C,T,x,N,E,M)}S.create=e;function t(C,T,x,N,E,M,D){return C[0]=T,C[1]=N,C[2]=M,C[3]=x,C[4]=E,C[5]=D,C}S.setAbcdef=t;function o(C,T){let[x,N,E,M,D,_]=a(C),[B,V,k,L,W,F]=a(T),j=B*x+V*E,H=B*N+V*M,q=k*x+L*E,re=k*N+L*M,ee=W*x+F*E+D,X=W*N+F*M+_;return S.create(j,H,q,re,ee,X)}S.append=o;function i(C,T){let[x,N,E,M,D,_]=a(C),[B,V,k,L,W,F]=a(T),j=x,H=N,q=E,re=M;(B!==1||V!==0||k!==0||L!==1)&&(j=x*B+N*k,H=x*V+N*L,q=E*B+M*k,re=E*V+M*L);let ee=D*B+_*k+W,X=D*V+_*L+F;return S.create(j,H,q,re,ee,X)}S.prepend=i;function a(C){return[C[0],C[3],C[1],C[4],C[2],C[5]]}S.getAbcdef=a;function s(C){let[T,x,N,E,M,D]=S.getAbcdef(C),_=T*E-x*N,B=E/_,V=-x/_,k=-N/_,L=T/_,W=(N*D-E*M)/_,F=-(T*D-x*M)/_;return S.create(B,V,k,L,W,F)}S.invert=s;function l([C,T],x){let[N,E,M,D,_,B]=S.getAbcdef(x);return[N*C+M*T+_,E*C+D*T+B]}S.apply=l;function c(C,T){let[x,N,E,M,D,_]=S.getAbcdef(T),B=1/(x*M+E*-N),[V,k]=C;return[M*B*V+-E*B*k+(_*E-D*M)*B,x*B*k+-N*B*V+(-_*x+D*N)*B]}S.applyInverse=c;function u(C,T,x=T){let[N,E,M,D,_,B]=S.getAbcdef(C);return S.setAbcdef(C,N*T,E*x,M*T,D*x,_*T,B*x),C}S.scale=u;function p(C,T){let x=Math.cos(T),N=Math.sin(T),[E,M,D,_,B,V]=S.getAbcdef(C);return S.setAbcdef(C,E*x-M*N,E*N+M*x,D*x-_*N,D*N+_*x,B*x-V*N,B*N+V*x),C}S.rotate=p;function d(C,T,x){let[N,E]=x,M=S.translate(C,-N,-E);return M=S.rotate(M,T),M=S.translate(M,N,E),M}S.rotateAround=d;function h(C,T,x){let[N,E,M,D,_,B]=S.getAbcdef(C);return S.setAbcdef(C,N,E,M,D,_+T,B+x),C}S.translate=h;function f(C,T,x){let[N,E,M,D]=S.getAbcdef(C);return S.setAbcdef(C,N,E,M,D,T,x),C}S.setTranslate=f;function m(C,T,x){let[N,E,M,D]=S.getAbcdef(C);return S.setAbcdef(C,N,E,M,D,T,x),C}S.setPosition=m;function y(C){let[T,x,N,E]=S.getAbcdef(C),M=Math.sqrt(T*T+x*x),D=Math.sqrt(N*N+E*E);return[M,D]}S.getScale=y;function g(C){let[,,,,T,x]=S.getAbcdef(C);return[T,x]}S.getPosition=g;function v(C,T){return S.decompose(C,T).rotation}S.getRotation=v;function w(C,T){let[x,N,E,M,D,_]=S.getAbcdef(C),{rotation:B,scale:V,shear:k}=Kv([[x,E],[N,M]]);return{position:[D+(T[0]*x+T[1]*E)-T[0],_+(T[0]*N+T[1]*M)-T[1]],scale:V,rotation:B,shear:k,pivot:T}}S.decompose=w;function O(C,T,x,N,E=[0,0]){let[M,D]=C,[_,B]=N,[V,k,L,W]=Qv({rotation:x,scale:T,shear:E}),F=M-(_*V+B*L)+_,j=D-(_*k+B*W)+B;return S.create(V,k,L,W,F,j)}S.compose=O})(Ee||(Ee={}));var z3=Math.PI/180,ese=180/Math.PI;function Zv(n,r,e,t,o,i){let a=n-e,s=r-t;return a*a/(o*o)+s*s/(i*i)<=1}function Jv(n){return n*z3}var $o=class{constructor(r,e,t){this.uuid=r;this.data=e;this.localMatrix=Ee.identity();this.worldMatrix=Ee.identity();this.ignoreCameraZoom=!1;this.visible=!0;this._singleBBox=new En;this._recursiveBBox=new En;this.singleBBoxNeedsUpdate=!0;this.recursiveBBoxNeedsUpdate=!0;this.stateSelection=null;this.prevState=null;this.currentState=null;this.reversibleToState=null;this.currentTransitionEvent=null;this.previousAction=null;this.name="";this.position=[0,0];this.scale=[1,1];this.rotation=0;this.shear=[0,0];this.emitter=Lo();this.dpr=t.dpr??1,this.dataPatched=e}project(r,e){let t=this.worldMatrix;return e&&(t=Ee.append(e.worldMatrix,t)),Ee.applyInverse(r,t)}intersects(r,e,t,o=!1){return this.visible&&!this.data.raycastLock&&this.intersectsInLocalSpace(...this.project([r,e],t),o)}intersectsInLocalSpace(r,e,t=!1){let{min:o,max:i}=t?this.recursiveBBox:this.singleBBox;return r>=o[0]&&r<=i[0]&&e>=o[1]&&e<=i[1]}applyTransforms(r){r.setTransform(this.worldMatrix,this.ignoreCameraZoom)}get singleBBox(){return this.singleBBoxNeedsUpdate&&(this.singleBBoxNeedsUpdate=!1,this._singleBBox.setFromObjectSize(this,!1),this._singleBBox.computeVertices(),this._singleBBox.computeEdges()),this._singleBBox}get recursiveBBox(){return this.recursiveBBoxNeedsUpdate&&(this.recursiveBBoxNeedsUpdate=!1,this._recursiveBBox.setFromObjectSize(this,!0),this._recursiveBBox.computeVertices(),this._recursiveBBox.computeEdges()),this._recursiveBBox}updateLocalMatrix(){this.localMatrix=Ee.compose(this.position,this.scale,Jv(this.rotation),Do.getPivot(this.dataPatched),this.shear)}updateWorldMatrix(r,e,t){let o=this.parent;e&&o!==null&&o!==void 0&&o.updateWorldMatrix(r,!0,!1),r&&this.updateLocalMatrix(),this.parent?this.worldMatrix=Ee.append(this.parent.worldMatrix,this.localMatrix):this.worldMatrix=Ee.copy(this.localMatrix),this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}get pivot(){return Do.getPivot(this.data)}getCenter(){return[0,0]}getHalfSize(){return[0,0]}get id(){return this.uuid}resetBBoxNeedsUpdateSelf(){this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}resetBBoxNeedsUpdate(){this.resetBBoxNeedsUpdateSelf(),this.traverseAncestors(r=>{r.resetBBoxNeedsUpdateSelf()})}updateTransformState(r){let e=!1;r.position!==void 0&&(e=!0,this.position=r.position),r.rotation!==void 0&&(e=!0,this.rotation=r.rotation),r.scale!==void 0&&(e=!0,this.scale=r.scale),r.shear!==void 0&&(e=!0,this.shear=r.shear),e&&(this.updateWorldMatrix(!0,!1,!0),this.resetBBoxNeedsUpdate())}updateByOp(r,e,t){r.type===0&&r.props.visible!==void 0&&(this.visible=r.props.visible),this.data=e,this.data=e;let o=r,i=Re(r.path,["states","*"]);if(i!==null){if(r.type===0){let[a]=i;if(this?.stateSelection===a){let s={...r.props};if(delete s.name,Object.values(r.props).some(l=>l===void 0)){let l=this.data;if(l!==void 0){let c=Ze.zoom(l,r.path.slice(2));if(c)for(let u in r.props)r.props[u]===void 0&&u in c&&(s[u]=c[u])}}o={...r,props:s,path:r.path.slice(2)}}}}else if(r.type===0){let a=this.stateSelection?this.data.states.data(this.stateSelection):void 0;if(a!==void 0){if(r.props.name!==void 0&&a.name){let{name:l,...c}=a;a=c}let s=Ze.removeOverridden(r.path,r.props,a);o={...r,props:s}}}this.updateByPatchedOpBase(o,Xn.patch(this.data,this.stateSelection?this.data.states.data(this.stateSelection):void 0),t)}changeSelectedState(r,e,t=!1){if(!(this.data.states.length===0&&!t)){for(let o of this.data.states)Xn.toOps(this.data,o.data).forEach(a=>{let s=qi.replaceProps(a,this.data);this.dataPatched=this.data,this.updateByPatchedOp(s,this.data,e)});if(r!==null){let o=this.data.states.data(r);o&&(this.dataPatched=Xn.patch(this.data,o),Xn.toOps(this.data,o).forEach(a=>{this.updateByPatchedOp(a,this.dataPatched,e)}))}t&&this.updateTransformState(this.dataPatched),this.stateSelection=r}}updateState(r,e){r.name!==void 0&&(this.name=r.name),r.visible!==void 0&&(this.visible=r.visible),this.updateTransformState(r)}updateByPatchedOpBase(r,e,t){this.dataPatched=e,this.updateByPatchedOp(r,e,t)}updateByPatchedOp(r,e,t){r.path.length===0&&r.type===0&&this.updateState(r.props,t),this.requestRender()}traverseFrameAncestors(r){this.traverseAncestors(e=>{e.data.type==="frame2d"&&r(e)})}traverseAncestors(r){let e=this.parent;for(;e;)r(e),e=e.parent}requestRender(){this.traverseFrameAncestors(r=>{r.requestRender()})}clone(r){let e=new $o(this.uuid,this.data,r);return e.parent=void 0,e}addEventListener(r,e){this.emitter.on(r,e)}removeEventListener(r,e){this.emitter.off(r,e)}dispatchEvent(r){this.emitter.emit(r.type,{...r,target:r.target??this})}traverseSortNextHelper(){let r=this.parent;if(r){let e=r.children;if(e){let t=e.indexOf(this)+1;return e[t]?e[t]:r.traverseSortNextHelper()}}}sortNext(){let r=this.children;return r&&r.length>0&&r[0]?r[0]:this.traverseSortNextHelper()}isDescendantOf(r){r instanceof $o&&(r=r.uuid);let e=this;for(;e.parent;){if(e.parent.uuid===r)return!0;e=e.parent}return!1}};var kt=class extends $o{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.context=o;this.children=[]}add(e){e.parent&&e.parent instanceof kt&&e.parent.remove(e),this.children.push(e),e.parent=this}remove(e){let t=this.children.indexOf(e);t>=0&&(this.children.splice(t,1),e.parent=void 0)}traverse(e){let t=e(this);if(t!==!0)for(let o of this.children)o instanceof kt?o.traverse(e):t=e(o)}intersectsChildrenHelper(e,t,o,i,a){for(let s of this.children)if(s.intersects(e,t,o,!1)&&(a.push(s),i)||s instanceof kt&&s.intersectsChildrenHelper(e,t,o,i,a))return!0;return!1}intersectsChildren(e,t,o,i=!1,a=[],s=!1){return this.intersectsChildrenHelper(e,t,o,i,a),a}intersectsChildrenHelperReverse(e,t,o,i,a){for(let s of this.children)if(s instanceof kt&&s.intersectsChildrenHelperReverse(e,t,o,i,a)||s.intersects(e,t,o,!1)&&(a.push(s),i))return!0;return!1}intersectsChildrenReverse(e,t,o,i=!1,a=[],s=!1){return this.intersectsChildrenHelperReverse(e,t,o,i,a),a}updateWorldMatrix(e,t,o){if(super.updateWorldMatrix(e,t,o),o&&this.children)for(let i of this.children)i.updateWorldMatrix(e,!1,!0)}find(e){let t;return this.traverse(o=>{o.uuid===e&&(t=o)}),t}innerDrawChildren(e){for(let t=this.children.length-1;t>=0;t--)this.children[t].draw(e)}resetBBoxNeedsUpdate(){super.resetBBoxNeedsUpdate(),this.traverse(e=>{e.resetBBoxNeedsUpdateSelf()})}clone(e){let t=new kt(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}},ir=class extends kt{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.updateState(t,o)}draw(e){!this.visible||(e.save(),this.applyTransforms(e),this.innerDrawChildren(e),e.restore())}clone(e){let t=new ir(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}};function G3(n,r){let[[e,t],[o,i]]=n,[[a,s],[l,c]]=r,u=(e-o)*(s-c)-(t-i)*(a-l);if(u===0)return!1;let p=((e-a)*(s-c)-(t-s)*(a-l))/u,d=-((e-o)*(t-s)-(t-i)*(e-a))/u;return p>=0&&p<=1&&d>=0&&d<=1}var tS=[[-1,1],[-1,-1],[1,-1],[1,1]],eS=(n,r,e)=>{let t=n.getCenter(),o=n.getHalfSize(),i=Ee.append(r,n.worldMatrix);o[0]===0&&o[1]===0?e.push(Ee.apply(t,i)):tS.forEach(a=>{let s=[a[0]*o[0]+t[0],a[1]*o[1]+t[1]];e.push(Ee.apply(s,i))})},En=class{constructor(){this.matrix=Ee.identity();this.min=[1/0,1/0];this.max=[-1/0,-1/0];this.vertices=[];this.edges=[]}setFromObjectSize(r,e=!1){r.updateWorldMatrix(),this.makeEmpty(),Ee.copy(r.worldMatrix,this.matrix);let t=Ee.invert(r.worldMatrix);this.expandByObjectSize(r,t,e)}expandByObjectSize(r,e,t=!1){let o=[];t===!0&&r instanceof kt?r.traverse(i=>{i.visible&&eS(i,e,o)}):eS(r,e,o),this.setFromPoints(o)}setFromSize(r,e,t){this.makeEmpty(),Ee.copy(t,this.matrix),this.expandBySize(r,e,t)}expandBySize(r,e,t){[Ee.apply([0,0],t),Ee.apply([0,e],t),Ee.apply([r,e],t),Ee.apply([r,0],t)].forEach(i=>this.expandByPoint(i))}getCenter(){let[r,e]=this.min,[t,o]=this.getHalfSize();return Ee.apply([r+t,e+o],this.matrix)}getSize(){return[this.max[0]-this.min[0],this.max[1]-this.min[1]]}getHalfSize(){return[(this.max[0]-this.min[0])*.5,(this.max[1]-this.min[1])*.5]}makeEmpty(){this.min=[1/0,1/0],this.max=[-1/0,-1/0]}setFromPoints(r){this.makeEmpty();for(let e of r)this.expandByPoint(e)}expandByPoint(r){this.min=[Math.min(this.min[0],r[0]),Math.min(this.min[1],r[1])],this.max=[Math.max(this.max[0],r[0]),Math.max(this.max[1],r[1])]}computeVertices(){let[r,e]=this.getHalfSize(),t=this.getCenter(),[o,i,a,s]=Ee.getAbcdef(this.matrix),l=Ee.create(o,i,a,s,t[0],t[1]);this.vertices=tS.map(([c,u])=>Ee.apply([c*r,u*e],l))}computeEdges(){this.edges=[];for(let r=0,e=this.vertices.length;r<e;++r)this.edges.push([this.vertices[r],this.vertices[(r+1)%e]])}project(r,e){let t=this.matrix;return e&&(t=Ee.append(e.worldMatrix,t)),Ee.applyInverse(r,t)}intersects(r,e,t){return this.intersectsInLocalSpace(...this.project([r,e],t))}intersectsInLocalSpace(r,e){let{min:t,max:o}=this;return r>=t[0]&&r<=o[0]&&e>=t[1]&&e<=o[1]}containsPoint(r){let[e,t]=r,[o,i]=this.min,[a,s]=this.max;return e>=o&&e<=a&&t>=i&&t<=s}intersectsBBox2D(r){for(let e=0,t=this.edges.length;e<t;e++){let o=this.edges[e];for(let i=0,a=r.edges.length;i<a;i++){let s=r.edges[i];if(G3(o,s))return!0}}for(let e=0,t=r.vertices.length;e<t;e++){let o=r.vertices[e];if(this.containsPoint(o))return!0}return!1}ensureMinMax(){let r=this.min,e=this.max;this.min=[Math.min(r[0],e[0]),Math.min(r[1],e[1])],this.max=[Math.max(r[0],e[0]),Math.max(r[1],e[1])]}copy(r){this.min=[...r.min],this.max=[...r.max],Ee.copy(r.matrix,this.matrix),this.computeVertices(),this.computeEdges()}clone(){let r=new En;return r.copy(this),r}};var oS,nS=new Promise(n=>{oS=n}),rS=!1;var cd;function iS(){if(rS)return;if(cd)return cd;async function n(){let e=await import("./ui.js");oS(e.default??e),rS=!0}return cd=n(),cd}function lS(n){let r=!1;return n.scene.objects.traverse((e,t)=>{(t.type==="Mesh"&&t.geometry.type==="UIGeometry"||t.type==="Page"&&t.uiFrame!==void 0)&&(r=!0)}),r}var Oe,Sh;async function F3(n){let r=await nS;Oe||(Sh||(Sh=r({locateFile:()=>n})),Oe=await Sh)}var aS=Ee.identity(),Tl=class{constructor(r,e=1){this.canvas=r;this._dpr=e;this._width=0;this._height=0;this._strokeMode="inside";this._layerBlur=0;this._backgroundBlur=0;this._dropShadowBlur=0;this._dropShadowOffsetX=0;this._dropShadowOffsetY=0;this._dropShadowColor=Me.transparent;this._innerShadowBlur=0;this._innerShadowOffsetX=0;this._innerShadowOffsetY=0;this._innerShadowSpread=0;this._innerShadowColor=Me.transparent;this._fonts=new Map;this._isSizeDirty=!1;try{let t=r.getBoundingClientRect();r.width=t.width*e,r.height=t.height*e}catch{console.log(r.width,e)}this._currentM3Transform=aS,this._currentTransform=new Float32Array(aS)}get dpr(){return this._dpr}set dpr(r){this._dpr=r,this._isSizeDirty=!0}async init(){if(!this.wasmURL)throw Error("Your must set the wasm binary url with renderer.wasmURL = ... before you can call renderer.init");await F3(this.wasmURL),this._surface=Oe.MakeWebGLCanvasSurface(this.canvas),this.ctx=this._surface?.getCanvas(),this._paint=new Oe.Paint,this._paint.setAntiAlias(!0),this._paintFill=this._paint.copy(),this._paintFill.setStyle(Oe.PaintStyle.Fill),this._paintStroke=this._paint.copy(),this._paintStroke.setStyle(Oe.PaintStyle.Stroke),this.ctx?.scale(this.dpr,this.dpr)}get currentTransform(){return this._currentM3Transform}get currentTransformBuffer(){return this._currentTransform}set currentTransform(r){this._currentM3Transform=r,this._currentTransform.set(r)}async loadFont(r,e){let t=await(await fetch(r)).arrayBuffer();this.registerFont(t,e)}registerFont(r,e){if(this._fonts.has(e))return;let t=Oe.FontMgr.FromData(r);if(t)this._fonts.set(e,t);else throw new Error("Invalid font data for "+e)}get width(){return this._width}get height(){return this._height}set strokeColor(r){this._paintStroke&&this._paintStroke.setColor(ud(r),Oe.ColorSpace.DISPLAY_P3)}set fillColor(r){this._paintFill&&this._paintFill.setColor(ud(r),Oe.ColorSpace.DISPLAY_P3)}set lineWidth(r){this._paintStroke&&this._paintStroke.setStrokeWidth(this._strokeMode==="center"?r:r*2)}set strokeMode(r){this._strokeMode=r}set dropShadowBlur(r){this._dropShadowBlur=r}set dropShadowColor(r){this._dropShadowColor=r}set dropShadowOffsetX(r){this._dropShadowOffsetX=r}set dropShadowOffsetY(r){this._dropShadowOffsetY=r}set innerShadowBlur(r){this._innerShadowBlur=r}set innerShadowColor(r){this._innerShadowColor=r}set innerShadowOffsetX(r){this._innerShadowOffsetX=r}set innerShadowOffsetY(r){this._innerShadowOffsetY=r}set innerShadowSpread(r){this._innerShadowSpread=r}set layerBlur(r){this._layerBlur=r}set backgroundBlur(r){this._backgroundBlur=r}clear(){this.ctx?.clear(Oe.TRANSPARENT)}save(){this.ctx?.save()}restore(){this.ctx?.restore()}beginPath(){this._currentPath?.delete(),this._currentPath=new Oe.Path}closePath(){let r=this._currentPath;if(r){if(r.isEmpty())return;let e=r.getBounds();(e[3]-e[1]||e[2]-e[0])&&r.close()}}fill(){this._paintInner(this._paintFill,!0)}stroke(){this._paintInner(this._paintStroke,!1)}clipRect(r,e,t,o,i=0,a=0,s=0,l=0){let c=Oe.XYWHRect(r,e,t,o);if(i===0&&a===0&&l===0&&s===0)this.ctx?.clipRect(c,Oe.ClipOp.Intersect,!0);else{let u=Oe.RRectXY(c,i,i);u[4]=u[5]=i,u[6]=u[7]=a,u[8]=u[9]=s,u[10]=u[11]=l,this.ctx?.clipRRect(u,Oe.ClipOp.Intersect,!0)}}_applyShadowOffsetMatrix(){if(this.ctx){let r=Ee.invert(this.currentTransform);this.ctx.concat(r);let e=Ee.translate(Ee.identity(),this._dropShadowOffsetX,this._dropShadowOffsetY);this.ctx.concat(e),this.ctx.concat(this._currentTransform)}}_applyEffectsToPaint(r,e,t=!0){if(this.ctx&&this._currentPath){let o,i=!1;if(t&&this._hasDropShadow()){let a=r.copy();a.setColor(ud(this._dropShadowColor));let s;this._dropShadowBlur>0&&(s=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._dropShadowBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(s)),this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Difference,!0),this._applyShadowOffsetMatrix(),e(a),this.ctx.restore(),a.delete(),s?.delete()}if(this._backgroundBlur>0&&t){this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Intersect,!0);let a=Oe.ImageFilter.MakeBlur(this._backgroundBlur,this._backgroundBlur,Oe.TileMode.Clamp,null),s=r.copy();s.setImageFilter(a),s.setAlphaf(1);let l=this._currentPath.computeTightBounds();this.ctx.saveLayer(s,l,null,Oe.SaveLayerInitWithPrevious),this.ctx.drawColor(r.getColor()),this.ctx.restore(),this.ctx.restore(),s.delete(),a.delete(),i=!0}if(this._layerBlur>0){let a=r.copy();o=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._layerBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(o),e(a),a.delete(),o.delete(),i=!0}if(i||e(r),t&&this._hasInnerShadow()){let a=new Oe.Paint;a.setAntiAlias(!0),a.setStyle(Oe.PaintStyle.Fill),a.setColor(ud(this._innerShadowColor));let s;this._innerShadowBlur>0&&(s=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._innerShadowBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(s));let l=this._currentPath.computeTightBounds(),[c,u,p,d]=l,h=p-c,f=d-u;this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Intersect,!0),this.ctx.saveLayer(a,l,null,Oe.SaveLayerInitWithPrevious),this.ctx?.translate(this._innerShadowOffsetX,this._innerShadowOffsetY),this.ctx.drawRect(Oe.XYWHRect(-1e3-this._innerShadowOffsetX,-1e3-this._innerShadowOffsetY,2e3+h+Math.abs(this._innerShadowOffsetX*2),2e3+f+Math.abs(this._innerShadowOffsetY*2)),a),a.setBlendMode(Oe.BlendMode.Clear),this.ctx.drawPath(this._currentPath,a),this.ctx.restore(),this.ctx.restore(),a.delete(),s?.delete()}}}_paintInner(r,e=!0){if(this.ctx&&this._currentPath&&r){let t=this.ctx,o=this._currentPath;this._applyEffectsToPaint(r,i=>{let a=!1;!e&&this._strokeMode!=="center"&&(t.save(),t.clipPath(o,this._strokeMode==="outside"?Oe.ClipOp.Difference:Oe.ClipOp.Intersect,!0),a=!0),t.drawPath(o,i),a&&t.restore()},e)}}_hasDropShadow(){return this._dropShadowColor?.a>0}_hasInnerShadow(){return this._innerShadowColor?.a>0}path(r){this._currentPath?.addPath(Oe.Path.MakeFromSVGString(r))}ellipse(r,e,t,o,i,a,s,l){if(!sS([r,e,t,o])||!this._currentPath)return;if(t<0||o<0)throw Error("radii cannot be negative");let c=Oe.XYWHRect(r-t,e-o,t*2,o*2);this._currentPath?.addOval(c)}rect(r,e,t,o,i=0,a=0,s=0,l=0){let c=Oe.XYWHRect(r,e,t,o);if(!!sS(c))if(i===0&&a===0&&l===0&&s===0)this._currentPath?.addRect(c);else{let u=Oe.RRectXY(c,i,i);u[4]=u[5]=i,u[6]=u[7]=a,u[8]=u[9]=s,u[10]=u[11]=l,this._currentPath?.addRRect(u)}}getHorizontalAlign(r){switch(r){case 2:return Oe.TextAlign.Right;case 3:return Oe.TextAlign.Center;case 4:return Oe.TextAlign.Justify;case 1:default:return Oe.TextAlign.Left}}drawTextInner(r,e,t,[o,i,a,s],l,c,u=!0){let p=0,{ctx:d}=this;if(!d)return p;let h=c.copy(),f=c.copy();return f.setAlphaf(0),this._applyEffectsToPaint(h,m=>{e.pushPaintStyle(t,m,f),e.addText(r);let y=e.build();y.layout(a);let g=i;l===2?g+=(s-y.getHeight())/2:l===3&&(g+=s-y.getHeight()),d.drawParagraph(y,o,g),p=y.getHeight(),e.reset(),y.delete()},u),h.delete(),f.delete(),p}drawText(r,e){let t=0,o=this._fonts.get(e.font),{ctx:i,_paintFill:a,_paintStroke:s}=this;if(o&&i){let l=new Oe.TextStyle({fontFamilies:[e.font],fontSize:e.fontSize,heightMultiplier:e.lineHeight,letterSpacing:e.letterSpacing}),c=new Oe.ParagraphStyle({textStyle:l,textAlign:this.getHorizontalAlign(e.horizontalAlign)}),u=Oe.XYWHRect(e.x,e.y,e.width,e.height),p=Oe.ParagraphBuilder.Make(c,o);a&&(t=this.drawTextInner(r,p,l,u,e.verticalAlign,a,!0)),s&&(t=this.drawTextInner(r,p,l,u,e.verticalAlign,s,!1)),p.delete()}return{height:t}}render(){this._surface?.flush()}moveTo(r,e){this._currentPath?.moveTo(r,e)}lineTo(r,e){this._currentPath?.lineTo(r,e)}bezierCurveTo(r,e,t,o,i,a){this._currentPath?.cubicTo(r,e,t,o,i,a)}quadraticCurveTo(r,e,t,o){this._currentPath?.quadTo(r,e,t,o)}setTransform(r,e=!1){if(!this.ctx)return;let t=this.ctx.getTotalMatrix(),o=Ee.invert(t);if(o&&this.ctx.concat(o),this.ctx?.scale(this.dpr,this.dpr),this.camera?.enabled&&(this.ctx?.concat(this.camera.worldMatrix),e)){let i=Ee.getScale(this.camera.worldMatrix);this.ctx?.scale(1/i[0],1/i[1])}this.ctx?.concat(r),this.currentTransform=r}transform(r){this.ctx?.concat(r)}setSize(r,e){!this._isSizeDirty&&r===this._width&&e===this._height||(this._isSizeDirty=!1,this._width=r,this._height=e,this.canvas.style.width=r+"px",this.canvas.style.height=e+"px",this.canvas.width=r*this.dpr,this.canvas.height=e*this.dpr,this._surface&&(this._surface=Oe.MakeWebGLCanvasSurface(this.canvas),this.ctx=this._surface?.getCanvas()))}};function sS(n){for(let r=0;r<n.length;r++)if(n[r]!==void 0&&!Number.isFinite(n[r]))return!1;return!0}function ud({r:n,g:r,b:e,a:t}){return Oe.Color4f(n,r,e,t)}var Il=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.blurRadius=0;this.offset=[0,0];this.spread=0;this.update(e)}update(r){r.color!==void 0&&(this.color=r.color),r.enabled!==void 0&&(this.enabled=r.enabled),r.blurRadius!==void 0&&(this.blurRadius=r.blurRadius),r.offset!==void 0&&(this.offset=r.offset),r.spread!==void 0&&(this.spread=r.spread)}};var Ml=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.radius=0;this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.radius!==void 0&&(this.radius=r.radius)}};var dd=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.color!==void 0&&(this.color=r.color)}};var pd=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.thickness=0;this.mode="inside";this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.color!==void 0&&(this.color=r.color),r.thickness!==void 0&&(this.thickness=r.thickness),r.mode!==void 0&&(this.mode=r.mode)}};var ar=class extends $o{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.autoClose=!0;this.fill=new dd(e+"-fill",t.fill,o),this.stroke=new pd(e+"-stroke",t.stroke,o),this.dropShadow=new Il(e+"-dropShadow",t.dropShadow,o),this.innerShadow=new Il(e+"-innerShadow",t.innerShadow,o),this.backgroundBlur=new Ml(e+"-backgroundBlur",t.backgroundBlur,o),this.layerBlur=new Ml(e+"-layerBlur",t.layerBlur,o)}applyFillStroke(e){e.fillColor=this.fill.enabled?this.fill.color:Me.transparent,e.strokeColor=this.stroke.enabled&&this.stroke.thickness>0?this.stroke.color:Me.transparent,e.strokeMode=this.stroke.mode,e.lineWidth=this.stroke.thickness}applyFilters(e){this.layerBlur.enabled?e.layerBlur=this.layerBlur.radius*5:e.layerBlur=0,this.backgroundBlur.enabled?e.backgroundBlur=this.backgroundBlur.radius*5:e.backgroundBlur=0,this.dropShadow.enabled?(e.dropShadowBlur=this.dropShadow.blurRadius*5,e.dropShadowColor=this.dropShadow.color,e.dropShadowOffsetX=this.dropShadow.offset[0],e.dropShadowOffsetY=this.dropShadow.offset[1]):e.dropShadowColor=Me.transparent,this.innerShadow.enabled?(e.innerShadowSpread=this.innerShadow.spread,e.innerShadowBlur=this.innerShadow.blurRadius*5,e.innerShadowColor=this.innerShadow.color,e.innerShadowOffsetX=this.innerShadow.offset[0],e.innerShadowOffsetY=this.innerShadow.offset[1]):e.innerShadowColor=Me.transparent}innerDraw(e){}draw(e){!this.visible||(e.save(),this.applyTransforms(e),this.applyFilters(e),this.applyFillStroke(e),e.beginPath(),this.innerDraw(e),this.autoClose&&e.closePath(),this.fill.enabled&&e.fill(),this.stroke.enabled&&e.stroke(),e.restore())}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.type===0&&(Re(e.path,["fill"])?this.fill.update(e.props):Re(e.path,["stroke"])?this.stroke.update(e.props):Re(e.path,["dropShadow"])?this.dropShadow.update(e.props):Re(e.path,["innerShadow"])?this.innerShadow.update(e.props):Re(e.path,["layerBlur"])?this.layerBlur.update(e.props):Re(e.path,["backgroundBlur"])?this.backgroundBlur.update(e.props):this.resetBBoxNeedsUpdate())}updateState(e,t){super.updateState(e,t),e.fill!==void 0&&this.fill.update(e.fill),e.stroke!==void 0&&this.stroke.update(e.stroke),e.dropShadow!==void 0&&this.dropShadow.update(e.dropShadow),e.innerShadow!==void 0&&this.innerShadow.update(e.innerShadow),e.layerBlur!==void 0&&this.layerBlur.update(e.layerBlur),e.backgroundBlur!==void 0&&this.backgroundBlur.update(e.backgroundBlur)}clone(e){let t=new ar(this.uuid,this.data,e);return t.parent=void 0,t}};var Nn=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.width=0;this.height=0;this.updateState(t,o)}innerDraw(e){e.ellipse(this.width*.5,this.height*.5,this.width*.5,this.height*.5,0,0,Math.PI*2)}intersectsInLocalSpace(e,t){return Zv(e,t,this.width*.5,this.height*.5,this.width*.5,this.height*.5)}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e)}clone(e){let t=new Nn(this.uuid,this.data,e);return t.parent=void 0,t}};var xo=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.width=0;this.height=0;this.cornerRadius=[0,0,0,0];this.updateState(t,o)}innerDraw(e){e.rect(0,0,this.width,this.height,...this.cornerRadius)}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateCornerState(e){e.cornerRadius!==void 0&&(this.cornerRadius=e.cornerRadius)}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateCornerState(e)}clone(e){let t=new xo(this.uuid,this.data,e);return t.parent=void 0,t}};var Dn=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this._textHeight=0;this._textHeightDirty=!0;this.width=0;this.height=0;this.updateState(t,o)}get textHeight(){return this._textHeight}applyFillStroke(e){e.fillColor=this.fill.enabled?this.fill.color:Me.transparent,e.strokeColor=this.stroke.enabled&&this.stroke.thickness>0?this.stroke.color:Me.transparent,e.strokeMode="center",e.lineWidth=this.stroke.thickness}innerDraw(e){this._fontHolder?.arrayBuffer&&this._fontHolder.arrayBuffer.byteLength>1&&this.data.font&&e.registerFont(this._fontHolder.arrayBuffer,this.data.font);let t=this.data.textTransform,o=this.data.text.textValue.toString(),i=t===2?o.toUpperCase():t===3?o.toLowerCase():o,{height:a}=e.drawText(i,{x:0,y:0,width:this.width,height:this.height,fontSize:this.data.fontSize,lineHeight:this.data.lineHeight??1,letterSpacing:this.data.letterSpacing??0,horizontalAlign:this.data.horizontalAlign,verticalAlign:this.data.verticalAlign,font:this.data.font});this._textHeight=a}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateFontState(e,{shared:t}){e.font!==void 0&&(this._fontHolder=t.getFont(e.font),this._fontHolder&&!this._fontHolder.isLoaded&&this._fontHolder.loadingPromise.then(()=>{this.requestRender()}))}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateFontState(e,t)}clone(e){let t=new Dn(this.uuid,this.data,e);return t.parent=void 0,t}};var fs=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.curves=[];this.extremasBBox={min:[0,0],max:[0,0]};this.updateState(t,o)}computeExtremas(){this.curves.length===0&&this.computeCurves();let e=this.curves.map(i=>fd.extremas(i)),t=[1/0,1/0],o=[-1/0,-1/0];for(let i=0,a=e.length;i<a;i++){let s=e[i];s[0][0]<t[0]&&(t[0]=s[0][0]),s[0][1]<t[1]&&(t[1]=s[0][1]),s[1][0]>o[0]&&(o[0]=s[1][0]),s[1][1]>o[1]&&(o[1]=s[1][1])}return this.extremasBBox.min=[t[0],t[1]],this.extremasBBox.max=[o[0],o[1]],this.extremasBBox}computeCurves(){this.curves=[];for(let o=1,i=this.data.points.length;o<i;o++){let a=this.data.points[o].data,s=this.data.points[o-1].data,l={start:s.position,cp1:s.controlNext.position,cp2:a.controlPrevious.position,end:a.position};this.curves.push(l)}let e=this.data.points[0].data,t=this.data.points[this.data.points.length-1].data;if(this.data.isClosed){let o={start:t.position,cp1:t.controlNext.position,cp2:e.controlPrevious.position,end:e.position};this.curves.push(o)}}getCenter(){let[e,t]=this.extremasBBox.min,[o,i]=this.getHalfSize();return[e+o,t+i]}getHalfSize(){let{min:e,max:t}=this.extremasBBox;return[(t[0]-e[0])*.5,(t[1]-e[1])*.5]}innerDraw(e){for(let i=0,a=this.data.points.length;i<a;i++){let s=this.data.points[i].data;if(i===0){let[l,c]=s.position;e.moveTo(l,c)}else{let l=this.data.points[i-1].data,[c,u]=l.controlNext.position,[p,d]=s.controlPrevious.position,[h,f]=s.position,m={start:l.position,cp1:l.controlNext.position,cp2:s.controlPrevious.position,end:s.position};fd.derive(m),e.bezierCurveTo(c,u,p,d,h,f)}}let t=this.data.points[0].data,o=this.data.points[this.data.points.length-1].data;if(this.data.isClosed){let[i,a]=o.controlNext.position,[s,l]=t.controlPrevious.position,[c,u]=t.position;e.bezierCurveTo(i,a,s,l,c,u)}}updateState(e,t){super.updateState(e,t),this.computeExtremas()}clone(e){let t=new fs(this.uuid,this.data,e);return t.parent=void 0,t}},fd;(i=>{function n(a){let s=a.start,l=a.cp1,c=a.cp2,u=a.end,p=[3*(l[0]-s[0]),3*(l[1]-s[1])],d=[3*(c[0]-l[0]),3*(c[1]-l[1])],h=[3*(u[0]-c[0]),3*(u[1]-c[1])],f={start:p,cp:d,end:h};return a.derivative=f,f.derivative=wh.derive(f),f}i.derive=n;function r(a,s,l,c=!1){let u=a-2*s+l;if(u!==0){let p=-Math.sqrt(Math.abs(s*s-a*l)),d=-a+s,h=-(p+d)/u,f=-(-p+d)/u;return[h,f]}else if(s!==l&&u===0)return[(2*s-l)/(2*(s-l))];return[]}function e(a){let s=a.derivative??i.derive(a),l=s.start,c=s.cp,u=s.end;return[r(l[0],c[0],u[0]),r(l[1],c[1],u[1])]}i.droot=e;function t(a){let[s,l]=i.droot(a),c=[a.start[0],a.end[0]],u=[a.start[1],a.end[1]];for(let p of s)c.push(i.compute(a,Math.min(1,Math.max(0,p)))[0]);for(let p of l)u.push(i.compute(a,Math.min(1,Math.max(0,p)))[1]);return c.sort((p,d)=>p-d),u.sort((p,d)=>p-d),[[c[0],u[0]],[c[c.length-1],u[u.length-1]]]}i.extremas=t;function o(a,s){if(s===0)return[...a.start];if(s===1)return[...a.end];let l=1-s,c=l*l,u=s*s,p=c*l,d=c*s*3,h=l*u*3,f=s*u;return[p*a.start[0]+d*a.cp1[0]+h*a.cp2[0]+f*a.end[0],p*a.start[1]+d*a.cp1[1]+h*a.cp2[1]+f*a.end[1]]}i.compute=o})(fd||(fd={}));var wh;(t=>{function n(o){let i=o.start,a=o.cp,s=o.end,l=[2*(a[0]-i[0]),2*(a[1]-i[1])],c=[2*(s[0]-a[0]),2*(s[1]-a[1])],u={start:l,end:c};return u.derivative=Ph.derive(u),o.derivative=u,u}t.derive=n;function r(o){let i=o.derivative??t.derive(o),a=i.start,s=i.end;return[a[0]!==s[0]?a[0]/(a[0]-s[0]):0,a[1]!==s[1]?a[1]/(a[1]-s[1]):0]}t.droot=r;function e(o,i){if(i===0)return[...o.start];if(i===1)return[...o.end];let a=1-i,s=a*a,l=i*i,c=s,u=a*i*2,p=l;return[c*o.start[0]+u*o.cp[0]+p*o.end[0],c*o.start[1]+u*o.cp[1]+p*o.end[1]]}t.compute=e})(wh||(wh={}));var Ph;(e=>{function n(t){let o=t.start,i=t.end,a=[i[0]-o[0],i[1]-o[1]];return t.derivative=a,t.derivative}e.derive=n;function r(t,o){if(o===0)return[...t.start];if(o===1)return[...t.end];let i=t.start,a=t.end;return[i[0]+(a[0]-i[0])*o,i[1]+(a[1]-i[1])*o]}e.compute=r})(Ph||(Ph={}));var fr=class extends kt{constructor(e,t,o){super(e,t,o);this.uuid=e;this.width=0;this.height=0;this.clipped=!0;this.background=new xo(e+"-background",la.defaultData,o),this.background.parent=this,this.updateState(t,o)}get fill(){return this.background.fill}get stroke(){return this.background.stroke}get backgroundBlur(){return this.background.backgroundBlur}get layerBlur(){return this.background.layerBlur}get dropShadow(){return this.background.dropShadow}get innerShadow(){return this.background.innerShadow}get cornerRadius(){return this.background.cornerRadius}set cornerRadius(e){this.background.cornerRadius=e}updateLocalMatrix(){super.updateLocalMatrix(),this.background?.updateLocalMatrix()}updateWorldMatrix(e,t,o){super.updateWorldMatrix(e,t,o),this.background?.updateWorldMatrix(e,t,o)}draw(e){if(!this.visible)return;e.save();let t=this.width,o=this.height;this.applyTransforms(e),this.background.width=t,this.background.height=o,this.background.draw(e),this.clipped&&e.clipRect(0,0,t,o,...this.cornerRadius),this.innerDrawChildren(e),e.restore()}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateCornerState(e){e.cornerRadius!==void 0&&(this.cornerRadius=e.cornerRadius)}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateCornerState(e),e.fill!==void 0&&this.fill.update(e.fill),e.stroke!==void 0&&this.stroke.update(e.stroke),e.dropShadow!==void 0&&this.dropShadow.update(e.dropShadow),e.innerShadow!==void 0&&this.innerShadow.update(e.innerShadow),e.layerBlur!==void 0&&this.layerBlur.update(e.layerBlur),e.backgroundBlur!==void 0&&this.backgroundBlur.update(e.backgroundBlur),e.clipped!==void 0&&(this.clipped=e.clipped)}requestRender(){super.requestRender(),this.dispatchEvent({type:"render"})}dispose(){this.removeEventListener("render")}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.type===0&&(Re(e.path,["fill"])?this.fill.update(e.props):Re(e.path,["stroke"])?this.stroke.update(e.props):Re(e.path,["dropShadow"])?this.dropShadow.update(e.props):Re(e.path,["innerShadow"])?this.innerShadow.update(e.props):Re(e.path,["layerBlur"])?this.layerBlur.update(e.props):Re(e.path,["backgroundBlur"])?this.backgroundBlur.update(e.props):this.resetBBoxNeedsUpdate())}clone(e){let t=new fr(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}};var pS=vs(Ch(),1),Yo=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this._pathBBox=new DOMRect;this.path="";this.updateState(t,o),this.autoClose=!1,this.computeSVGBBox()}computeSVGBBox(){let e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");document.body.appendChild(e),t.setAttribute("d",this.path),e.appendChild(t),this._pathBBox=t.getBBox(),e.remove()}innerDraw(e){e.path(this.path)}intersectsInLocalSpace(e,t){return e>=this._pathBBox.x&&e<=this._pathBBox.x+this._pathBBox.width&&t>=this._pathBBox.y&&t<=this._pathBBox.y+this._pathBBox.height}getCenter(){return[(this._pathBBox.x+this._pathBBox.width)/2,(this._pathBBox.y+this._pathBBox.height)/2]}getHalfSize(){return[(this._pathBBox.x+this._pathBBox.width)/2,(this._pathBBox.y+this._pathBBox.height)/2]}updateState(e,t){super.updateState(e,t),e.path!==void 0&&(this.path=e.path,this.computeSVGBBox())}clone(e){let t=new Yo(this.uuid,this.data,e);return t.parent=void 0,t}};function fS(n,r=1,e=1){if(r<=0||e<=0)return n;let o=(0,pS.parseSVG)(n).map(i=>{let a={...i};return"x"in a&&(a.x=a.x*r),"y"in a&&(a.y=a.y*e),"x1"in a&&(a.x1=a.x1*r),"x2"in a&&(a.x2=a.x2*r),"y1"in a&&(a.y1=a.y1*e),"y2"in a&&(a.y2=a.y2*e),"rx"in a&&(a.rx=a.rx*r),"ry"in a&&(a.ry=a.ry*e),a});return hS(o)}function hS(n){let r=["rx","ry","xAxisRotation","largeArc","sweep","x1","y1","x2","y2","x","y"],e;return n.map(t=>{let o=[];r.forEach(a=>{if(a in t){let s=t[a]*1;o.length&&s>=0&&o.push(","),o.push(s)}});let i=(e===t.code?o[0]<0?"":",":t.code)+o.join("");return e=t.code,i}).join("")}function mS(n,r,e){switch(r.type){case"ellipse2d":return new Nn(n,r,e);case"rectangle2d":return new xo(n,r,e);case"text2d":return new Dn(n,r,e);case"vector2d":return new fs(n,r,e);case"path2d":return new Yo(n,r,e);case"frame2d":return new fr(n,r,e);case"group2d":default:return new ir(n,r,e)}}var Oh=class{constructor(r,e,t){this.uuid=r;this.data=e;this.group=new ir(Oh.GROUP_ID,{...Rs.defaultData},t),this.createChildrenObjects(e.objects,this.group,t)}createObject(r,e,t,o,i,a){let s=mS(r,e,a);s&&(o.add(s),o.children.splice(i,0,o.children.pop()),s.updateWorldMatrix(),t.length>0&&(s instanceof ir||s instanceof fr)&&this.createChildrenObjects(t,s,a))}createChildrenObjects(r,e,t){let o=0;for(let i of r)this.createObject(i.id,i.data,i.children,e,o,t),o+=1}draw(r){this.group.draw(r)}updateEntityByOp(r,e,t,o){let i=this.find(r);if(i)try{i.updateByOp(e,t,{shared:o})}catch(a){console.error(a)}}updateTreeByOp(r,e){if(r.path.length===0&&r.type===7){let t=r.parent===null?this.group:this.find(r.parent);t!==void 0&&t instanceof kt&&(this.createObject(r.id,r.data,r.children,t,r.localIndex,e),t.requestRender())}else if(r.path.length===0&&r.type===8){let t=this.find(r.id);if(t!==void 0&&t.parent!==void 0&&t.parent instanceof kt){let o=t.parent;t.resetBBoxNeedsUpdate(),o?.remove(t),o?.requestRender()}}else if(r.path.length===0&&r.type===9){let t=this.find(r.id);if(t!==void 0){let o=t.parent,i=r.parent===null?this:this.find(r.parent);if(i===void 0&&!1&&console.error("unexpected",i,r),i instanceof kt||i===this){i.add(t);let a=r.localIndex;i.children.splice(a,0,i.children.pop()),t.updateWorldMatrix(!0,!1,!0),o?.requestRender(),t.requestRender()}t.resetBBoxNeedsUpdate()}}}add(r){this.group.add(r)}remove(r){this.group.remove(r)}traverse(r){this.group.traverse(e=>{e!==this.group&&r(e)})}intersectsChildren(r,e,t,o=!1,i=[]){return this.group.intersectsChildren(r,e,t,o,i,!0)}intersectsChildrenReverse(r,e,t,o=!1,i=[]){return this.group.intersectsChildrenReverse(r,e,t,o,i,!0)}find(r){return this.group.find(r)}get children(){return this.group.children}project(r,e){return this.group.project(r,e)}getWithSortKey(r){let e=this.find(r);if(e===void 0)return;let t=[],o=e;for(;o!==this.group;){let i=o;o=o.parent;let a=o.children.indexOf(i);t.splice(0,0,a)}return{entity:e,sortKey:t}}getAllSorted(r){let e=[];for(let t of r){let o=this.getWithSortKey(t.id);o!==void 0&&e.push(o)}return e.sort((t,o)=>jl(t.sortKey,o.sortKey)),e.map(t=>t.entity)}},mi=Oh;mi.GROUP_ID="scene2d";function Ah({constraints:n,newParentWidth:r,newParentHeight:e,initialParentWidth:t,initialParentHeight:o,objectInitialWidth:i,objectInitialHeight:a,objectInitialPosition:s}){let{horizontalConstraint:l,verticalConstraint:c}=n,u=r-t,p=e-o,d=i,h=a,f=s[0],m=s[1];if(l!==0){if(l===1)f+=u;else if(l===3)f+=u/2;else if(l===2)d=Math.max(1,d+u);else if(l===4){let y=r/t;d*=y,f*=y}}if(c!==0){if(c===1)m+=p;else if(c===3)m+=p/2;else if(c===2)h=Math.max(1,h+p);else if(c===4){let y=e/o;h*=y,m*=y}}return{width:d,height:h,position:[f,m]}}var H3=vs(Ch(),1);var Mce={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:72/6,pc:1,px:-1},px:{mm:1,px:1,cm:1,in:1,pt:1,pc:1}};import{BufferGeometry as W3,CanvasTexture as q3,Float32BufferAttribute as yS,HalfFloatType as $3,MathUtils as Y3,Mesh as X3,OrthographicCamera as K3,ShaderMaterial as Q3,Uniform as Z3,WebGLRenderTarget as J3}from"three";var e_=`
2955
+ `,CD=Sl.lights_fragment_begin,OD=Sl.shadowmask_pars_fragment,Gv=null,AD=n=>{switch(n){case"low":return 8;case"medium":return 16;case"high":return 32;default:return 16}},Fv=(n="medium")=>{if(Gv===n)return!1;Gv=n;let r=AD(n);Sl.shadowmap_pars_fragment=PD(r);let e=CD.slice();e=e.replace("getShadow( spotShadowMap[ i ]",`getShadow( UNROLLED_LOOP_INDEX + ${3}, spotShadowMap[ i ]`),e=e.replace("getShadow( directionalShadowMap[ i ]","getShadow( UNROLLED_LOOP_INDEX, directionalShadowMap[ i ]"),Sl.lights_fragment_begin=e;let t=OD.slice();return t=t.replaceAll("getShadow(","getShadow( UNROLLED_LOOP_INDEX, "),Sl.shadowmask_pars_fragment=t,!0};import{DirectionalLight as ND,CameraHelper as jv}from"three";import{DirectionalLightHelper as TD}from"three";var ss=class extends yo(TD){constructor(e,t=15,o=10066329){super(e,t,o);this.object=e;this.added=!1;this.name=`DirectionalLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,ss.geometryHelper,e,t)}};import{PointLightHelper as ID}from"three";var ls=class extends yo(ID){constructor(e,t=15,o=6710886){super(e,t,o);this.object=e;this.name=`PointLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,ls.geometryHelper,e,t)}};import{SpotLightHelper as MD,Vector3 as ED}from"three";var nd=class extends yo(MD){constructor(e,t=6710886){super(e,t);this.object=e;this.name=`SpotLightHelper: ${e.uuid}`}raycast(e,t){go(this.object,nd.geometryHelper,e,t)}update(){if(this.object!==void 0){let e=nd._vector,t=this.object.distance?this.object.distance:1e3,o=t*Math.tan(this.object.angle);this.cone.scale.set(o,o,t),e.setFromMatrixPosition(this.object.target.matrixWorld),this.cone.lookAt(e);let i=this.color!==void 0?this.color:this.light.color;if(this.cone.material instanceof Array)for(let a=0,s=this.cone.material.length;a<s;a++)this.cone.material[a].color.set(i);else this.cone.material.color.set(i)}}},wl=nd;wl._vector=new ED;function DD(n,r){n.shadow.camera.right=r/2,n.shadow.camera.left=-r/2,n.shadow.camera.top=r/2,n.shadow.camera.bottom=-r/2,n.shadow.needsUpdate=!0}var cs=class extends as(ND,ss){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=2048,this.shadow.mapSize.height=2048,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.top=1250,i.bottom=-1250,i.right=1250,i.left=-1250,i.near=-1e4,i.far=2500;let a=new jv(this.shadow.camera);a.visible=!1,this.gizmos.shadowmap=a}update(){this.shadow.camera.updateProjectionMatrix();for(let r in this.gizmos){let e=this.gizmos[r];e instanceof jv&&e.update()}}updateMatrixWorld(r){super.updateMatrixWorld(r),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e);let t=r.depth!==void 0&&r.depth!==this.shadow.camera.far||r.size!==void 0&&r.size/2!==this.shadow.camera.right;r.size!==void 0&&DD(this,r.size),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null)),r.penumbraSize!==void 0&&e.scene.markPenumbraSizeDirty(),t&&this.update()}};import{Scene as f_}from"three";import{SpotLight as _D,CameraHelper as kv,MathUtils as BD,Vector3 as qv,Quaternion as RD}from"three";var Uv=new qv,Hv=new qv,Wv=new RD,us=class extends as(_D,wl){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=1024,this.shadow.mapSize.height=1024,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.fov=BD.RAD2DEG*2*this.angle,i.aspect=1,i.near=100,i.far=2500;let a=new kv(this.shadow.camera);a.visible=!1,this.gizmos.shadowmap=a,this.update()}update(){this.shadow.camera.updateProjectionMatrix();for(let r in this.gizmos){let e=this.gizmos[r];e instanceof kv&&e.update()}}updateMatrixWorld(r){super.updateMatrixWorld(r),Hv.setFromMatrixPosition(this.matrixWorld),Wv.setFromRotationMatrix(this.matrixWorld),Uv.copy(this.up).applyQuaternion(Wv).negate().multiplyScalar(this.distance),this.target.position.copy(Hv).add(Uv),this.target.updateMatrixWorld(),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e),r.distance!==void 0&&(this.distance=r.distance),r.decay!==void 0&&(this.decay=r.decay),r.angle!==void 0&&(this.angle=r.angle),r.penumbra!==void 0&&(this.penumbra=r.penumbra),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.penumbraSize!==void 0&&e.scene.markPenumbraSizeDirty(),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null))}};function LD(n){let r=(n[0][0]+n[1][1])/2,e=(n[0][0]-n[1][1])/2,t=(n[1][0]+n[0][1])/2,o=(n[1][0]-n[0][1])/2,i=Math.sqrt(r*r+o*o),a=Math.sqrt(e*e+t*t),s=i+a,l=i-a,c=Math.atan2(t,e),u=Math.atan2(o,r),p=(u-c)/2,d=(u+c)/2,f=[[Math.cos(d),Math.sin(d)],[-Math.sin(d),Math.cos(d)]],h=[[s,0],[0,l]],m=[[Math.cos(p),Math.sin(p)],[-Math.sin(p),Math.cos(p)]];return f[0][0]*=-1,f[0][1]*=-1,m[0][0]*=-1,m[1][0]*=-1,[f,h,m]}function id(n,r){return[[n[0][0]*r[0][0]+n[0][1]*r[1][0],n[0][0]*r[0][1]+n[0][1]*r[1][1]],[n[1][0]*r[0][0]+n[1][1]*r[1][0],n[1][0]*r[0][1]+n[1][1]*r[1][1]]]}function $v(n){return[[n[0][0],n[1][0]],[n[0][1],n[1][1]]]}function Yv(n){let[r,e,t]=LD(n),o=id(r,$v(t)),i=id(id(t,e),$v(t)),a=Math.atan2(o[1][0],o[0][0]),s=[i[0][0],i[1][1]],l=[i[0][1]/i[1][1],i[1][0]/i[0][0]];return{rotation:a,scale:s,shear:l}}function Xv({rotation:n,scale:r,shear:e}){let t=Math.cos(n),o=Math.sin(n),i=[[t,-o],[o,t]],a=[[r[0],e[0]*r[1]],[e[1]*r[0],r[1]]],s=id(i,a);return[s[0][0],s[1][0],s[0][1],s[1][1]]}var Ee;(v=>{function n(){return[1,0,0,0,1,0,0,0,1]}v.identity=n;function r(A,T=v.identity()){for(let g=0,D=A.length;g<D;g++)T[g]=A[g];return T}v.copy=r;function e(A,T,g,D,E,M){return v.setAbcdef(v.identity(),A,T,g,D,E,M)}v.create=e;function t(A,T,g,D,E,M,N){return A[0]=T,A[1]=D,A[2]=M,A[3]=g,A[4]=E,A[5]=N,A}v.setAbcdef=t;function o(A,T){let[g,D,E,M,N,_]=a(A),[B,V,k,L,W,F]=a(T),j=B*g+V*E,H=B*D+V*M,q=k*g+L*E,re=k*D+L*M,ee=W*g+F*E+N,X=W*D+F*M+_;return v.create(j,H,q,re,ee,X)}v.append=o;function i(A,T){let[g,D,E,M,N,_]=a(A),[B,V,k,L,W,F]=a(T),j=g,H=D,q=E,re=M;(B!==1||V!==0||k!==0||L!==1)&&(j=g*B+D*k,H=g*V+D*L,q=E*B+M*k,re=E*V+M*L);let ee=N*B+_*k+W,X=N*V+_*L+F;return v.create(j,H,q,re,ee,X)}v.prepend=i;function a(A){return[A[0],A[3],A[1],A[4],A[2],A[5]]}v.getAbcdef=a;function s(A){let[T,g,D,E,M,N]=v.getAbcdef(A),_=T*E-g*D,B=E/_,V=-g/_,k=-D/_,L=T/_,W=(D*N-E*M)/_,F=-(T*N-g*M)/_;return v.create(B,V,k,L,W,F)}v.invert=s;function l([A,T],g){let[D,E,M,N,_,B]=v.getAbcdef(g);return[D*A+M*T+_,E*A+N*T+B]}v.apply=l;function c(A,T){let[g,D,E,M,N,_]=v.getAbcdef(T),B=1/(g*M+E*-D),[V,k]=A;return[M*B*V+-E*B*k+(_*E-N*M)*B,g*B*k+-D*B*V+(-_*g+N*D)*B]}v.applyInverse=c;function u(A,T,g=T){let[D,E,M,N,_,B]=v.getAbcdef(A);return v.setAbcdef(A,D*T,E*g,M*T,N*g,_*T,B*g),A}v.scale=u;function p(A,T){let g=Math.cos(T),D=Math.sin(T),[E,M,N,_,B,V]=v.getAbcdef(A);return v.setAbcdef(A,E*g-M*D,E*D+M*g,N*g-_*D,N*D+_*g,B*g-V*D,B*D+V*g),A}v.rotate=p;function d(A,T,g){let[D,E]=g,M=v.translate(A,-D,-E);return M=v.rotate(M,T),M=v.translate(M,D,E),M}v.rotateAround=d;function f(A,T,g){let[D,E,M,N,_,B]=v.getAbcdef(A);return v.setAbcdef(A,D,E,M,N,_+T,B+g),A}v.translate=f;function h(A,T,g){let[D,E,M,N]=v.getAbcdef(A);return v.setAbcdef(A,D,E,M,N,T,g),A}v.setTranslate=h;function m(A,T,g){let[D,E,M,N]=v.getAbcdef(A);return v.setAbcdef(A,D,E,M,N,T,g),A}v.setPosition=m;function y(A){let[T,g,D,E]=v.getAbcdef(A),M=Math.sqrt(T*T+g*g),N=Math.sqrt(D*D+E*E);return[M,N]}v.getScale=y;function b(A){let[,,,,T,g]=v.getAbcdef(A);return[T,g]}v.getPosition=b;function S(A,T){return v.decompose(A,T).rotation}v.getRotation=S;function P(A,T){let[g,D,E,M,N,_]=v.getAbcdef(A),{rotation:B,scale:V,shear:k}=Yv([[g,E],[D,M]]);return{position:[N+(T[0]*g+T[1]*E)-T[0],_+(T[0]*D+T[1]*M)-T[1]],scale:V,rotation:B,shear:k,pivot:T}}v.decompose=P;function C(A,T,g,D,E=[0,0]){let[M,N]=A,[_,B]=D,[V,k,L,W]=Xv({rotation:g,scale:T,shear:E}),F=M-(_*V+B*L)+_,j=N-(_*k+B*W)+B;return v.create(V,k,L,W,F,j)}v.compose=C})(Ee||(Ee={}));var VD=Math.PI/180,ese=180/Math.PI;function Kv(n,r,e,t,o,i){let a=n-e,s=r-t;return a*a/(o*o)+s*s/(i*i)<=1}function Qv(n){return n*VD}var qo=class{constructor(r,e,t){this.uuid=r;this.data=e;this.localMatrix=Ee.identity();this.worldMatrix=Ee.identity();this.ignoreCameraZoom=!1;this.visible=!0;this._singleBBox=new Mn;this._recursiveBBox=new Mn;this.singleBBoxNeedsUpdate=!0;this.recursiveBBoxNeedsUpdate=!0;this.stateSelection=null;this.prevState=null;this.currentState=null;this.reversibleToState=null;this.currentTransitionEvent=null;this.previousAction=null;this.name="";this.position=[0,0];this.scale=[1,1];this.rotation=0;this.shear=[0,0];this.emitter=Lo();this.dpr=t.dpr??1,this.dataPatched=e}project(r,e){let t=this.worldMatrix;return e&&(t=Ee.append(e.worldMatrix,t)),Ee.applyInverse(r,t)}intersects(r,e,t,o=!1){return this.visible&&!this.data.raycastLock&&this.intersectsInLocalSpace(...this.project([r,e],t),o)}intersectsInLocalSpace(r,e,t=!1){let{min:o,max:i}=t?this.recursiveBBox:this.singleBBox;return r>=o[0]&&r<=i[0]&&e>=o[1]&&e<=i[1]}applyTransforms(r){r.setTransform(this.worldMatrix,this.ignoreCameraZoom)}get singleBBox(){return this.singleBBoxNeedsUpdate&&(this.singleBBoxNeedsUpdate=!1,this._singleBBox.setFromObjectSize(this,!1),this._singleBBox.computeVertices(),this._singleBBox.computeEdges()),this._singleBBox}get recursiveBBox(){return this.recursiveBBoxNeedsUpdate&&(this.recursiveBBoxNeedsUpdate=!1,this._recursiveBBox.setFromObjectSize(this,!0),this._recursiveBBox.computeVertices(),this._recursiveBBox.computeEdges()),this._recursiveBBox}updateLocalMatrix(){this.localMatrix=Ee.compose(this.position,this.scale,Qv(this.rotation),Do.getPivot(this.dataPatched),this.shear)}updateWorldMatrix(r,e,t){let o=this.parent;e&&o!==null&&o!==void 0&&o.updateWorldMatrix(r,!0,!1),r&&this.updateLocalMatrix(),this.parent?this.worldMatrix=Ee.append(this.parent.worldMatrix,this.localMatrix):this.worldMatrix=Ee.copy(this.localMatrix),this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}get pivot(){return Do.getPivot(this.data)}getCenter(){return[0,0]}getHalfSize(){return[0,0]}get id(){return this.uuid}resetBBoxNeedsUpdateSelf(){this.singleBBoxNeedsUpdate=!0,this.recursiveBBoxNeedsUpdate=!0}resetBBoxNeedsUpdate(){this.resetBBoxNeedsUpdateSelf(),this.traverseAncestors(r=>{r.resetBBoxNeedsUpdateSelf()})}updateTransformState(r){let e=!1;r.position!==void 0&&(e=!0,this.position=r.position),r.rotation!==void 0&&(e=!0,this.rotation=r.rotation),r.scale!==void 0&&(e=!0,this.scale=r.scale),r.shear!==void 0&&(e=!0,this.shear=r.shear),e&&(this.updateWorldMatrix(!0,!1,!0),this.resetBBoxNeedsUpdate())}updateByOp(r,e,t){r.type===0&&r.props.visible!==void 0&&(this.visible=r.props.visible),this.data=e,this.data=e;let o=r,i=Re(r.path,["states","*"]);if(i!==null){if(r.type===0){let[a]=i;if(this?.stateSelection===a){let s={...r.props};if(delete s.name,Object.values(r.props).some(l=>l===void 0)){let l=this.data;if(l!==void 0){let c=Ze.zoom(l,r.path.slice(2));if(c)for(let u in r.props)r.props[u]===void 0&&u in c&&(s[u]=c[u])}}o={...r,props:s,path:r.path.slice(2)}}}}else if(r.type===0){let a=this.stateSelection?this.data.states.data(this.stateSelection):void 0;if(a!==void 0){if(r.props.name!==void 0&&a.name){let{name:l,...c}=a;a=c}let s=Ze.removeOverridden(r.path,r.props,a);o={...r,props:s}}}this.updateByPatchedOpBase(o,Yn.patch(this.data,this.stateSelection?this.data.states.data(this.stateSelection):void 0),t)}changeSelectedState(r,e,t=!1){if(!(this.data.states.length===0&&!t)){for(let o of this.data.states)Yn.toOps(this.data,o.data).forEach(a=>{let s=Wi.replaceProps(a,this.data);this.dataPatched=this.data,this.updateByPatchedOp(s,this.data,e)});if(r!==null){let o=this.data.states.data(r);o&&(this.dataPatched=Yn.patch(this.data,o),Yn.toOps(this.data,o).forEach(a=>{this.updateByPatchedOp(a,this.dataPatched,e)}))}t&&this.updateTransformState(this.dataPatched),this.stateSelection=r}}updateState(r,e){r.name!==void 0&&(this.name=r.name),r.visible!==void 0&&(this.visible=r.visible),this.updateTransformState(r)}updateByPatchedOpBase(r,e,t){this.dataPatched=e,this.updateByPatchedOp(r,e,t)}updateByPatchedOp(r,e,t){r.path.length===0&&r.type===0&&this.updateState(r.props,t),this.requestRender()}traverseFrameAncestors(r){this.traverseAncestors(e=>{e.data.type==="frame2d"&&r(e)})}traverseAncestors(r){let e=this.parent;for(;e;)r(e),e=e.parent}requestRender(){this.traverseFrameAncestors(r=>{r.requestRender()})}clone(r){let e=new qo(this.uuid,this.data,r);return e.parent=void 0,e}addEventListener(r,e){this.emitter.on(r,e)}removeEventListener(r,e){this.emitter.off(r,e)}dispatchEvent(r){this.emitter.emit(r.type,{...r,target:r.target??this})}traverseSortNextHelper(){let r=this.parent;if(r){let e=r.children;if(e){let t=e.indexOf(this)+1;return e[t]?e[t]:r.traverseSortNextHelper()}}}sortNext(){let r=this.children;return r&&r.length>0&&r[0]?r[0]:this.traverseSortNextHelper()}isDescendantOf(r){r instanceof qo&&(r=r.uuid);let e=this;for(;e.parent;){if(e.parent.uuid===r)return!0;e=e.parent}return!1}};var kt=class extends qo{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.context=o;this.children=[]}add(e){e.parent&&e.parent instanceof kt&&e.parent.remove(e),this.children.push(e),e.parent=this}remove(e){let t=this.children.indexOf(e);t>=0&&(this.children.splice(t,1),e.parent=void 0)}traverse(e){let t=e(this);if(t!==!0)for(let o of this.children)o instanceof kt?o.traverse(e):t=e(o)}intersectsChildrenHelper(e,t,o,i,a){for(let s of this.children)if(s.intersects(e,t,o,!1)&&(a.push(s),i)||s instanceof kt&&s.intersectsChildrenHelper(e,t,o,i,a))return!0;return!1}intersectsChildren(e,t,o,i=!1,a=[],s=!1){return this.intersectsChildrenHelper(e,t,o,i,a),a}intersectsChildrenHelperReverse(e,t,o,i,a){for(let s of this.children)if(s instanceof kt&&s.intersectsChildrenHelperReverse(e,t,o,i,a)||s.intersects(e,t,o,!1)&&(a.push(s),i))return!0;return!1}intersectsChildrenReverse(e,t,o,i=!1,a=[],s=!1){return this.intersectsChildrenHelperReverse(e,t,o,i,a),a}updateWorldMatrix(e,t,o){if(super.updateWorldMatrix(e,t,o),o&&this.children)for(let i of this.children)i.updateWorldMatrix(e,!1,!0)}find(e){let t;return this.traverse(o=>{o.uuid===e&&(t=o)}),t}innerDrawChildren(e){for(let t=this.children.length-1;t>=0;t--)this.children[t].draw(e)}resetBBoxNeedsUpdate(){super.resetBBoxNeedsUpdate(),this.traverse(e=>{e.resetBBoxNeedsUpdateSelf()})}clone(e){let t=new kt(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}},ir=class extends kt{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.updateState(t,o)}draw(e){!this.visible||(e.save(),this.applyTransforms(e),this.innerDrawChildren(e),e.restore())}clone(e){let t=new ir(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}};function zD(n,r){let[[e,t],[o,i]]=n,[[a,s],[l,c]]=r,u=(e-o)*(s-c)-(t-i)*(a-l);if(u===0)return!1;let p=((e-a)*(s-c)-(t-s)*(a-l))/u,d=-((e-o)*(t-s)-(t-i)*(e-a))/u;return p>=0&&p<=1&&d>=0&&d<=1}var Jv=[[-1,1],[-1,-1],[1,-1],[1,1]],Zv=(n,r,e)=>{let t=n.getCenter(),o=n.getHalfSize(),i=Ee.append(r,n.worldMatrix);o[0]===0&&o[1]===0?e.push(Ee.apply(t,i)):Jv.forEach(a=>{let s=[a[0]*o[0]+t[0],a[1]*o[1]+t[1]];e.push(Ee.apply(s,i))})},Mn=class{constructor(){this.matrix=Ee.identity();this.min=[1/0,1/0];this.max=[-1/0,-1/0];this.vertices=[];this.edges=[]}setFromObjectSize(r,e=!1){r.updateWorldMatrix(),this.makeEmpty(),Ee.copy(r.worldMatrix,this.matrix);let t=Ee.invert(r.worldMatrix);this.expandByObjectSize(r,t,e)}expandByObjectSize(r,e,t=!1){let o=[];t===!0&&r instanceof kt?r.traverse(i=>{i.visible&&Zv(i,e,o)}):Zv(r,e,o),this.setFromPoints(o)}setFromSize(r,e,t){this.makeEmpty(),Ee.copy(t,this.matrix),this.expandBySize(r,e,t)}expandBySize(r,e,t){[Ee.apply([0,0],t),Ee.apply([0,e],t),Ee.apply([r,e],t),Ee.apply([r,0],t)].forEach(i=>this.expandByPoint(i))}getCenter(){let[r,e]=this.min,[t,o]=this.getHalfSize();return Ee.apply([r+t,e+o],this.matrix)}getSize(){return[this.max[0]-this.min[0],this.max[1]-this.min[1]]}getHalfSize(){return[(this.max[0]-this.min[0])*.5,(this.max[1]-this.min[1])*.5]}makeEmpty(){this.min=[1/0,1/0],this.max=[-1/0,-1/0]}setFromPoints(r){this.makeEmpty();for(let e of r)this.expandByPoint(e)}expandByPoint(r){this.min=[Math.min(this.min[0],r[0]),Math.min(this.min[1],r[1])],this.max=[Math.max(this.max[0],r[0]),Math.max(this.max[1],r[1])]}computeVertices(){let[r,e]=this.getHalfSize(),t=this.getCenter(),[o,i,a,s]=Ee.getAbcdef(this.matrix),l=Ee.create(o,i,a,s,t[0],t[1]);this.vertices=Jv.map(([c,u])=>Ee.apply([c*r,u*e],l))}computeEdges(){this.edges=[];for(let r=0,e=this.vertices.length;r<e;++r)this.edges.push([this.vertices[r],this.vertices[(r+1)%e]])}project(r,e){let t=this.matrix;return e&&(t=Ee.append(e.worldMatrix,t)),Ee.applyInverse(r,t)}intersects(r,e,t){return this.intersectsInLocalSpace(...this.project([r,e],t))}intersectsInLocalSpace(r,e){let{min:t,max:o}=this;return r>=t[0]&&r<=o[0]&&e>=t[1]&&e<=o[1]}containsPoint(r){let[e,t]=r,[o,i]=this.min,[a,s]=this.max;return e>=o&&e<=a&&t>=i&&t<=s}intersectsBBox2D(r){for(let e=0,t=this.edges.length;e<t;e++){let o=this.edges[e];for(let i=0,a=r.edges.length;i<a;i++){let s=r.edges[i];if(zD(o,s))return!0}}for(let e=0,t=r.vertices.length;e<t;e++){let o=r.vertices[e];if(this.containsPoint(o))return!0}return!1}ensureMinMax(){let r=this.min,e=this.max;this.min=[Math.min(r[0],e[0]),Math.min(r[1],e[1])],this.max=[Math.max(r[0],e[0]),Math.max(r[1],e[1])]}copy(r){this.min=[...r.min],this.max=[...r.max],Ee.copy(r.matrix,this.matrix),this.computeVertices(),this.computeEdges()}clone(){let r=new Mn;return r.copy(this),r}};var tS,rS=new Promise(n=>{tS=n}),eS=!1;var ad;function oS(){if(eS)return;if(ad)return ad;async function n(){let e=await import("./ui.js");tS(e.default??e),eS=!0}return ad=n(),ad}function aS(n){let r=!1;return n.scene.objects.traverse((e,t)=>{(t.type==="Mesh"&&t.geometry.type==="UIGeometry"||t.type==="Page"&&t.uiFrame!==void 0)&&(r=!0)}),r}var Oe,bh;async function GD(n){let r=await rS;Oe||(bh||(bh=r({locateFile:()=>n})),Oe=await bh)}var nS=Ee.identity(),Cl=class{constructor(r,e=1){this.canvas=r;this._dpr=e;this._width=0;this._height=0;this._strokeMode="inside";this._layerBlur=0;this._backgroundBlur=0;this._dropShadowBlur=0;this._dropShadowOffsetX=0;this._dropShadowOffsetY=0;this._dropShadowColor=Me.transparent;this._innerShadowBlur=0;this._innerShadowOffsetX=0;this._innerShadowOffsetY=0;this._innerShadowSpread=0;this._innerShadowColor=Me.transparent;this._fonts=new Map;this._isSizeDirty=!1;try{let t=r.getBoundingClientRect();r.width=t.width*e,r.height=t.height*e}catch{console.log(r.width,e)}this._currentM3Transform=nS,this._currentTransform=new Float32Array(nS)}get dpr(){return this._dpr}set dpr(r){this._dpr=r,this._isSizeDirty=!0}async init(){if(!this.wasmURL)throw Error("Your must set the wasm binary url with renderer.wasmURL = ... before you can call renderer.init");await GD(this.wasmURL),this._surface=Oe.MakeWebGLCanvasSurface(this.canvas),this.ctx=this._surface?.getCanvas(),this._paint=new Oe.Paint,this._paint.setAntiAlias(!0),this._paintFill=this._paint.copy(),this._paintFill.setStyle(Oe.PaintStyle.Fill),this._paintStroke=this._paint.copy(),this._paintStroke.setStyle(Oe.PaintStyle.Stroke),this.ctx?.scale(this.dpr,this.dpr)}get currentTransform(){return this._currentM3Transform}get currentTransformBuffer(){return this._currentTransform}set currentTransform(r){this._currentM3Transform=r,this._currentTransform.set(r)}async loadFont(r,e){let t=await(await fetch(r)).arrayBuffer();this.registerFont(t,e)}registerFont(r,e){if(this._fonts.has(e))return;let t=Oe.FontMgr.FromData(r);if(t)this._fonts.set(e,t);else throw new Error("Invalid font data for "+e)}get width(){return this._width}get height(){return this._height}set strokeColor(r){this._paintStroke&&this._paintStroke.setColor(sd(r),Oe.ColorSpace.DISPLAY_P3)}set fillColor(r){this._paintFill&&this._paintFill.setColor(sd(r),Oe.ColorSpace.DISPLAY_P3)}set lineWidth(r){this._paintStroke&&this._paintStroke.setStrokeWidth(this._strokeMode==="center"?r:r*2)}set strokeMode(r){this._strokeMode=r}set dropShadowBlur(r){this._dropShadowBlur=r}set dropShadowColor(r){this._dropShadowColor=r}set dropShadowOffsetX(r){this._dropShadowOffsetX=r}set dropShadowOffsetY(r){this._dropShadowOffsetY=r}set innerShadowBlur(r){this._innerShadowBlur=r}set innerShadowColor(r){this._innerShadowColor=r}set innerShadowOffsetX(r){this._innerShadowOffsetX=r}set innerShadowOffsetY(r){this._innerShadowOffsetY=r}set innerShadowSpread(r){this._innerShadowSpread=r}set layerBlur(r){this._layerBlur=r}set backgroundBlur(r){this._backgroundBlur=r}clear(){this.ctx?.clear(Oe.TRANSPARENT)}save(){this.ctx?.save()}restore(){this.ctx?.restore()}beginPath(){this._currentPath?.delete(),this._currentPath=new Oe.Path}closePath(){let r=this._currentPath;if(r){if(r.isEmpty())return;let e=r.getBounds();(e[3]-e[1]||e[2]-e[0])&&r.close()}}fill(){this._paintInner(this._paintFill,!0)}stroke(){this._paintInner(this._paintStroke,!1)}clipRect(r,e,t,o,i=0,a=0,s=0,l=0){let c=Oe.XYWHRect(r,e,t,o);if(i===0&&a===0&&l===0&&s===0)this.ctx?.clipRect(c,Oe.ClipOp.Intersect,!0);else{let u=Oe.RRectXY(c,i,i);u[4]=u[5]=i,u[6]=u[7]=a,u[8]=u[9]=s,u[10]=u[11]=l,this.ctx?.clipRRect(u,Oe.ClipOp.Intersect,!0)}}_applyShadowOffsetMatrix(){if(this.ctx){let r=Ee.invert(this.currentTransform);this.ctx.concat(r);let e=Ee.translate(Ee.identity(),this._dropShadowOffsetX,this._dropShadowOffsetY);this.ctx.concat(e),this.ctx.concat(this._currentTransform)}}_applyEffectsToPaint(r,e,t=!0){if(this.ctx&&this._currentPath){let o,i=!1;if(t&&this._hasDropShadow()){let a=r.copy();a.setColor(sd(this._dropShadowColor));let s;this._dropShadowBlur>0&&(s=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._dropShadowBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(s)),this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Difference,!0),this._applyShadowOffsetMatrix(),e(a),this.ctx.restore(),a.delete(),s?.delete()}if(this._backgroundBlur>0&&t){this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Intersect,!0);let a=Oe.ImageFilter.MakeBlur(this._backgroundBlur,this._backgroundBlur,Oe.TileMode.Clamp,null),s=r.copy();s.setImageFilter(a),s.setAlphaf(1);let l=this._currentPath.computeTightBounds();this.ctx.saveLayer(s,l,null,Oe.SaveLayerInitWithPrevious),this.ctx.drawColor(r.getColor()),this.ctx.restore(),this.ctx.restore(),s.delete(),a.delete(),i=!0}if(this._layerBlur>0){let a=r.copy();o=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._layerBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(o),e(a),a.delete(),o.delete(),i=!0}if(i||e(r),t&&this._hasInnerShadow()){let a=new Oe.Paint;a.setAntiAlias(!0),a.setStyle(Oe.PaintStyle.Fill),a.setColor(sd(this._innerShadowColor));let s;this._innerShadowBlur>0&&(s=Oe.MaskFilter.MakeBlur(Oe.BlurStyle.Normal,this._innerShadowBlur*this.dpr*(this.camera?.scale??1),!1),a.setMaskFilter(s));let l=this._currentPath.computeTightBounds(),[c,u,p,d]=l,f=p-c,h=d-u;this.ctx.save(),this.ctx.clipPath(this._currentPath,Oe.ClipOp.Intersect,!0),this.ctx.saveLayer(a,l,null,Oe.SaveLayerInitWithPrevious),this.ctx?.translate(this._innerShadowOffsetX,this._innerShadowOffsetY),this.ctx.drawRect(Oe.XYWHRect(-1e3-this._innerShadowOffsetX,-1e3-this._innerShadowOffsetY,2e3+f+Math.abs(this._innerShadowOffsetX*2),2e3+h+Math.abs(this._innerShadowOffsetY*2)),a),a.setBlendMode(Oe.BlendMode.Clear),this.ctx.drawPath(this._currentPath,a),this.ctx.restore(),this.ctx.restore(),a.delete(),s?.delete()}}}_paintInner(r,e=!0){if(this.ctx&&this._currentPath&&r){let t=this.ctx,o=this._currentPath;this._applyEffectsToPaint(r,i=>{let a=!1;!e&&this._strokeMode!=="center"&&(t.save(),t.clipPath(o,this._strokeMode==="outside"?Oe.ClipOp.Difference:Oe.ClipOp.Intersect,!0),a=!0),t.drawPath(o,i),a&&t.restore()},e)}}_hasDropShadow(){return this._dropShadowColor?.a>0}_hasInnerShadow(){return this._innerShadowColor?.a>0}path(r){this._currentPath?.addPath(Oe.Path.MakeFromSVGString(r))}ellipse(r,e,t,o,i,a,s,l){if(!iS([r,e,t,o])||!this._currentPath)return;if(t<0||o<0)throw Error("radii cannot be negative");let c=Oe.XYWHRect(r-t,e-o,t*2,o*2);this._currentPath?.addOval(c)}rect(r,e,t,o,i=0,a=0,s=0,l=0){let c=Oe.XYWHRect(r,e,t,o);if(!!iS(c))if(i===0&&a===0&&l===0&&s===0)this._currentPath?.addRect(c);else{let u=Oe.RRectXY(c,i,i);u[4]=u[5]=i,u[6]=u[7]=a,u[8]=u[9]=s,u[10]=u[11]=l,this._currentPath?.addRRect(u)}}getHorizontalAlign(r){switch(r){case 2:return Oe.TextAlign.Right;case 3:return Oe.TextAlign.Center;case 4:return Oe.TextAlign.Justify;case 1:default:return Oe.TextAlign.Left}}drawTextInner(r,e,t,[o,i,a,s],l,c,u=!0){let p=0,{ctx:d}=this;if(!d)return p;let f=c.copy(),h=c.copy();return h.setAlphaf(0),this._applyEffectsToPaint(f,m=>{e.pushPaintStyle(t,m,h),e.addText(r);let y=e.build();y.layout(a);let b=i;l===2?b+=(s-y.getHeight())/2:l===3&&(b+=s-y.getHeight()),d.drawParagraph(y,o,b),p=y.getHeight(),e.reset(),y.delete()},u),f.delete(),h.delete(),p}drawText(r,e){let t=0,o=this._fonts.get(e.font),{ctx:i,_paintFill:a,_paintStroke:s}=this;if(o&&i){let l=new Oe.TextStyle({fontFamilies:[e.font],fontSize:e.fontSize,heightMultiplier:e.lineHeight,letterSpacing:e.letterSpacing}),c=new Oe.ParagraphStyle({textStyle:l,textAlign:this.getHorizontalAlign(e.horizontalAlign)}),u=Oe.XYWHRect(e.x,e.y,e.width,e.height),p=Oe.ParagraphBuilder.Make(c,o);a&&(t=this.drawTextInner(r,p,l,u,e.verticalAlign,a,!0)),s&&(t=this.drawTextInner(r,p,l,u,e.verticalAlign,s,!1)),p.delete()}return{height:t}}render(){this._surface?.flush()}moveTo(r,e){this._currentPath?.moveTo(r,e)}lineTo(r,e){this._currentPath?.lineTo(r,e)}bezierCurveTo(r,e,t,o,i,a){this._currentPath?.cubicTo(r,e,t,o,i,a)}quadraticCurveTo(r,e,t,o){this._currentPath?.quadTo(r,e,t,o)}setTransform(r,e=!1){if(!this.ctx)return;let t=this.ctx.getTotalMatrix(),o=Ee.invert(t);if(o&&this.ctx.concat(o),this.ctx?.scale(this.dpr,this.dpr),this.camera?.enabled&&(this.ctx?.concat(this.camera.worldMatrix),e)){let i=Ee.getScale(this.camera.worldMatrix);this.ctx?.scale(1/i[0],1/i[1])}this.ctx?.concat(r),this.currentTransform=r}transform(r){this.ctx?.concat(r)}setSize(r,e){!this._isSizeDirty&&r===this._width&&e===this._height||(this._isSizeDirty=!1,this._width=r,this._height=e,this.canvas.style.width=r+"px",this.canvas.style.height=e+"px",this.canvas.width=r*this.dpr,this.canvas.height=e*this.dpr,this._surface&&(this._surface=Oe.MakeWebGLCanvasSurface(this.canvas),this.ctx=this._surface?.getCanvas()))}};function iS(n){for(let r=0;r<n.length;r++)if(n[r]!==void 0&&!Number.isFinite(n[r]))return!1;return!0}function sd({r:n,g:r,b:e,a:t}){return Oe.Color4f(n,r,e,t)}var Ol=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.blurRadius=0;this.offset=[0,0];this.spread=0;this.update(e)}update(r){r.color!==void 0&&(this.color=r.color),r.enabled!==void 0&&(this.enabled=r.enabled),r.blurRadius!==void 0&&(this.blurRadius=r.blurRadius),r.offset!==void 0&&(this.offset=r.offset),r.spread!==void 0&&(this.spread=r.spread)}};var Al=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.radius=0;this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.radius!==void 0&&(this.radius=r.radius)}};var ld=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.color!==void 0&&(this.color=r.color)}};var cd=class{constructor(r,e,t){this.uuid=r;this.data=e;this.enabled=!1;this.color=Me.transparent;this.thickness=0;this.mode="inside";this.update(e)}update(r){r.enabled!==void 0&&(this.enabled=r.enabled),r.color!==void 0&&(this.color=r.color),r.thickness!==void 0&&(this.thickness=r.thickness),r.mode!==void 0&&(this.mode=r.mode)}};var ar=class extends qo{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.autoClose=!0;this.fill=new ld(e+"-fill",t.fill,o),this.stroke=new cd(e+"-stroke",t.stroke,o),this.dropShadow=new Ol(e+"-dropShadow",t.dropShadow,o),this.innerShadow=new Ol(e+"-innerShadow",t.innerShadow,o),this.backgroundBlur=new Al(e+"-backgroundBlur",t.backgroundBlur,o),this.layerBlur=new Al(e+"-layerBlur",t.layerBlur,o)}applyFillStroke(e){e.fillColor=this.fill.enabled?this.fill.color:Me.transparent,e.strokeColor=this.stroke.enabled&&this.stroke.thickness>0?this.stroke.color:Me.transparent,e.strokeMode=this.stroke.mode,e.lineWidth=this.stroke.thickness}applyFilters(e){this.layerBlur.enabled?e.layerBlur=this.layerBlur.radius*5:e.layerBlur=0,this.backgroundBlur.enabled?e.backgroundBlur=this.backgroundBlur.radius*5:e.backgroundBlur=0,this.dropShadow.enabled?(e.dropShadowBlur=this.dropShadow.blurRadius*5,e.dropShadowColor=this.dropShadow.color,e.dropShadowOffsetX=this.dropShadow.offset[0],e.dropShadowOffsetY=this.dropShadow.offset[1]):e.dropShadowColor=Me.transparent,this.innerShadow.enabled?(e.innerShadowSpread=this.innerShadow.spread,e.innerShadowBlur=this.innerShadow.blurRadius*5,e.innerShadowColor=this.innerShadow.color,e.innerShadowOffsetX=this.innerShadow.offset[0],e.innerShadowOffsetY=this.innerShadow.offset[1]):e.innerShadowColor=Me.transparent}innerDraw(e){}draw(e){!this.visible||(e.save(),this.applyTransforms(e),this.applyFilters(e),this.applyFillStroke(e),e.beginPath(),this.innerDraw(e),this.autoClose&&e.closePath(),this.fill.enabled&&e.fill(),this.stroke.enabled&&e.stroke(),e.restore())}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.type===0&&(Re(e.path,["fill"])?this.fill.update(e.props):Re(e.path,["stroke"])?this.stroke.update(e.props):Re(e.path,["dropShadow"])?this.dropShadow.update(e.props):Re(e.path,["innerShadow"])?this.innerShadow.update(e.props):Re(e.path,["layerBlur"])?this.layerBlur.update(e.props):Re(e.path,["backgroundBlur"])?this.backgroundBlur.update(e.props):this.resetBBoxNeedsUpdate())}updateState(e,t){super.updateState(e,t),e.fill!==void 0&&this.fill.update(e.fill),e.stroke!==void 0&&this.stroke.update(e.stroke),e.dropShadow!==void 0&&this.dropShadow.update(e.dropShadow),e.innerShadow!==void 0&&this.innerShadow.update(e.innerShadow),e.layerBlur!==void 0&&this.layerBlur.update(e.layerBlur),e.backgroundBlur!==void 0&&this.backgroundBlur.update(e.backgroundBlur)}clone(e){let t=new ar(this.uuid,this.data,e);return t.parent=void 0,t}};var En=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.width=0;this.height=0;this.updateState(t,o)}innerDraw(e){e.ellipse(this.width*.5,this.height*.5,this.width*.5,this.height*.5,0,0,Math.PI*2)}intersectsInLocalSpace(e,t){return Kv(e,t,this.width*.5,this.height*.5,this.width*.5,this.height*.5)}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e)}clone(e){let t=new En(this.uuid,this.data,e);return t.parent=void 0,t}};var xo=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.width=0;this.height=0;this.cornerRadius=[0,0,0,0];this.updateState(t,o)}innerDraw(e){e.rect(0,0,this.width,this.height,...this.cornerRadius)}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateCornerState(e){e.cornerRadius!==void 0&&(this.cornerRadius=e.cornerRadius)}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateCornerState(e)}clone(e){let t=new xo(this.uuid,this.data,e);return t.parent=void 0,t}};var Nn=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this._textHeight=0;this._textHeightDirty=!0;this.width=0;this.height=0;this.updateState(t,o)}get textHeight(){return this._textHeight}applyFillStroke(e){e.fillColor=this.fill.enabled?this.fill.color:Me.transparent,e.strokeColor=this.stroke.enabled&&this.stroke.thickness>0?this.stroke.color:Me.transparent,e.strokeMode="center",e.lineWidth=this.stroke.thickness}innerDraw(e){this._fontHolder?.arrayBuffer&&this._fontHolder.arrayBuffer.byteLength>1&&this.data.font&&e.registerFont(this._fontHolder.arrayBuffer,this.data.font);let t=this.data.textTransform,o=this.data.text.textValue.toString(),i=t===2?o.toUpperCase():t===3?o.toLowerCase():o,{height:a}=e.drawText(i,{x:0,y:0,width:this.width,height:this.height,fontSize:this.data.fontSize,lineHeight:this.data.lineHeight??1,letterSpacing:this.data.letterSpacing??0,horizontalAlign:this.data.horizontalAlign,verticalAlign:this.data.verticalAlign,font:this.data.font});this._textHeight=a}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateFontState(e,{shared:t}){e.font!==void 0&&(this._fontHolder=t.getFont(e.font),this._fontHolder&&!this._fontHolder.isLoaded&&this._fontHolder.loadingPromise.then(()=>{this.requestRender()}))}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateFontState(e,t)}clone(e){let t=new Nn(this.uuid,this.data,e);return t.parent=void 0,t}};var ds=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this.curves=[];this.extremasBBox={min:[0,0],max:[0,0]};this.updateState(t,o)}computeExtremas(){this.curves.length===0&&this.computeCurves();let e=this.curves.map(i=>ud.extremas(i)),t=[1/0,1/0],o=[-1/0,-1/0];for(let i=0,a=e.length;i<a;i++){let s=e[i];s[0][0]<t[0]&&(t[0]=s[0][0]),s[0][1]<t[1]&&(t[1]=s[0][1]),s[1][0]>o[0]&&(o[0]=s[1][0]),s[1][1]>o[1]&&(o[1]=s[1][1])}return this.extremasBBox.min=[t[0],t[1]],this.extremasBBox.max=[o[0],o[1]],this.extremasBBox}computeCurves(){this.curves=[];for(let o=1,i=this.data.points.length;o<i;o++){let a=this.data.points[o].data,s=this.data.points[o-1].data,l={start:s.position,cp1:s.controlNext.position,cp2:a.controlPrevious.position,end:a.position};this.curves.push(l)}let e=this.data.points[0].data,t=this.data.points[this.data.points.length-1].data;if(this.data.isClosed){let o={start:t.position,cp1:t.controlNext.position,cp2:e.controlPrevious.position,end:e.position};this.curves.push(o)}}getCenter(){let[e,t]=this.extremasBBox.min,[o,i]=this.getHalfSize();return[e+o,t+i]}getHalfSize(){let{min:e,max:t}=this.extremasBBox;return[(t[0]-e[0])*.5,(t[1]-e[1])*.5]}innerDraw(e){for(let i=0,a=this.data.points.length;i<a;i++){let s=this.data.points[i].data;if(i===0){let[l,c]=s.position;e.moveTo(l,c)}else{let l=this.data.points[i-1].data,[c,u]=l.controlNext.position,[p,d]=s.controlPrevious.position,[f,h]=s.position,m={start:l.position,cp1:l.controlNext.position,cp2:s.controlPrevious.position,end:s.position};ud.derive(m),e.bezierCurveTo(c,u,p,d,f,h)}}let t=this.data.points[0].data,o=this.data.points[this.data.points.length-1].data;if(this.data.isClosed){let[i,a]=o.controlNext.position,[s,l]=t.controlPrevious.position,[c,u]=t.position;e.bezierCurveTo(i,a,s,l,c,u)}}updateState(e,t){super.updateState(e,t),this.computeExtremas()}clone(e){let t=new ds(this.uuid,this.data,e);return t.parent=void 0,t}},ud;(i=>{function n(a){let s=a.start,l=a.cp1,c=a.cp2,u=a.end,p=[3*(l[0]-s[0]),3*(l[1]-s[1])],d=[3*(c[0]-l[0]),3*(c[1]-l[1])],f=[3*(u[0]-c[0]),3*(u[1]-c[1])],h={start:p,cp:d,end:f};return a.derivative=h,h.derivative=vh.derive(h),h}i.derive=n;function r(a,s,l,c=!1){let u=a-2*s+l;if(u!==0){let p=-Math.sqrt(Math.abs(s*s-a*l)),d=-a+s,f=-(p+d)/u,h=-(-p+d)/u;return[f,h]}else if(s!==l&&u===0)return[(2*s-l)/(2*(s-l))];return[]}function e(a){let s=a.derivative??i.derive(a),l=s.start,c=s.cp,u=s.end;return[r(l[0],c[0],u[0]),r(l[1],c[1],u[1])]}i.droot=e;function t(a){let[s,l]=i.droot(a),c=[a.start[0],a.end[0]],u=[a.start[1],a.end[1]];for(let p of s)c.push(i.compute(a,Math.min(1,Math.max(0,p)))[0]);for(let p of l)u.push(i.compute(a,Math.min(1,Math.max(0,p)))[1]);return c.sort((p,d)=>p-d),u.sort((p,d)=>p-d),[[c[0],u[0]],[c[c.length-1],u[u.length-1]]]}i.extremas=t;function o(a,s){if(s===0)return[...a.start];if(s===1)return[...a.end];let l=1-s,c=l*l,u=s*s,p=c*l,d=c*s*3,f=l*u*3,h=s*u;return[p*a.start[0]+d*a.cp1[0]+f*a.cp2[0]+h*a.end[0],p*a.start[1]+d*a.cp1[1]+f*a.cp2[1]+h*a.end[1]]}i.compute=o})(ud||(ud={}));var vh;(t=>{function n(o){let i=o.start,a=o.cp,s=o.end,l=[2*(a[0]-i[0]),2*(a[1]-i[1])],c=[2*(s[0]-a[0]),2*(s[1]-a[1])],u={start:l,end:c};return u.derivative=Sh.derive(u),o.derivative=u,u}t.derive=n;function r(o){let i=o.derivative??t.derive(o),a=i.start,s=i.end;return[a[0]!==s[0]?a[0]/(a[0]-s[0]):0,a[1]!==s[1]?a[1]/(a[1]-s[1]):0]}t.droot=r;function e(o,i){if(i===0)return[...o.start];if(i===1)return[...o.end];let a=1-i,s=a*a,l=i*i,c=s,u=a*i*2,p=l;return[c*o.start[0]+u*o.cp[0]+p*o.end[0],c*o.start[1]+u*o.cp[1]+p*o.end[1]]}t.compute=e})(vh||(vh={}));var Sh;(e=>{function n(t){let o=t.start,i=t.end,a=[i[0]-o[0],i[1]-o[1]];return t.derivative=a,t.derivative}e.derive=n;function r(t,o){if(o===0)return[...t.start];if(o===1)return[...t.end];let i=t.start,a=t.end;return[i[0]+(a[0]-i[0])*o,i[1]+(a[1]-i[1])*o]}e.compute=r})(Sh||(Sh={}));var fr=class extends kt{constructor(e,t,o){super(e,t,o);this.uuid=e;this.width=0;this.height=0;this.clipped=!0;this.background=new xo(e+"-background",sa.defaultData,o),this.background.parent=this,this.updateState(t,o)}get fill(){return this.background.fill}get stroke(){return this.background.stroke}get backgroundBlur(){return this.background.backgroundBlur}get layerBlur(){return this.background.layerBlur}get dropShadow(){return this.background.dropShadow}get innerShadow(){return this.background.innerShadow}get cornerRadius(){return this.background.cornerRadius}set cornerRadius(e){this.background.cornerRadius=e}updateLocalMatrix(){super.updateLocalMatrix(),this.background?.updateLocalMatrix()}updateWorldMatrix(e,t,o){super.updateWorldMatrix(e,t,o),this.background?.updateWorldMatrix(e,t,o)}draw(e){if(!this.visible)return;e.save();let t=this.width,o=this.height;this.applyTransforms(e),this.background.width=t,this.background.height=o,this.background.draw(e),this.clipped&&e.clipRect(0,0,t,o,...this.cornerRadius),this.innerDrawChildren(e),e.restore()}getCenter(){return[this.width*.5,this.height*.5]}getHalfSize(){return[this.width*.5,this.height*.5]}updateCornerState(e){e.cornerRadius!==void 0&&(this.cornerRadius=e.cornerRadius)}updateSizeState(e){let t=!1;e.width!==void 0&&(this.width=typeof e.width=="number"?e.width:this.width,t=!0),e.height!==void 0&&(this.height=typeof e.height=="number"?e.height:this.height,t=!0),t&&this.updateWorldMatrix(!0,!1,!0)}updateState(e,t){super.updateState(e,t),this.updateSizeState(e),this.updateCornerState(e),e.fill!==void 0&&this.fill.update(e.fill),e.stroke!==void 0&&this.stroke.update(e.stroke),e.dropShadow!==void 0&&this.dropShadow.update(e.dropShadow),e.innerShadow!==void 0&&this.innerShadow.update(e.innerShadow),e.layerBlur!==void 0&&this.layerBlur.update(e.layerBlur),e.backgroundBlur!==void 0&&this.backgroundBlur.update(e.backgroundBlur),e.clipped!==void 0&&(this.clipped=e.clipped)}requestRender(){super.requestRender(),this.dispatchEvent({type:"render"})}dispose(){this.removeEventListener("render")}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.type===0&&(Re(e.path,["fill"])?this.fill.update(e.props):Re(e.path,["stroke"])?this.stroke.update(e.props):Re(e.path,["dropShadow"])?this.dropShadow.update(e.props):Re(e.path,["innerShadow"])?this.innerShadow.update(e.props):Re(e.path,["layerBlur"])?this.layerBlur.update(e.props):Re(e.path,["backgroundBlur"])?this.backgroundBlur.update(e.props):this.resetBBoxNeedsUpdate())}clone(e){let t=new fr(this.uuid,this.data,e);t.parent=void 0;for(let o of this.children)t.add(o.clone(e));return t}};var uS=xs(wh(),1),$o=class extends ar{constructor(e,t,o){super(e,t,o);this.uuid=e;this.data=t;this._pathBBox=new DOMRect;this.path="";this.updateState(t,o),this.autoClose=!1,this.computeSVGBBox()}computeSVGBBox(){let e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");document.body.appendChild(e),t.setAttribute("d",this.path),e.appendChild(t),this._pathBBox=t.getBBox(),e.remove()}innerDraw(e){e.path(this.path)}intersectsInLocalSpace(e,t){return e>=this._pathBBox.x&&e<=this._pathBBox.x+this._pathBBox.width&&t>=this._pathBBox.y&&t<=this._pathBBox.y+this._pathBBox.height}getCenter(){return[(this._pathBBox.x+this._pathBBox.width)/2,(this._pathBBox.y+this._pathBBox.height)/2]}getHalfSize(){return[(this._pathBBox.x+this._pathBBox.width)/2,(this._pathBBox.y+this._pathBBox.height)/2]}updateState(e,t){super.updateState(e,t),e.path!==void 0&&(this.path=e.path,this.computeSVGBBox())}clone(e){let t=new $o(this.uuid,this.data,e);return t.parent=void 0,t}};function dS(n,r=1,e=1){if(r<=0||e<=0)return n;let o=(0,uS.parseSVG)(n).map(i=>{let a={...i};return"x"in a&&(a.x=a.x*r),"y"in a&&(a.y=a.y*e),"x1"in a&&(a.x1=a.x1*r),"x2"in a&&(a.x2=a.x2*r),"y1"in a&&(a.y1=a.y1*e),"y2"in a&&(a.y2=a.y2*e),"rx"in a&&(a.rx=a.rx*r),"ry"in a&&(a.ry=a.ry*e),a});return pS(o)}function pS(n){let r=["rx","ry","xAxisRotation","largeArc","sweep","x1","y1","x2","y2","x","y"],e;return n.map(t=>{let o=[];r.forEach(a=>{if(a in t){let s=t[a]*1;o.length&&s>=0&&o.push(","),o.push(s)}});let i=(e===t.code?o[0]<0?"":",":t.code)+o.join("");return e=t.code,i}).join("")}function fS(n,r,e){switch(r.type){case"ellipse2d":return new En(n,r,e);case"rectangle2d":return new xo(n,r,e);case"text2d":return new Nn(n,r,e);case"vector2d":return new ds(n,r,e);case"path2d":return new $o(n,r,e);case"frame2d":return new fr(n,r,e);case"group2d":default:return new ir(n,r,e)}}var Ph=class{constructor(r,e,t){this.uuid=r;this.data=e;this.group=new ir(Ph.GROUP_ID,{..._s.defaultData},t),this.createChildrenObjects(e.objects,this.group,t)}createObject(r,e,t,o,i,a){let s=fS(r,e,a);s&&(o.add(s),o.children.splice(i,0,o.children.pop()),s.updateWorldMatrix(),t.length>0&&(s instanceof ir||s instanceof fr)&&this.createChildrenObjects(t,s,a))}createChildrenObjects(r,e,t){let o=0;for(let i of r)this.createObject(i.id,i.data,i.children,e,o,t),o+=1}draw(r){this.group.draw(r)}updateEntityByOp(r,e,t,o){let i=this.find(r);if(i)try{i.updateByOp(e,t,{shared:o})}catch(a){console.error(a)}}updateTreeByOp(r,e){if(r.path.length===0&&r.type===7){let t=r.parent===null?this.group:this.find(r.parent);t!==void 0&&t instanceof kt&&(this.createObject(r.id,r.data,r.children,t,r.localIndex,e),t.requestRender())}else if(r.path.length===0&&r.type===8){let t=this.find(r.id);if(t!==void 0&&t.parent!==void 0&&t.parent instanceof kt){let o=t.parent;t.resetBBoxNeedsUpdate(),o?.remove(t),o?.requestRender()}}else if(r.path.length===0&&r.type===9){let t=this.find(r.id);if(t!==void 0){let o=t.parent,i=r.parent===null?this:this.find(r.parent);if(i===void 0&&!1&&console.error("unexpected",i,r),i instanceof kt||i===this){i.add(t);let a=r.localIndex;i.children.splice(a,0,i.children.pop()),t.updateWorldMatrix(!0,!1,!0),o?.requestRender(),t.requestRender()}t.resetBBoxNeedsUpdate()}}}add(r){this.group.add(r)}remove(r){this.group.remove(r)}traverse(r){this.group.traverse(e=>{e!==this.group&&r(e)})}intersectsChildren(r,e,t,o=!1,i=[]){return this.group.intersectsChildren(r,e,t,o,i,!0)}intersectsChildrenReverse(r,e,t,o=!1,i=[]){return this.group.intersectsChildrenReverse(r,e,t,o,i,!0)}find(r){return this.group.find(r)}get children(){return this.group.children}project(r,e){return this.group.project(r,e)}getWithSortKey(r){let e=this.find(r);if(e===void 0)return;let t=[],o=e;for(;o!==this.group;){let i=o;o=o.parent;let a=o.children.indexOf(i);t.splice(0,0,a)}return{entity:e,sortKey:t}}getAllSorted(r){let e=[];for(let t of r){let o=this.getWithSortKey(t.id);o!==void 0&&e.push(o)}return e.sort((t,o)=>zl(t.sortKey,o.sortKey)),e.map(t=>t.entity)}},hi=Ph;hi.GROUP_ID="scene2d";function Ch({constraints:n,newParentWidth:r,newParentHeight:e,initialParentWidth:t,initialParentHeight:o,objectInitialWidth:i,objectInitialHeight:a,objectInitialPosition:s}){let{horizontalConstraint:l,verticalConstraint:c}=n,u=r-t,p=e-o,d=i,f=a,h=s[0],m=s[1];if(l!==0){if(l===1)h+=u;else if(l===3)h+=u/2;else if(l===2)d=Math.max(1,d+u);else if(l===4){let y=r/t;d*=y,h*=y}}if(c!==0){if(c===1)m+=p;else if(c===3)m+=p/2;else if(c===2)f=Math.max(1,f+p);else if(c===4){let y=e/o;f*=y,m*=y}}return{width:d,height:f,position:[h,m]}}var UD=xs(wh(),1);var Mce={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:72/6,pc:1,px:-1},px:{mm:1,px:1,cm:1,in:1,pt:1,pc:1}};import{BufferGeometry as HD,CanvasTexture as WD,Float32BufferAttribute as hS,HalfFloatType as qD,MathUtils as $D,Mesh as YD,OrthographicCamera as XD,ShaderMaterial as KD,Uniform as QD,WebGLRenderTarget as ZD}from"three";var JD=`
2923
2956
  varying vec2 vUv;
2924
2957
  void main() {
2925
2958
  vUv = uv;
2926
2959
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
2927
- }`,t_=`
2960
+ }`,e_=`
2928
2961
  uniform sampler2D tDiffuse;
2929
2962
  varying vec2 vUv;
2930
2963
  void main() {
2931
2964
  vec4 texel = texture2D( tDiffuse, vUv );
2932
2965
  gl_FragColor = texel;
2933
- }`,r_=new K3(-1,1,1,-1,0,1),Mh=class extends W3{constructor(){super(),this.setAttribute("position",new yS([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new yS([0,2,0,0,2,0],2))}},o_=new Mh,Eh=class{constructor(r){this._mesh=new X3(o_,r)}dispose(){this._mesh.geometry.dispose()}render(r){r.render(this._mesh,r_)}get material(){return this._mesh.material}set material(r){this._mesh.material=r}},gS=new Q3({defines:{},uniforms:{tDiffuse:new Z3(null)},vertexShader:e_,fragmentShader:t_}),n_=new Eh(gS),Th=null,Ih=null,i_=()=>(Th===null&&(Th=document.createElement("canvas")),Th),a_=n=>(Ih===null&&(Ih=new Tl(n)),Ih),s_=Ee.identity(),hs=class{constructor(r,e,t,o){this.uuid=r;this.width=e;this.height=t;this.context=o;this.enabled=!0;this.isScreenSpace=!1;this.dpr=window.devicePixelRatio;this.isFrameDirty=!1;this.onRenderRequestedDownstream=()=>{this.isFrameDirty=!0,this.context.shared.requestRender()};this._innerApplySize=()=>{let r=this.width,e=this.height,t=this.dpr;this.renderer.dpr=this.isScreenSpace?t:Math.floor(2048/Math.max(r,e)),this.renderer.setSize(r,e)};this.onFrameOverrideObjectEvent=r=>{if(r.target?.uuid!==void 0){let e=this.frameRoot?.find(r.target.uuid);e&&e.dispatchEvent({...r,target:e})}};this.scene2d=new mi(Y3.generateUUID(),tu.defaultData,{dpr:window.devicePixelRatio,shared:o.shared}),this.canvas=i_(),this.renderer=a_(this.canvas),this.promise=this.init(),this.renderTarget=new J3(1,1,{type:$3,stencilBuffer:!1,depthBuffer:!1}),o.shared.addUIBuffer(this.uuid,this.renderTarget),this.textureHolder=o.shared.uiBuffer(this.uuid)}get canvasTexture(){return this._canvasTexture||(this._canvasTexture=new q3(this.canvas)),this._canvasTexture}async init(){this.renderer instanceof Tl&&(this.renderer.wasmURL=Rb.skiaWasmUrl),await this.renderer.init()}render(r){if(this.isFrameDirty){this.isFrameDirty=!1,this._innerApplySize(),this.renderer.clear(),this.frameOverride?.draw(this.renderer),this.renderer.render(),gS.uniforms.tDiffuse.value=this.canvasTexture,this.canvasTexture.needsUpdate=!0;let e=r.getRenderTarget();r.setRenderTarget(this.renderTarget),r.clear(),n_.render(r),r.setRenderTarget(e),this.textureHolder?.setNeedsUpdate(!0)}}updateEntity2DByOp(r,e,t,o){this.scene2d.updateEntityByOp(r,e,t,o),this.applySize()}updateTreeByOp(r,e){this.scene2d.updateTreeByOp(r,e),this.applySize()}applyOverrides(r){if(this.frameOverride&&this.frameRoot){this.frameOverride.position=[0,0],this.frameOverride.rotation=0;let e=r?.width??this.width,t=r?.height??this.height;this.frameOverride.width=e,this.frameOverride.height=t,this.frameOverride.localMatrix=s_,this.isScreenSpace&&(this.frameOverride.fill.color=Me.from0to1([0,0,0,0])),this.frameOverride.data={...this.frameOverride.data,width:e,height:t},xS({objectOverride:this.frameOverride,objectRoot:this.frameRoot,newParentWidth:this.frameOverride.width,newParentHeight:this.frameOverride.height,initialParentWidth:this.frameRoot.width,initialParentHeight:this.frameRoot.height}),this.frameOverride.updateWorldMatrix(!0,!1,!0)}}applySize(r,e=window.devicePixelRatio){let t=Math.max(1,r?.width??this.width),o=Math.max(1,r?.height??this.height);this.dpr=e,this.width=t,this.height=o,this._innerApplySize();let i=1,a=512,s=512;(t*e<a||o*e<s)&&(i=Math.max(a/(t*e),s/(o*e))),this.renderTarget.setSize(t*e*i,o*e*i),this._canvasTexture?.dispose(),this._canvasTexture=void 0,this.applyOverrides(r),this.frameOverride?.requestRender()}applyFrame(r){let e=this.context.scene.find2D(r);if(!(!e||!(e instanceof fr)))return this.disposeFrameOverride(),this.frameRoot=e,this.frameOverride=e.clone({dpr:this.renderer.dpr,shared:this.context.shared}),this.scene2d.add(this.frameOverride),this.applySize(),this.frame?.addEventListener("render",this.onRenderRequestedDownstream),this.frameOverride.traverse(t=>{t.addEventListener("beginState",this.onFrameOverrideObjectEvent)}),this.frameOverride.traverse(t=>{t.addEventListener("completeState",this.onFrameOverrideObjectEvent)}),this.frame?.requestRender(),e}get frame(){return this.frameOverride}get frameId(){return this.frame?.uuid}find(r){return this.scene2d.find(r)}get texture(){return this.textureHolder?.getTexture(1001)}disposeFrameOverride(){this.frameOverride?.removeEventListener("render",this.onRenderRequestedDownstream),this.frameOverride?.traverse(r=>{r.removeEventListener("beginStateChange",this.onFrameOverrideObjectEvent)}),this.frameOverride?.traverse(r=>{r.removeEventListener("completeState",this.onFrameOverrideObjectEvent)}),this.frameOverride&&this.scene2d.remove(this.frameOverride)}};function xS({objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i}){if(n instanceof fr&&r instanceof fr||n instanceof ir&&r instanceof ir)for(let a=0,s=n.children.length;a<s;a++){let l=n.children[a],c=r.children[a];l&&c&&l.uuid===c.uuid&&c_({objectOverride:l,objectRoot:c,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i})}}function l_(n){if(Nh(n))return[n.width,n.height];if(n instanceof Yo){let[r,e]=n.getHalfSize();return[r*2,e*2]}else if(n instanceof ir){let[r,e]=n.recursiveBBox.getHalfSize();return[r*2,e*2]}return[0,0]}function c_({objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i}){let[a,s]=l_(r),{width:l,height:c,position:u}=Ah({constraints:n.data,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i,objectInitialWidth:a,objectInitialHeight:s,objectInitialPosition:r.position});if(n.position=u,n.data={...n.data,position:u},n.states)for(let p in n.states)u_({stateId:p,objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i});if(Nh(n)||n instanceof ir)Nh(n)&&(n.width=l,n.height=c,n.data={...n.data,width:l,height:c}),xS({objectOverride:n,objectRoot:r,newParentWidth:l,newParentHeight:c,initialParentWidth:a,initialParentHeight:s});else if(n instanceof Yo){let p=r,d=a!==0?l/a:1,h=s!==0?c/s:1;n.path=fS(p.path,d,h),n.data={...n.data,path:n.path}}}function u_({stateId:n,objectOverride:r,objectRoot:e,newParentWidth:t,newParentHeight:o,initialParentWidth:i,initialParentHeight:a}){let s=r.states?.[n],l=e.states?.[n];if(s&&l){let{width:c,height:u,position:p}=Ah({constraints:r.data,newParentWidth:t,newParentHeight:o,initialParentWidth:i,initialParentHeight:a,objectInitialWidth:Do.isResizeable(l)?l.width:0,objectInitialHeight:Do.isResizeable(l)?l.height:0,objectInitialPosition:l.position});Object.assign(r.states[n],{position:p}),Do.isResizeable(s)&&Object.assign(r.states[n],{width:c,height:u})}}function Nh(n){return n instanceof xo||n instanceof fr||n instanceof Nn||n instanceof Dn}var Tr=class extends fa(h_){constructor(e,t,o){super();this.data=t;this.bgColor=new At(1,1,1,1);this.fog=null;this.backupFog=new p_(16777215,.1,2e3);this.fogUseBGColor=!1;this.isActive=!1;this.aoColor=new d_;this.penumbraSizeArrayCache=null;this.super_Entity(e,t),this.personalCamera=new qo(cn,{...$n.defaultData,...t.camera,name:"Personal Camera"}),this.personalCamera.objectHelper.visible=!1,this.add(this.personalCamera),this.activeCamera=this.personalCamera,this.ambientLight=new f_(13882323,8553090,.75),this.ambientLight.name="Default Ambient Light",this.ambientLight.layers.enable(3),this.ambientLight.removeFromParent(),this.add(this.ambientLight),t.uiScene?this.uiScene=new mi((Array.isArray(e)?e[0]:e)+"-ui",t.uiScene,{dpr:window.devicePixelRatio,shared:o.shared}):t.uiFrame&&this.createUICanvas(t.uiFrame,o)}get scene(){return this.parent}get postprocessing(){return this.data.postprocessing}get frameId(){return this.data.uiFrame}get frame(){return this.uiCanvas?.frame}createUICanvas(e,t){this.uiCanvas=new hs(this.uuid+"-uiscreen",window.innerWidth,window.innerHeight,t),this.uiCanvas.isScreenSpace=!0,this.uiCanvas.promise.then(()=>{this.uiCanvas?.applyFrame(e),this.uiCanvas?.applySize()})}updateVisible(){}setBackgroundColor(e){this.bgColor=e,this.fogUseBGColor===!0&&(this.backupFog.color=e)}entityChildrenCount(){return this.uiScene?this.uiScene.children.length:super.entityChildrenCount()}updateAmbientLight(e,t){e.color!==void 0&&(this.ambientLight.color=jt(e.color,t)),e.intensity!==void 0&&(this.ambientLight.intensity=e.intensity),e.enabled!==void 0&&(e.enabled?this.add(this.ambientLight):this.remove(this.ambientLight))}onDeactive(){this.isActive=!1}onActive(e){this.isActive=!0,e.fog=this.fog,this.traverseEntity(t=>{t instanceof nr&&t.recomputeBoolean()}),this.updateShadow(this.data.shadow)}forceMaterialsUpdate(){this.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t of e.material)t.needsUpdate=!0;else e.material.needsUpdate=!0,e.material.dispose()})}updateShadow(e){e.softShadowQuality!==void 0&&this.isActive&&kv(e.softShadowQuality)&&this.forceMaterialsUpdate()}updateFog(e,t){if(e.enabled?this.fog=this.backupFog:this.fog=null,this.isActive){let o=this.scene;o.fog=this.fog}this.fogUseBGColor=e.useBackgroundColor,e.useBackgroundColor?this.backupFog.color.set(this.bgColor):this.backupFog.color=jt(e.color,t),this.backupFog.near=e.near,this.backupFog.far=e.far}updateAo(e,t){e.aoColor!==void 0&&(this.aoColor=jt(e.aoColor,t))}updateByOp(e,t,o,i){let a=this.data.uiFrame;super.updateByOp(e,t,o,i);let s=t;Re(e.path,["fog"])?this.updateFog(s.fog,o.shared):Re(e.path,["ao"])?this.updateAo(s.ao,o.shared):Re(e.path,["ambient"])?this.updateAmbientLight(s.ambient,o.shared):Re(e.path,["shadow"])?this.updateShadow(s.shadow):e.type===0&&e.path.length===0&&(e.props.uiFrame!==void 0||a!==s.uiFrame)&&this.updateUIFrame(e.props.uiFrame,o)}updateUIFrame(e,t){e?(this.uiCanvas||this.createUICanvas(e,t),this.uiCanvas.enabled=!0,this.uiCanvas.applyFrame(e)):this.uiCanvas&&(this.uiCanvas.enabled=!1)}updateState(e,t){this.updateState_Entity(e,t),e.backgroundColor!==void 0&&this.setBackgroundColor(jt(e.backgroundColor,t.shared)),e.fog!==void 0&&this.updateFog(e.fog,t.shared),e.ambient!==void 0&&this.updateAmbientLight(e.ambient,t.shared),e.ao!==void 0&&this.updateAo(e.ao,t.shared),e.shadow!==void 0&&this.updateShadow(e.shadow)}createFrame(e,t){}raycast(e,t){super.raycast(e,t)}switchActiveCamera(e){e&&e.isDescendantOf(this)&&(this.activeCamera!==this.personalCamera&&(this.activeCamera.objectHelper.visible=!0),this.activeCamera=e,e.objectHelper.visible=!1)}get playCamera(){return this.scene?.find(this.data.publish.playCamera)??this.personalCamera}switchToPlayCamera(){this.switchActiveCamera(this.playCamera)}get penumbraSizeArray(){return this.penumbraSizeArrayCache===null&&this.updatePenumbraSizeArray(),this.penumbraSizeArrayCache}updatePenumbraSizeArray(){this.penumbraSizeArrayCache=new Array(5).fill(.5);let e=0,t=0;this.traverseEntity(o=>{if(!o.visible)return!0;o instanceof ds&&o.visible&&e<3&&(this.penumbraSizeArrayCache[e]=o.data.penumbraSize??.5,e+=1),o instanceof ps&&o.visible&&e<5-3&&(this.penumbraSizeArrayCache[3+t]=o.data.penumbraSize??.5,t+=1)})}raycastWithClones(e){let t=[],o=i=>{for(let a of i.children){let s=a.cloner;Le.is(a)&&(a.visible||s?.object.data.visible)&&((In(a)||Pl(a)&&this.scene.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),El(a,e,t,!0)),o(a))}};return o(this),t}updateEntity2DByOp(e,t,o,i){this.uiCanvas?.updateEntity2DByOp(e,t,o,i)}};import{PointLight as m_,Vector3 as md,Box3 as y_,Box3Helper as bS,Color as g_}from"three";var yd=class extends ls(m_,us){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=1024,this.shadow.mapSize.height=1024,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.fov=90,i.aspect=1,i.near=100,i.far=2500;let a=new md(-i.far+this.position.x,-i.far+this.position.y,-i.far+this.position.z),s=new md(i.far+this.position.x,i.far+this.position.y,i.far+this.position.z),l=new y_(a,s),c=new bS(l,new g_(16755200));c.visible=!1,this.gizmos.shadowmap=c,this.update()}update(){if(this.shadow&&(this.shadow.camera.updateProjectionMatrix(),this.gizmos))for(let r in this.gizmos){let e=this.gizmos[r];if(e instanceof bS){let t=this.shadow.camera,o=new md(-t.far+this.position.x,-t.far+this.position.y,-t.far+this.position.z),i=new md(t.far+this.position.x,t.far+this.position.y,t.far+this.position.z);e.box.set(o,i),e.updateMatrixWorld(!0)}}}updateMatrixWorld(r){super.updateMatrixWorld(r),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e),r.distance!==void 0&&(this.distance=r.distance),r.decay!==void 0&&(this.decay=r.decay),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null))}};var gd=class extends lt{get forceComputeSize(){return!0}get shape(){return this.geometry.userData.shape}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?rl(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};var ms=class extends lt{constructor(e,t,o){super(e,t,o);this._shapeId=null;this._context=o}updateState(e,t){super.updateState(e,t),this.updateShape()}updateShape(){let e={...this.data.geometry.extrusion.shape};for(let i in e)typeof e[i]=="string"&&(e[i]=this._context.shared.getVariable(e[i],[this.uuid,"geometry","extrusion","shape",i]));let t;if(e.type==="Custom"){let i=e.shapeId;if(i!==this._shapeId&&this.detachShape(),i){this._shapeId=i;let a=this._context.scene.find(i);a?.data&&(a.attachedPaths.add(this),t=a.geometry.userData?.shape),t||this._context.scene.addPendingCommand(()=>this.updateShape())}}else{let i;switch(e.type){case"Rectangle":i=Oa;break;case"Ellipse":i=Sa;break;case"Polygon":i=Cu;break;case"Star":i=Ou;break;default:throw new Error(`Unknown shape type: ${e.type}`)}t=i.create({parameters:e}).userData.shape}let o=this.geometry;t&&o.inputs&&(o.inputs.shapeData=t,o.build(),this.attachedSurfaceCloners.forEach(i=>i.update()))}detachShape(){this._shapeId!==null&&this._context.scene.find(this._shapeId)?.attachedPaths.delete(this)}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.updateShape(),this.refreshAttachedPaths(e)}updateTransformState(e,t){return super.updateTransformState(e,t)}updateGeometryInteractions(e,t){super.updateGeometryInteractions(e,t),this.updateShape()}updateEntityBoxSize(e,t){let o=this.geometry.getAttribute("position");o!==void 0?rl(o,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:o.count,e,t):super.updateEntityBoxSize(e,t)}};var xd=class extends An{constructor(e,t,o){super(e,t,o);this.data=t}};import{Group as x_,Matrix4 as b_,Skeleton as v_}from"three";var Xo=class extends Or(x_,Ar){constructor(e,t,o){super();t.type==="Instance"&&typeof e=="string"&&(t=this.transformAssignData(t,o)),this.super_Entity(e,t),this.objectHelper.update()}get isComponentRoot(){return this.data.type==="Component"&&typeof this.identity=="string"}get isInstanceRoot(){return this.data.type==="Instance"&&typeof this.identity=="string"}transformAssignData(e,t){let o=na.getComponentData({scene:t.scene.data,shared:t.shared.data},e.component);if(o){let i,a;for(let s of ro.rootOverrideProps)e[s]===void 0?(i===void 0&&(i={...e}),i[s]=o.data[s]):(a===void 0&&(a={}),a[s]=e[s],i===void 0&&(i={...e}),i[s]=Kr.apply(o.data[s],e[s]));return this.overrideData=a,i}else return{...bt.defaultData,...e,...Er(bt.defaultData,ro.rootOverrideProps)}}updateByOp(e,t,o,i){let a;if(this.isInstanceRoot&&!i){if(t=this.transformAssignData(t,o),e.type===0&&e.path.length===0&&this.component)for(let s of ro.rootOverrideProps)s in e.props&&e.props[s]===void 0&&(a===void 0&&(a={...e,props:{...e.props}}),a.props[s]=this.component.data[s]);else if(e.type===0&&e.path.length>0&&ro.rootOverrideProps.includes(e.path[0])){let s=e.path[0];a===void 0&&(a={...e,path:[],props:{[s]:t[s]}})}}super.updateByOp(a??e,t,o,i)}updateState(e,t){this.updateState_Entity(e,t)}expandInstanceChildren(e){let t=this.data;if(this.component===void 0){let o=e.scene.find(t.component)??null,i=!1;if(o!==this.oldComponent){if(this.oldComponent){let a=0;for(let s of this.children)if(Le.is(s))e.scene.disposeAndUnregisterEntityRecursivelyIfNotReregistered(s),bd(s),a+=1;else break;this.children.splice(0,a)}i=!0}if(o){let a={};SS(e,[this.uuid],t.overrides,this,o,o,0,i,a);for(let s of this.children)if(Le.is(s)){let l=s.data;l.type==="Empty"&&l.animations&&s.traverseEntity(c=>{let u=c.dataPatched;if(c instanceof lt&&u.bones&&u.boneInverses){let p=c.dataPatched;if(p.bones&&p.boneInverses){let d=p.bones.map(m=>e.scene.find(a[m])),h=p.boneInverses.map(m=>new b_().fromArray(m)),f=new v_(d,h);c.bind(f,c.bindMatrix)}}else c.matrixAutoUpdate=!0})}}this.oldComponent=this.component}}};function bd(n){if(n.component){let r=n.component.instances.indexOf(n);r>=0&&n.component.instances.splice(r,1);for(let e of n.children)Le.is(e)&&bd(e)}}function vS(n,r,e,t){return n.component===r&&Xd(n.identity,t)?n.overrideData===e?2:1:0}function SS(n,r,e,t,o,i,a,s,l){if(a>50)return!1;if(t.component!==o){if(t.component){let u=t.component.instances.indexOf(t);u>=0&&t.component.instances.splice(u,1)}o.instances.find(u=>u===t)||o.instances.push(t),t.component=o}o instanceof Xo&&o.isInstanceRoot&&o.expandInstanceChildren(n);let c=0;for(let u of o.children)if(Le.is(u)){let p=[...r,...typeof u.identity=="string"?[u.identity]:u.identity],d=ra.resolve(e,p,1);if(d!=null&&!(d instanceof Qe)){if(!1)debugger;Object.setPrototypeOf(d,Qe.prototype),console.error("wrong prototype")}let h=null,f;if(!s){let m=t.children[c];if(h=Le.is(m)?m:null,h!==null){let y=vS(h,u,d,p);f=y>=1?h.stateSelection:void 0,y!==2&&(h=null)}if(h===null&&(h=n.scene.findInstance(p)??null,h!==null)){let y=vS(h,u,d,p);if(f=y>=1?h.stateSelection:void 0,y!==2)h=null;else{let g=h.parent.children.indexOf(h);h.parent.children.splice(g,1),t.children.splice(c,0,h),h.parent===t?(g<=c&&console.error("not possible"),void 0):(h.parent=t,h.matrixWorldNeedsUpdate=!0,h.resetBBoxNeedsUpdate(),h.updateVisible(),n.pendingDeletes.delete(h),void 0)}}}if(h===null){let m=d?Kr.apply(u.data,d):u.data;Nr.is(m.type)&&(m={...m,type:"Empty"}),h=Rr.createEntity(p,m,n),h.overrideData=d,t.add(h),t.children.splice(t.children.length-1,1),t.children.splice(c,0,h),h.updateState(h.data,n),f&&h.changeSelectedState(f,n),n.scene.registerInstanceAndSetUuid(h)}if(h.isBone){let m=h.identity[h.identity.length-1];l[m]=h.uuid}c+=1,SS(n,r,e,h,u,i,a+1,s,l)}if(!s){let u=c;for(;;){let p=t.children[c];if(Le.is(p))n.pendingDeletes.add(p);else break;c+=1}t.children.splice(u,c-u)}return!0}import{Bone as S_}from"three";var vd=class extends Or(S_,Ar){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update(),this.matrixAutoUpdate=!0}updateState(r,e){this.updateState_Entity(r,e)}};var yi=class extends lt{constructor(e,t,o){super(e,t,o);this.onBeforeRender=e=>{this.uiCanvas.render(e)};this.uiCanvas=new hs(e+"-canvas",t.geometry.width,t.geometry.height,o),this.uiCanvas.promise.then(()=>{this.applyFrame(this.dataPatched.geometry.frame,o.shared)})}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),e.type===0&&(e.props.frame!==void 0&&this.applyFrame(e.props.frame,o.shared),(e.props.width!==void 0||e.props.height!==void 0)&&this.applySize(e.props,o.shared))}applySize(e,t){let o=e?.width??this.dataPatched.geometry.width,i=e?.height??this.dataPatched.geometry.height;this.uiCanvas.applySize({width:o,height:i}),this.applyGeometryParametersFromFrame(t)}applyFrame(e,t){this.uiCanvas.applyFrame(e),this.applyGeometryParametersFromFrame(t),this.applyMaterialParametersFromFrame({shared:t})}applyGeometryParametersFromFrame(e){let t=this.frame;t&&(Object.assign(this.data,{geometry:Object.assign(this.data.geometry,{cornerRadius:t.cornerRadius,cornerType:0})}),Object.assign(this.dataPatched,{geometry:Object.assign(this.dataPatched.geometry,{cornerRadius:t.cornerRadius,cornerType:0})}),this.localGeometry?.dispose(),this.localGeometry=Vo(this.dataPatched.geometry,e,this.data.flatShading,this))}applyMaterialParametersFromFrame(e){let t=this.frame;if(t){let o=t.data.backgroundBlur;Object.assign(this.data.material.layers[0].data.texture,{image:this.uiCanvas.uuid}),Object.assign(this.data.material.layers[1].data,{roughness:o.radius,alpha:o.enabled?1:0}),Object.assign(this.dataPatched.material.layers[0].data.texture,{image:this.uiCanvas.uuid}),Object.assign(this.dataPatched.material.layers[1].data,{roughness:o.radius,alpha:o.enabled?1:0}),this.material.reset(this.dataPatched.material,e,!0)}}updateEntity2DByOp(e,t,o,i){this.uiCanvas.updateEntity2DByOp(e,t,o,i),e===this.frameId&&t.type===0&&(t.props.cornerRadius!==void 0?this.applyGeometryParametersFromFrame(i):Re(t.path,["backgroundBlur"])&&this.applyMaterialParametersFromFrame({shared:i}))}get frame(){return this.uiCanvas.frame}get frameId(){return this.frame?.uuid}removeInteractionGeometry(e){super.removeInteractionGeometry(e),this.applySize({},e)}updateGeometryInteractions(e,t){super.updateGeometryInteractions(e,t),this.applySize({width:e.width,height:e.height},t)}};import{Object3D as D_,Vector3 as Ir,InstancedMesh as __,InstancedBufferAttribute as B_,PlaneGeometry as R_,Vector4 as Nl,Quaternion as kS,TextureLoader as L_,Texture as US,Euler as V_,MathUtils as zh}from"three";import{GPUComputationRenderer as z_}from"three/examples/jsm/misc/GPUComputationRenderer.js";import{Vector3 as wS,FloatType as Dh,DataTexture as _h,RGBAFormat as Bh,Mesh as w_,Euler as bde,Matrix4 as vde}from"three";import{MeshSurfaceSampler as P_}from"three/examples/jsm/math/MeshSurfaceSampler.js";function PS(n){let r=new Float32Array(n*n*2);for(let e=0;e<n;e++)for(let t=0;t<n;t++){let o=e*n+t;r[o*2+0]=e/(n-1),r[o*2+1]=t/(n-1)}return r}function CS(n){let r=Math.ceil(Math.sqrt(n));return Math.max(r,1)}function OS(n,r){let e=new w_(n.geometry,n.material),t=[],o=[],i=new wS,a=new wS;e.geometry.index!==null&&(e.geometry=e.geometry.toNonIndexed());let s=new P_(e).build();for(let u=0;u<r;u++)s.sample(i,a),t.push(i.x,i.y,i.z),o.push(a.x,a.y,a.z);let l=new Float32Array(t),c=new Float32Array(o);return{positions:l,normals:c}}function Rh(n,r){let e=n,t=new Float32Array(4*r*r);for(let i=0;i<r*r;i++)t[4*i]=e[3*i],t[4*i+1]=e[3*i+1],t[4*i+2]=e[3*i+2],t[4*i+3]=0;let o=new _h(t,r,r,Bh,Dh);return o.needsUpdate=!0,o}function AS({size:n}){let r=new Float32Array(4*n*n);for(let t=0;t<n*n;t++)r[4*t]=t,r[4*t+1]=0,r[4*t+2]=0,r[4*t+3]=0;let e=new _h(r,n,n,Bh,Dh);return e.needsUpdate=!0,e}function TS(n){let r=new Float32Array(4*n*n);for(let t=0;t<n*n;t++)r[4*t]=0,r[4*t+1]=0,r[4*t+2]=0,r[4*t+3]=0;let e=new _h(r,n,n,Bh,Dh);return e.needsUpdate=!0,e}var IS=`
2966
+ }`,t_=new XD(-1,1,1,-1,0,1),Th=class extends HD{constructor(){super(),this.setAttribute("position",new hS([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new hS([0,2,0,0,2,0],2))}},r_=new Th,Ih=class{constructor(r){this._mesh=new YD(r_,r)}dispose(){this._mesh.geometry.dispose()}render(r){r.render(this._mesh,t_)}get material(){return this._mesh.material}set material(r){this._mesh.material=r}},mS=new KD({defines:{},uniforms:{tDiffuse:new QD(null)},vertexShader:JD,fragmentShader:e_}),o_=new Ih(mS),Oh=null,Ah=null,n_=()=>(Oh===null&&(Oh=document.createElement("canvas")),Oh),i_=n=>(Ah===null&&(Ah=new Cl(n)),Ah),a_=Ee.identity(),ps=class{constructor(r,e,t,o){this.uuid=r;this.width=e;this.height=t;this.context=o;this.enabled=!0;this.isScreenSpace=!1;this.dpr=window.devicePixelRatio;this.isFrameDirty=!1;this.onRenderRequestedDownstream=()=>{this.isFrameDirty=!0,this.context.shared.requestRender()};this._innerApplySize=()=>{let r=this.width,e=this.height,t=this.dpr;this.renderer.dpr=this.isScreenSpace?t:Math.floor(2048/Math.max(r,e)),this.renderer.setSize(r,e)};this.onFrameOverrideObjectEvent=r=>{if(r.target?.uuid!==void 0){let e=this.frameRoot?.find(r.target.uuid);e&&e.dispatchEvent({...r,target:e})}};this.scene2d=new hi($D.generateUUID(),Zc.defaultData,{dpr:window.devicePixelRatio,shared:o.shared}),this.canvas=n_(),this.renderer=i_(this.canvas),this.promise=this.init(),this.renderTarget=new ZD(1,1,{type:qD,stencilBuffer:!1,depthBuffer:!1}),o.shared.addUIBuffer(this.uuid,this.renderTarget),this.textureHolder=o.shared.uiBuffer(this.uuid)}get canvasTexture(){return this._canvasTexture||(this._canvasTexture=new WD(this.canvas)),this._canvasTexture}async init(){this.renderer instanceof Cl&&(this.renderer.wasmURL=Bb.skiaWasmUrl),await this.renderer.init()}render(r){if(this.isFrameDirty){this.isFrameDirty=!1,this._innerApplySize(),this.renderer.clear(),this.frameOverride?.draw(this.renderer),this.renderer.render(),mS.uniforms.tDiffuse.value=this.canvasTexture,this.canvasTexture.needsUpdate=!0;let e=r.getRenderTarget();r.setRenderTarget(this.renderTarget),r.clear(),o_.render(r),r.setRenderTarget(e),this.textureHolder?.setNeedsUpdate(!0)}}updateEntity2DByOp(r,e,t,o){this.scene2d.updateEntityByOp(r,e,t,o),this.applySize()}updateTreeByOp(r,e){this.scene2d.updateTreeByOp(r,e),this.applySize()}applyOverrides(r){if(this.frameOverride&&this.frameRoot){this.frameOverride.position=[0,0],this.frameOverride.rotation=0;let e=r?.width??this.width,t=r?.height??this.height;this.frameOverride.width=e,this.frameOverride.height=t,this.frameOverride.localMatrix=a_,this.isScreenSpace&&(this.frameOverride.fill.color=Me.from0to1([0,0,0,0])),this.frameOverride.data={...this.frameOverride.data,width:e,height:t},yS({objectOverride:this.frameOverride,objectRoot:this.frameRoot,newParentWidth:this.frameOverride.width,newParentHeight:this.frameOverride.height,initialParentWidth:this.frameRoot.width,initialParentHeight:this.frameRoot.height}),this.frameOverride.updateWorldMatrix(!0,!1,!0)}}applySize(r,e=window.devicePixelRatio){let t=Math.max(1,r?.width??this.width),o=Math.max(1,r?.height??this.height);this.dpr=e,this.width=t,this.height=o,this._innerApplySize();let i=1,a=512,s=512;(t*e<a||o*e<s)&&(i=Math.max(a/(t*e),s/(o*e))),this.renderTarget.setSize(t*e*i,o*e*i),this._canvasTexture?.dispose(),this._canvasTexture=void 0,this.applyOverrides(r),this.frameOverride?.requestRender()}applyFrame(r){let e=this.context.scene.find2D(r);if(!(!e||!(e instanceof fr)))return this.disposeFrameOverride(),this.frameRoot=e,this.frameOverride=e.clone({dpr:this.renderer.dpr,shared:this.context.shared}),this.scene2d.add(this.frameOverride),this.applySize(),this.frame?.addEventListener("render",this.onRenderRequestedDownstream),this.frameOverride.traverse(t=>{t.addEventListener("beginState",this.onFrameOverrideObjectEvent)}),this.frameOverride.traverse(t=>{t.addEventListener("completeState",this.onFrameOverrideObjectEvent)}),this.frame?.requestRender(),e}get frame(){return this.frameOverride}get frameId(){return this.frame?.uuid}find(r){return this.scene2d.find(r)}get texture(){return this.textureHolder?.getTexture(1001)}disposeFrameOverride(){this.frameOverride?.removeEventListener("render",this.onRenderRequestedDownstream),this.frameOverride?.traverse(r=>{r.removeEventListener("beginStateChange",this.onFrameOverrideObjectEvent)}),this.frameOverride?.traverse(r=>{r.removeEventListener("completeState",this.onFrameOverrideObjectEvent)}),this.frameOverride&&this.scene2d.remove(this.frameOverride)}};function yS({objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i}){if(n instanceof fr&&r instanceof fr||n instanceof ir&&r instanceof ir)for(let a=0,s=n.children.length;a<s;a++){let l=n.children[a],c=r.children[a];l&&c&&l.uuid===c.uuid&&l_({objectOverride:l,objectRoot:c,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i})}}function s_(n){if(Mh(n))return[n.width,n.height];if(n instanceof $o){let[r,e]=n.getHalfSize();return[r*2,e*2]}else if(n instanceof ir){let[r,e]=n.recursiveBBox.getHalfSize();return[r*2,e*2]}return[0,0]}function l_({objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i}){let[a,s]=s_(r),{width:l,height:c,position:u}=Ch({constraints:n.data,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i,objectInitialWidth:a,objectInitialHeight:s,objectInitialPosition:r.position});if(n.position=u,n.data={...n.data,position:u},n.states)for(let p in n.states)c_({stateId:p,objectOverride:n,objectRoot:r,newParentWidth:e,newParentHeight:t,initialParentWidth:o,initialParentHeight:i});if(Mh(n)||n instanceof ir)Mh(n)&&(n.width=l,n.height=c,n.data={...n.data,width:l,height:c}),yS({objectOverride:n,objectRoot:r,newParentWidth:l,newParentHeight:c,initialParentWidth:a,initialParentHeight:s});else if(n instanceof $o){let p=r,d=a!==0?l/a:1,f=s!==0?c/s:1;n.path=dS(p.path,d,f),n.data={...n.data,path:n.path}}}function c_({stateId:n,objectOverride:r,objectRoot:e,newParentWidth:t,newParentHeight:o,initialParentWidth:i,initialParentHeight:a}){let s=r.states?.[n],l=e.states?.[n];if(s&&l){let{width:c,height:u,position:p}=Ch({constraints:r.data,newParentWidth:t,newParentHeight:o,initialParentWidth:i,initialParentHeight:a,objectInitialWidth:Do.isResizeable(l)?l.width:0,objectInitialHeight:Do.isResizeable(l)?l.height:0,objectInitialPosition:l.position});Object.assign(r.states[n],{position:p}),Do.isResizeable(s)&&Object.assign(r.states[n],{width:c,height:u})}}function Mh(n){return n instanceof xo||n instanceof fr||n instanceof En||n instanceof Nn}var Tr=class extends pa(f_){constructor(e,t,o){super();this.data=t;this.bgColor=new At(1,1,1,1);this.fog=null;this.backupFog=new d_(16777215,.1,2e3);this.fogUseBGColor=!1;this.isActive=!1;this.aoColor=new u_;this.penumbraSizeArrayCache=null;this.super_Entity(e,t),this.personalCamera=new Wo(ln,{...qn.defaultData,...t.camera,name:"Personal Camera"}),this.personalCamera.objectHelper.visible=!1,this.add(this.personalCamera),this.activeCamera=this.personalCamera,this.ambientLight=new p_(13882323,8553090,.75),this.ambientLight.name="Default Ambient Light",this.ambientLight.layers.enable(3),this.ambientLight.removeFromParent(),this.add(this.ambientLight),t.uiScene?this.uiScene=new hi((Array.isArray(e)?e[0]:e)+"-ui",t.uiScene,{dpr:window.devicePixelRatio,shared:o.shared}):t.uiFrame&&this.createUICanvas(t.uiFrame,o)}get scene(){return this.parent}get postprocessing(){return this.data.postprocessing}get frameId(){return this.data.uiFrame}get frame(){return this.uiCanvas?.frame}createUICanvas(e,t){this.uiCanvas=new ps(this.uuid+"-uiscreen",window.innerWidth,window.innerHeight,t),this.uiCanvas.isScreenSpace=!0,this.uiCanvas.promise.then(()=>{this.uiCanvas?.applyFrame(e),this.uiCanvas?.applySize()})}updateVisible(){}setBackgroundColor(e){this.bgColor=e,this.fogUseBGColor===!0&&(this.backupFog.color=e)}entityChildrenCount(){return this.uiScene?this.uiScene.children.length:super.entityChildrenCount()}updateAmbientLight(e,t){e.color!==void 0&&(this.ambientLight.color=jt(e.color,t)),e.intensity!==void 0&&(this.ambientLight.intensity=e.intensity),e.enabled!==void 0&&(e.enabled?this.add(this.ambientLight):this.remove(this.ambientLight))}onDeactive(){this.isActive=!1}onActive(e){this.isActive=!0,e.fog=this.fog,this.traverseEntity(t=>{t instanceof nr&&t.recomputeBoolean()}),this.updateShadow(this.data.shadow)}forceMaterialsUpdate(){this.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t of e.material)t.needsUpdate=!0;else e.material.needsUpdate=!0,e.material.dispose()})}updateShadow(e){e.softShadowQuality!==void 0&&this.isActive&&Fv(e.softShadowQuality)&&this.forceMaterialsUpdate()}updateFog(e,t){if(e.enabled?this.fog=this.backupFog:this.fog=null,this.isActive){let o=this.scene;o.fog=this.fog}this.fogUseBGColor=e.useBackgroundColor,e.useBackgroundColor?this.backupFog.color.set(this.bgColor):this.backupFog.color=jt(e.color,t),this.backupFog.near=e.near,this.backupFog.far=e.far}updateAo(e,t){e.aoColor!==void 0&&(this.aoColor=jt(e.aoColor,t))}updateByOp(e,t,o,i){let a=this.data.uiFrame;super.updateByOp(e,t,o,i);let s=t;Re(e.path,["fog"])?this.updateFog(s.fog,o.shared):Re(e.path,["ao"])?this.updateAo(s.ao,o.shared):Re(e.path,["ambient"])?this.updateAmbientLight(s.ambient,o.shared):Re(e.path,["shadow"])?this.updateShadow(s.shadow):e.type===0&&e.path.length===0&&(e.props.uiFrame!==void 0||a!==s.uiFrame)&&this.updateUIFrame(e.props.uiFrame,o)}updateUIFrame(e,t){e?(this.uiCanvas||this.createUICanvas(e,t),this.uiCanvas.enabled=!0,this.uiCanvas.applyFrame(e)):this.uiCanvas&&(this.uiCanvas.enabled=!1)}updateState(e,t){this.updateState_Entity(e,t),e.backgroundColor!==void 0&&this.setBackgroundColor(jt(e.backgroundColor,t.shared)),e.fog!==void 0&&this.updateFog(e.fog,t.shared),e.ambient!==void 0&&this.updateAmbientLight(e.ambient,t.shared),e.ao!==void 0&&this.updateAo(e.ao,t.shared),e.shadow!==void 0&&this.updateShadow(e.shadow)}createFrame(e,t){}raycast(e,t){super.raycast(e,t)}switchActiveCamera(e){e&&e.isDescendantOf(this)&&(this.activeCamera!==this.personalCamera&&(this.activeCamera.objectHelper.visible=!0),this.activeCamera=e,e.objectHelper.visible=!1)}get playCamera(){return this.scene?.find(this.data.publish.playCamera)??this.personalCamera}switchToPlayCamera(){this.switchActiveCamera(this.playCamera)}get penumbraSizeArray(){return this.penumbraSizeArrayCache===null&&this.updatePenumbraSizeArray(),this.penumbraSizeArrayCache}updatePenumbraSizeArray(){this.penumbraSizeArrayCache=new Array(5).fill(.5);let e=0,t=0;this.traverseEntity(o=>{if(!o.visible)return!0;o instanceof cs&&o.visible&&e<3&&(this.penumbraSizeArrayCache[e]=o.data.penumbraSize??.5,e+=1),o instanceof us&&o.visible&&e<5-3&&(this.penumbraSizeArrayCache[3+t]=o.data.penumbraSize??.5,t+=1)})}raycastWithClones(e){let t=[],o=i=>{for(let a of i.children){let s=a.cloner;Le.is(a)&&(a.visible||s?.object.data.visible)&&((Tn(a)||vl(a)&&this.scene.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),Tl(a,e,t,!0)),o(a))}};return o(this),t}updateEntity2DByOp(e,t,o,i){this.uiCanvas?.updateEntity2DByOp(e,t,o,i)}};import{PointLight as h_,Vector3 as pd,Box3 as m_,Box3Helper as gS,Color as y_}from"three";var fd=class extends as(h_,ls){constructor(r,e,t){super(),this.super_Entity(r,e),this.castShadow=!0,this.shadow.mapSize.width=1024,this.shadow.mapSize.height=1024,this.shadow.normalBias=1,this.layers.enable(3);let i=this.shadow.camera;i.fov=90,i.aspect=1,i.near=100,i.far=2500;let a=new pd(-i.far+this.position.x,-i.far+this.position.y,-i.far+this.position.z),s=new pd(i.far+this.position.x,i.far+this.position.y,i.far+this.position.z),l=new m_(a,s),c=new gS(l,new y_(16755200));c.visible=!1,this.gizmos.shadowmap=c,this.update()}update(){if(this.shadow&&(this.shadow.camera.updateProjectionMatrix(),this.gizmos))for(let r in this.gizmos){let e=this.gizmos[r];if(e instanceof gS){let t=this.shadow.camera,o=new pd(-t.far+this.position.x,-t.far+this.position.y,-t.far+this.position.z),i=new pd(t.far+this.position.x,t.far+this.position.y,t.far+this.position.z);e.box.set(o,i),e.updateMatrixWorld(!0)}}}updateMatrixWorld(r){super.updateMatrixWorld(r),this.objectHelper&&this.objectHelper.update()}updateState(r,e){this.updateState_Light(r,e),r.distance!==void 0&&(this.distance=r.distance),r.decay!==void 0&&(this.decay=r.decay),r.shadowRadius!==void 0&&(this.shadow.radius=r.shadowRadius),r.shadowResolution!==void 0&&(this.shadow.mapSize.set(r.shadowResolution,r.shadowResolution),this.shadow.map&&(this.shadow.map.dispose(),this.shadow.map=null))}};var hd=class extends lt{get forceComputeSize(){return!0}get shape(){return this.geometry.userData.shape}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?el(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};var fs=class extends lt{constructor(e,t,o){super(e,t,o);this._shapeId=null;this._context=o}updateState(e,t){super.updateState(e,t),this.updateShape(),this.refreshAttachedCloners(t)}updateShape(){let e={...this.data.geometry.extrusion.shape};for(let i in e)typeof e[i]=="string"&&(e[i]=this._context.shared.getVariable(e[i],[this.uuid,"geometry","extrusion","shape",i]));let t;if(e.type==="Custom"){let i=e.shapeId;if(i!==this._shapeId&&this.detachShape(),i){this._shapeId=i;let a=this._context.scene.find(i);a?.data&&(a.attachedPaths.add(this),t=a.geometry.userData?.shape),t||this._context.scene.addPendingCommand(()=>this.updateShape())}}else{let i;switch(e.type){case"Rectangle":i=Ca;break;case"Ellipse":i=va;break;case"Polygon":i=vu;break;case"Star":i=Su;break;default:throw new Error(`Unknown shape type: ${e.type}`)}t=i.create({parameters:e}).userData.shape}let o=this.geometry;t&&o.inputs&&(o.inputs.shapeData=t,o.build())}detachShape(){this._shapeId!==null&&this._context.scene.find(this._shapeId)?.attachedPaths.delete(this)}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.updateShape(),this.refreshAttachedPaths(e)}updateTransformState(e,t){return super.updateTransformState(e,t)}updateGeometryInteractions(e,t){super.updateGeometryInteractions(e,t),this.updateShape()}updateEntityBoxSize(e,t){let o=this.geometry.getAttribute("position");o!==void 0?el(o,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:o.count,e,t):super.updateEntityBoxSize(e,t)}};var md=class extends On{constructor(e,t,o){super(e,t,o);this.data=t}};import{Group as g_,Matrix4 as x_,Skeleton as b_}from"three";var Yo=class extends Or(g_,Ar){constructor(e,t,o){super();t.type==="Instance"&&typeof e=="string"&&(t=this.transformAssignData(t,o)),this.super_Entity(e,t),this.objectHelper.update()}get isComponentRoot(){return this.data.type==="Component"&&typeof this.identity=="string"}get isInstanceRoot(){return this.data.type==="Instance"&&typeof this.identity=="string"}transformAssignData(e,t){let o=oa.getComponentData({scene:t.scene.data,shared:t.shared.data},e.component);if(o){let i,a;for(let s of ro.rootOverrideProps)e[s]===void 0?(i===void 0&&(i={...e}),i[s]=o.data[s]):(a===void 0&&(a={}),a[s]=e[s],i===void 0&&(i={...e}),i[s]=Kr.apply(o.data[s],e[s]));return this.overrideData=a,i}else return{...bt.defaultData,...e,...Er(bt.defaultData,ro.rootOverrideProps)}}updateByOp(e,t,o,i){let a;if(this.isInstanceRoot&&!i){if(t=this.transformAssignData(t,o),e.type===0&&e.path.length===0&&this.component)for(let s of ro.rootOverrideProps)s in e.props&&e.props[s]===void 0&&(a===void 0&&(a={...e,props:{...e.props}}),a.props[s]=this.component.data[s]);else if(e.type===0&&e.path.length>0&&ro.rootOverrideProps.includes(e.path[0])){let s=e.path[0];a===void 0&&(a={...e,path:[],props:{[s]:t[s]}})}}super.updateByOp(a??e,t,o,i)}updateState(e,t){this.updateState_Entity(e,t)}expandInstanceChildren(e){let t=this.data;if(this.component===void 0){let o=e.scene.find(t.component)??null,i=!1;if(o!==this.oldComponent){if(this.oldComponent){let a=0;for(let s of this.children)if(Le.is(s))e.scene.disposeAndUnregisterEntityRecursivelyIfNotReregistered(s),yd(s),a+=1;else break;this.children.splice(0,a)}i=!0}if(o){let a={};bS(e,[this.uuid],t.overrides,this,o,o,0,i,a);for(let s of this.children)if(Le.is(s)){let l=s.data;l.type==="Empty"&&l.animations&&s.traverseEntity(c=>{let u=c.dataPatched;if(c instanceof lt&&u.bones&&u.boneInverses){let p=c.dataPatched;if(p.bones&&p.boneInverses){let d=p.bones.map(m=>e.scene.find(a[m])),f=p.boneInverses.map(m=>new x_().fromArray(m)),h=new b_(d,f);c.bind(h,c.bindMatrix)}}else c.matrixAutoUpdate=!0})}}this.oldComponent=this.component}}};function yd(n){if(n.component){let r=n.component.instances.indexOf(n);r>=0&&n.component.instances.splice(r,1);for(let e of n.children)Le.is(e)&&yd(e)}}function xS(n,r,e,t){return n.component===r&&qd(n.identity,t)?n.overrideData===e?2:1:0}function bS(n,r,e,t,o,i,a,s,l){if(a>50)return!1;if(t.component!==o){if(t.component){let u=t.component.instances.indexOf(t);u>=0&&t.component.instances.splice(u,1)}o.instances.find(u=>u===t)||o.instances.push(t),t.component=o}o instanceof Yo&&o.isInstanceRoot&&o.expandInstanceChildren(n);let c=0;for(let u of o.children)if(Le.is(u)){let p=[...r,...typeof u.identity=="string"?[u.identity]:u.identity],d=ta.resolve(e,p,1);if(d!=null&&!(d instanceof Qe)){if(!1)debugger;Object.setPrototypeOf(d,Qe.prototype),console.error("wrong prototype")}let f=null,h;if(!s){let m=t.children[c];if(f=Le.is(m)?m:null,f!==null){let y=xS(f,u,d,p);h=y>=1?f.stateSelection:void 0,y!==2&&(f=null)}if(f===null&&(f=n.scene.findInstance(p)??null,f!==null)){let y=xS(f,u,d,p);if(h=y>=1?f.stateSelection:void 0,y!==2)f=null;else{let b=f.parent.children.indexOf(f);f.parent.children.splice(b,1),t.children.splice(c,0,f),f.parent===t?(b<=c&&console.error("not possible"),void 0):(f.parent=t,f.matrixWorldNeedsUpdate=!0,f.resetBBoxNeedsUpdate(),f.updateVisible(),n.pendingDeletes.delete(f),void 0)}}}if(f===null){let m=d?Kr.apply(u.data,d):u.data;Nr.is(m.type)&&(m={...m,type:"Empty"}),f=Rr.createEntity(p,m,n),f.overrideData=d,t.add(f),t.children.splice(t.children.length-1,1),t.children.splice(c,0,f),f.updateState(f.data,n),h&&f.changeSelectedState(h,n),n.scene.registerInstanceAndSetUuid(f)}if(f.isBone){let m=f.identity[f.identity.length-1];l[m]=f.uuid}c+=1,bS(n,r,e,f,u,i,a+1,s,l)}if(!s){let u=c;for(;;){let p=t.children[c];if(Le.is(p))n.pendingDeletes.add(p);else break;c+=1}t.children.splice(u,c-u)}return!0}import{Bone as v_}from"three";var gd=class extends Or(v_,Ar){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update(),this.matrixAutoUpdate=!0}updateState(r,e){this.updateState_Entity(r,e)}};var mi=class extends lt{constructor(e,t,o){super(e,t,o);this.onBeforeRender=e=>{this.uiCanvas.render(e)};this.uiCanvas=new ps(e+"-canvas",t.geometry.width,t.geometry.height,o),this.uiCanvas.promise.then(()=>{this.applyFrame(this.dataPatched.geometry.frame,o.shared)})}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),e.type===0&&(e.props.frame!==void 0&&this.applyFrame(e.props.frame,o.shared),(e.props.width!==void 0||e.props.height!==void 0)&&this.applySize(e.props,o.shared))}applySize(e,t){let o=e?.width??this.dataPatched.geometry.width,i=e?.height??this.dataPatched.geometry.height;this.uiCanvas.applySize({width:o,height:i}),this.applyGeometryParametersFromFrame(t)}applyFrame(e,t){this.uiCanvas.applyFrame(e),this.applyGeometryParametersFromFrame(t),this.applyMaterialParametersFromFrame({shared:t})}applyGeometryParametersFromFrame(e){let t=this.frame;t&&(Object.assign(this.data,{geometry:Object.assign(this.data.geometry,{cornerRadius:t.cornerRadius,cornerType:0})}),Object.assign(this.dataPatched,{geometry:Object.assign(this.dataPatched.geometry,{cornerRadius:t.cornerRadius,cornerType:0})}),this.localGeometry?.dispose(),this.localGeometry=Vo(this.dataPatched.geometry,e,this.data.flatShading,this))}applyMaterialParametersFromFrame(e){let t=this.frame;if(t){let o=t.data.backgroundBlur;Object.assign(this.data.material.layers[0].data.texture,{image:this.uiCanvas.uuid}),Object.assign(this.data.material.layers[1].data,{roughness:o.radius,alpha:o.enabled?1:0}),Object.assign(this.dataPatched.material.layers[0].data.texture,{image:this.uiCanvas.uuid}),Object.assign(this.dataPatched.material.layers[1].data,{roughness:o.radius,alpha:o.enabled?1:0}),this.material.reset(this.dataPatched.material,e,!0)}}updateEntity2DByOp(e,t,o,i){this.uiCanvas.updateEntity2DByOp(e,t,o,i),e===this.frameId&&t.type===0&&(t.props.cornerRadius!==void 0?this.applyGeometryParametersFromFrame(i):Re(t.path,["backgroundBlur"])&&this.applyMaterialParametersFromFrame({shared:i}))}get frame(){return this.uiCanvas.frame}get frameId(){return this.frame?.uuid}removeInteractionGeometry(e){super.removeInteractionGeometry(e),this.applySize({},e)}updateGeometryInteractions(e,t){super.updateGeometryInteractions(e,t),this.applySize({width:e.width,height:e.height},t)}};import{Object3D as N_,Vector3 as Ir,InstancedMesh as D_,InstancedBufferAttribute as __,PlaneGeometry as B_,Vector4 as Il,Quaternion as FS,TextureLoader as R_,Texture as jS,Euler as L_,MathUtils as Lh}from"three";import{GPUComputationRenderer as V_}from"three/examples/jsm/misc/GPUComputationRenderer.js";import{Vector3 as vS,FloatType as Eh,DataTexture as Nh,RGBAFormat as Dh,Mesh as S_,Euler as bde,Matrix4 as vde}from"three";import{MeshSurfaceSampler as w_}from"three/examples/jsm/math/MeshSurfaceSampler.js";function SS(n){let r=new Float32Array(n*n*2);for(let e=0;e<n;e++)for(let t=0;t<n;t++){let o=e*n+t;r[o*2+0]=e/(n-1),r[o*2+1]=t/(n-1)}return r}function wS(n){let r=Math.ceil(Math.sqrt(n));return Math.max(r,1)}function PS(n,r){let e=new S_(n.geometry,n.material),t=[],o=[],i=new vS,a=new vS;e.geometry.index!==null&&(e.geometry=e.geometry.toNonIndexed());let s=new w_(e).build();for(let u=0;u<r;u++)s.sample(i,a),t.push(i.x,i.y,i.z),o.push(a.x,a.y,a.z);let l=new Float32Array(t),c=new Float32Array(o);return{positions:l,normals:c}}function _h(n,r){let e=n,t=new Float32Array(4*r*r);for(let i=0;i<r*r;i++)t[4*i]=e[3*i],t[4*i+1]=e[3*i+1],t[4*i+2]=e[3*i+2],t[4*i+3]=0;let o=new Nh(t,r,r,Dh,Eh);return o.needsUpdate=!0,o}function CS({size:n}){let r=new Float32Array(4*n*n);for(let t=0;t<n*n;t++)r[4*t]=t,r[4*t+1]=0,r[4*t+2]=0,r[4*t+3]=0;let e=new Nh(r,n,n,Dh,Eh);return e.needsUpdate=!0,e}function OS(n){let r=new Float32Array(4*n*n);for(let t=0;t<n*n;t++)r[4*t]=0,r[4*t+1]=0,r[4*t+2]=0,r[4*t+3]=0;let e=new Nh(r,n,n,Dh,Eh);return e.needsUpdate=!0,e}var AS=`
2934
2967
  // uniform sampler2D uCurrentPosition; // Pass in the variable from GPGPU
2935
2968
  // uniform sampler2D uCurrentVelocity; // Pass in the variable from GPGPU
2936
2969
  // uniform sampler2D uCurrentEmissionRate; // Pass in the variable from GPGPU
@@ -2999,7 +3032,7 @@ void main() {
2999
3032
  gl_FragColor = mix(vec4(0.0), activeColor, isActive);
3000
3033
 
3001
3034
  }
3002
- `;var MS=`
3035
+ `;var TS=`
3003
3036
 
3004
3037
  vec3 mod289(vec3 x) {
3005
3038
  return x - floor(x * (1.0 / 289.0)) * 289.0;
@@ -3201,7 +3234,7 @@ vec3 fbm_vec3(vec3 p, float frequency, float offset)
3201
3234
  );
3202
3235
  }
3203
3236
 
3204
- `;var ES=`
3237
+ `;var IS=`
3205
3238
  #ifdef USE_COLLIDER
3206
3239
  float restitution = max(uBounce * 2., .01); // Energy Loss
3207
3240
  // SPHERE COLLIDER
@@ -3269,7 +3302,7 @@ vec3 fbm_vec3(vec3 p, float frequency, float offset)
3269
3302
  #endif
3270
3303
  #endif
3271
3304
  // END COLLIDER
3272
- `;var NS=`
3305
+ `;var MS=`
3273
3306
  #ifdef USE_ATTRACTOR
3274
3307
 
3275
3308
  #ifdef USE_SPHERE_COLLIDER
@@ -3343,7 +3376,7 @@ vec3 fbm_vec3(vec3 p, float frequency, float offset)
3343
3376
  velocity *= uForceDamping;
3344
3377
  #endif
3345
3378
  #endif
3346
- `;var DS=`
3379
+ `;var ES=`
3347
3380
  #ifdef USE_VORTEX
3348
3381
  // Box dimensions
3349
3382
  vec3 boxHalfSize = uColliderSize / 2.0;
@@ -3382,7 +3415,7 @@ vec3 fbm_vec3(vec3 p, float frequency, float offset)
3382
3415
  velocity += applyForce( originDirection * uSpeed * (1. - uForceDamping) , mass * .5);
3383
3416
  }
3384
3417
  #endif
3385
- `;var _S=`
3418
+ `;var NS=`
3386
3419
  // uniform sampler2D uCurrentPosition; // Pass in the variable from GPGPU
3387
3420
  // uniform sampler2D uCurrentVelocity; // Pass in the variable from GPGPU
3388
3421
  // uniform sampler2D uCurrentEmissionRate; // Pass in the variable from GPGPU
@@ -3408,7 +3441,7 @@ uniform float uForceDamping;
3408
3441
  uniform float uForceIntensity;
3409
3442
 
3410
3443
 
3411
- `+MS+`
3444
+ `+TS+`
3412
3445
  float rand(vec2 co){
3413
3446
  return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
3414
3447
  }
@@ -3484,11 +3517,11 @@ void main() {
3484
3517
  #endif
3485
3518
 
3486
3519
  // COLLIDER
3487
- ${ES}
3520
+ ${IS}
3488
3521
  // ATTRACTION
3489
- ${NS}
3522
+ ${MS}
3490
3523
  // VORTEX
3491
- ${DS}
3524
+ ${ES}
3492
3525
  }
3493
3526
  // End isActive
3494
3527
 
@@ -3506,7 +3539,7 @@ void main() {
3506
3539
 
3507
3540
  gl_FragColor = vec4(velocity, collisionFlag);
3508
3541
  }
3509
- `;import{ShaderMaterial as C_}from"three";var Lh=`
3542
+ `;import{ShaderMaterial as P_}from"three";var Bh=`
3510
3543
 
3511
3544
  // Linear Fade In
3512
3545
  float linearFadeIn(float t) {
@@ -3539,7 +3572,7 @@ void main() {
3539
3572
  float constant(float t) {
3540
3573
  return 1.0;
3541
3574
  }
3542
- `;var BS=`
3575
+ `;var DS=`
3543
3576
 
3544
3577
  float rand(vec3 co){
3545
3578
  return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
@@ -3554,7 +3587,7 @@ vec3 applyForce(vec3 force, float mass) {
3554
3587
 
3555
3588
  return acceleration;
3556
3589
  }
3557
- `;var RS=`
3590
+ `;var _S=`
3558
3591
  vec3 rgb2xyz (in vec3 rgb) {
3559
3592
  float r = rgb.r;
3560
3593
  float g = rgb.g;
@@ -3645,7 +3678,7 @@ vec3 lab2rgb (in vec3 lab) {
3645
3678
  return(rgb);
3646
3679
  }
3647
3680
 
3648
- `;var LS=`
3681
+ `;var BS=`
3649
3682
  uniform sampler2D uPosition;
3650
3683
  uniform float uSize;
3651
3684
  uniform float uSizeEnd;
@@ -3666,9 +3699,9 @@ vec3 lab2rgb (in vec3 lab) {
3666
3699
  varying vec2 vUv;
3667
3700
  varying vec2 vRef;
3668
3701
 
3669
- ${BS}
3670
- ${Lh}
3671
- `,VS=({easeSize:n="linearFadeOut"})=>`
3702
+ ${DS}
3703
+ ${Bh}
3704
+ `,RS=({easeSize:n="linearFadeOut"})=>`
3672
3705
  vUv = uv;
3673
3706
  vRef = ref;
3674
3707
  // Normalized LifeTime 1 to 0
@@ -3720,7 +3753,7 @@ vec3 lab2rgb (in vec3 lab) {
3720
3753
  mvPosition = modelViewMatrix * instanceMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
3721
3754
  mvPosition.xy += rotatedPosition;
3722
3755
  gl_Position = projectionMatrix * mvPosition;
3723
- `,zS=`
3756
+ `,LS=`
3724
3757
  uniform vec4 uColor; // start color
3725
3758
  uniform vec4 uColor2; // end color
3726
3759
  uniform sampler2D uTexture; // texture
@@ -3731,10 +3764,10 @@ vec3 lab2rgb (in vec3 lab) {
3731
3764
  float random(vec2 co) {
3732
3765
  return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
3733
3766
  }
3734
- `+Lh+`
3735
- ${RS}
3767
+ `+Bh+`
3768
+ ${_S}
3736
3769
 
3737
- `,GS=({easeOpacity:n="linearFadeOut"})=>`
3770
+ `,VS=({easeOpacity:n="linearFadeOut"})=>`
3738
3771
  // if Particle is dead, hide it
3739
3772
  if (v_LifeLeft <= 0.005 ) {
3740
3773
  discard;
@@ -3755,7 +3788,7 @@ vec3 lab2rgb (in vec3 lab) {
3755
3788
 
3756
3789
  gl_FragColor = vec4(finalColor, finalAlpha);
3757
3790
 
3758
- `;var Sd=class extends C_{constructor(e,t){super();this.needsJitter=!0;this.type="ParticleMaterial";this.easeOpacity="linearFadeIn";this.easeSize="linearFadeIn";this.useSizeEnd=!1;this.isColoringRandom=!1;this.init(e,t),this.context=t}reset(){}init(e,t){this.transparent=!0,this.depthTest=!0,this.depthWrite=!1,this.easeOpacity=e.ease,this.easeSize=e.easeSize,this.layers=[],qe.startContext(qe.globalContext),this.lightLayer=new Xt(0,"",{...xt.defaultData("light","phong"),visible:!1},new Go,{},t.shared),qe.endContext(qe.globalContext),this.build()}updateState(e){e.coloring!==void 0&&(this.isColoringRandom=e.coloring==="random"),e.color!==void 0&&(e.color instanceof Array?this.uniforms.uColor.value=e.color:this.uniforms.uColor.value=this.context.shared.color(e.color)),e.color2!==void 0&&(e.color2 instanceof Array?this.uniforms.uColor2.value=e.color2:this.uniforms.uColor2.value=this.context.shared.color(e.color2)),e.size!==void 0&&(this.uniforms.uSize.value=e.size[0],this.uniforms.uSizeEnd.value=e.size[1],e.size[0]!==e.size[1]?this.useSizeEnd=!0:this.useSizeEnd=!1),e.ease!==void 0&&(this.easeOpacity=e.ease,this.build()),e.easeSize!==void 0&&(this.easeSize=e.easeSize,this.build()),this.needsUpdate=!0}onBeforeCompile(e){this.build(),e.defines=this.defines,e.uniforms=this.uniforms,e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader}build(){let e=new Ra;return e.needsJitter=this.needsJitter,e.addFragmentParsCode(Ob),e.buildShader("vertex",this.fragment),e.buildShader("fragment",this.fragment),e.addFragmentFinalCode(Ab),this.isColoringRandom&&e.define("USE_RANDOM_COLORING"),this.useSizeEnd&&e.define("USE_SIZE_END"),e.addVertexParsCode(LS),e.addFragmentParsCode(zS),e.addVertexFinalCode(VS({easeSize:this.easeSize})),e.addFragmentFinalCode(GS({easeOpacity:this.easeOpacity})),this.vertexShader=e.getCode("vertex"),this.fragmentShader=e.getCode("fragment"),this.defines=e.defines,this.uniforms={...e.uniforms,...this.uniforms},this.extensions=e.extensions,this}get nodeMaterial(){return this}get fragment(){return this.lightLayer.node}getDefines(){return this.defines}nodeMaterialDispose(){this.layers.forEach(e=>e.dispose()),super.dispose()}};import{BoxGeometry as O_,ConeGeometry as A_,MeshBasicMaterial as T_,SphereGeometry as Vh,Vector3 as I_}from"three";import{Mesh as M_}from"three";import{TorusGeometry as E_}from"three";import{PlaneGeometry as N_}from"three";var ys=class{constructor(r,e,t,o){this.type="SphereEmitterShape";this.targetMesh=void 0;this.size=r,this.type=t,this.textureSize=CS(e);let i=1;this.targetMesh=o?.type==="Mesh"&&o?o:this.getMesh(t,i);let{positions:a,dataTexture:s,dataTextureNormals:l}=this.createPositions(this.textureSize,this.targetMesh??this.getMesh(t,i));this.positionsTexture=s,this.positionsAttribute=a,this.directionsTexture=l}createPositions(r,e){let{positions:t,normals:o}=OS(e,r*r),i=Rh(t,r),a=Rh(o,r);return{dataTexture:i,positions:t,dataTextureNormals:a}}getMesh(r,e){let t=null;switch(r){case"SphereEmitterShape":{t=new Vh(e*.5,32,32);break}case"TorusEmitterShape":{t=new E_(e*.5,.3,15,40);break}case"ConeEmitterShape":{t=new A_(e,e,15);break}case"BoxEmitterShape":{t=new O_(e,e,e);break}case"PlaneEmitterShape":{t=new N_(e,e),t.rotateX(-Math.PI/2);break}case"MeshEmitterShape":{t=new Vh(e,32,32);break}default:{t=new Vh(e,32,32);break}}return new M_(t,new T_({color:16711680}))}applyToShader(r,e){this.size=new I_().fromArray(e.size),r.uEmitterSize.value=this.size}dispose(){this.positionsTexture.dispose(),this.directionsTexture.dispose(),this.positionsAttribute=new Float32Array}};function _n(n){let r={...n},e=Qi.defaultData;r.forceFieldObjectId&&(r.colliderEntityId=r.forceFieldObjectId);let t={...e.shape,...r.shape},o={...e.renderMaterial,...r.renderMaterial};return{...e,...r,shape:t,renderMaterial:o}}var FS=`
3791
+ `;var xd=class extends P_{constructor(e,t){super();this.needsJitter=!0;this.type="ParticleMaterial";this.easeOpacity="linearFadeIn";this.easeSize="linearFadeIn";this.useSizeEnd=!1;this.isColoringRandom=!1;this.init(e,t),this.context=t}reset(){}init(e,t){this.transparent=!0,this.depthTest=!0,this.depthWrite=!1,this.easeOpacity=e.ease,this.easeSize=e.easeSize,this.layers=[],qe.startContext(qe.globalContext),this.lightLayer=new Xt(0,"",{...xt.defaultData("light","phong"),visible:!1},new Go,{},t.shared),qe.endContext(qe.globalContext),this.build()}updateState(e){e.coloring!==void 0&&(this.isColoringRandom=e.coloring==="random"),e.color!==void 0&&(e.color instanceof Array?this.uniforms.uColor.value=e.color:this.uniforms.uColor.value=this.context.shared.color(e.color)),e.color2!==void 0&&(e.color2 instanceof Array?this.uniforms.uColor2.value=e.color2:this.uniforms.uColor2.value=this.context.shared.color(e.color2)),e.size!==void 0&&(this.uniforms.uSize.value=e.size[0],this.uniforms.uSizeEnd.value=e.size[1],e.size[0]!==e.size[1]?this.useSizeEnd=!0:this.useSizeEnd=!1),e.ease!==void 0&&(this.easeOpacity=e.ease,this.build()),e.easeSize!==void 0&&(this.easeSize=e.easeSize,this.build()),this.needsUpdate=!0}onBeforeCompile(e){this.build(),e.defines=this.defines,e.uniforms=this.uniforms,e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader}build(){let e=new Ba;return e.needsJitter=this.needsJitter,e.addFragmentParsCode(Cb),e.buildShader("vertex",this.fragment),e.buildShader("fragment",this.fragment),e.addFragmentFinalCode(Ob),this.isColoringRandom&&e.define("USE_RANDOM_COLORING"),this.useSizeEnd&&e.define("USE_SIZE_END"),e.addVertexParsCode(BS),e.addFragmentParsCode(LS),e.addVertexFinalCode(RS({easeSize:this.easeSize})),e.addFragmentFinalCode(VS({easeOpacity:this.easeOpacity})),this.vertexShader=e.getCode("vertex"),this.fragmentShader=e.getCode("fragment"),this.defines=e.defines,this.uniforms={...e.uniforms,...this.uniforms},this.extensions=e.extensions,this}get nodeMaterial(){return this}get fragment(){return this.lightLayer.node}getDefines(){return this.defines}nodeMaterialDispose(){this.layers.forEach(e=>e.dispose()),super.dispose()}};import{BoxGeometry as C_,ConeGeometry as O_,MeshBasicMaterial as A_,SphereGeometry as Rh,Vector3 as T_}from"three";import{Mesh as I_}from"three";import{TorusGeometry as M_}from"three";import{PlaneGeometry as E_}from"three";var hs=class{constructor(r,e,t,o){this.type="SphereEmitterShape";this.targetMesh=void 0;this.size=r,this.type=t,this.textureSize=wS(e);let i=1;this.targetMesh=o?.type==="Mesh"&&o?o:this.getMesh(t,i);let{positions:a,dataTexture:s,dataTextureNormals:l}=this.createPositions(this.textureSize,this.targetMesh??this.getMesh(t,i));this.positionsTexture=s,this.positionsAttribute=a,this.directionsTexture=l}createPositions(r,e){let{positions:t,normals:o}=PS(e,r*r),i=_h(t,r),a=_h(o,r);return{dataTexture:i,positions:t,dataTextureNormals:a}}getMesh(r,e){let t=null;switch(r){case"SphereEmitterShape":{t=new Rh(e*.5,32,32);break}case"TorusEmitterShape":{t=new M_(e*.5,.3,15,40);break}case"ConeEmitterShape":{t=new O_(e,e,15);break}case"BoxEmitterShape":{t=new C_(e,e,e);break}case"PlaneEmitterShape":{t=new E_(e,e),t.rotateX(-Math.PI/2);break}case"MeshEmitterShape":{t=new Rh(e,32,32);break}default:{t=new Rh(e,32,32);break}}return new I_(t,new A_({color:16711680}))}applyToShader(r,e){this.size=new T_().fromArray(e.size),r.uEmitterSize.value=this.size}dispose(){this.positionsTexture.dispose(),this.directionsTexture.dispose(),this.positionsAttribute=new Float32Array}};function Dn(n){let r={...n},e=Ki.defaultData;r.forceFieldObjectId&&(r.colliderEntityId=r.forceFieldObjectId);let t={...e.shape,...r.shape},o={...e.renderMaterial,...r.renderMaterial};return{...e,...r,shape:t,renderMaterial:o}}var zS=`
3759
3792
  // uniform sampler2D uCurrentPosition; // Pass in the variable from GPGPU
3760
3793
  // uniform sampler2D uCurrentVelocity; // Pass in the variable from GPGPU
3761
3794
  // uniform sampler2D uCurrentEmissionRate; // Pass in the variable from GPGPU
@@ -3802,8 +3835,8 @@ void main() {
3802
3835
 
3803
3836
 
3804
3837
  }
3805
- `;var Gh=10,wd=class extends D_{constructor(e,t){super();this.type="ParticleEmitter";this.debugMode=!1;this.worldSpace=!0;this.rootObject=null;this.gpuCompute=null;this.positionSimRT=null;this.velocitySimRT=null;this.emissionRateSimRT=null;this.emitterShape=void 0;this.isEmitting=!1;this.hasBeenReset=!1;this.emittedParticlesAmount=0;this.lastEmitTime=0;this.globalTime=0;this.targetFPS=60;this.previousRatio=1;this.lerpFactor=.4;this.particlesAmount=0;this.noiseStrength=0;this.noiseScale=0;this.isBillboardBased=!0;this.simFeaturesDefinition={USE_COLLIDER:!1,USE_ATTRACTOR:!1,USE_VORTEX:!1,USE_SPHERE_COLLIDER:!1,USE_BOX_COLLIDER:!1,USE_FORCE_LOCAL_SPACE:!1,USE_NORMALS:!1,USE_CURL_NOISE:!0,USE_SIMPLEX_NOISE:!1,USE_FBM_NOISE:!1};this.textureLoader=new L_;this.currentWorldPosition=new Ir;this.systemQuaternion=new kS;this.worldGravity=new Ir(0,0,0);this.directionAxis=new Ir(0,0,0);this.colliderV3=new Ir(0,0,0);this.colliderQuaternion=new kS(0,0,0,1);this.matrixAutoUpdate=!0,this.renderer=e,this.system=t,this.shared=t.context.shared;let o=t.data;this.material=new Sd(o.renderMaterial,t.context),this.material.uniforms={uSize:{value:0},uSizeEnd:{value:0},uColor:{value:o.renderMaterial.color},uColor2:{value:o.renderMaterial.color2},uPosition:{value:new Ir(0,0,0)},uEmissionData:{value:new Ir(0,0,0)},uTexture:{value:this.defaultTexture},uWorldOffset:{value:new Ir(0,0,0)},uWorldQuaternion:{value:new Nl(0,0,0,1)},uRandScaleFactor:{value:o.randomScale??0},uRandRotationFactor:{value:o.randomRotation??0},uRotation:{value:o.renderMaterial.spriteRotation[0]??0},uRotationEnd:{value:o.renderMaterial.spriteRotation[1]??0}},this.setTexture(this.material.uniforms,o.renderMaterial.texture),this.init(o)}setTexture(e,t){let o=t.data;if(typeof t=="string"){let i=this.shared.image(t),a=new US(i.img);a.needsUpdate=!0,e.uTexture.value=a;return}if(typeof o!="string"){let i=new Image;i.onload=()=>{let l=new US(i);l.needsUpdate=!0,e.uTexture.value=l};let a=new Blob([o],{type:"image/*"}),s=URL.createObjectURL(a);i.src=s}}updateGeometryAttributes(e,t){let o=PS(t);!this.emitterShape?.positionsAttribute||e.geometry.setAttribute("ref",new B_(o,2))}applyWorldSpace(){if(!this.system.started||!this.worldSpace||!this.positionSimRT||!this.velocitySimRT)return;let e=this.system;e.getWorldQuaternion(this.systemQuaternion),this.systemQuaternion.invert(),e.getWorldPosition(this.currentWorldPosition),this.material.uniforms.uWorldOffset.value=this.currentWorldPosition,this.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize()),this.positionSimRT.material.uniforms.uWorldOffset.value=this.currentWorldPosition,this.systemQuaternion.invert(),this.positionSimRT.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize()),this.velocitySimRT.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize())}update(e,t){if(!this.gpuCompute||!this.positionSimRT||!this.velocitySimRT||!this.emissionRateSimRT||this.hasBeenReset)return;if(this.checkIfAllParticlesAreDead()&&!this.hasBeenReset){this.reset();return}this.applyWorldSpace(),this.globalTime=e,this.positionSimRT.material.uniforms.uTime.value=e,this.emissionRateSimRT.material.uniforms.uTime.value=e;let o=1e3/t,i=this.targetFPS/o,a=this.previousRatio+(i-this.previousRatio)*this.lerpFactor;this.positionSimRT.material.uniforms.uFPSRatio.value=a,this.previousRatio=a;let s=this.isEmitting?this.GoEmitSomeParticles(e,this.system.data.birthRatePerSec):0;this.emissionRateSimRT.material.uniforms.uLastIndexEmitted.value=this.emittedParticlesAmount,this.emissionRateSimRT.material.uniforms.uParticlesToEmit.value=s,this.material.uniforms.uPosition.value=this.gpuCompute.getCurrentRenderTarget(this.positionSimRT)?.texture,this.system.colliderEntities.length>0&&this.renderColliders(),this.gpuCompute.compute()}renderColliders(){if(!this.velocitySimRT)return;let e=this.system.colliderEntities[0],t=this.simFeaturesDefinition.USE_COLLIDER||this.simFeaturesDefinition.USE_ATTRACTOR||this.simFeaturesDefinition.USE_VORTEX;if(e.destroyedInAction&&t&&this.init(_n({...this.system.data,colliderEntityId:null})),!e||e.destroyedInAction)return;e.getWorldPosition(this.colliderV3),this.colliderV3.y===0&&(this.colliderV3.y=1e-4),this.velocitySimRT.material.uniforms.uColliderPos.value.copy(this.colliderV3);let o=e.data.size;this.colliderV3.fromArray(o),this.velocitySimRT.material.uniforms.uColliderSize.value.copy(this.simFeaturesDefinition.USE_SPHERE_COLLIDER?this.colliderV3.multiplyScalar(.5):this.colliderV3),e.getWorldQuaternion(this.colliderQuaternion),this.velocitySimRT.material.uniforms.uColliderQuaternion.value.copy(this.colliderQuaternion.normalize()),this.velocitySimRT.material.uniforms.uColliderQuaternionInvert.value.copy(this.colliderQuaternion.normalize().invert())}updateState(e){!this.velocitySimRT||!this.positionSimRT||(e.renderMaterial&&this.updateMaterialState(e.renderMaterial),this.updateParticleState(e))}updateVariableState(e,t){if(!this.velocitySimRT||!this.positionSimRT)return;t[2]==="size"&&this.material.updateState({size:[e,this.material.uniforms.uSizeEnd.value]}),t[2]==="sizeEnd"&&this.material.updateState({size:[this.material.uniforms.uSize.value,e]});let o=(i,a)=>{let s=[...this.system.data.shape.size];s[i]=a,this.updateParticleState({shape:{...this.system.data.shape,size:s}})};t[2]==="shape_size_0"&&o(0,e),t[2]==="shape_size_1"&&o(1,e),t[2]==="shape_size_2"&&o(2,e),t[2]==="speed"&&(this.velocitySimRT.material.uniforms.uSpeed.value=e/Gh),t[2]==="gravity"&&this.worldGravity.set(0,e/100,0),t[2]==="noiseStrength"&&(this.noiseStrength=e,this.velocitySimRT.material.uniforms.uNoiseStrength.value=this.noiseStrength),t[2]==="noiseScale"&&(this.noiseScale=e,this.velocitySimRT.material.uniforms.uNoiseScale.value=this.noiseScale),t[2]==="direction_x"&&(this.directionAxis=this.getDirectionAxis([Number(e),this.system.data.direction[1],this.system.data.direction[2]])),t[2]==="direction_y"&&(this.directionAxis=this.getDirectionAxis([this.system.data.direction[0],Number(e),this.system.data.direction[2]])),t[2]==="direction_z"&&(this.directionAxis=this.getDirectionAxis([this.system.data.direction[0],this.system.data.direction[1],Number(e)]))}updateMaterialState(e){this.material.updateState({...e,size:e.size?[Number(this.shared.getVariable(e.size[0],[this.uuid,"particles","size"])),Number(this.shared.getVariable(e.size[1],[this.uuid,"particles","sizeEnd"]))]:[0,0]}),e.texture&&(this.setTexture(this.material.uniforms,e.texture),this.material.needsUpdate=!0)}updateParticleState(e){if(!(!this.positionSimRT||!this.velocitySimRT)){if(this.shouldReInitGPUCompute(e)&&this.init(_n(this.system.data)),e.life!==void 0&&(this.positionSimRT.material.uniforms.uMaxLifeTime.value=e.life),e.speed!==void 0&&(this.velocitySimRT.material.uniforms.uSpeed.value=Number(this.shared.getVariable(e.speed,[this.uuid,"particles","speed"]))/Gh),e.collisionBounce!==void 0&&(this.velocitySimRT.material.uniforms.uBounce.value=e.collisionBounce),e.noiseStrength!==void 0&&(this.noiseStrength=Number(this.shared.getVariable(e.noiseStrength,[this.uuid,"particles","noiseStrength"])),this.velocitySimRT.material.uniforms.uNoiseStrength.value=this.noiseStrength),e.noiseScale!==void 0&&(this.noiseScale=Number(this.shared.getVariable(e.noiseScale,[this.uuid,"particles","noiseScale"])),this.velocitySimRT.material.uniforms.uNoiseScale.value=this.noiseScale),e.noiseSeed!==void 0&&(this.velocitySimRT.material.uniforms.uNoiseSeed.value=e.noiseSeed),e.randomMass!==void 0&&(this.velocitySimRT.material.uniforms.uRandomMassFactor.value=e.randomMass),e.renderMaterial?.size!==void 0){let t=this.shared.getVariable(e.renderMaterial.size[0],[this.uuid,"particles","size"]);this.velocitySimRT.material.uniforms.particleSize.value=Number(t)}if(e.renderMaterial?.spriteRotation!==void 0&&(this.material.uniforms.uRotation.value=e.renderMaterial.spriteRotation[0],this.material.uniforms.uRotationEnd.value=e.renderMaterial.spriteRotation[1]),e.shape!==void 0){let t=e.shape.size??this.system.data.shape.size,o=[Number(this.shared.getVariable(t[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(t[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(t[2],[this.uuid,"particles","shape_size_2"]))],i={..._n(this.system.data).shape,size:o};this.emitterShape?.applyToShader(this.positionSimRT.material.uniforms,i)}if(e.gravity!==void 0&&(this.worldGravity.set(0,Number(this.shared.getVariable(this.system.data.gravity,[this.uuid,"particles","gravity"]))/100,0),this.velocitySimRT.material.uniforms.uGravity={value:this.worldGravity}),e.direction!==void 0){let t=this.getDirectionFromVariable(e.direction);this.directionAxis=this.getDirectionAxis(t),this.velocitySimRT.material.uniforms.uDirectionsAxis.value=this.directionAxis}e.randomRotation!==void 0&&(this.material.uniforms.uRandRotationFactor.value=e.randomRotation),e.randomScale!==void 0&&(this.material.uniforms.uRandScaleFactor.value=e.randomScale)}}updateForceFieldParameters(e){!this.velocitySimRT||(e.forceIntensity!==void 0&&(this.velocitySimRT.material.uniforms.uForceIntensity.value=e.forceIntensity),e.forceDambing!==void 0&&(this.velocitySimRT.material.uniforms.uForceDamping.value=e.forceDambing))}getDirectionAxis(e){let t=[Number(e[0])*zh.DEG2RAD,Number(e[1])*zh.DEG2RAD,Number(e[2])*zh.DEG2RAD],o=new V_(t[0],t[1],t[2],"XYZ");return this.directionAxis.set(0,1,0).applyEuler(o).normalize(),this.velocitySimRT&&(this.velocitySimRT.material.uniforms.uDirectionsAxis.value=this.directionAxis),this.directionAxis}shouldReInitGPUCompute(e){let{birthRatePerSec:t,rootObjectType:o,colliderEntityId:i,shape:a,emitTimeDuration:s,emitTimeCycle:l,life:c,directionMode:u,noiseType:p}=e;return t!==void 0||o!==void 0||(i||i===null)||l!==void 0||a!==void 0||c!==void 0||s!==void 0||u!==void 0||p!==void 0}init(e){this.dispose(),this.particlesAmount=this.getMaxParticlesAmount({birthRatePerSecond:e.birthRatePerSec,particleMaxLifeTime:e.life,loopDuration:e.emitTimeCycle==="infinity"?0:e.emitTimeDuration}),this.particlesAmount>1e5&&(console.warn(`The maximum number of particles is limited to ${1e5}.`),this.particlesAmount=1e5),this.emitterShape=this.createShape(e.shape,this.particlesAmount);let t=setInterval(()=>{if(!!this.emitterShape)if(isNaN(this.emitterShape.positionsTexture.source.data.data[0])){this.init(e);return}else clearInterval(t)},100);if(!this.emitterShape)return;let o=new z_(this.emitterShape.textureSize,this.emitterShape.textureSize,this.renderer),i=this.updateSimulationDefinition(e),a=o.addVariable("uCurrentPosition",i+IS,this.emitterShape.positionsTexture),s=o.addVariable("uCurrentVelocity",i+_S,this.emitterShape.directionsTexture),l=o.addVariable("uCurrentEmissionRate",FS,TS(this.emitterShape.textureSize));o.setVariableDependencies(a,[a,s,l]),o.setVariableDependencies(s,[a,s,l]),o.setVariableDependencies(l,[a,s,l]);let c=AS({size:this.emitterShape.textureSize}),u={uOriginalPosition:{value:this.emitterShape.positionsTexture},uWorldOffset:{value:new Ir(0,0,0)},uWorldQuaternion:{value:new Nl(0,0,0,1)},uTime:{value:0},uFPSRatio:{value:1},uMaxLifeTime:{value:e.life},uEmitterSize:{value:new Ir(Number(this.shared.getVariable(e.shape.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.shape.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.shape.size[2],[this.uuid,"particles","shape_size_2"])))},particleSize:{value:0}};a.material.uniforms=u;let p=this.getDirectionFromVariable(e.direction);this.directionAxis=this.getDirectionAxis(p),this.worldGravity.set(0,Number(this.shared.getVariable(this.system.data.gravity,[this.uuid,"particles","gravity"]))/100,0),this.noiseStrength=Number(this.shared.getVariable(e.noiseStrength,[this.uuid,"particles","noiseStrength"])),this.noiseScale=Number(this.shared.getVariable(e.noiseScale,[this.uuid,"particles","noiseScale"]));let d=e.colliderEntityId&&this.system.getColliderData(e.colliderEntityId),h={uOriginalPosition:{value:this.emitterShape.positionsTexture},uDirections:{value:this.emitterShape.directionsTexture},uDirectionsAxis:{value:this.directionAxis},uWorldQuaternion:{value:new Nl(0,0,0,1)},uColliderPos:{value:new Ir(0,0,0)},uColliderSize:{value:new Ir(0,0,0)},uForceIntensity:{value:d?d.forceIntensity:0},uForceDamping:{value:d?d.forceDambing:0},uColliderQuaternion:{value:new Nl(0,0,0,1)},uColliderQuaternionInvert:{value:new Nl(0,0,0,1)},particleSize:{value:0},uGravity:{value:this.worldGravity},uNoiseStrength:{value:this.noiseStrength},uNoiseScale:{value:this.noiseScale},uNoiseSeed:{value:e.noiseSeed},uRandomMassFactor:{value:e.randomMass},uBounce:{value:e.collisionBounce},uSpeed:{value:Number(this.shared.getVariable(e.speed,[this.uuid,"particles","speed"]))/Gh}};s.material.uniforms=h;let f={uIndex:{value:c},uTime:{value:0},uLastIndexEmitted:{value:0},uParticlesToEmit:{value:0}};l.material.uniforms=f;let m=[Number(this.shared.getVariable(e.shape.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.shape.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.shape.size[2],[this.uuid,"particles","shape_size_2"]))],y={..._n(this.system.data).shape,size:m};this.emitterShape.applyToShader(a.material.uniforms,y),o.init(),this.gpuCompute=o,this.positionSimRT=a,this.velocitySimRT=s,this.emissionRateSimRT=l,this.rootObject=this.createPrimaryEmitter(this.emitterShape.textureSize),this.add(this.rootObject),this.material.needsUpdate=!0}getDirectionFromVariable(e){let t=Number(this.shared.getVariable(e[0],[this.uuid,"particles","direction_x"])),o=Number(this.shared.getVariable(e[1],[this.uuid,"particles","direction_y"])),i=Number(this.shared.getVariable(e[2],[this.uuid,"particles","direction_z"]));return[t,o,i]}updateSimulationDefinition(e){if(this.simFeaturesDefinition.USE_COLLIDER=!1,this.simFeaturesDefinition.USE_ATTRACTOR=!1,this.simFeaturesDefinition.USE_VORTEX=!1,this.simFeaturesDefinition.USE_SPHERE_COLLIDER=!1,this.simFeaturesDefinition.USE_BOX_COLLIDER=!1,this.simFeaturesDefinition.USE_FORCE_LOCAL_SPACE=!1,this.simFeaturesDefinition.USE_NORMALS=!1,this.simFeaturesDefinition.USE_CURL_NOISE=!1,this.simFeaturesDefinition.USE_SIMPLEX_NOISE=!1,this.simFeaturesDefinition.USE_FBM_NOISE=!1,e.colliderEntityId&&this.system.colliderEntities.length>0){let o=this.system.getColliderData(e.colliderEntityId);switch(o?.forceType){case"attractor":this.simFeaturesDefinition.USE_ATTRACTOR=!0;break;case"collider":this.simFeaturesDefinition.USE_COLLIDER=!0;break;case"vortex":this.simFeaturesDefinition.USE_VORTEX=!0;break}let i=o?.colliderType;i==="sphere"&&(this.simFeaturesDefinition.USE_SPHERE_COLLIDER=!0),i==="box"&&(this.simFeaturesDefinition.USE_BOX_COLLIDER=!0),o?.forceRange==="helper"&&(this.simFeaturesDefinition.USE_FORCE_LOCAL_SPACE=!0)}e.directionMode==="normals"&&(this.simFeaturesDefinition.USE_NORMALS=!0),e.noiseType==="curl"&&(this.simFeaturesDefinition.USE_CURL_NOISE=!0),e.noiseType==="simplex"&&(this.simFeaturesDefinition.USE_SIMPLEX_NOISE=!0),e.noiseType==="fbm"&&(this.simFeaturesDefinition.USE_FBM_NOISE=!0);let t="";for(let[o,i]of Object.entries(this.simFeaturesDefinition))i&&(t+=`#define ${o}
3806
- `);return t}createShape(e,t){this.emitterShape&&this.emitterShape.dispose();let o=new Ir(Number(this.shared.getVariable(e.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.size[2],[this.uuid,"particles","shape_size_2"])));if(e.type==="MeshEmitterShape"){let i=null;return this.system.context.scene.traverseEntity(a=>{a.uuid===e.fromMeshId&&(i=a)}),i?new ys(o,t,e.type,i):new ys(o,t,"SphereEmitterShape")}else return new ys(o,t,e.type)}createPrimaryEmitter(e){let t,o=e*e;return t=new __(new R_(1,1,1),this.material,o),this.updateGeometryAttributes(t,e),this.material.needsUpdate=!0,t.onBeforeRender=()=>{this.applyWorldSpace()},t}getMaxParticlesAmount({birthRatePerSecond:e,particleMaxLifeTime:t,loopDuration:o=0}){return Math.ceil(e*(t+o))}dispose(){!this.gpuCompute||(this.rootObject?.parent?.remove(this.rootObject),this.gpuCompute.dispose(),this.material.nodeMaterialDispose(),this.emitterShape?.dispose())}GoEmitSomeParticles(e,t){let o=e-this.lastEmitTime,i=1/t;if(o>=i){let a=Math.max(1,Math.floor(o/i));return this.lastEmitTime=e,this.emittedParticlesAmount+a>this.particlesAmount&&(this.emittedParticlesAmount=0),this.emittedParticlesAmount+=a,a}return 0}checkIfAllParticlesAreDead(){return this.lastEmitTime+this.system.data.life+1<this.globalTime}reset(){this.hasBeenReset=!0,this.lastEmitTime=0,this.emittedParticlesAmount=0,this.gpuCompute&&this.init(_n(this.system.data))}startEmitting(e){this.isEmitting=!0,this.hasBeenReset=!1,this.lastEmitTime=e}stopEmitting(){this.isEmitting=!1}};import{BufferGeometry as G_,Float32BufferAttribute as F_,MeshBasicMaterial as j_}from"three";var Pd=class extends Ct{constructor(e,t,o){super(e,t);this.type="ParticleSystem";this.geometry=new G_;this.actualTime=0;this.currentLoopTime=0;this.started=!1;this.stopped=!1;this.timeoutId=void 0;this.isFrozen=!1;this.isIdle=!0;this.emitter=null;this.colliderEntities=[];this.renderer=null;this.isPreWarm=!1;this._hasOnAfterRenderBeenCalled=!1;this.onAfterRender=e=>{this._hasOnAfterRenderBeenCalled||(this._hasOnAfterRenderBeenCalled=!0,this.init(e))};this.context=o,this.data={...t,..._n(t)},this.geometry.setAttribute("position",new F_([],3)),this.material=new j_({colorWrite:!1}),this.frustumCulled=!1}init(e){this.renderer=e,this.emitter=new wd(e,this),this.add(this.emitter),this.updateParticleState(this.data)}update(e){if(!this.isReady||!this.started||this.isFrozen||this.isIdle)return;this.actualTime+=e,this.stopped||(this.currentLoopTime+=e);let t=this.data.emitTimeCycle==="one_time";if((this.data.emitTimeCycle==="loop"||t)&&this.currentLoopTime>this.data.emitTimeDuration*1e3&&(this.stopped||(this.stop(),t||this.start(this.data.emitTimeDelay*1e3))),this.emitter&&this.started){let i=this.actualTime/1e3;this.emitter.update(i,e)}this.scale.set(1,1,1),this.updateMatrix()}isReady(){return!!this.emitter}hasCollider(e){return this.colliderEntities.some(t=>t.identity===e)}getColliderData(e){let t=this.colliderEntities.find(o=>o.identity===e);return t?t.data:null}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),Re(e.path,["renderMaterial"])&&this.updateParticleState({renderMaterial:{...this.data.renderMaterial,...nt.drop(e,1).props}}),Re(e.path,["shape"])&&this.updateParticleState({shape:{...this.data.shape,...nt.drop(e,1).props}})}updateState(e,t){super.updateState(e,t),this.updateParticleState(e)}updateParticleState(e){if(!!this.emitter){if(e.colliderEntityId!==void 0&&e.colliderEntityId!==null){let t=this.context.scene.find(e.colliderEntityId);this.colliderEntities=t?[t]:[]}e.colliderEntityId===null&&(this.colliderEntities=[]),this.emitter.updateState(e),e.emitTimeCycle&&this.started&&this.start()}}updateFromColliderEntity(e){!this.emitter||(this.emitter.updateForceFieldParameters(e),this.stop(),this.start())}start(e=0){if(this.currentLoopTime=0,e){this.timeoutId=window.setTimeout(()=>{this.start(0)},e);return}this.started=!0,this.stopped=!1,this.isFrozen=!1,this.emitter?.startEmitting(this.actualTime/1e3)}froze(){this.isFrozen=!0}unFroze(){this.isFrozen=!1}stop(){this.stopped=!0,this.currentLoopTime=0,this.emitter?.stopEmitting(),clearTimeout(this.timeoutId)}reset(){this.started=!1,this.stopped=!1,this.emitter?.reset()}wakeUp(){this.isIdle=!1}sleep(){this.isIdle=!0,this.reset()}};function k_(){try{let n=window.location.href;if(n.includes("reducesubdiv=")){let r=n.indexOf("reducesubdiv=")+13;return parseInt(n.slice(r,r+1))}}catch{}}var Fh=k_();function U_(n,r,e){Fh!==void 0&&(r?.geometry?.subdivisions??0)>Fh&&(console.log("reducing subdivisions",r.name,r.geometry.subdivisions),r.geometry.subdivisions=Fh);let t;return r.geometry.type==="TextGeometry"?new An(n,r,e):r.geometry.type==="InputGeometry"?new xd(n,r,e):(r.geometry.type==="SubdivGeometry"?t=new ui(n,r,e):r.geometry.type==="PathGeometry"?t=new ms(n,r,e):r.geometry.type==="VectorGeometry"?t=new gd(n,r,e):r.geometry.type==="BooleanGeometry"?t=new nr(n,r,e):r.geometry.type==="UIGeometry"?t=new yi(n,r,e):t=new lt(n,r,e),t)}function Cd(n,r,e){return console.assert(r.type!==void 0),r.type==="Mesh"?U_(n,r,e):r.type==="Empty"?new Mn(n,r):r.type==="Particle"?new Pd(n,r,e):r.type==="ParticleCollider"?new ad(n,r,e):r.type==="Splat"?new Mn(n,r):r.type==="Bone"?new vd(n,r):r.type==="Page"?new Tr(n,r,e):r.type==="PointLight"?new yd(n,r,e):r.type==="SpotLight"?new ps(n,r,e):r.type==="DirectionalLight"?new ds(n,r,e):r.type==="Component"||r.type==="Instance"?new Xo(n,r,e):Nr.is(r.type)?new qo(n,r):(console.error(r),new Mn(n,r))}Rr.createEntity=Cd;function H_(n,r,e){let t=Cd(n.identity,r,e),o=n.children,i=n.attachedPaths,a=n.parent,s=n.component,l=n.instances,c=n.overrideData,u=n.uuid,p=n.stateSelection;n.dispose();for(let d of Object.keys(n))delete n[d];Object.setPrototypeOf(n,Object.getPrototypeOf(t));for(let d of Object.keys(t))n[d]=t[d];n.children=[...n.children,...o],n.attachedPaths=i,n.parent=a,n.component=s,n.instances=l,n.uuid=u,n.overrideData=c,n.updateState(n.data,e),p&&n.changeSelectedState(p,e),n.resetBBoxNeedsUpdate()}Rr.changeEntityProptotype=H_;Rr.Cloner=is;function HS(n,r,e,t){n.updateByOp(r,e,t,!1)}import{Matrix4 as $_,Ray as Y_,Raycaster as X_}from"three";function WS(n,r){let e=!1,t=r.getLayersOfType("transmission"),o=r.getLayersOfType("outline");return o.length>0&&(n.layers.set(8),t.length>0&&n.layers.enable(3),e=!0,rs(n),ts(n)),t.length===0&&o.length===0&&n.layers.set(0),n instanceof or&&n.needsAO&&n.layers.enable(5),e}function qS(n,r){if(!r.layers)return!1;let e=!1,t=r.getLayersOfType("transmission").filter(i=>i.data.visible),o=r.getLayersOfType("outline").filter(i=>i.data.visible);return t.length>0&&(n.layers.set(3),o.length>0&&n.layers.enable(8),e=!0),t.length===0&&o.length===0&&n.layers.set(0),n.needsAO&&n.layers.enable(5),e}function $S(n){let r=!1;return n.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)WS(e,e.material[t])&&(r=!0);else WS(e,e.material)&&(r=!0)}),r}function YS(n){let r=!1;return n.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)qS(e,e.material[t])&&(r=!0);else qS(e,e.material)&&(r=!0)}),r}var K_=new X_,Q_=new $_,Z_=new Y_;function El(n,r,e,t=!1){let o=n.cloner;if(o)for(let i of o.children){let a=Q_.copy(i.matrixWorld).invert(),s=Z_.copy(r.ray).applyMatrix4(a),l=n.matrixWorld;s.applyMatrix4(l);let c=K_;c.set(s.origin,s.direction),c.near=r.near,c.far=r.far;let u=c.intersectObject(n,!1);u.length>0&&e.push({...u[0],object:t?i:n})}}var Od=class{constructor(){this._constraints=new Map}setConstraint(r,e){e===null?this._constraints.delete(r):this._constraints.set(r,e)}removeDependencies(r){this._constraints.delete(r)}applyConstraints(r){let e=new Set;this._constraints.forEach((t,o)=>{let i=[o,t],a=t;for(;this._constraints.has(a);){if(a=this._constraints.get(a),i.includes(a)){console.warn(`circular dependency detected: ${i.join(" -> ")}`);break}e.has(a)||i.push(a)}for(let s=i.length-2;s>=0;s--)if(!e.has(i[s])){let l=r.find(i[s]);l?l.applyPathSnapping(r):console.warn(`missing entity ${i[s]}`),e.add(i[s])}})}findDependency(r,e){let t=r;for(;this._constraints.has(t);)if(t=this._constraints.get(t),t===e)return!0;return!1}};var XS="AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGAIf39/f39/f38AYAABfwISAQNlbnYGbWVtb3J5AgMAgIAEAwQDAAECBzkDEV9fd2FzbV9jYWxsX2N0b3JzAAALc29ydEluZGV4ZXMAARNlbXNjcmlwdGVuX3Rsc19pbml0AAIK3gMDAwABC9IDAwF/BnwBfgJAIAdFDQAgAysDUCEMIAMrAzAhDSADKwMQIQ5BACEDRP///////+9/IQtEAAAAAAAAEAAhCgNAIAIgA0ECdGoCfyAOIAEgA0EMbGoiCCoCALuiIA0gCCoCBLuioCAMIAgqAgi7oqBEAAAAAAAAsECiIgmZRAAAAAAAAOBBYwRAIAmqDAELQYCAgIB4CzYCACAJIAsgCSALYxshCyAJIAogCSAKZBshCiADQQFqIgMgB0cNAAsgB0UNACAGuCAKIAuhoyEJQQAhAwNAAn8gCSACIANBAnRqIgEoAgC3IAuhoiIKmUQAAAAAAADgQWMEQCAKqgwBC0GAgICAeAshCCABIAg2AgAgBCAIQQJ0aiIBIAEoAgBBAWo2AgAgA0EBaiIDIAdHDQALCyAGQQJPBEAgBCgCACEIQQEhAwNAIAQgA0ECdGoiASABKAIAIAhqIgg2AgAgA0EBaiIDIAZHDQALCyAHQQFrIgGtIQ8DQCAEIAIgD6dBAnQiA2ooAgBBAnRqIgcgBygCAEEBayIHNgIAIAUgASAHa0ECdGogACADaigCADYCACAPUCEDIA9CAX0hDyADRQ0ACyAGBEAgBEEAIAZBAnT8CwALCwQAQQAL";var bo=class{};$r(bo,"DepthMapRange",1<<16),$r(bo,"MemoryPageSize",65536),$r(bo,"BytesPerFloat",4),$r(bo,"BytesPerInt",4);function J_(n){let r,e,t,o,i,a,s,l,c,u,p,d,h,f,m,y;function g(M){let D=new Float64Array(u,a,16);for(let B=0;B<16;B++)D[B]=M[B];let _;if(t>1){r.exports.sortIndexes(o,i,c,a,s,l,d.DepthMapRange,t);let B=new Uint32Array(t);_=B.buffer,B.set(new Uint32Array(u,l,t))}else if(t===1){let B=new Uint32Array(t);B[0]=new Uint32Array(u,o,e)[0],_=B.buffer}else _=new ArrayBuffer(0);n.postMessage({sortDone:!0,indexesBuffer:_},[_])}function v(M,D,_){let B=new Float32Array(u,i,e*3);t=0;let V=new Uint32Array(u,o,e);for(let k=0;k<_.length-1;k++){let L=D[k],W=M[k].elements,F=L.filter(H=>H.enabled&&H.mode==="Include").map(H=>H.type==="Box"?C(H):N(H)),j=L.filter(H=>H.enabled&&H.mode==="Exclude").map(H=>H.type==="Box"?C(H):N(H));for(let H=_[k];H<_[k+1];H++){let q=h[H*3],re=h[H*3+1],ee=h[H*3+2];if((F.length===0||O(q,re,ee,F))&&(j.length===0||!O(q,re,ee,j))){let X=1/(W[3]*q+W[7]*re+W[11]*ee+W[15]);B[t*3]=(W[0]*q+W[4]*re+W[8]*ee+W[12])*X,B[t*3+1]=(W[1]*q+W[5]*re+W[9]*ee+W[13])*X,B[t*3+2]=(W[2]*q+W[6]*re+W[10]*ee+W[14])*X,V[t]=H,t++}}}}function w(M,D){let _=[],B=D.filter(L=>L.enabled&&L.mode==="Include").map(L=>L.type==="Box"?C(L):N(L)),V=D.filter(L=>L.enabled&&L.mode==="Exclude").map(L=>L.type==="Box"?C(L):N(L)),k=M.length;for(let L=0;L<k;L+=3){let W=M[L],F=M[L+1],j=M[L+2];(B.length===0||O(W,F,j,B))&&(V.length===0||!O(W,F,j,V))||_.push(L/3)}return _}function O(M,D,_,B,V){return B[V==="Intersect"?"every":"some"](k=>{let L=S(M,D,_,k.invRotationMatrix,k.cropCenter);return Array.isArray(k)?x(L.x,L.y,L.z,k):E(L.x,L.y,L.z,k)})}function S(M,D,_,B,V){let k=M-V[0],L=D-V[1],W=_-V[2],F=1/(B[3]*k+B[7]*L+B[11]*W+B[15]);return{x:(B[0]*k+B[4]*L+B[8]*W+B[12])*F+V[0],y:(B[1]*k+B[5]*L+B[9]*W+B[13])*F+V[1],z:(B[2]*k+B[6]*L+B[10]*W+B[14])*F+V[2]}}function C(M){let D=M.cropSize[0]/2,_=M.cropSize[1]/2,B=M.cropSize[2]/2,V=[M.cropCenter[0]-D,M.cropCenter[1]-_,M.cropCenter[2]-B,M.cropCenter[0]+D,M.cropCenter[1]+_,M.cropCenter[2]+B],k=T(M.cropRotation);return Object.assign(V,{invRotationMatrix:k,cropCenter:M.cropCenter})}function T(M){let D=[],_=M[0]*Math.PI/180,B=M[1]*Math.PI/180,V=M[2]*Math.PI/180,k=Math.cos(_),L=Math.sin(_),W=Math.cos(B),F=Math.sin(B),j=Math.cos(V),H=Math.sin(V),q=k*j,re=k*H,ee=L*j,X=L*H;return D[0]=W*j,D[1]=-W*H,D[2]=F,D[4]=re+ee*F,D[5]=q-X*F,D[6]=-L*W,D[8]=X-q*F,D[9]=ee+re*F,D[10]=k*W,D[12]=0,D[13]=0,D[14]=0,D[3]=0,D[7]=0,D[11]=0,D[15]=1,D}function x(M,D,_,B){return M>=B[0]&&M<=B[3]&&D>=B[1]&&D<=B[4]&&_>=B[2]&&_<=B[5]}function N(M){let D=2/M.cropSize[0],_=2/M.cropSize[1],B=2/M.cropSize[2],V=T(M.cropRotation);return{invRadiusX:D,invRadiusY:_,invRadiusZ:B,cropCenter:M.cropCenter,invRotationMatrix:V}}function E(M,D,_,B){let V=(M-B.cropCenter[0])*B.invRadiusX,k=(D-B.cropCenter[1])*B.invRadiusY,L=(_-B.cropCenter[2])*B.invRadiusZ;return V*V+k*k+L*L<=1}n.onmessage=M=>{if(M.data.getCroppedIndexes){let D=new Uint32Array(w(new Float32Array(M.data.positions),M.data.crops)).buffer;n.postMessage({outOfBoundsIndexes:D},[D])}else if(M.data.positions)p=M.data.positions,h=new Float32Array(p),m=M.data.meshMatrixWorlds,y=M.data.cropsArray,f=M.data.meshIndexIntervals,v(m,y,f),n.postMessage({sortSetupComplete:!0});else if(M.data.sort||M.data.newMatrixWorlds||M.data.newCropsArray)(M.data.newMatrixWorlds||M.data.newCropsArray)&&(y=M.data.newCropsArray||y,m=M.data.newMatrixWorlds||m,v(m,y,f)),g(M.data.sort.view,M.data.sort.cameraPosition);else if(M.data.init){d=M.data.init.Constants,e=M.data.init.splatCount;let D=d.BytesPerInt,_=d.BytesPerFloat*3,B=new Uint8Array(M.data.init.sorterWasmBytes),V=D+_,k=e*V,L=e*d.BytesPerInt*2+d.DepthMapRange*d.BytesPerInt*2,W=d.MemoryPageSize*32,F=k+L+W,j=Math.floor(F/d.MemoryPageSize)+1,H={module:{},env:{memory:new WebAssembly.Memory({initial:j*2,maximum:j*3,shared:!0})}};WebAssembly.compile(B).then(q=>WebAssembly.instantiate(q,H)).then(q=>{r=q,o=0,i=e*D,a=i+e*_,c=a+16*d.BytesPerFloat*2,s=c+e*d.BytesPerInt,l=s+d.DepthMapRange*d.BytesPerInt,u=H.env.memory.buffer,n.postMessage({sortSetupPhase1Complete:!0})})}}}function KS(n){let r=new Worker(URL.createObjectURL(new Blob(["(",J_.toString(),")(self)"],{type:"application/javascript"}))),e=atob(XS),t=new Uint8Array(e.length);for(let o=0;o<e.length;o++)t[o]=e.charCodeAt(o);return r.postMessage({init:{sorterWasmBytes:t.buffer,splatCount:n,Constants:{BytesPerFloat:bo.BytesPerFloat,BytesPerInt:bo.BytesPerInt,DepthMapRange:bo.DepthMapRange,MemoryPageSize:bo.MemoryPageSize}}}),r}import{Matrix4 as r1,Quaternion as o1,Vector2 as mB,Vector3 as gs}from"three";import{BufferAttribute as eB,BufferGeometry as tB,Color as rB,DataTexture as Td,DataUtils as oB,DoubleSide as nB,DynamicDrawUsage as iB,FloatType as ZS,HalfFloatType as aB,InstancedBufferAttribute as sB,InstancedBufferGeometry as lB,Mesh as cB,NormalBlending as uB,RGBAFormat as dB,RGBAIntegerFormat as pB,RGFormat as JS,ShaderMaterial as fB,UnsignedIntType as hB,Vector2 as Bn}from"three";var Ad=function(){let n=new Float32Array(1),r=new Int32Array(n.buffer);return function(e){return n[0]=e,r[0]}}(),QS=function(n,r,e,t){return n+(r<<8)+(e<<16)+(t<<24)};var Id=new Bn;function Md(n){let r=!1;return n.scene.objects.traverse((e,t)=>{if(t.visible===!1)return!0;t.type==="Splat"&&(r=!0)}),r}var Rn=class extends cB{constructor(e,t,o,i,a=!1,s=1,l,c){super(o,i);this.splatCount=t,this.meshIndexIntervals=l,this.meshMatrixWorlds=c,this.splatBuffers=e,this.geometry=o,this.material=i,this.splatDataTextures=null,this.halfPrecisionCovariancesOnGPU=a,this.devicePixelRatio=s,this.resetLocalSplatDataAndTexturesFromSplatBuffer()}static buildMesh(e,t,o=!1,i=1,a,s){let l=Rn.buildGeomtery(t),c=Rn.buildMaterial(a);return new Rn(e,t,l,c,o,i,a,s)}static buildMaterial(e){let t=`
3838
+ `;var Vh=10,bd=class extends N_{constructor(e,t){super();this.type="ParticleEmitter";this.debugMode=!1;this.worldSpace=!0;this.rootObject=null;this.gpuCompute=null;this.positionSimRT=null;this.velocitySimRT=null;this.emissionRateSimRT=null;this.emitterShape=void 0;this.isEmitting=!1;this.hasBeenReset=!1;this.emittedParticlesAmount=0;this.lastEmitTime=0;this.globalTime=0;this.targetFPS=60;this.previousRatio=1;this.lerpFactor=.4;this.particlesAmount=0;this.noiseStrength=0;this.noiseScale=0;this.isBillboardBased=!0;this.simFeaturesDefinition={USE_COLLIDER:!1,USE_ATTRACTOR:!1,USE_VORTEX:!1,USE_SPHERE_COLLIDER:!1,USE_BOX_COLLIDER:!1,USE_FORCE_LOCAL_SPACE:!1,USE_NORMALS:!1,USE_CURL_NOISE:!0,USE_SIMPLEX_NOISE:!1,USE_FBM_NOISE:!1};this.textureLoader=new R_;this.currentWorldPosition=new Ir;this.systemQuaternion=new FS;this.worldGravity=new Ir(0,0,0);this.directionAxis=new Ir(0,0,0);this.colliderV3=new Ir(0,0,0);this.colliderQuaternion=new FS(0,0,0,1);this.matrixAutoUpdate=!0,this.renderer=e,this.system=t,this.shared=t.context.shared;let o=t.data;this.material=new xd(o.renderMaterial,t.context),this.material.uniforms={uSize:{value:0},uSizeEnd:{value:0},uColor:{value:o.renderMaterial.color},uColor2:{value:o.renderMaterial.color2},uPosition:{value:new Ir(0,0,0)},uEmissionData:{value:new Ir(0,0,0)},uTexture:{value:this.defaultTexture},uWorldOffset:{value:new Ir(0,0,0)},uWorldQuaternion:{value:new Il(0,0,0,1)},uRandScaleFactor:{value:o.randomScale??0},uRandRotationFactor:{value:o.randomRotation??0},uRotation:{value:o.renderMaterial.spriteRotation[0]??0},uRotationEnd:{value:o.renderMaterial.spriteRotation[1]??0}},this.setTexture(this.material.uniforms,o.renderMaterial.texture),this.init(o)}setTexture(e,t){let o=t.data;if(typeof t=="string"){let i=this.shared.image(t),a=new jS(i.img);a.needsUpdate=!0,e.uTexture.value=a;return}if(typeof o!="string"){let i=new Image;i.onload=()=>{let l=new jS(i);l.needsUpdate=!0,e.uTexture.value=l};let a=new Blob([o],{type:"image/*"}),s=URL.createObjectURL(a);i.src=s}}updateGeometryAttributes(e,t){let o=SS(t);!this.emitterShape?.positionsAttribute||e.geometry.setAttribute("ref",new __(o,2))}applyWorldSpace(){if(!this.system.started||!this.worldSpace||!this.positionSimRT||!this.velocitySimRT)return;let e=this.system;e.getWorldQuaternion(this.systemQuaternion),this.systemQuaternion.invert(),e.getWorldPosition(this.currentWorldPosition),this.material.uniforms.uWorldOffset.value=this.currentWorldPosition,this.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize()),this.positionSimRT.material.uniforms.uWorldOffset.value=this.currentWorldPosition,this.systemQuaternion.invert(),this.positionSimRT.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize()),this.velocitySimRT.material.uniforms.uWorldQuaternion.value.copy(this.systemQuaternion.normalize())}update(e,t){if(!this.gpuCompute||!this.positionSimRT||!this.velocitySimRT||!this.emissionRateSimRT||this.hasBeenReset)return;if(this.checkIfAllParticlesAreDead()&&!this.hasBeenReset){this.reset();return}this.applyWorldSpace(),this.globalTime=e,this.positionSimRT.material.uniforms.uTime.value=e,this.emissionRateSimRT.material.uniforms.uTime.value=e;let o=1e3/t,i=this.targetFPS/o,a=this.previousRatio+(i-this.previousRatio)*this.lerpFactor;this.positionSimRT.material.uniforms.uFPSRatio.value=a,this.previousRatio=a;let s=this.isEmitting?this.GoEmitSomeParticles(e,this.system.data.birthRatePerSec):0;this.emissionRateSimRT.material.uniforms.uLastIndexEmitted.value=this.emittedParticlesAmount,this.emissionRateSimRT.material.uniforms.uParticlesToEmit.value=s,this.material.uniforms.uPosition.value=this.gpuCompute.getCurrentRenderTarget(this.positionSimRT)?.texture,this.system.colliderEntities.length>0&&this.renderColliders(),this.gpuCompute.compute()}renderColliders(){if(!this.velocitySimRT)return;let e=this.system.colliderEntities[0],t=this.simFeaturesDefinition.USE_COLLIDER||this.simFeaturesDefinition.USE_ATTRACTOR||this.simFeaturesDefinition.USE_VORTEX;if(e.destroyedInAction&&t&&this.init(Dn({...this.system.data,colliderEntityId:null})),!e||e.destroyedInAction)return;e.getWorldPosition(this.colliderV3),this.colliderV3.y===0&&(this.colliderV3.y=1e-4),this.velocitySimRT.material.uniforms.uColliderPos.value.copy(this.colliderV3);let o=e.data.size;this.colliderV3.fromArray(o),this.velocitySimRT.material.uniforms.uColliderSize.value.copy(this.simFeaturesDefinition.USE_SPHERE_COLLIDER?this.colliderV3.multiplyScalar(.5):this.colliderV3),e.getWorldQuaternion(this.colliderQuaternion),this.velocitySimRT.material.uniforms.uColliderQuaternion.value.copy(this.colliderQuaternion.normalize()),this.velocitySimRT.material.uniforms.uColliderQuaternionInvert.value.copy(this.colliderQuaternion.normalize().invert())}updateState(e){!this.velocitySimRT||!this.positionSimRT||(e.renderMaterial&&this.updateMaterialState(e.renderMaterial),this.updateParticleState(e))}updateVariableState(e,t){if(!this.velocitySimRT||!this.positionSimRT)return;t[2]==="size"&&this.material.updateState({size:[e,this.material.uniforms.uSizeEnd.value]}),t[2]==="sizeEnd"&&this.material.updateState({size:[this.material.uniforms.uSize.value,e]});let o=(i,a)=>{let s=[...this.system.data.shape.size];s[i]=a,this.updateParticleState({shape:{...this.system.data.shape,size:s}})};t[2]==="shape_size_0"&&o(0,e),t[2]==="shape_size_1"&&o(1,e),t[2]==="shape_size_2"&&o(2,e),t[2]==="speed"&&(this.velocitySimRT.material.uniforms.uSpeed.value=e/Vh),t[2]==="gravity"&&this.worldGravity.set(0,e/100,0),t[2]==="noiseStrength"&&(this.noiseStrength=e,this.velocitySimRT.material.uniforms.uNoiseStrength.value=this.noiseStrength),t[2]==="noiseScale"&&(this.noiseScale=e,this.velocitySimRT.material.uniforms.uNoiseScale.value=this.noiseScale),t[2]==="direction_x"&&(this.directionAxis=this.getDirectionAxis([Number(e),this.system.data.direction[1],this.system.data.direction[2]])),t[2]==="direction_y"&&(this.directionAxis=this.getDirectionAxis([this.system.data.direction[0],Number(e),this.system.data.direction[2]])),t[2]==="direction_z"&&(this.directionAxis=this.getDirectionAxis([this.system.data.direction[0],this.system.data.direction[1],Number(e)]))}updateMaterialState(e){this.material.updateState({...e,size:e.size?[Number(this.shared.getVariable(e.size[0],[this.uuid,"particles","size"])),Number(this.shared.getVariable(e.size[1],[this.uuid,"particles","sizeEnd"]))]:[0,0]}),e.texture&&(this.setTexture(this.material.uniforms,e.texture),this.material.needsUpdate=!0)}updateParticleState(e){if(!(!this.positionSimRT||!this.velocitySimRT)){if(this.shouldReInitGPUCompute(e)&&this.init(Dn(this.system.data)),e.life!==void 0&&(this.positionSimRT.material.uniforms.uMaxLifeTime.value=e.life),e.speed!==void 0&&(this.velocitySimRT.material.uniforms.uSpeed.value=Number(this.shared.getVariable(e.speed,[this.uuid,"particles","speed"]))/Vh),e.collisionBounce!==void 0&&(this.velocitySimRT.material.uniforms.uBounce.value=e.collisionBounce),e.noiseStrength!==void 0&&(this.noiseStrength=Number(this.shared.getVariable(e.noiseStrength,[this.uuid,"particles","noiseStrength"])),this.velocitySimRT.material.uniforms.uNoiseStrength.value=this.noiseStrength),e.noiseScale!==void 0&&(this.noiseScale=Number(this.shared.getVariable(e.noiseScale,[this.uuid,"particles","noiseScale"])),this.velocitySimRT.material.uniforms.uNoiseScale.value=this.noiseScale),e.noiseSeed!==void 0&&(this.velocitySimRT.material.uniforms.uNoiseSeed.value=e.noiseSeed),e.randomMass!==void 0&&(this.velocitySimRT.material.uniforms.uRandomMassFactor.value=e.randomMass),e.renderMaterial?.size!==void 0){let t=this.shared.getVariable(e.renderMaterial.size[0],[this.uuid,"particles","size"]);this.velocitySimRT.material.uniforms.particleSize.value=Number(t)}if(e.renderMaterial?.spriteRotation!==void 0&&(this.material.uniforms.uRotation.value=e.renderMaterial.spriteRotation[0],this.material.uniforms.uRotationEnd.value=e.renderMaterial.spriteRotation[1]),e.shape!==void 0){let t=e.shape.size??this.system.data.shape.size,o=[Number(this.shared.getVariable(t[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(t[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(t[2],[this.uuid,"particles","shape_size_2"]))],i={...Dn(this.system.data).shape,size:o};this.emitterShape?.applyToShader(this.positionSimRT.material.uniforms,i)}if(e.gravity!==void 0&&(this.worldGravity.set(0,Number(this.shared.getVariable(this.system.data.gravity,[this.uuid,"particles","gravity"]))/100,0),this.velocitySimRT.material.uniforms.uGravity={value:this.worldGravity}),e.direction!==void 0){let t=this.getDirectionFromVariable(e.direction);this.directionAxis=this.getDirectionAxis(t),this.velocitySimRT.material.uniforms.uDirectionsAxis.value=this.directionAxis}e.randomRotation!==void 0&&(this.material.uniforms.uRandRotationFactor.value=e.randomRotation),e.randomScale!==void 0&&(this.material.uniforms.uRandScaleFactor.value=e.randomScale)}}updateForceFieldParameters(e){!this.velocitySimRT||(e.forceIntensity!==void 0&&(this.velocitySimRT.material.uniforms.uForceIntensity.value=e.forceIntensity),e.forceDambing!==void 0&&(this.velocitySimRT.material.uniforms.uForceDamping.value=e.forceDambing))}getDirectionAxis(e){let t=[Number(e[0])*Lh.DEG2RAD,Number(e[1])*Lh.DEG2RAD,Number(e[2])*Lh.DEG2RAD],o=new L_(t[0],t[1],t[2],"XYZ");return this.directionAxis.set(0,1,0).applyEuler(o).normalize(),this.velocitySimRT&&(this.velocitySimRT.material.uniforms.uDirectionsAxis.value=this.directionAxis),this.directionAxis}shouldReInitGPUCompute(e){let{birthRatePerSec:t,rootObjectType:o,colliderEntityId:i,shape:a,emitTimeDuration:s,emitTimeCycle:l,life:c,directionMode:u,noiseType:p}=e;return t!==void 0||o!==void 0||(i||i===null)||l!==void 0||a!==void 0||c!==void 0||s!==void 0||u!==void 0||p!==void 0}init(e){this.dispose(),this.particlesAmount=this.getMaxParticlesAmount({birthRatePerSecond:e.birthRatePerSec,particleMaxLifeTime:e.life,loopDuration:e.emitTimeCycle==="infinity"?0:e.emitTimeDuration}),this.particlesAmount>1e5&&(console.warn(`The maximum number of particles is limited to ${1e5}.`),this.particlesAmount=1e5),this.emitterShape=this.createShape(e.shape,this.particlesAmount);let t=setInterval(()=>{if(!!this.emitterShape)if(isNaN(this.emitterShape.positionsTexture.source.data.data[0])){this.init(e);return}else clearInterval(t)},100);if(!this.emitterShape)return;let o=new V_(this.emitterShape.textureSize,this.emitterShape.textureSize,this.renderer),i=this.updateSimulationDefinition(e),a=o.addVariable("uCurrentPosition",i+AS,this.emitterShape.positionsTexture),s=o.addVariable("uCurrentVelocity",i+NS,this.emitterShape.directionsTexture),l=o.addVariable("uCurrentEmissionRate",zS,OS(this.emitterShape.textureSize));o.setVariableDependencies(a,[a,s,l]),o.setVariableDependencies(s,[a,s,l]),o.setVariableDependencies(l,[a,s,l]);let c=CS({size:this.emitterShape.textureSize}),u={uOriginalPosition:{value:this.emitterShape.positionsTexture},uWorldOffset:{value:new Ir(0,0,0)},uWorldQuaternion:{value:new Il(0,0,0,1)},uTime:{value:0},uFPSRatio:{value:1},uMaxLifeTime:{value:e.life},uEmitterSize:{value:new Ir(Number(this.shared.getVariable(e.shape.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.shape.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.shape.size[2],[this.uuid,"particles","shape_size_2"])))},particleSize:{value:0}};a.material.uniforms=u;let p=this.getDirectionFromVariable(e.direction);this.directionAxis=this.getDirectionAxis(p),this.worldGravity.set(0,Number(this.shared.getVariable(this.system.data.gravity,[this.uuid,"particles","gravity"]))/100,0),this.noiseStrength=Number(this.shared.getVariable(e.noiseStrength,[this.uuid,"particles","noiseStrength"])),this.noiseScale=Number(this.shared.getVariable(e.noiseScale,[this.uuid,"particles","noiseScale"]));let d=e.colliderEntityId&&this.system.getColliderData(e.colliderEntityId),f={uOriginalPosition:{value:this.emitterShape.positionsTexture},uDirections:{value:this.emitterShape.directionsTexture},uDirectionsAxis:{value:this.directionAxis},uWorldQuaternion:{value:new Il(0,0,0,1)},uColliderPos:{value:new Ir(0,0,0)},uColliderSize:{value:new Ir(0,0,0)},uForceIntensity:{value:d?d.forceIntensity:0},uForceDamping:{value:d?d.forceDambing:0},uColliderQuaternion:{value:new Il(0,0,0,1)},uColliderQuaternionInvert:{value:new Il(0,0,0,1)},particleSize:{value:0},uGravity:{value:this.worldGravity},uNoiseStrength:{value:this.noiseStrength},uNoiseScale:{value:this.noiseScale},uNoiseSeed:{value:e.noiseSeed},uRandomMassFactor:{value:e.randomMass},uBounce:{value:e.collisionBounce},uSpeed:{value:Number(this.shared.getVariable(e.speed,[this.uuid,"particles","speed"]))/Vh}};s.material.uniforms=f;let h={uIndex:{value:c},uTime:{value:0},uLastIndexEmitted:{value:0},uParticlesToEmit:{value:0}};l.material.uniforms=h;let m=[Number(this.shared.getVariable(e.shape.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.shape.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.shape.size[2],[this.uuid,"particles","shape_size_2"]))],y={...Dn(this.system.data).shape,size:m};this.emitterShape.applyToShader(a.material.uniforms,y),o.init(),this.gpuCompute=o,this.positionSimRT=a,this.velocitySimRT=s,this.emissionRateSimRT=l,this.rootObject=this.createPrimaryEmitter(this.emitterShape.textureSize),this.add(this.rootObject),this.material.needsUpdate=!0}getDirectionFromVariable(e){let t=Number(this.shared.getVariable(e[0],[this.uuid,"particles","direction_x"])),o=Number(this.shared.getVariable(e[1],[this.uuid,"particles","direction_y"])),i=Number(this.shared.getVariable(e[2],[this.uuid,"particles","direction_z"]));return[t,o,i]}updateSimulationDefinition(e){if(this.simFeaturesDefinition.USE_COLLIDER=!1,this.simFeaturesDefinition.USE_ATTRACTOR=!1,this.simFeaturesDefinition.USE_VORTEX=!1,this.simFeaturesDefinition.USE_SPHERE_COLLIDER=!1,this.simFeaturesDefinition.USE_BOX_COLLIDER=!1,this.simFeaturesDefinition.USE_FORCE_LOCAL_SPACE=!1,this.simFeaturesDefinition.USE_NORMALS=!1,this.simFeaturesDefinition.USE_CURL_NOISE=!1,this.simFeaturesDefinition.USE_SIMPLEX_NOISE=!1,this.simFeaturesDefinition.USE_FBM_NOISE=!1,e.colliderEntityId&&this.system.colliderEntities.length>0){let o=this.system.getColliderData(e.colliderEntityId);switch(o?.forceType){case"attractor":this.simFeaturesDefinition.USE_ATTRACTOR=!0;break;case"collider":this.simFeaturesDefinition.USE_COLLIDER=!0;break;case"vortex":this.simFeaturesDefinition.USE_VORTEX=!0;break}let i=o?.colliderType;i==="sphere"&&(this.simFeaturesDefinition.USE_SPHERE_COLLIDER=!0),i==="box"&&(this.simFeaturesDefinition.USE_BOX_COLLIDER=!0),o?.forceRange==="helper"&&(this.simFeaturesDefinition.USE_FORCE_LOCAL_SPACE=!0)}e.directionMode==="normals"&&(this.simFeaturesDefinition.USE_NORMALS=!0),e.noiseType==="curl"&&(this.simFeaturesDefinition.USE_CURL_NOISE=!0),e.noiseType==="simplex"&&(this.simFeaturesDefinition.USE_SIMPLEX_NOISE=!0),e.noiseType==="fbm"&&(this.simFeaturesDefinition.USE_FBM_NOISE=!0);let t="";for(let[o,i]of Object.entries(this.simFeaturesDefinition))i&&(t+=`#define ${o}
3839
+ `);return t}createShape(e,t){this.emitterShape&&this.emitterShape.dispose();let o=new Ir(Number(this.shared.getVariable(e.size[0],[this.uuid,"particles","shape_size_0"])),Number(this.shared.getVariable(e.size[1],[this.uuid,"particles","shape_size_1"])),Number(this.shared.getVariable(e.size[2],[this.uuid,"particles","shape_size_2"])));if(e.type==="MeshEmitterShape"){let i=null;return this.system.context.scene.traverseEntity(a=>{a.uuid===e.fromMeshId&&(i=a)}),i?new hs(o,t,e.type,i):new hs(o,t,"SphereEmitterShape")}else return new hs(o,t,e.type)}createPrimaryEmitter(e){let t,o=e*e;return t=new D_(new B_(1,1,1),this.material,o),this.updateGeometryAttributes(t,e),this.material.needsUpdate=!0,t.onBeforeRender=()=>{this.applyWorldSpace()},t}getMaxParticlesAmount({birthRatePerSecond:e,particleMaxLifeTime:t,loopDuration:o=0}){return Math.ceil(e*(t+o))}dispose(){!this.gpuCompute||(this.rootObject?.parent?.remove(this.rootObject),this.gpuCompute.dispose(),this.material.nodeMaterialDispose(),this.emitterShape?.dispose())}GoEmitSomeParticles(e,t){let o=e-this.lastEmitTime,i=1/t;if(o>=i){let a=Math.max(1,Math.floor(o/i));return this.lastEmitTime=e,this.emittedParticlesAmount+a>this.particlesAmount&&(this.emittedParticlesAmount=0),this.emittedParticlesAmount+=a,a}return 0}checkIfAllParticlesAreDead(){return this.lastEmitTime+this.system.data.life+1<this.globalTime}reset(){this.hasBeenReset=!0,this.lastEmitTime=0,this.emittedParticlesAmount=0,this.gpuCompute&&this.init(Dn(this.system.data))}startEmitting(e){this.isEmitting=!0,this.hasBeenReset=!1,this.lastEmitTime=e}stopEmitting(){this.isEmitting=!1}};import{BufferGeometry as z_,Float32BufferAttribute as G_,MeshBasicMaterial as F_}from"three";var vd=class extends Ct{constructor(e,t,o){super(e,t);this.type="ParticleSystem";this.geometry=new z_;this.actualTime=0;this.currentLoopTime=0;this.started=!1;this.stopped=!1;this.timeoutId=void 0;this.isFrozen=!1;this.isIdle=!0;this.emitter=null;this.colliderEntities=[];this.renderer=null;this.isPreWarm=!1;this._hasOnAfterRenderBeenCalled=!1;this.onAfterRender=e=>{this._hasOnAfterRenderBeenCalled||(this._hasOnAfterRenderBeenCalled=!0,this.init(e))};this.context=o,this.data={...t,...Dn(t)},this.geometry.setAttribute("position",new G_([],3)),this.material=new F_({colorWrite:!1}),this.frustumCulled=!1}init(e){this.renderer=e,this.emitter=new bd(e,this),this.add(this.emitter),this.updateParticleState(this.data)}update(e){if(!this.isReady||!this.started||this.isFrozen||this.isIdle)return;this.actualTime+=e,this.stopped||(this.currentLoopTime+=e);let t=this.data.emitTimeCycle==="one_time";if((this.data.emitTimeCycle==="loop"||t)&&this.currentLoopTime>this.data.emitTimeDuration*1e3&&(this.stopped||(this.stop(),t||this.start(this.data.emitTimeDelay*1e3))),this.emitter&&this.started){let i=this.actualTime/1e3;this.emitter.update(i,e)}this.scale.set(1,1,1),this.updateMatrix()}isReady(){return!!this.emitter}hasCollider(e){return this.colliderEntities.some(t=>t.identity===e)}getColliderData(e){let t=this.colliderEntities.find(o=>o.identity===e);return t?t.data:null}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),Re(e.path,["renderMaterial"])&&this.updateParticleState({renderMaterial:{...this.data.renderMaterial,...nt.drop(e,1).props}}),Re(e.path,["shape"])&&this.updateParticleState({shape:{...this.data.shape,...nt.drop(e,1).props}})}updateState(e,t){super.updateState(e,t),this.updateParticleState(e)}updateParticleState(e){if(!!this.emitter){if(e.colliderEntityId!==void 0&&e.colliderEntityId!==null){let t=this.context.scene.find(e.colliderEntityId);this.colliderEntities=t?[t]:[]}e.colliderEntityId===null&&(this.colliderEntities=[]),this.emitter.updateState(e),e.emitTimeCycle&&this.started&&this.start()}}updateFromColliderEntity(e){!this.emitter||(this.emitter.updateForceFieldParameters(e),this.stop(),this.start())}start(e=0){if(this.currentLoopTime=0,e){this.timeoutId=window.setTimeout(()=>{this.start(0)},e);return}this.started=!0,this.stopped=!1,this.isFrozen=!1,this.emitter?.startEmitting(this.actualTime/1e3)}froze(){this.isFrozen=!0}unFroze(){this.isFrozen=!1}stop(){this.stopped=!0,this.currentLoopTime=0,this.emitter?.stopEmitting(),clearTimeout(this.timeoutId)}reset(){this.started=!1,this.stopped=!1,this.emitter?.reset()}wakeUp(){this.isIdle=!1}sleep(){this.isIdle=!0,this.reset()}};function j_(){try{let n=window.location.href;if(n.includes("reducesubdiv=")){let r=n.indexOf("reducesubdiv=")+13;return parseInt(n.slice(r,r+1))}}catch{}}var zh=j_();function k_(n,r,e){zh!==void 0&&(r?.geometry?.subdivisions??0)>zh&&(console.log("reducing subdivisions",r.name,r.geometry.subdivisions),r.geometry.subdivisions=zh);let t;return r.geometry.type==="TextGeometry"?new On(n,r,e):r.geometry.type==="InputGeometry"?new md(n,r,e):(r.geometry.type==="SubdivGeometry"?t=new ci(n,r,e):r.geometry.type==="PathGeometry"?t=new fs(n,r,e):r.geometry.type==="VectorGeometry"?t=new hd(n,r,e):r.geometry.type==="BooleanGeometry"?t=new nr(n,r,e):r.geometry.type==="UIGeometry"?t=new mi(n,r,e):t=new lt(n,r,e),t)}function Sd(n,r,e){return console.assert(r.type!==void 0),r.type==="Mesh"?k_(n,r,e):r.type==="Empty"?new In(n,r):r.type==="Particle"?new vd(n,r,e):r.type==="ParticleCollider"?new od(n,r,e):r.type==="Splat"?new In(n,r):r.type==="Bone"?new gd(n,r):r.type==="Page"?new Tr(n,r,e):r.type==="PointLight"?new fd(n,r,e):r.type==="SpotLight"?new us(n,r,e):r.type==="DirectionalLight"?new cs(n,r,e):r.type==="Component"||r.type==="Instance"?new Yo(n,r,e):Nr.is(r.type)?new Wo(n,r):(console.error(r),new In(n,r))}Rr.createEntity=Sd;function U_(n,r,e){let t=Sd(n.identity,r,e),o=n.children,i=n.attachedPaths,a=n.parent,s=n.component,l=n.instances,c=n.overrideData,u=n.uuid,p=n.stateSelection;n.dispose();for(let d of Object.keys(n))delete n[d];Object.setPrototypeOf(n,Object.getPrototypeOf(t));for(let d of Object.keys(t))n[d]=t[d];n.children=[...n.children,...o],n.attachedPaths=i,n.parent=a,n.component=s,n.instances=l,n.uuid=u,n.overrideData=c,n.updateState(n.data,e),p&&n.changeSelectedState(p,e),n.resetBBoxNeedsUpdate()}Rr.changeEntityProptotype=U_;Rr.Cloner=os;function kS(n,r,e,t){n.updateByOp(r,e,t,!1)}import{Matrix4 as q_,Ray as $_,Raycaster as Y_}from"three";function US(n,r){let e=!1,t=r.getLayersOfType("transmission"),o=r.getLayersOfType("outline");return o.length>0&&(n.layers.set(8),t.length>0&&n.layers.enable(3),e=!0,ts(n),es(n)),t.length===0&&o.length===0&&n.layers.set(0),n instanceof or&&n.needsAO&&n.layers.enable(5),e}function HS(n,r){if(!r.layers)return!1;let e=!1,t=r.getLayersOfType("transmission").filter(i=>i.data.visible),o=r.getLayersOfType("outline").filter(i=>i.data.visible);return t.length>0&&(n.layers.set(3),o.length>0&&n.layers.enable(8),e=!0),t.length===0&&o.length===0&&n.layers.set(0),n.needsAO&&n.layers.enable(5),e}function WS(n){let r=!1;return n.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)US(e,e.material[t])&&(r=!0);else US(e,e.material)&&(r=!0)}),r}function qS(n){let r=!1;return n.traverseEntity(e=>{if(e instanceof or)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)HS(e,e.material[t])&&(r=!0);else HS(e,e.material)&&(r=!0)}),r}var X_=new Y_,K_=new q_,Q_=new $_;function Tl(n,r,e,t=!1){let o=n.cloner;if(o)for(let i of o.children){let a=K_.copy(i.matrixWorld).invert(),s=Q_.copy(r.ray).applyMatrix4(a),l=n.matrixWorld;s.applyMatrix4(l);let c=X_;c.set(s.origin,s.direction),c.near=r.near,c.far=r.far;let u=c.intersectObject(n,!1);u.length>0&&e.push({...u[0],object:t?i:n})}}var wd=class{constructor(){this._constraints=new Map}setConstraint(r,e){e===null?this._constraints.delete(r):this._constraints.set(r,e)}removeDependencies(r){this._constraints.delete(r)}applyConstraints(r){let e=new Set;this._constraints.forEach((t,o)=>{let i=[o,t],a=t;for(;this._constraints.has(a);){if(a=this._constraints.get(a),i.includes(a)){console.warn(`circular dependency detected: ${i.join(" -> ")}`);break}e.has(a)||i.push(a)}for(let s=i.length-2;s>=0;s--)if(!e.has(i[s])){let l=r.find(i[s]);l?l.applyPathSnapping(r):console.warn(`missing entity ${i[s]}`),e.add(i[s])}})}findDependency(r,e){let t=r;for(;this._constraints.has(t);)if(t=this._constraints.get(t),t===e)return!0;return!1}};var $S="AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGAIf39/f39/f38AYAABfwISAQNlbnYGbWVtb3J5AgMAgIAEAwQDAAECBzkDEV9fd2FzbV9jYWxsX2N0b3JzAAALc29ydEluZGV4ZXMAARNlbXNjcmlwdGVuX3Rsc19pbml0AAIK3gMDAwABC9IDAwF/BnwBfgJAIAdFDQAgAysDUCEMIAMrAzAhDSADKwMQIQ5BACEDRP///////+9/IQtEAAAAAAAAEAAhCgNAIAIgA0ECdGoCfyAOIAEgA0EMbGoiCCoCALuiIA0gCCoCBLuioCAMIAgqAgi7oqBEAAAAAAAAsECiIgmZRAAAAAAAAOBBYwRAIAmqDAELQYCAgIB4CzYCACAJIAsgCSALYxshCyAJIAogCSAKZBshCiADQQFqIgMgB0cNAAsgB0UNACAGuCAKIAuhoyEJQQAhAwNAAn8gCSACIANBAnRqIgEoAgC3IAuhoiIKmUQAAAAAAADgQWMEQCAKqgwBC0GAgICAeAshCCABIAg2AgAgBCAIQQJ0aiIBIAEoAgBBAWo2AgAgA0EBaiIDIAdHDQALCyAGQQJPBEAgBCgCACEIQQEhAwNAIAQgA0ECdGoiASABKAIAIAhqIgg2AgAgA0EBaiIDIAZHDQALCyAHQQFrIgGtIQ8DQCAEIAIgD6dBAnQiA2ooAgBBAnRqIgcgBygCAEEBayIHNgIAIAUgASAHa0ECdGogACADaigCADYCACAPUCEDIA9CAX0hDyADRQ0ACyAGBEAgBEEAIAZBAnT8CwALCwQAQQAL";var bo=class{};$r(bo,"DepthMapRange",1<<16),$r(bo,"MemoryPageSize",65536),$r(bo,"BytesPerFloat",4),$r(bo,"BytesPerInt",4);function Z_(n){let r,e,t,o,i,a,s,l,c,u,p,d,f,h,m,y;function b(M){let N=new Float64Array(u,a,16);for(let B=0;B<16;B++)N[B]=M[B];let _;if(t>1){r.exports.sortIndexes(o,i,c,a,s,l,d.DepthMapRange,t);let B=new Uint32Array(t);_=B.buffer,B.set(new Uint32Array(u,l,t))}else if(t===1){let B=new Uint32Array(t);B[0]=new Uint32Array(u,o,e)[0],_=B.buffer}else _=new ArrayBuffer(0);n.postMessage({sortDone:!0,indexesBuffer:_},[_])}function S(M,N,_){let B=new Float32Array(u,i,e*3);t=0;let V=new Uint32Array(u,o,e);for(let k=0;k<_.length-1;k++){let L=N[k],W=M[k].elements,F=L.filter(H=>H.enabled&&H.mode==="Include").map(H=>H.type==="Box"?A(H):D(H)),j=L.filter(H=>H.enabled&&H.mode==="Exclude").map(H=>H.type==="Box"?A(H):D(H));for(let H=_[k];H<_[k+1];H++){let q=f[H*3],re=f[H*3+1],ee=f[H*3+2];if((F.length===0||C(q,re,ee,F))&&(j.length===0||!C(q,re,ee,j))){let X=1/(W[3]*q+W[7]*re+W[11]*ee+W[15]);B[t*3]=(W[0]*q+W[4]*re+W[8]*ee+W[12])*X,B[t*3+1]=(W[1]*q+W[5]*re+W[9]*ee+W[13])*X,B[t*3+2]=(W[2]*q+W[6]*re+W[10]*ee+W[14])*X,V[t]=H,t++}}}}function P(M,N){let _=[],B=N.filter(L=>L.enabled&&L.mode==="Include").map(L=>L.type==="Box"?A(L):D(L)),V=N.filter(L=>L.enabled&&L.mode==="Exclude").map(L=>L.type==="Box"?A(L):D(L)),k=M.length;for(let L=0;L<k;L+=3){let W=M[L],F=M[L+1],j=M[L+2];(B.length===0||C(W,F,j,B))&&(V.length===0||!C(W,F,j,V))||_.push(L/3)}return _}function C(M,N,_,B,V){return B[V==="Intersect"?"every":"some"](k=>{let L=v(M,N,_,k.invRotationMatrix,k.cropCenter);return Array.isArray(k)?g(L.x,L.y,L.z,k):E(L.x,L.y,L.z,k)})}function v(M,N,_,B,V){let k=M-V[0],L=N-V[1],W=_-V[2],F=1/(B[3]*k+B[7]*L+B[11]*W+B[15]);return{x:(B[0]*k+B[4]*L+B[8]*W+B[12])*F+V[0],y:(B[1]*k+B[5]*L+B[9]*W+B[13])*F+V[1],z:(B[2]*k+B[6]*L+B[10]*W+B[14])*F+V[2]}}function A(M){let N=M.cropSize[0]/2,_=M.cropSize[1]/2,B=M.cropSize[2]/2,V=[M.cropCenter[0]-N,M.cropCenter[1]-_,M.cropCenter[2]-B,M.cropCenter[0]+N,M.cropCenter[1]+_,M.cropCenter[2]+B],k=T(M.cropRotation);return Object.assign(V,{invRotationMatrix:k,cropCenter:M.cropCenter})}function T(M){let N=[],_=M[0]*Math.PI/180,B=M[1]*Math.PI/180,V=M[2]*Math.PI/180,k=Math.cos(_),L=Math.sin(_),W=Math.cos(B),F=Math.sin(B),j=Math.cos(V),H=Math.sin(V),q=k*j,re=k*H,ee=L*j,X=L*H;return N[0]=W*j,N[1]=-W*H,N[2]=F,N[4]=re+ee*F,N[5]=q-X*F,N[6]=-L*W,N[8]=X-q*F,N[9]=ee+re*F,N[10]=k*W,N[12]=0,N[13]=0,N[14]=0,N[3]=0,N[7]=0,N[11]=0,N[15]=1,N}function g(M,N,_,B){return M>=B[0]&&M<=B[3]&&N>=B[1]&&N<=B[4]&&_>=B[2]&&_<=B[5]}function D(M){let N=2/M.cropSize[0],_=2/M.cropSize[1],B=2/M.cropSize[2],V=T(M.cropRotation);return{invRadiusX:N,invRadiusY:_,invRadiusZ:B,cropCenter:M.cropCenter,invRotationMatrix:V}}function E(M,N,_,B){let V=(M-B.cropCenter[0])*B.invRadiusX,k=(N-B.cropCenter[1])*B.invRadiusY,L=(_-B.cropCenter[2])*B.invRadiusZ;return V*V+k*k+L*L<=1}n.onmessage=M=>{if(M.data.getCroppedIndexes){let N=new Uint32Array(P(new Float32Array(M.data.positions),M.data.crops)).buffer;n.postMessage({outOfBoundsIndexes:N},[N])}else if(M.data.positions)p=M.data.positions,f=new Float32Array(p),m=M.data.meshMatrixWorlds,y=M.data.cropsArray,h=M.data.meshIndexIntervals,S(m,y,h),n.postMessage({sortSetupComplete:!0});else if(M.data.sort||M.data.newMatrixWorlds||M.data.newCropsArray)(M.data.newMatrixWorlds||M.data.newCropsArray)&&(y=M.data.newCropsArray||y,m=M.data.newMatrixWorlds||m,S(m,y,h)),b(M.data.sort.view,M.data.sort.cameraPosition);else if(M.data.init){d=M.data.init.Constants,e=M.data.init.splatCount;let N=d.BytesPerInt,_=d.BytesPerFloat*3,B=new Uint8Array(M.data.init.sorterWasmBytes),V=N+_,k=e*V,L=e*d.BytesPerInt*2+d.DepthMapRange*d.BytesPerInt*2,W=d.MemoryPageSize*32,F=k+L+W,j=Math.floor(F/d.MemoryPageSize)+1,H={module:{},env:{memory:new WebAssembly.Memory({initial:j*2,maximum:j*3,shared:!0})}};WebAssembly.compile(B).then(q=>WebAssembly.instantiate(q,H)).then(q=>{r=q,o=0,i=e*N,a=i+e*_,c=a+16*d.BytesPerFloat*2,s=c+e*d.BytesPerInt,l=s+d.DepthMapRange*d.BytesPerInt,u=H.env.memory.buffer,n.postMessage({sortSetupPhase1Complete:!0})})}}}function YS(n){let r=new Worker(URL.createObjectURL(new Blob(["(",Z_.toString(),")(self)"],{type:"application/javascript"}))),e=atob($S),t=new Uint8Array(e.length);for(let o=0;o<e.length;o++)t[o]=e.charCodeAt(o);return r.postMessage({init:{sorterWasmBytes:t.buffer,splatCount:n,Constants:{BytesPerFloat:bo.BytesPerFloat,BytesPerInt:bo.BytesPerInt,DepthMapRange:bo.DepthMapRange,MemoryPageSize:bo.MemoryPageSize}}}),r}import{Matrix4 as e1,Quaternion as t1,Vector2 as hB,Vector3 as ms}from"three";import{BufferAttribute as J_,BufferGeometry as eB,Color as tB,DataTexture as Cd,DataUtils as rB,DoubleSide as oB,DynamicDrawUsage as nB,FloatType as KS,HalfFloatType as iB,InstancedBufferAttribute as aB,InstancedBufferGeometry as sB,Mesh as lB,NormalBlending as cB,RGBAFormat as uB,RGBAIntegerFormat as dB,RGFormat as QS,ShaderMaterial as pB,UnsignedIntType as fB,Vector2 as _n}from"three";var Pd=function(){let n=new Float32Array(1),r=new Int32Array(n.buffer);return function(e){return n[0]=e,r[0]}}(),XS=function(n,r,e,t){return n+(r<<8)+(e<<16)+(t<<24)};var Od=new _n;function Ad(n){let r=!1;return n.scene.objects.traverse((e,t)=>{if(t.visible===!1)return!0;t.type==="Splat"&&(r=!0)}),r}var Bn=class extends lB{constructor(e,t,o,i,a=!1,s=1,l,c){super(o,i);this.splatCount=t,this.meshIndexIntervals=l,this.meshMatrixWorlds=c,this.splatBuffers=e,this.geometry=o,this.material=i,this.splatDataTextures=null,this.halfPrecisionCovariancesOnGPU=a,this.devicePixelRatio=s,this.resetLocalSplatDataAndTexturesFromSplatBuffer()}static buildMesh(e,t,o=!1,i=1,a,s){let l=Bn.buildGeomtery(t),c=Bn.buildMaterial(a);return new Bn(e,t,l,c,o,i,a,s)}static buildMaterial(e){let t=`
3807
3840
  precision highp float;
3808
3841
  #include <common>
3809
3842
 
@@ -3957,4 +3990,4 @@ void main() {
3957
3990
  A = exp(A) * vColor.a;
3958
3991
  gl_FragColor = vec4(color.rgb, A);
3959
3992
  gVelocity = vec4(0.0); // so it is ignored by TAA
3960
- }`,i={covariancesTexture:{type:"t",value:null},centersColorsTexture:{type:"t",value:null},meshIndexIntervals:{value:e},meshMatrixWorldsTexture:{type:"t",value:null},focal:{type:"v2",value:new Bn},viewport:{type:"v2",value:new Bn},basisViewport:{type:"v2",value:new Bn},debugColor:{type:"v3",value:new rB},covariancesTextureSize:{type:"v2",value:new Bn(1024,1024)},centersColorsTextureSize:{type:"v2",value:new Bn(1024,1024)},orthoZoom:{type:"f",value:-1}};return new fB({uniforms:i,vertexShader:t,fragmentShader:o,transparent:!0,alphaTest:1,blending:uB,depthTest:!0,depthWrite:!1,side:nB})}static buildGeomtery(e){let t=new tB;t.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),i=new eB(o,3);t.setAttribute("position",i),i.setXYZ(0,-1,-1,0),i.setXYZ(1,-1,1,0),i.setXYZ(2,1,1,0),i.setXYZ(3,1,-1,0),i.needsUpdate=!0;let a=new lB().copy(t),s=new Uint32Array(e),l=new sB(s,1,!1);return l.setUsage(iB),a.setAttribute("splatIndex",l),a.instanceCount=e,a}resetLocalSplatDataAndTexturesFromSplatBuffer(){this.updateLocalSplatDataFromSplatBuffer(),this.allocateAndStoreLocalSplatDataInTextures()}updateLocalSplatDataFromSplatBuffer(){this.splatBuffers.forEach(i=>i.buildPreComputedBuffers()),this.covariances=new Float32Array(this.splatCount*6),this.colors=new Uint8Array(this.splatCount*4),this.centers=new Float32Array(this.splatCount*3);let e=0,t=0,o=0;for(let i of this.splatBuffers){let a=i.nsplats;this.colors.subarray(e,e+a*4).set(i.colorsA),e+=a*4,this.centers.subarray(t,t+a*3).set(i.decoded.xyz.denormDequant().data),t+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(i.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,i=new Bn(4096,1024);for(;i.x*i.y*2<o*6;)i.y*=2;let a=new Bn(4096,1024);for(;a.x*a.y*4<o*4;)a.y*=2;let s,l;if(this.halfPrecisionCovariancesOnGPU){l=new Uint16Array(i.x*i.y*2);for(let f=0;f<this.covariances.length;f++)l[f]=oB.toHalfFloat(this.covariances[f]);s=new Td(l,i.x,i.y,JS,aB)}else l=new Float32Array(i.x*i.y*2),l.set(this.covariances),s=new Td(l,i.x,i.y,JS,ZS);s.needsUpdate=!0,this.material.uniforms.covariancesTexture.value=s,this.material.uniforms.covariancesTextureSize.value.copy(i);let c=new Uint32Array(a.x*a.y*4);for(let f=0;f<o;f++){let m=f*4,y=f*3,g=f*4;c[g]=QS(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[g+1]=Ad(this.centers[y]),c[g+2]=Ad(this.centers[y+1]),c[g+3]=Ad(this.centers[y+2])}let u=new Td(c,a.x,a.y,pB,hB);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let p=256*4,d=new Float32Array(256*16);for(let f=0;f<this.meshMatrixWorlds.length;f++)d.set(this.meshMatrixWorlds[f].elements,f*16);let h=new Td(d,p,1,dB,ZS);h.needsUpdate=!0,this.material.uniforms.meshMatrixWorldsTexture.value=h,this.material.uniformsNeedUpdate=!0,this.splatDataTextures={covariances:{data:l,texture:s,size:i},centerColors:{data:c,texture:u,size:a},meshMatrixWorlds:{data:d,texture:h}}}updateIndexes(e){let t=this.geometry;t.attributes.splatIndex.set(e),t.attributes.splatIndex.needsUpdate=!0,t.instanceCount=e.length}updateUniforms(e,t,o,i){this.splatCount>0&&(Id.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(Id),this.material.uniforms.basisViewport.value.set(2/Id.x,2/Id.y),this.material.uniforms.focal.value.set(t,o),this.material.uniforms.orthoZoom.value=i,this.material.uniformsNeedUpdate=!0)}getSplatDataTextures(){return this.splatDataTextures}getSplatCount(){return this.splatCount}getCenters(){return this.centers}getColors(){return this.colors}getCovariances(){return this.covariances}dispose(){this.geometry.dispose(),this.material.dispose(),this.splatDataTextures&&(this.splatDataTextures.covariances.texture.dispose(),this.splatDataTextures.centerColors.texture.dispose(),this.splatDataTextures.meshMatrixWorlds.texture.dispose()),this.removeFromParent()}};var t1,jh=new Promise(n=>{t1=n}),e1=!1;var Ed;function kh(){if(e1)return;if(Ed)return Ed;async function n(){let e=await import("./gaussian-splat-compression.js");t1(e),e1=!0}return Ed=n(),Ed}var n1;jh.then(n=>n1=n);var Dl=class{constructor(r={}){$r(this,"updateView",function(){let r=new r1,e=[],t=new gs(0,0,-1),o=new gs(0,0,-1),i=new gs,a=new gs;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let d=!1,h=!1;if(o.dot(t)<=.95&&(d=!0),a.copy(l.position).sub(i).length()>=1&&(h=!0),!d&&!h&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,i.copy(l.position),t.copy(o),r.copy(l.matrixWorld).invert(),r.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let p={sort:{view:r.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=p:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(p))}}());this.scene=r.scene,this.currentPage=null,this.devicePixelRatio=window.devicePixelRatio,this.sortWorker=null,this.splatRenderCount=0,this.splatSortCount=0,this.splatMesh=null,this.sortRunning=!1,this.meshMatrixWorlds=null,this.meshMatrixWorldsOld=null,this.cropsArray=null,this.splatEntries=null,this.queuedMessage=null,this.needsInitialRender=!0,this.dummyPerspectiveMatrix=new r1().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(r,e){let t=new mB;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(r.getSize(t),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*t.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*t.y*.45,this.splatMesh.updateUniforms(t,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(r={}){this.activePage=this.scene.activePage,r.position&&(r.position=new gs().fromArray(r.position)),r.orientation&&(r.orientation=new o1().fromArray(r.orientation)),r.halfPrecisionCovariances=!!r.halfPrecisionCovariances;let e=[];if(this.splatEntries=e,this.activePage.traverseVisibleEntity(a=>{a.data.type==="Splat"&&e.push(a)}),this.splatMesh&&this.splatMesh.dispose(),e.length===0)return this.splatMesh=null,!1;this.meshMatrixWorlds=e.map(a=>a.matrixWorld),this.meshMatrixWorldsOld=e.map(a=>a.matrixWorld.clone()),this.cropsArray=e.map(a=>a.data.crops.map(s=>s.data));let t=e.map(a=>new n1.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,i=[0];for(let a of t)o+=a.getSplatCount(),i.push(o);return this.setupSplatMesh(t,o,r.position,r.orientation,r.halfPrecisionCovariances,this.devicePixelRatio,i,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let r=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)r.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,t)=>e.equals(this.meshMatrixWorldsOld[t]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let r=!1;return this.splatEntries.forEach((e,t)=>{e.data.crops.forEach((o,i)=>{this.cropsArray[t][i]===void 0?(r=!0,this.cropsArray[t][i]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[t][i][a][c])?(r=!0,this.cropsArray[t][i][a]=s):s!==this.cropsArray[t][i]?.[a]&&(r=!0,this.cropsArray[t][i][a]=s)})}),e.data.crops.length!==this.cropsArray[t]?.length&&(this.cropsArray[t].length=e.data.crops.length,r=!0)}),r}setupSplatMesh(r,e,t=new gs,o=new o1,i=!1,a=1,s,l){this.splatMesh=Rn.buildMesh(r,e,i,a,s,l),this.splatMesh.position.copy(t),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,p)=>this.update(c,p)}setupSortWorker(r){this.sortWorker=KS(r),this.sortWorker.onmessage=e=>{e.data.sortDone?(this.sortRunning=!1,this.splatMesh?.updateIndexes(new Uint32Array(e.data.indexesBuffer)),this.lastSortTime=e.data.sortTime,this.queuedMessage&&(this.sortWorker.postMessage(this.queuedMessage),this.queuedMessage=null)):e.data.sortCanceled?this.sortRunning=!1:e.data.sortSetupPhase1Complete?this.sortWorker.postMessage({positions:this.splatMesh.getCenters().buffer,meshMatrixWorlds:this.splatMesh.meshMatrixWorlds,meshIndexIntervals:this.splatMesh.meshIndexIntervals,cropsArray:this.cropsArray}):e.data.sortSetupComplete&&(this.splatDataTextures=this.splatMesh.getSplatDataTextures(),this.scene.activePage.add(this.splatMesh),this.needsInitialRender=!0)}}update(r,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(r,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var wB=new vB;wB.wireframe=!0;var i1=new gB,Nd=class extends yB{constructor(e,t){super();this.data=e;this.sharedAssets=t;this.enableHelpers=!1;this.wireframeState=!1;this.needsTransmissionDirty=!0;this.needsNormalDirty=!0;this._needsTransmission=!1;this._needsNormal=!1;this.geometryCacheChanged=!1;this.splatViewer=null;this.entityByUuid={};this.entityIdentityToEntity={};this.toExpandCloner=new Set;this.toUpdateCloner=new Set;this.pendingCommands=[];this.pathConstraints=new Od;this.invisibleObjects=new Mn("jflkdsafjasdifjaslk",{...Uc.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,t),this.matrixAutoUpdate=!1,this.errorPage=new Tr("fdasfa",{...To.defaultData,name:""},{shared:t,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=YS(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=$S(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let t=e.identity.join("-"),o=this.entityIdentityToEntity[t];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[t]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof Tr&&(e.penumbraSizeArrayCache=null)}findInstance(e){return this.entityIdentityToEntity[e.join("-")]}get bgColor(){return this.activePage.bgColor}get postprocessing(){return this.activePage.data.postprocessing}getWithSortKey(e){let t=this.find(e);if(t===void 0)return;let o=[],i=t;for(;i!==this;){let a=i;i=i.parent;let s=i.children.indexOf(a);o.splice(0,0,s)}return{entity:t,sortKey:o}}getAllSorted(e){let t=[];for(let o of e){let i=this.getWithSortKey(o.id);i!==void 0&&t.push(i)}return t.sort((o,i)=>jl(o.sortKey,i.sortKey)),t.map(o=>o.entity)}nonExistOrDescendantOf(e,t){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===t)return!0;o=o.parent}return!1}find(e){if(this.activePage&&this.activePage.personalCamera.parent){if(e==="f23858d0-4a3b-4bd8-8173-66ed0af7f6fb-personalCamera")return this.activePage.personalCamera;if(e===cn)return this.activePage.personalCamera}if(e===""||e===void 0)return;let t=this.entityByUuid[e];return t===void 0?this.getObjectByProperty("uuid",e):t}find2D(e){for(let t of this.children)if(t instanceof Tr&&t.uiScene){let o=t.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let t of this.children)if(t instanceof Tr&&t.uiScene&&t.uiScene.find(e))return t.uiScene}find2DInUIObjects(e){let t;return this.traverseEntity(o=>{t===void 0&&o instanceof yi&&(t=o.uiCanvas.find(e))}),t}traverse2D(e){for(let t of this.children)t instanceof Tr&&t.uiScene&&t.uiScene.traverse(e)}debugEnsureEntity(e){let t=this.find(e);if(t){if(Array.isArray(t.identity)&&this.findInstance(t.identity)===void 0){console.error("not found instance");debugger}}else{console.error("not found");debugger}}addPendingExpandCloner(e){this.toExpandCloner.add(e)}addPendingUpdateCloner(e){this.toUpdateCloner.add(e)}markToExpandCloner(e){this.toExpandCloner.add(e),e.traverseEntityAncestors(t=>{this.toExpandCloner.add(t)})}doPendingExpandCloner(){this.toExpandCloner.forEach(e=>{e.expandCloner(this)}),this.toExpandCloner.clear()}doPendingUpdateCloner(){this.toUpdateCloner.forEach(e=>{e.cloner?.update()}),this.toUpdateCloner.clear()}doPendingUpdates(){this.doPendingExpandCloner(),this.doPendingUpdateCloner(),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,t){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,t)}updateTreeByOp(e,t){if(e.path.length===0&&e.type===7){let o=e.parent===null?this:this.find(e.parent);if(o===void 0)throw new Error("unexpected");let i=this.createObject(e.id,e.data,e.children,o,e.localIndex,t);i.updateVisible(this),i.resetBBoxNeedsUpdate(),In(i)&&wl(i.parent)&&(i.invalidateUpstreamBooleanData(),i.parent.invalidateDownstreamBooleanData().recomputeBoolean()),this.markNeedsRecomputeInstancesForAncessors(o),this.markNeedsRecomputeInstancesForChildren(i),this.markToExpandCloner(i),this.markPenumbraSizeDirty(),i.updatePathSnapping()}else if(e.path.length===0&&e.type===8){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markToExpandCloner(o),o.resetBBoxNeedsUpdate(),this.unregisterObject(o);let i=o.parent;this.markNeedsRecomputeInstancesForAncessors(i),this.markNeedsRecomputeInstancesForChildren(o),this.markPenumbraSizeDirty(),o.parent.remove(o),wl(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),In(o)&&(o.freeBooleanPointer(),i instanceof nr&&i.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof ms&&o.detachShape(),this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(o),this.pathConstraints.removeDependencies(o.uuid),o.updatePathSnapping()}else if(e.path.length===0&&e.type===9){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markNeedsRecomputeInstancesForChildren(o);let i=o.parent;this.markNeedsRecomputeInstancesForAncessors(i),o.cloner?.resetOnMove(),this.markToExpandCloner(o);let a=e.parent===null?this:this.find(e.parent);if(a===void 0)throw new Error("unexpected");a.add(o),this.markNeedsRecomputeInstancesForAncessors(a),this.markToExpandCloner(o),o.invalidateClonerTransform(o),o.updateVisible(this),o.resetBBoxNeedsUpdate(),this.markPenumbraSizeDirty();let s=e.localIndex;a.children.splice(s,0,a.children.pop()),In(o)&&(o.invalidateUpstreamBooleanData(),wl(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():i instanceof nr&&i.invalidateDownstreamBooleanData().recomputeBoolean()),o.updatePathSnapping()}this.markNeedsUpdateRendererDirty(),this.markGeometryCacheDirty()}get playPage(){return this.find(this.data.publish.playPage)??this.errorPage}updatePage(e){this.activePage&&this.activePage.onDeactive(),this.activePage=this.errorPage;for(let t of this.children)t instanceof Tr&&(t.visible=t.uuid===e,t.visible&&(this.activePage=t,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,t,o,i){if(t.type===0){if(("overrides"in t.props||"component"in t.props)&&this.markNeedsRecomputeInstances(),"visible"in t.props&&this.markPenumbraSizeDirty(),t.path.includes("overrides")&&"states"in t.props){let{rest:s}=t.props;t={...t,props:s},this.markNeedsRecomputeInstances()}t.path[0]==="pathSnapping"&&t.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,t.props.pathId)}let a=this.find(e);if(a)try{HS(a,t,o,{scene:this,shared:i}),a instanceof lt&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,t,o,i,a,s=[]){e.updateEntityByOp(t,o,i,a),this.traverseEntity(l=>{(l instanceof yi||l instanceof Tr)&&(s.includes(l.frameId??"")||l.frameId===t)&&l.updateEntity2DByOp(t,o,i,a)})}get activeCamera(){return this.activePage.activeCamera}switchActiveCamera(e){this.activePage.switchActiveCamera(e)}isInvisibleObjects(e){return e===this.invisibleObjects||e.hasAnccestor(this.invisibleObjects)}init(e,t){let o=Object.entries(t.data.lib.components).map((i,a)=>({data:i[1].asset.data,children:i[1].asset.children,id:i[0],fi:a}));this.invisibleObjects.updateState(this.invisibleObjects.data,{scene:this,shared:t}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,t),this.createChildrenObjects(e.objects,this,t),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(t,!0),this.traverseEntity(i=>{i instanceof qo&&i.updateUp()}),this.doPendingExpandCloner(),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(t=>{(t.data.type==="Component"||t.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){Le.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(t=>{Le.is(t)&&t.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,t,o,i,a,s,l){if(e){let c=i.find(e);c&&c!==i&&a.forInstancesRec(u=>{u.data=rn(u.data,p=>{let d=p.events.data(l.id),h=u.goUp(s);if(h){let f=[...Fl(h.identity),e].join("-"),m=this.entityIdentityToEntity[f];if(m){let y=m.uuid,g=Ze.zoom(d,t);g[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,t,o,i,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,i,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,i,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...t,l.id,"ifActions"],o,i,a,s),this.rewriteActions(l.data.elseActions,[...t,l.id,"elseActions"],o,i,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof Xo&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((t,o)=>{t.data.events.forEach(i=>{if(i.data.type==="GameControl"){let a=!1;if(t.forInstancesRec(s=>{s.data=rn(s.data,l=>{s.isInstanceRoot||(l.events.delete(i.id),a=!0)}).data}),a===!1)for(let s of $c.list)this.rewriteActions(i.data.gameActions[s],["gameActions",s],e,t,o,i)}else i.data.type==="Conditional"?(i.data.condition.type==="Distance"?(this.relativeizeInner(i.data.condition.fromObject,["condition"],"fromObject",e,t,o,i),this.relativeizeInner(i.data.condition.toObject,["condition"],"toObject",e,t,o,i)):i.data.condition.type==="State"?this.relativeizeInner(i.data.condition.object,["condition"],"object",e,t,o,i):i.data.condition.type==="Comparison"&&(i.data.condition.lOperand.type==="Property"&&this.relativeizeInner(i.data.condition.lOperand.value[0],["condition","lOperand","value"],0,e,t,o,i),i.data.condition.rOperand.type==="Property"&&this.relativeizeInner(i.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,t,o,i)),this.rewriteActions(i.data.inActions,["inActions"],e,t,o,i),this.rewriteActions(i.data.outActions,["outActions"],e,t,o,i)):"actions"in i.data&&this.rewriteActions(i.data.actions,["actions"],e,t,o,i)})}),!0})}expandInstances(e,t,o){let i=new Set;this.traverseEntity(a=>{if(a instanceof Xo&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:i}),t||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of i)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),bd(a)}recomputeInstances(e,t){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof Xo&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,t))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(t=>{let o=typeof t.identity=="string"?t.identity:t.identity.join("-");this.entityIdentityToEntity[o]===t&&(delete this.entityByUuid[t.uuid],delete this.entityIdentityToEntity[o]),t.dispose()})}clearScene(){for(let e of this.children)Le.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,t){this.init(e,t)}raycast(e){return this.raycast1(e,!1)}raycast1(e,t){let o=[],i=a=>{for(let s of a.children){let l=s.cloner;if(Le.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(t===!0&&s.isInstanceRoot){let c=[];if(e.intersectObject(s,!0,c),c.length){let u=c[0];u.object=s,u.point.applyMatrix4(u.object.matrixWorld);let p=s.matrixWorld.clone().invert();u.point.applyMatrix4(p),o.push(u)}}else(In(s)||Pl(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),El(s,e,o)),i(s)}};return i(this.activePage),o}raycastWithClones(e){let t=[],o=i=>{for(let a of i.children){let s=a.cloner;Le.is(a)&&(a.visible||s?.object.data.visible)&&((In(a)||Pl(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),El(a,e,t,!0)),o(a))}};return o(this),t}forEachEntity(e){for(let t of this.children)Le.is(t)&&e(t)}traverseConcreteEntity(e){for(let t of this.children)Le.is(t)&&t.isConcreteEntity&&t.traverseEntity(e)}traverseEntity(e){for(let t of this.children)Le.is(t)&&t.traverseEntity(e)}updateFont(e,t){this.traverseEntity(o=>{if(o instanceof lt&&o.data.type==="Mesh"&&(o.data.geometry.type==="TextGeometry"||o.data.geometry.type==="InputGeometry")&&o.data.geometry.font===e){let i=o.geometry,a=o.data.geometry;i.updateFont(e,t).then(()=>{i.update(a);let s=o.invalidateDownstreamBooleanData();wl(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let t of this.children)ca.is(t)&&t.traverseObject(e)}traverseVisibleEntity(e){for(let t of this.children)Le.is(t)&&t.visible&&t.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,t,o){let i=0;for(let a of e)this.createObject(a.id,a.data,a.children,t,i,o),i+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let t of e.children)this.unregisterObject(t)}createObject(e,t,o,i,a,s){let l={scene:this,shared:s},c=Cd(e,t,l);return c&&(this.entityByUuid[e]=c,i.add(c),i.children.splice(a,0,i.children.pop()),o.length>0&&(c.isInstanceRoot?console.error("instance should not have children!"):this.createChildrenObjects(o,c,s)),c.updateState(t,l),c instanceof lt&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),t.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,t.pathSnapping.pathId)),t.type==="Empty"&&t.animations&&c.traverseEntity(u=>{let p=u.dataPatched;if(u instanceof lt&&p.bones&&p.boneInverses){let d=p.bones.map(m=>this.find(m)),h=p.boneInverses.map(m=>new xB().fromArray(m)),f=new SB(d,h);u.bind(f,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let t=[];for(let i=0,a=e.length;i<a;++i){let{id:s,recursive:l}=e[i],c=this.find(s),u=l?c.recursiveBBox:c.singleBBox;t.push(...u.vertices)}let o=new bB;return o.setFromPoints(t),o.getCenter(i1),i1}copyMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e);o?t.copy(o.matrixWorld):t.identity()}copyParentMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e)?.parent;o?t.copy(o.matrixWorld):t.identity()}traverseMaterial(e){this.traverseEntity(t=>{if(t instanceof Ct)if(Array.isArray(t.material))for(let o=0;o<t.material.length;o++)t.material[o]instanceof rr&&e(t.material[o]);else t.material instanceof rr&&e(t.material)})}updateViewPlaneSize(e,t,o=!1){this.traverseConcreteEntity(i=>{i instanceof qo&&i.setViewplaneSize(e,t,o)})}initializeSplatViewer(){this.splatViewer=new Dl({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};import{DRACOLoader as PB}from"three/examples/jsm/loaders/DRACOLoader.js";var Ln;function a1(){return Ln||(Ln=new PB,Ln.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),Ln.decoderPending}async function CB(n){if(Ln){let r={attributeIDs:Ln.defaultAttributeIDs,attributeTypes:Ln.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await Ln.decodeGeometry(new Int8Array(n).buffer,r)}catch(t){console.error(t)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([t,o])=>({name:t,itemSize:o.itemSize,array:o.array}))}}return null}async function s1(n,r){let[e,t]=tp(Ec.deserialize(new Uint8Array(n)));return Kc(e),r&&r(e),t.result().data}function l1(n){let r=[];return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="NonParametricGeometry"&&t.geometry.data.draco!==void 0&&r.push(t)}),r}async function c1(n){for(let r of n){let e=await CB(r.geometry.data.draco);if(e){let t=r.geometry.data;e.index&&(t.index={array:e.index.array,itemSize:1,normalized:!1,type:"Uint32Array"});let o={};e.attributes.forEach(({name:i,array:a,itemSize:s})=>{o[i]={array:a,itemSize:s,type:"Float32Array",normalized:!1}}),t.attributes=o,t.draco=void 0}}}import{Mesh as Bhe}from"three";import{mergeBufferGeometries as Vhe}from"three/examples/jsm/utils/BufferGeometryUtils.js";function u1(n){let r;if(!!n.index)for(let e=0;e<n.index.array.length;e+=3)r=n.index.array[e],n.index.array[e]=n.index.array[e+2],n.index.array[e+2]=r}import{Color as d1,ShaderLib as OB}from"three";function p1(n){let r=new Set;return n.traverse(e=>{if(e instanceof or)if(dt(e.material))e.material.forEach(t=>{let o=t;r.has(o)||r.add(o)});else{let t=e.material;r.has(t)||r.add(t)}}),r.forEach(e=>{if(e instanceof Array)return;let t=e.onBeforeCompile.bind(e);if(AB(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new d1,specularColor:new d1});let o=0;e.onBeforeCompile=(i,a)=>{t&&t(i,a),i.uniforms=Object.assign({},OB.physical.uniforms,i.uniforms),e.getLayersOfType("transmission").forEach(s=>{if(i.uniforms.transmissionSamplerMap.value){let l=s.color;l&&(l.transmissionSamplerMap.value=i.uniforms.transmissionSamplerMap.value,l.transmissionSamplerSize.value=i.uniforms.transmissionSamplerSize.value,l.aspectRatio.value=Bb(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else TB(e)||(e.onBeforeCompile=(o,i)=>{t&&t(o,i),e.transparent=!1})}),n}function AB(n){return n.getLayersOfType("transmission").length>0}function TB(n){let r=0;for(let e of n.layers){if(e.data.type!=="displace"&&e.data.isMask)return!0;if(e.type!=="light"&&e.type!=="fresnel"){let o=e.uniforms["f"+e.id+"_alpha"];o&&(r+=(1-r)*o.value)}}return r<1}function f1(n){return n.traverse(r=>{if(r.type==="Camera"){let e=r;e.type=e.cameraType}}),n}function h1(n){let r=[],e=(t,o=0)=>{let i=o>0?t+o:t;return r.includes(i)?e(t,o+1):i};return n.traverse(t=>{if(r.includes(t.name)){let o=t.name,i=e(t.name);if(t.name=i,t.isMesh){let a=t;a.material instanceof Array?a.material.forEach(s=>{s.name=s.name.replace(o,i)}):a.material.isAsset||(a.material.name=a.material.name.replace(o,i))}}r.push(t.name)}),n}import{mergeBufferGeometries as IB}from"three/examples/jsm/utils/BufferGeometryUtils.js";function m1(n){let r=[];return n.traverse(e=>{e instanceof is&&r.push(e)}),r.forEach(e=>{let t=e.object,a=[...e.children.map(s=>{s.updateMatrix();let l;if(s.geometry!==void 0)try{l=s.geometry.clone().applyMatrix4(s.matrix)}catch(c){console.error(c)}return l!==void 0&&s.matrix.determinant()<0&&u1(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&t instanceof Ct&&a.unshift(t.geometry),a.length){let s=IB(a);t instanceof Ct&&(t.geometry=s)}e.removeFromParent(),t.setFromClonerState(null,{scene:n,shared:av})}),n}function y1(n){return n.traverse(r=>{r.matrixAutoUpdate=!0}),n}function g1(n){Object.values(n.shared.materials).forEach(r=>{Uh(r)}),n.scene.objects.traverse((r,e)=>{"material"in e?Uh(e.material):"materials"in e&&e.materials.forEach(t=>{Uh(t)})})}function Uh(n){if(typeof n=="string")return;let r=[];n.layers.forEach((e,t)=>{e.type==="outline"&&r.push(t)}),r.reverse().forEach(e=>{n.layers.delete(e)}),r.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var S1=vs(b1(),1);var v1="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",Hh=class extends EB{load(r,e,t,o=console.error){let i=new MB(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),r.endsWith(".spline")?console.warn(v1+" The .spline files are only meant to be used by the Editor."):r.endsWith(".splinecode")||console.warn(v1),i.load(r,async a=>{try{if(typeof a=="string")throw new Error("The .spline file is not binary!");let s=await this.parse(a);e(s)}catch(s){o(s)}},t,o)}async parse(r){let e=await s1(r,g1),t=l1(e);e.version&&(0,S1.default)(e.version,"1.9.44")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([t.length&&a1(),hv(e)&&lb(),Ov(e)&&Xb(),lS(e)&&iS(),Md(e)&&kh()].filter(Boolean)),t.length&&await c1(t);let o=!1,i=new ci(e.shared,{},o);Object.values(i.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new Nd(e.scene,i);Md(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=m1(a),a=p1(a),a=f1(a),a=h1(a),a=y1(a),a}};export{Hh as default};
3993
+ }`,i={covariancesTexture:{type:"t",value:null},centersColorsTexture:{type:"t",value:null},meshIndexIntervals:{value:e},meshMatrixWorldsTexture:{type:"t",value:null},focal:{type:"v2",value:new _n},viewport:{type:"v2",value:new _n},basisViewport:{type:"v2",value:new _n},debugColor:{type:"v3",value:new tB},covariancesTextureSize:{type:"v2",value:new _n(1024,1024)},centersColorsTextureSize:{type:"v2",value:new _n(1024,1024)},orthoZoom:{type:"f",value:-1}};return new pB({uniforms:i,vertexShader:t,fragmentShader:o,transparent:!0,alphaTest:1,blending:cB,depthTest:!0,depthWrite:!1,side:oB})}static buildGeomtery(e){let t=new eB;t.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),i=new J_(o,3);t.setAttribute("position",i),i.setXYZ(0,-1,-1,0),i.setXYZ(1,-1,1,0),i.setXYZ(2,1,1,0),i.setXYZ(3,1,-1,0),i.needsUpdate=!0;let a=new sB().copy(t),s=new Uint32Array(e),l=new aB(s,1,!1);return l.setUsage(nB),a.setAttribute("splatIndex",l),a.instanceCount=e,a}resetLocalSplatDataAndTexturesFromSplatBuffer(){this.updateLocalSplatDataFromSplatBuffer(),this.allocateAndStoreLocalSplatDataInTextures()}updateLocalSplatDataFromSplatBuffer(){this.splatBuffers.forEach(i=>i.buildPreComputedBuffers()),this.covariances=new Float32Array(this.splatCount*6),this.colors=new Uint8Array(this.splatCount*4),this.centers=new Float32Array(this.splatCount*3);let e=0,t=0,o=0;for(let i of this.splatBuffers){let a=i.nsplats;this.colors.subarray(e,e+a*4).set(i.colorsA),e+=a*4,this.centers.subarray(t,t+a*3).set(i.decoded.xyz.denormDequant().data),t+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(i.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,i=new _n(4096,1024);for(;i.x*i.y*2<o*6;)i.y*=2;let a=new _n(4096,1024);for(;a.x*a.y*4<o*4;)a.y*=2;let s,l;if(this.halfPrecisionCovariancesOnGPU){l=new Uint16Array(i.x*i.y*2);for(let h=0;h<this.covariances.length;h++)l[h]=rB.toHalfFloat(this.covariances[h]);s=new Cd(l,i.x,i.y,QS,iB)}else l=new Float32Array(i.x*i.y*2),l.set(this.covariances),s=new Cd(l,i.x,i.y,QS,KS);s.needsUpdate=!0,this.material.uniforms.covariancesTexture.value=s,this.material.uniforms.covariancesTextureSize.value.copy(i);let c=new Uint32Array(a.x*a.y*4);for(let h=0;h<o;h++){let m=h*4,y=h*3,b=h*4;c[b]=XS(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[b+1]=Pd(this.centers[y]),c[b+2]=Pd(this.centers[y+1]),c[b+3]=Pd(this.centers[y+2])}let u=new Cd(c,a.x,a.y,dB,fB);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let p=256*4,d=new Float32Array(256*16);for(let h=0;h<this.meshMatrixWorlds.length;h++)d.set(this.meshMatrixWorlds[h].elements,h*16);let f=new Cd(d,p,1,uB,KS);f.needsUpdate=!0,this.material.uniforms.meshMatrixWorldsTexture.value=f,this.material.uniformsNeedUpdate=!0,this.splatDataTextures={covariances:{data:l,texture:s,size:i},centerColors:{data:c,texture:u,size:a},meshMatrixWorlds:{data:d,texture:f}}}updateIndexes(e){let t=this.geometry;t.attributes.splatIndex.set(e),t.attributes.splatIndex.needsUpdate=!0,t.instanceCount=e.length}updateUniforms(e,t,o,i){this.splatCount>0&&(Od.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(Od),this.material.uniforms.basisViewport.value.set(2/Od.x,2/Od.y),this.material.uniforms.focal.value.set(t,o),this.material.uniforms.orthoZoom.value=i,this.material.uniformsNeedUpdate=!0)}getSplatDataTextures(){return this.splatDataTextures}getSplatCount(){return this.splatCount}getCenters(){return this.centers}getColors(){return this.colors}getCovariances(){return this.covariances}dispose(){this.geometry.dispose(),this.material.dispose(),this.splatDataTextures&&(this.splatDataTextures.covariances.texture.dispose(),this.splatDataTextures.centerColors.texture.dispose(),this.splatDataTextures.meshMatrixWorlds.texture.dispose()),this.removeFromParent()}};var JS,Gh=new Promise(n=>{JS=n}),ZS=!1;var Td;function Fh(){if(ZS)return;if(Td)return Td;async function n(){let e=await import("./gaussian-splat-compression.js");JS(e),ZS=!0}return Td=n(),Td}var r1;Gh.then(n=>r1=n);var Ml=class{constructor(r={}){$r(this,"updateView",function(){let r=new e1,e=[],t=new ms(0,0,-1),o=new ms(0,0,-1),i=new ms,a=new ms;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let d=!1,f=!1;if(o.dot(t)<=.95&&(d=!0),a.copy(l.position).sub(i).length()>=1&&(f=!0),!d&&!f&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,i.copy(l.position),t.copy(o),r.copy(l.matrixWorld).invert(),r.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let p={sort:{view:r.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=p:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(p))}}());this.scene=r.scene,this.currentPage=null,this.devicePixelRatio=window.devicePixelRatio,this.sortWorker=null,this.splatRenderCount=0,this.splatSortCount=0,this.splatMesh=null,this.sortRunning=!1,this.meshMatrixWorlds=null,this.meshMatrixWorldsOld=null,this.cropsArray=null,this.splatEntries=null,this.queuedMessage=null,this.needsInitialRender=!0,this.dummyPerspectiveMatrix=new e1().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(r,e){let t=new hB;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(r.getSize(t),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*t.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*t.y*.45,this.splatMesh.updateUniforms(t,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(r={}){this.activePage=this.scene.activePage,r.position&&(r.position=new ms().fromArray(r.position)),r.orientation&&(r.orientation=new t1().fromArray(r.orientation)),r.halfPrecisionCovariances=!!r.halfPrecisionCovariances;let e=[];if(this.splatEntries=e,this.activePage.traverseVisibleEntity(a=>{a.data.type==="Splat"&&e.push(a)}),this.splatMesh&&this.splatMesh.dispose(),e.length===0)return this.splatMesh=null,!1;this.meshMatrixWorlds=e.map(a=>a.matrixWorld),this.meshMatrixWorldsOld=e.map(a=>a.matrixWorld.clone()),this.cropsArray=e.map(a=>a.data.crops.map(s=>s.data));let t=e.map(a=>new r1.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,i=[0];for(let a of t)o+=a.getSplatCount(),i.push(o);return this.setupSplatMesh(t,o,r.position,r.orientation,r.halfPrecisionCovariances,this.devicePixelRatio,i,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let r=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)r.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,t)=>e.equals(this.meshMatrixWorldsOld[t]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let r=!1;return this.splatEntries.forEach((e,t)=>{e.data.crops.forEach((o,i)=>{this.cropsArray[t][i]===void 0?(r=!0,this.cropsArray[t][i]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[t][i][a][c])?(r=!0,this.cropsArray[t][i][a]=s):s!==this.cropsArray[t][i]?.[a]&&(r=!0,this.cropsArray[t][i][a]=s)})}),e.data.crops.length!==this.cropsArray[t]?.length&&(this.cropsArray[t].length=e.data.crops.length,r=!0)}),r}setupSplatMesh(r,e,t=new ms,o=new t1,i=!1,a=1,s,l){this.splatMesh=Bn.buildMesh(r,e,i,a,s,l),this.splatMesh.position.copy(t),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,p)=>this.update(c,p)}setupSortWorker(r){this.sortWorker=YS(r),this.sortWorker.onmessage=e=>{e.data.sortDone?(this.sortRunning=!1,this.splatMesh?.updateIndexes(new Uint32Array(e.data.indexesBuffer)),this.lastSortTime=e.data.sortTime,this.queuedMessage&&(this.sortWorker.postMessage(this.queuedMessage),this.queuedMessage=null)):e.data.sortCanceled?this.sortRunning=!1:e.data.sortSetupPhase1Complete?this.sortWorker.postMessage({positions:this.splatMesh.getCenters().buffer,meshMatrixWorlds:this.splatMesh.meshMatrixWorlds,meshIndexIntervals:this.splatMesh.meshIndexIntervals,cropsArray:this.cropsArray}):e.data.sortSetupComplete&&(this.splatDataTextures=this.splatMesh.getSplatDataTextures(),this.scene.activePage.add(this.splatMesh),this.needsInitialRender=!0)}}update(r,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(r,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var SB=new bB;SB.wireframe=!0;var o1=new yB,Id=class extends mB{constructor(e,t){super();this.data=e;this.sharedAssets=t;this.enableHelpers=!1;this.wireframeState=!1;this.needsTransmissionDirty=!0;this.needsNormalDirty=!0;this._needsTransmission=!1;this._needsNormal=!1;this.geometryCacheChanged=!1;this.splatViewer=null;this.entityByUuid={};this.entityIdentityToEntity={};this.toExpandCloner=new Set;this.toUpdateCloner=new Set;this.pendingCommands=[];this.pathConstraints=new wd;this.invisibleObjects=new In("jflkdsafjasdifjaslk",{...Fc.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,t),this.matrixAutoUpdate=!1,this.errorPage=new Tr("fdasfa",{...To.defaultData,name:""},{shared:t,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=qS(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=WS(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let t=e.identity.join("-"),o=this.entityIdentityToEntity[t];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[t]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof Tr&&(e.penumbraSizeArrayCache=null)}findInstance(e){return this.entityIdentityToEntity[e.join("-")]}get bgColor(){return this.activePage.bgColor}get postprocessing(){return this.activePage.data.postprocessing}getWithSortKey(e){let t=this.find(e);if(t===void 0)return;let o=[],i=t;for(;i!==this;){let a=i;i=i.parent;let s=i.children.indexOf(a);o.splice(0,0,s)}return{entity:t,sortKey:o}}getAllSorted(e){let t=[];for(let o of e){let i=this.getWithSortKey(o.id);i!==void 0&&t.push(i)}return t.sort((o,i)=>zl(o.sortKey,i.sortKey)),t.map(o=>o.entity)}nonExistOrDescendantOf(e,t){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===t)return!0;o=o.parent}return!1}find(e){if(this.activePage&&this.activePage.personalCamera.parent){if(e==="f23858d0-4a3b-4bd8-8173-66ed0af7f6fb-personalCamera")return this.activePage.personalCamera;if(e===ln)return this.activePage.personalCamera}if(e===""||e===void 0)return;let t=this.entityByUuid[e];return t===void 0?this.getObjectByProperty("uuid",e):t}find2D(e){for(let t of this.children)if(t instanceof Tr&&t.uiScene){let o=t.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let t of this.children)if(t instanceof Tr&&t.uiScene&&t.uiScene.find(e))return t.uiScene}find2DInUIObjects(e){let t;return this.traverseEntity(o=>{t===void 0&&o instanceof mi&&(t=o.uiCanvas.find(e))}),t}traverse2D(e){for(let t of this.children)t instanceof Tr&&t.uiScene&&t.uiScene.traverse(e)}debugEnsureEntity(e){let t=this.find(e);if(t){if(Array.isArray(t.identity)&&this.findInstance(t.identity)===void 0){console.error("not found instance");debugger}}else{console.error("not found");debugger}}addPendingExpandCloner(e){this.toExpandCloner.add(e)}addPendingUpdateCloner(e){this.toUpdateCloner.add(e)}markToExpandCloner(e){this.toExpandCloner.add(e),e.traverseEntityAncestors(t=>{this.toExpandCloner.add(t)})}doPendingExpandCloner(){this.toExpandCloner.forEach(e=>{e.expandCloner(this)}),this.toExpandCloner.clear()}doPendingUpdateCloner(){this.toUpdateCloner.forEach(e=>{e.cloner?.update()}),this.toUpdateCloner.clear()}doPendingUpdates(){this.doPendingExpandCloner(),this.doPendingUpdateCloner(),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,t){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,t)}updateTreeByOp(e,t){if(e.path.length===0&&e.type===7){let o=e.parent===null?this:this.find(e.parent);if(o===void 0)throw new Error("unexpected");let i=this.createObject(e.id,e.data,e.children,o,e.localIndex,t);i.updateVisible(this),i.resetBBoxNeedsUpdate(),Tn(i)&&bl(i.parent)&&(i.invalidateUpstreamBooleanData(),i.parent.invalidateDownstreamBooleanData().recomputeBoolean()),this.markNeedsRecomputeInstancesForAncessors(o),this.markNeedsRecomputeInstancesForChildren(i),this.markToExpandCloner(i),this.markPenumbraSizeDirty(),i.updatePathSnapping()}else if(e.path.length===0&&e.type===8){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markToExpandCloner(o),o.resetBBoxNeedsUpdate(),this.unregisterObject(o);let i=o.parent;this.markNeedsRecomputeInstancesForAncessors(i),this.markNeedsRecomputeInstancesForChildren(o),this.markPenumbraSizeDirty(),o.parent.remove(o),bl(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),Tn(o)&&(o.freeBooleanPointer(),i instanceof nr&&i.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof fs&&o.detachShape(),this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(o),this.pathConstraints.removeDependencies(o.uuid),o.updatePathSnapping()}else if(e.path.length===0&&e.type===9){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markNeedsRecomputeInstancesForChildren(o);let i=o.parent;this.markNeedsRecomputeInstancesForAncessors(i),o.cloner?.resetOnMove(),this.markToExpandCloner(o);let a=e.parent===null?this:this.find(e.parent);if(a===void 0)throw new Error("unexpected");a.add(o),this.markNeedsRecomputeInstancesForAncessors(a),this.markToExpandCloner(o),o.invalidateClonerTransform(o),o.updateVisible(this),o.resetBBoxNeedsUpdate(),this.markPenumbraSizeDirty();let s=e.localIndex;a.children.splice(s,0,a.children.pop()),Tn(o)&&(o.invalidateUpstreamBooleanData(),bl(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():i instanceof nr&&i.invalidateDownstreamBooleanData().recomputeBoolean()),o.updatePathSnapping()}this.markNeedsUpdateRendererDirty(),this.markGeometryCacheDirty()}get playPage(){return this.find(this.data.publish.playPage)??this.errorPage}updatePage(e){this.activePage&&this.activePage.onDeactive(),this.activePage=this.errorPage;for(let t of this.children)t instanceof Tr&&(t.visible=t.uuid===e,t.visible&&(this.activePage=t,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,t,o,i){if(t.type===0){if(("overrides"in t.props||"component"in t.props)&&this.markNeedsRecomputeInstances(),"visible"in t.props&&this.markPenumbraSizeDirty(),t.path.includes("overrides")&&"states"in t.props){let{rest:s}=t.props;t={...t,props:s},this.markNeedsRecomputeInstances()}t.path[0]==="pathSnapping"&&t.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,t.props.pathId)}let a=this.find(e);if(a)try{kS(a,t,o,{scene:this,shared:i}),a instanceof lt&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,t,o,i,a,s=[]){e.updateEntityByOp(t,o,i,a),this.traverseEntity(l=>{(l instanceof mi||l instanceof Tr)&&(s.includes(l.frameId??"")||l.frameId===t)&&l.updateEntity2DByOp(t,o,i,a)})}get activeCamera(){return this.activePage.activeCamera}switchActiveCamera(e){this.activePage.switchActiveCamera(e)}isInvisibleObjects(e){return e===this.invisibleObjects||e.hasAnccestor(this.invisibleObjects)}init(e,t){let o=Object.entries(t.data.lib.components).map((i,a)=>({data:i[1].asset.data,children:i[1].asset.children,id:i[0],fi:a}));this.invisibleObjects.updateState(this.invisibleObjects.data,{scene:this,shared:t}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,t),this.createChildrenObjects(e.objects,this,t),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(t,!0),this.traverseEntity(i=>{i instanceof Wo&&i.updateUp()}),this.doPendingExpandCloner(),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(t=>{(t.data.type==="Component"||t.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){Le.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(t=>{Le.is(t)&&t.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,t,o,i,a,s,l){if(e){let c=i.find(e);c&&c!==i&&a.forInstancesRec(u=>{u.data=tn(u.data,p=>{let d=p.events.data(l.id),f=u.goUp(s);if(f){let h=[...Vl(f.identity),e].join("-"),m=this.entityIdentityToEntity[h];if(m){let y=m.uuid,b=Ze.zoom(d,t);b[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,t,o,i,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,i,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,i,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...t,l.id,"ifActions"],o,i,a,s),this.rewriteActions(l.data.elseActions,[...t,l.id,"elseActions"],o,i,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof Yo&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((t,o)=>{t.data.events.forEach(i=>{if(i.data.type==="GameControl"){let a=!1;if(t.forInstancesRec(s=>{s.data=tn(s.data,l=>{s.isInstanceRoot||(l.events.delete(i.id),a=!0)}).data}),a===!1)for(let s of Hc.list)this.rewriteActions(i.data.gameActions[s],["gameActions",s],e,t,o,i)}else i.data.type==="Conditional"?(i.data.condition.type==="Distance"?(this.relativeizeInner(i.data.condition.fromObject,["condition"],"fromObject",e,t,o,i),this.relativeizeInner(i.data.condition.toObject,["condition"],"toObject",e,t,o,i)):i.data.condition.type==="State"?this.relativeizeInner(i.data.condition.object,["condition"],"object",e,t,o,i):i.data.condition.type==="Comparison"&&(i.data.condition.lOperand.type==="Property"&&this.relativeizeInner(i.data.condition.lOperand.value[0],["condition","lOperand","value"],0,e,t,o,i),i.data.condition.rOperand.type==="Property"&&this.relativeizeInner(i.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,t,o,i)),this.rewriteActions(i.data.inActions,["inActions"],e,t,o,i),this.rewriteActions(i.data.outActions,["outActions"],e,t,o,i)):"actions"in i.data&&this.rewriteActions(i.data.actions,["actions"],e,t,o,i)})}),!0})}expandInstances(e,t,o){let i=new Set;this.traverseEntity(a=>{if(a instanceof Yo&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:i}),t||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of i)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),yd(a)}recomputeInstances(e,t){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof Yo&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,t))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(t=>{let o=typeof t.identity=="string"?t.identity:t.identity.join("-");this.entityIdentityToEntity[o]===t&&(delete this.entityByUuid[t.uuid],delete this.entityIdentityToEntity[o]),t.dispose()})}clearScene(){for(let e of this.children)Le.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,t){this.init(e,t)}raycast(e){return this.raycast1(e,!1)}raycast1(e,t){let o=[],i=a=>{for(let s of a.children){let l=s.cloner;if(Le.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(t===!0&&s.isInstanceRoot){let c=[];if(e.intersectObject(s,!0,c),c.length){let u=c[0];u.object=s,u.point.applyMatrix4(u.object.matrixWorld);let p=s.matrixWorld.clone().invert();u.point.applyMatrix4(p),o.push(u)}}else(Tn(s)||vl(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),Tl(s,e,o)),i(s)}};return i(this.activePage),o}raycastWithClones(e){let t=[],o=i=>{for(let a of i.children){let s=a.cloner;Le.is(a)&&(a.visible||s?.object.data.visible)&&((Tn(a)||vl(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),Tl(a,e,t,!0)),o(a))}};return o(this),t}forEachEntity(e){for(let t of this.children)Le.is(t)&&e(t)}traverseConcreteEntity(e){for(let t of this.children)Le.is(t)&&t.isConcreteEntity&&t.traverseEntity(e)}traverseEntity(e){for(let t of this.children)Le.is(t)&&t.traverseEntity(e)}updateFont(e,t){this.traverseEntity(o=>{if(o instanceof lt&&o.data.type==="Mesh"&&(o.data.geometry.type==="TextGeometry"||o.data.geometry.type==="InputGeometry")&&o.data.geometry.font===e){let i=o.geometry,a=o.data.geometry;i.updateFont(e,t).then(()=>{i.update(a);let s=o.invalidateDownstreamBooleanData();bl(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let t of this.children)la.is(t)&&t.traverseObject(e)}traverseVisibleEntity(e){for(let t of this.children)Le.is(t)&&t.visible&&t.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,t,o){let i=0;for(let a of e)this.createObject(a.id,a.data,a.children,t,i,o),i+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let t of e.children)this.unregisterObject(t)}createObject(e,t,o,i,a,s){let l={scene:this,shared:s},c=Sd(e,t,l);return c&&(this.entityByUuid[e]=c,i.add(c),i.children.splice(a,0,i.children.pop()),o.length>0&&(c.isInstanceRoot?console.error("instance should not have children!"):this.createChildrenObjects(o,c,s)),c.updateState(t,l),c instanceof lt&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),t.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,t.pathSnapping.pathId)),t.type==="Empty"&&t.animations&&c.traverseEntity(u=>{let p=u.dataPatched;if(u instanceof lt&&p.bones&&p.boneInverses){let d=p.bones.map(m=>this.find(m)),f=p.boneInverses.map(m=>new gB().fromArray(m)),h=new vB(d,f);u.bind(h,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let t=[];for(let i=0,a=e.length;i<a;++i){let{id:s,recursive:l}=e[i],c=this.find(s),u=l?c.recursiveBBox:c.singleBBox;t.push(...u.vertices)}let o=new xB;return o.setFromPoints(t),o.getCenter(o1),o1}copyMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e);o?t.copy(o.matrixWorld):t.identity()}copyParentMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e)?.parent;o?t.copy(o.matrixWorld):t.identity()}traverseMaterial(e){this.traverseEntity(t=>{if(t instanceof Ct)if(Array.isArray(t.material))for(let o=0;o<t.material.length;o++)t.material[o]instanceof rr&&e(t.material[o]);else t.material instanceof rr&&e(t.material)})}updateViewPlaneSize(e,t,o=!1){this.traverseConcreteEntity(i=>{i instanceof Wo&&i.setViewplaneSize(e,t,o)})}initializeSplatViewer(){this.splatViewer=new Ml({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};import{DRACOLoader as wB}from"three/examples/jsm/loaders/DRACOLoader.js";var Rn;function n1(){return Rn||(Rn=new wB,Rn.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),Rn.decoderPending}async function PB(n){if(Rn){let r={attributeIDs:Rn.defaultAttributeIDs,attributeTypes:Rn.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await Rn.decodeGeometry(new Int8Array(n).buffer,r)}catch(t){console.error(t)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([t,o])=>({name:t,itemSize:o.itemSize,array:o.array}))}}return null}async function i1(n,r){let[e,t]=Zd(Tc.deserialize(new Uint8Array(n)));return $c(e),r&&r(e),t.result().data}function a1(n){let r=[];return n.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="NonParametricGeometry"&&t.geometry.data.draco!==void 0&&r.push(t)}),r}async function s1(n){for(let r of n){let e=await PB(r.geometry.data.draco);if(e){let t=r.geometry.data;e.index&&(t.index={array:e.index.array,itemSize:1,normalized:!1,type:"Uint32Array"});let o={};e.attributes.forEach(({name:i,array:a,itemSize:s})=>{o[i]={array:a,itemSize:s,type:"Float32Array",normalized:!1}}),t.attributes=o,t.draco=void 0}}}import{Mesh as Bhe}from"three";import{mergeBufferGeometries as Vhe}from"three/examples/jsm/utils/BufferGeometryUtils.js";function l1(n){let r;if(!!n.index)for(let e=0;e<n.index.array.length;e+=3)r=n.index.array[e],n.index.array[e]=n.index.array[e+2],n.index.array[e+2]=r}import{Color as c1,ShaderLib as CB}from"three";function u1(n){let r=new Set;return n.traverse(e=>{if(e instanceof or)if(dt(e.material))e.material.forEach(t=>{let o=t;r.has(o)||r.add(o)});else{let t=e.material;r.has(t)||r.add(t)}}),r.forEach(e=>{if(e instanceof Array)return;let t=e.onBeforeCompile.bind(e);if(OB(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new c1,specularColor:new c1});let o=0;e.onBeforeCompile=(i,a)=>{t&&t(i,a),i.uniforms=Object.assign({},CB.physical.uniforms,i.uniforms),e.getLayersOfType("transmission").forEach(s=>{if(i.uniforms.transmissionSamplerMap.value){let l=s.color;l&&(l.transmissionSamplerMap.value=i.uniforms.transmissionSamplerMap.value,l.transmissionSamplerSize.value=i.uniforms.transmissionSamplerSize.value,l.aspectRatio.value=_b(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else AB(e)||(e.onBeforeCompile=(o,i)=>{t&&t(o,i),e.transparent=!1})}),n}function OB(n){return n.getLayersOfType("transmission").length>0}function AB(n){let r=0;for(let e of n.layers){if(e.data.type!=="displace"&&e.data.isMask)return!0;if(e.type!=="light"&&e.type!=="fresnel"){let o=e.uniforms["f"+e.id+"_alpha"];o&&(r+=(1-r)*o.value)}}return r<1}function d1(n){return n.traverse(r=>{if(r.type==="Camera"){let e=r;e.type=e.cameraType}}),n}function p1(n){let r=[],e=(t,o=0)=>{let i=o>0?t+o:t;return r.includes(i)?e(t,o+1):i};return n.traverse(t=>{if(r.includes(t.name)){let o=t.name,i=e(t.name);if(t.name=i,t.isMesh){let a=t;a.material instanceof Array?a.material.forEach(s=>{s.name=s.name.replace(o,i)}):a.material.isAsset||(a.material.name=a.material.name.replace(o,i))}}r.push(t.name)}),n}import{mergeBufferGeometries as TB}from"three/examples/jsm/utils/BufferGeometryUtils.js";function f1(n){let r=[];return n.traverse(e=>{e instanceof os&&r.push(e)}),r.forEach(e=>{let t=e.object,a=[...e.children.map(s=>{s.updateMatrix();let l;if(s.geometry!==void 0)try{l=s.geometry.clone().applyMatrix4(s.matrix)}catch(c){console.error(c)}return l!==void 0&&s.matrix.determinant()<0&&l1(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&t instanceof Ct&&a.unshift(t.geometry),a.length){let s=TB(a);t instanceof Ct&&(t.geometry=s)}e.removeFromParent(),t.setFromClonerState(null,{scene:n,shared:iv})}),n}function h1(n){return n.traverse(r=>{r.matrixAutoUpdate=!0}),n}function m1(n){Object.values(n.shared.materials).forEach(r=>{jh(r)}),n.scene.objects.traverse((r,e)=>{"material"in e?jh(e.material):"materials"in e&&e.materials.forEach(t=>{jh(t)})})}function jh(n){if(typeof n=="string")return;let r=[];n.layers.forEach((e,t)=>{e.type==="outline"&&r.push(t)}),r.reverse().forEach(e=>{n.layers.delete(e)}),r.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var b1=xs(g1(),1);var x1="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",kh=class extends MB{load(r,e,t,o=console.error){let i=new IB(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),r.endsWith(".spline")?console.warn(x1+" The .spline files are only meant to be used by the Editor."):r.endsWith(".splinecode")||console.warn(x1),i.load(r,async a=>{try{if(typeof a=="string")throw new Error("The .spline file is not binary!");let s=await this.parse(a);e(s)}catch(s){o(s)}},t,o)}async parse(r){let e=await i1(r,m1),t=a1(e);e.version&&(0,b1.default)(e.version,"1.9.46")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([t.length&&n1(),fv(e)&&sb(),Pv(e)&&Yb(),aS(e)&&oS(),Ad(e)&&Fh()].filter(Boolean)),t.length&&await s1(t);let o=!1,i=new li(e.shared,{},o);Object.values(i.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new Id(e.scene,i);Ad(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=f1(a),a=u1(a),a=d1(a),a=p1(a),a=h1(a),a}};export{kh as default};