mjswan 0.8.1-beta.0 → 0.8.1

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.
@@ -58,7 +58,7 @@ ${o?`${s(`light`)}{${o}}`:``}`}function Qn({color:e,theme:t,autoContrast:n}){ret
58
58
  Prefix can't start with '-' when allowNegative is true.
59
59
  prefix: `+i+`
60
60
  allowNegative: `+a+`
61
- `),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}function dh(e){e=uh(e),e.decimalSeparator,e.allowedDecimalSeparators,e.thousandsGroupStyle;var t=e.suffix,n=e.allowNegative,r=e.allowLeadingZeros,i=e.onKeyDown;i===void 0&&(i=Em);var a=e.onBlur;a===void 0&&(a=Em);var o=e.thousandSeparator,s=e.decimalScale,c=e.fixedDecimalScale,l=e.prefix;l===void 0&&(l=``);var u=e.defaultValue,d=e.value,f=e.valueIsNumericString,p=e.onValueChange,m=wm(e,[`decimalSeparator`,`allowedDecimalSeparators`,`thousandsGroupStyle`,`suffix`,`allowNegative`,`allowLeadingZeros`,`onKeyDown`,`onBlur`,`thousandSeparator`,`decimalScale`,`fixedDecimalScale`,`prefix`,`defaultValue`,`value`,`valueIsNumericString`,`onValueChange`]),h=ih(e),g=h.decimalSeparator,_=h.allowedDecimalSeparators,v=function(t){return rh(t,e)},y=function(t,n){return ch(t,n,e)},b=km(d)?u:d,x=f??sh(b,l,t);km(d)?km(u)||(x||=typeof u==`number`):x||=typeof d==`number`;var S=function(e){return jm(e)?e:(typeof e==`number`&&(e=Bm(e)),x&&typeof s==`number`?Vm(e,s,!!c):e)},C=$m(S(d),S(u),!!x,v,y,p),w=C[0],T=w.numAsString,E=w.formattedValue,D=C[1];return Object.assign(Object.assign({},m),{value:E,valueIsNumericString:!1,isValidInputCharacter:function(e){return e===g?!0:Om(e)},isCharacterSame:function(e){var t=e.currentValue,n=e.lastValue,r=e.formattedValue,i=e.currentValueIndex,a=e.formattedValueIndex,o=t[i],u=r[a],f=Um(n,t).to,p=function(e){return y(e).indexOf(`.`)+l.length};return d===0&&c&&s&&t[f.start]===g&&p(t)<i&&p(r)>a?!1:i>=f.start&&i<f.end&&_&&_.includes(o)&&u===g?!0:o===u},onValueChange:D,format:v,removeFormatting:y,getCaretBoundary:function(t){return lh(t,e)},onKeyDown:function(e){var t=e.target,r=e.key,a=t.selectionStart,u=t.selectionEnd,d=t.value;if(d===void 0&&(d=``),(r===`Backspace`||r===`Delete`)&&u<l.length&&d!==`-`){e.preventDefault();return}if(a!==u){i(e);return}r===`Backspace`&&d[0]===`-`&&a===l.length+1&&n&&Hm(t,1),s&&c&&(r===`Backspace`&&d[a-1]===g?(Hm(t,a-1),e.preventDefault()):r===`Delete`&&d[a]===g&&e.preventDefault()),_?.includes(r)&&d[a]===g&&Hm(t,a+1);var f=o===!0?`,`:o;r===`Backspace`&&d[a-1]===f&&Hm(t,a-1),r===`Delete`&&d[a]===f&&Hm(t,a+1),i(e)},onBlur:function(t){var n=T;n.match(/\d/g)||(n=``),r||(n=Lm(n)),c&&s&&(n=Vm(n,s,c)),n!==T&&D({formattedValue:rh(n,e),value:n,floatValue:parseFloat(n)},{event:t,source:Tm.event}),a(t)}})}function fh(e){var t=dh(e);return b.createElement(nh,Object.assign({},t))}var ph={root:`m_e2f5cd4e`,controls:`m_95e17d22`,control:`m_80b4b171`};function mh({direction:e,style:t,...n}){return(0,G.jsx)(`svg`,{style:{width:`var(--ni-chevron-size)`,height:`var(--ni-chevron-size)`,transform:e===`up`?`rotate(180deg)`:void 0,...t},viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...n,children:(0,G.jsx)(`path`,{d:`M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})}var hh=/^(0\.0*|-0(\.0*)?)$/,gh=/^-?0\d+(\.\d+)?\.?$/,_h=/\.\d*0$/,vh=/^-?\d+\.$/;function yh(e){return typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))}function bh(e){return typeof e==`number`?e<2**53-1:e===``||yh(e)&&Number(e)<2**53-1}function xh(e){return e.toString().replace(`.`,``).length}function Sh(e,t){return(typeof e==`number`?e<2**53-1:!Number.isNaN(Number(e)))&&!Number.isNaN(e)&&xh(t)<14&&t!==``}function Ch(e,t,n){return e===void 0?!0:(t===void 0||e>=t)&&(n===void 0||e<=n)}var wh={step:1,clampBehavior:`blur`,allowDecimal:!0,allowNegative:!0,withKeyboardEvents:!0,allowLeadingZeros:!0,trimLeadingZeroesOnBlur:!0,startValue:0,allowedDecimalSeparators:[`.`,`,`]},Th=en((e,{size:t})=>({controls:{"--ni-chevron-size":nt(t,`ni-chevron-size`)}}));function Eh(e,t,n){let r=e.toString(),i=vh.test(r),a=r.replace(/^0+(?=\d)/,``),o=parseFloat(a);if(Number.isNaN(o))return a;if(o>2**53-1)return t===void 0?a:t;let s=ut(o,n,t);return i?`${s.toString().replace(/^0+(?=\d)/,``)}.`:s}var Dh=_i((e,t)=>{let n=K(`NumberInput`,wh,e),{className:r,classNames:i,styles:a,unstyled:o,vars:s,onChange:c,onValueChange:l,value:u,defaultValue:d,max:f,min:p,step:m,hideControls:h,rightSection:g,isAllowed:_,clampBehavior:v,onBlur:y,allowDecimal:x,decimalScale:S,onKeyDown:C,onKeyDownCapture:w,handlersRef:T,startValue:E,disabled:D,rightSectionPointerEvents:O,allowNegative:k,readOnly:A,size:j,rightSectionWidth:M,stepHoldInterval:N,stepHoldDelay:P,allowLeadingZeros:F,withKeyboardEvents:I,trimLeadingZeroesOnBlur:L,allowedDecimalSeparators:R,attributes:z,...B}=n,V=jr({name:`NumberInput`,classes:ph,props:n,classNames:i,styles:a,unstyled:o,attributes:z,vars:s,varsResolver:Th}),{resolvedClassNames:ee,resolvedStyles:te}=mr({classNames:i,styles:a,props:n}),[ne,re]=Vt({value:u,defaultValue:d,finalValue:``,onChange:c}),ie=P!==void 0&&N!==void 0,ae=(0,b.useRef)(null),oe=(0,b.useRef)(null),se=(0,b.useRef)(0),H=(e,t)=>{t.source===`event`&&re(Sh(e.floatValue,e.value)&&!hh.test(e.value)&&!(F&&gh.test(e.value))&&!_h.test(e.value)&&!vh.test(e.value)?e.floatValue:e.value),l?.(e,t)},ce=e=>{let t=String(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0},le=e=>{ae.current&&e!==void 0&&ae.current.setSelectionRange(e,e)},ue=(0,b.useRef)(et);ue.current=()=>{if(!bh(ne))return;let e,t=ce(ne),n=ce(m),r=Math.max(t,n),i=10**r;if(!yh(ne)&&(typeof ne!=`number`||Number.isNaN(ne)))e=ut(E,p,f);else if(f!==void 0){let t=(Math.round(Number(ne)*i)+Math.round(m*i))/i;e=t<=f?t:f}else e=(Math.round(Number(ne)*i)+Math.round(m*i))/i;let a=e.toFixed(r);re(parseFloat(a)),l?.({floatValue:parseFloat(a),formattedValue:a,value:a},{source:`increment`}),setTimeout(()=>le(ae.current?.value.length),0)};let U=(0,b.useRef)(et);U.current=()=>{if(!bh(ne))return;let e,t=p===void 0?k?-(2**53-1):0:p,n=ce(ne),r=ce(m),i=Math.max(n,r),a=10**i;if(!yh(ne)&&typeof ne!=`number`||Number.isNaN(ne))e=ut(E,t,f);else{let n=(Math.round(Number(ne)*a)-Math.round(m*a))/a;e=t!==void 0&&n<t?t:n}let o=e.toFixed(i);re(parseFloat(o)),l?.({floatValue:parseFloat(o),formattedValue:o,value:o},{source:`decrement`}),setTimeout(()=>le(ae.current?.value.length),0)};let de=e=>{let t=e.clipboardData.getData(`text`),n=B.decimalSeparator||`.`,r=(R||[`.`,`,`]).filter(e=>e!==n);if(r.some(e=>t.includes(e))){e.preventDefault();let i=t;r.forEach(e=>{i=i.split(e).join(n)});let a=ae.current;if(a){let e=a.selectionStart??0,t=a.selectionEnd??0,n=a.value,r=n.substring(0,e)+i+n.substring(t);(Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set)?.call(a,r),a.dispatchEvent(new Event(`change`,{bubbles:!0}));let o=e+i.length;setTimeout(()=>le(o),0)}}B.onPaste?.(e)},fe=e=>{C?.(e),!(A||!I)&&(e.key===`ArrowUp`&&(e.preventDefault(),ue.current?.()),e.key===`ArrowDown`&&(e.preventDefault(),U.current?.()))},pe=e=>{if(w?.(e),e.key===`Backspace`){let t=ae.current;t&&t.selectionStart===0&&t.selectionStart===t.selectionEnd&&(e.preventDefault(),window.setTimeout(()=>le(0),0))}},me=e=>{let t=ne;v===`blur`&&typeof t==`number`&&(t=ut(t,p,f)),L&&typeof t==`string`&&ce(t)<15&&(t=Eh(t,f,p)),ne!==t&&re(t),y?.(e)};It(T,{increment:ue.current,decrement:U.current});let he=e=>{e?ue.current?.():U.current?.(),se.current+=1},ge=e=>{if(he(e),ie){let t=typeof N==`number`?N:N(se.current);oe.current=window.setTimeout(()=>ge(e),t)}},_e=(e,t)=>{e.preventDefault(),ae.current?.focus(),he(t),ie&&(oe.current=window.setTimeout(()=>ge(t),P))},ve=()=>{oe.current&&window.clearTimeout(oe.current),oe.current=null,se.current=0},ye=(0,G.jsxs)(`div`,{...V(`controls`),children:[(0,G.jsx)(Gc,{...V(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof ne==`number`&&f!==void 0&&ne>=f,mod:{direction:`up`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{_e(e,!0)},onPointerUp:ve,onPointerLeave:ve,children:(0,G.jsx)(mh,{direction:`up`})}),(0,G.jsx)(Gc,{...V(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof ne==`number`&&p!==void 0&&ne<=p,mod:{direction:`down`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{_e(e,!1)},onPointerUp:ve,onPointerLeave:ve,children:(0,G.jsx)(mh,{direction:`down`})})]});return(0,G.jsx)(Vu,{component:fh,allowNegative:k,className:nn(ph.root,r),size:j,inputMode:`decimal`,...B,readOnly:A,disabled:D,value:ne,getInputRef:Rt(t,ae),onValueChange:H,rightSection:h||A||!bh(ne)?g:g||ye,classNames:ee,styles:te,unstyled:o,__staticSelector:`NumberInput`,decimalScale:x?S:0,onPaste:de,onKeyDown:fe,onKeyDownCapture:pe,rightSectionPointerEvents:O??(D?`none`:void 0),rightSectionWidth:M??`var(--ni-right-section-width-${j||`sm`})`,allowLeadingZeros:F,allowedDecimalSeparators:R,onBlur:me,attributes:z,isAllowed:e=>v===`strict`?_?_(e)&&Ch(e.floatValue,p,f):Ch(e.floatValue,p,f):_?_(e):!0})});Dh.classes={...Vu.classes,...ph},Dh.displayName=`@mantine/core/NumberInput`;var Oh={duration:100,transition:`fade`};function kh(e,t){return{...Oh,...t,...e}}var Ah={tooltip:`m_1b3c8819`,arrow:`m_f898399f`};function jh({offset:e,position:t,defaultOpened:n}){let[r,i]=(0,b.useState)(n),a=(0,b.useRef)(null),{x:o,y:s,elements:c,refs:l,update:u,placement:d}=tc({placement:t,middleware:[ds({crossAxis:!0,padding:5,rootBoundary:`document`})]}),f=d.includes(`right`)?e:t.includes(`left`)?e*-1:0,p=d.includes(`bottom`)?e:t.includes(`top`)?e*-1:0,m=(0,b.useCallback)(({clientX:e,clientY:t})=>{l.setPositionReference({getBoundingClientRect(){return{width:0,height:0,x:e,y:t,left:e+f,top:t+p,right:e,bottom:t}}})},[c.reference]);return(0,b.useEffect)(()=>{if(l.floating.current){let e=a.current;e.addEventListener(`mousemove`,m);let t=$i(l.floating.current);return t.forEach(e=>{e.addEventListener(`scroll`,u)}),()=>{e.removeEventListener(`mousemove`,m),t.forEach(e=>{e.removeEventListener(`scroll`,u)})}}},[c.reference,l.floating.current,u,m,r]),{handleMouseMove:m,x:o,y:s,opened:r,setOpened:i,boundaryRef:a,floating:l.setFloating}}var Mh={refProp:`ref`,withinPortal:!0,offset:10,position:`right`,zIndex:$e(`popover`)},Nh=en((e,{radius:t,color:n})=>({tooltip:{"--tooltip-radius":t===void 0?void 0:it(t),"--tooltip-bg":n?An(n,e):void 0,"--tooltip-color":n?`var(--mantine-color-white)`:void 0}})),Ph=_i((e,t)=>{let n=K(`TooltipFloating`,Mh,e),{children:r,refProp:i,withinPortal:a,style:o,className:s,classNames:c,styles:l,unstyled:u,radius:d,color:f,label:p,offset:m,position:h,multiline:g,zIndex:_,disabled:v,defaultOpened:y,variant:x,vars:S,portalProps:C,attributes:w,...T}=n,E=qn(),D=jr({name:`TooltipFloating`,props:n,classes:Ah,className:s,style:o,classNames:c,styles:l,unstyled:u,attributes:w,rootSelector:`tooltip`,vars:S,varsResolver:Nh}),{handleMouseMove:O,x:k,y:A,opened:j,boundaryRef:M,floating:N,setOpened:P}=jh({offset:m,position:h,defaultOpened:y}),F=$t(r);if(!F)throw Error(`[@mantine/core] Tooltip.Floating component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);let I=Rt(M,Yt(F),t),L=F.props,R=e=>{L.onMouseEnter?.(e),O(e),P(!0)},z=e=>{L.onMouseLeave?.(e),P(!1)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dl,{...C,withinPortal:a,children:(0,G.jsx)(q,{...T,...D(`tooltip`,{style:{...si(o,E),zIndex:_,display:!v&&j?`block`:`none`,top:(A&&Math.round(A))??``,left:(k&&Math.round(k))??``}}),variant:x,ref:N,mod:{multiline:g},children:p})}),(0,b.cloneElement)(F,{...L,[i]:I,onMouseEnter:R,onMouseLeave:z})]})});Ph.classes=Ah,Ph.displayName=`@mantine/core/TooltipFloating`;var Fh=(0,b.createContext)(!1),Ih=Fh.Provider,Lh=()=>(0,b.useContext)(Fh),Rh={openDelay:0,closeDelay:0};function zh(e){let{openDelay:t,closeDelay:n,children:r}=K(`TooltipGroup`,Rh,e);return(0,G.jsx)(Ih,{value:!0,children:(0,G.jsx)(Js,{delay:{open:t,close:n},children:r})})}zh.displayName=`@mantine/core/TooltipGroup`,zh.extend=e=>e;function Bh(e){if(e===void 0)return{shift:!0,flip:!0};let t={...e};return e.shift===void 0&&(t.shift=!0),e.flip===void 0&&(t.flip=!0),t}function Vh(e){let t=Bh(e.middlewares),n=[us(e.offset)];return t.shift&&n.push(ds(typeof t.shift==`boolean`?{padding:8}:{padding:8,...t.shift})),t.flip&&n.push(typeof t.flip==`boolean`?ps():ps(t.flip)),n.push(_s({element:e.arrowRef,padding:e.arrowOffset})),t.inline?n.push(typeof t.inline==`boolean`?gs():gs(t.inline)):e.inline&&n.push(gs()),n}function Hh(e){let[t,n]=(0,b.useState)(e.defaultOpened),r=typeof e.opened==`boolean`?e.opened:t,i=Lh(),a=Pt(),o=(0,b.useCallback)(e=>{n(e),e&&g(a)},[a]),{x:s,y:c,context:l,refs:u,placement:d,middlewareData:{arrow:{x:f,y:p}={}}}=tc({strategy:e.strategy,placement:e.position,open:r,onOpenChange:o,middleware:Vh(e),whileElementsMounted:qo}),{delay:m,currentId:h,setCurrentId:g}=Ys(l,{id:a}),{getReferenceProps:_,getFloatingProps:v}=ac([Ws(l,{enabled:e.events?.hover,delay:i?m:{open:e.openDelay,close:e.closeDelay},mouseOnly:!e.events?.touch}),rc(l,{enabled:e.events?.focus,visibleOnly:!0}),sc(l,{role:`tooltip`}),$s(l,{enabled:e.opened===void 0})]);bt(()=>{e.onPositionChange?.(d)},[d]);let y=r&&h&&h!==a;return{x:s,y:c,arrowX:f,arrowY:p,reference:u.setReference,floating:u.setFloating,getFloatingProps:v,getReferenceProps:_,isGroupPhase:y,opened:r,placement:d}}var Uh={position:`top`,refProp:`ref`,withinPortal:!0,arrowSize:4,arrowOffset:5,arrowRadius:0,arrowPosition:`side`,offset:5,transitionProps:{duration:100,transition:`fade`},events:{hover:!0,focus:!1,touch:!1},zIndex:$e(`popover`),positionDependencies:[],middlewares:{flip:!0,shift:!0,inline:!1}},Wh=en((e,{radius:t,color:n,variant:r,autoContrast:i})=>{let a=e.variantColorResolver({theme:e,color:n||e.primaryColor,autoContrast:i,variant:r||`filled`});return{tooltip:{"--tooltip-radius":t===void 0?void 0:it(t),"--tooltip-bg":n?a.background:void 0,"--tooltip-color":n?a.color:void 0}}}),Gh=_i((e,t)=>{let n=K(`Tooltip`,Uh,e),{children:r,position:i,refProp:a,label:o,openDelay:s,closeDelay:c,onPositionChange:l,opened:u,defaultOpened:d,withinPortal:f,radius:p,color:m,classNames:h,styles:g,unstyled:_,style:v,className:y,withArrow:x,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,offset:E,transitionProps:D,multiline:O,events:k,zIndex:A,disabled:j,positionDependencies:M,onClick:N,onMouseEnter:P,onMouseLeave:F,inline:I,variant:L,keepMounted:R,vars:z,portalProps:B,mod:V,floatingStrategy:ee,middlewares:te,autoContrast:ne,attributes:re,target:ie,...ae}=K(`Tooltip`,Uh,n),{dir:oe}=bi(),se=(0,b.useRef)(null),H=Hh({position:nl(oe,i),closeDelay:c,openDelay:s,onPositionChange:l,opened:u,defaultOpened:d,events:k,arrowRef:se,arrowOffset:C,offset:typeof E==`number`?E+(x?S/2:0):E,positionDependencies:[...M,ie??r],inline:I,strategy:ee,middlewares:te});(0,b.useEffect)(()=>{let e=ie instanceof HTMLElement?ie:typeof ie==`string`?document.querySelector(ie):ie?.current||null;e&&H.reference(e)},[ie,H]);let ce=jr({name:`Tooltip`,props:n,classes:Ah,className:y,style:v,classNames:h,styles:g,unstyled:_,attributes:re,rootSelector:`tooltip`,vars:z,varsResolver:Wh}),le=$t(r);if(!ie&&!le)throw Error(`[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);if(ie){let e=kh(D,{duration:100,transition:`fade`});return(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(dl,{...B,withinPortal:f,children:(0,G.jsx)(_l,{...e,keepMounted:R,mounted:!j&&!!H.opened,duration:H.isGroupPhase?10:e.duration,children:e=>(0,G.jsxs)(q,{...ae,"data-fixed":ee===`fixed`||void 0,variant:L,mod:[{multiline:O},V],...H.getFloatingProps({ref:H.floating,className:ce(`tooltip`).className,style:{...ce(`tooltip`).style,...e,zIndex:A,top:H.y??0,left:H.x??0}}),children:[o,(0,G.jsx)(tl,{ref:se,arrowX:H.arrowX,arrowY:H.arrowY,visible:x,position:H.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ce(`arrow`)})]})})})})}let ue=le.props,U=Rt(H.reference,Yt(le),t),de=kh(D,{duration:100,transition:`fade`});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dl,{...B,withinPortal:f,children:(0,G.jsx)(_l,{...de,keepMounted:R,mounted:!j&&!!H.opened,duration:H.isGroupPhase?10:de.duration,children:e=>(0,G.jsxs)(q,{...ae,"data-fixed":ee===`fixed`||void 0,variant:L,mod:[{multiline:O},V],...H.getFloatingProps({ref:H.floating,className:ce(`tooltip`).className,style:{...ce(`tooltip`).style,...e,zIndex:A,top:H.y??0,left:H.x??0}}),children:[o,(0,G.jsx)(tl,{ref:se,arrowX:H.arrowX,arrowY:H.arrowY,visible:x,position:H.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ce(`arrow`)})]})})}),(0,b.cloneElement)(le,H.getReferenceProps({onClick:N,onMouseEnter:P,onMouseLeave:F,onMouseMove:n.onMouseMove,onPointerDown:n.onPointerDown,onPointerEnter:n.onPointerEnter,...ue,className:nn(y,ue.className),[a]:U}))]})});Gh.classes=Ah,Gh.displayName=`@mantine/core/Tooltip`,Gh.Floating=Ph,Gh.Group=zh;var Kh={withCheckIcon:!0,allowDeselect:!0,checkIconPosition:`left`,openOnFocus:!0},qh=_i((e,t)=>{let n=K(`Select`,Kh,e),{classNames:r,styles:i,unstyled:a,vars:o,dropdownOpened:s,defaultDropdownOpened:c,onDropdownClose:l,onDropdownOpen:u,onFocus:d,onBlur:f,onClick:p,onChange:m,data:h,value:g,defaultValue:_,selectFirstOptionOnChange:v,selectFirstOptionOnDropdownOpen:y,onOptionSubmit:x,comboboxProps:S,readOnly:C,disabled:w,filter:T,limit:E,withScrollArea:D,maxDropdownHeight:O,size:k,searchable:A,rightSection:j,checkIconPosition:M,withCheckIcon:N,withAlignedLabels:P,nothingFoundMessage:F,name:I,form:L,searchValue:R,defaultSearchValue:z,onSearchChange:B,allowDeselect:V,error:ee,rightSectionPointerEvents:te,id:ne,clearable:re,clearButtonProps:ie,hiddenInputProps:ae,renderOption:oe,onClear:se,autoComplete:H,scrollAreaProps:ce,__defaultRightSection:le,__clearSection:ue,__clearable:U,chevronColor:de,autoSelectOnBlur:fe,openOnFocus:pe,attributes:me,...he}=n,ge=(0,b.useMemo)(()=>nd(h),[h]),_e=(0,b.useRef)({}),ve=(0,b.useMemo)(()=>rd(ge),[ge]),ye=Pt(ne),[be,xe,Se]=Vt({value:g,defaultValue:_,finalValue:null,onChange:m}),Ce=typeof be==`string`?be in ve?ve[be]:_e.current[be]:void 0,we=Wt(Ce),[Te,Ee,De]=Vt({value:R,defaultValue:z,finalValue:Ce?Ce.label:``,onChange:B}),Oe=jd({opened:s,defaultOpened:c,onDropdownOpen:()=>{u?.(),y?Oe.selectFirstOption():Oe.updateSelectedOptionIndex(`active`,{scrollIntoView:!0})},onDropdownClose:()=>{l?.(),setTimeout(Oe.resetSelectedOption,0)}}),ke=e=>{Ee(e),Oe.resetSelectedOption()},{resolvedClassNames:Ae,resolvedStyles:je}=mr({props:n,styles:i,classNames:r});(0,b.useEffect)(()=>{v&&Oe.selectFirstOption()},[v,Te]),(0,b.useEffect)(()=>{g===null&&ke(``),typeof g==`string`&&Ce&&(we?.value!==Ce.value||we?.label!==Ce.label)&&ke(Ce.label)},[g,Ce]),(0,b.useEffect)(()=>{!Se&&!De&&ke(typeof be==`string`?be in ve?ve[be]?.label:_e.current[be]?.label||``:``)},[ve,be]),(0,b.useEffect)(()=>{be&&be in ve&&(_e.current[be]=ve[be])},[ve,be]);let Me=(0,G.jsx)(Pd.ClearButton,{...ie,onClear:()=>{xe(null,null),ke(``),se?.()}}),Ne=re&&!!be&&!w&&!C;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Pd,{store:Oe,__staticSelector:`Select`,classNames:Ae,styles:je,unstyled:a,readOnly:C,size:k,attributes:me,keepMounted:fe,onOptionSubmit:e=>{x?.(e);let t=V&&ve[e].value===be?null:ve[e],n=t?t.value:null;n!==be&&xe(n,t),!Se&&ke(typeof n==`string`&&t?.label||``),Oe.closeDropdown()},...S,children:[(0,G.jsx)(Pd.Target,{targetType:A?`input`:`button`,autoComplete:H,children:(0,G.jsx)(Vu,{id:ye,ref:t,__defaultRightSection:(0,G.jsx)(Pd.Chevron,{size:k,error:ee,unstyled:a,color:de}),__clearSection:Me,__clearable:Ne,rightSection:j,rightSectionPointerEvents:te||`none`,...he,size:k,__staticSelector:`Select`,disabled:w,readOnly:C||!A,value:Te,onChange:e=>{ke(e.currentTarget.value),Oe.openDropdown(),v&&Oe.selectFirstOption()},onFocus:e=>{pe&&A&&Oe.openDropdown(),d?.(e)},onBlur:e=>{fe&&Oe.clickSelectedOption(),A&&Oe.closeDropdown();let t=typeof be==`string`&&(be in ve?ve[be]:_e.current[be]);ke(t&&t.label||``),f?.(e)},onClick:e=>{A?Oe.openDropdown():Oe.toggleDropdown(),p?.(e)},classNames:Ae,styles:je,unstyled:a,pointer:!A,error:ee,attributes:me})}),(0,G.jsx)(ff,{data:ge,hidden:C||w,filter:T,search:Te,limit:E,hiddenWhenEmpty:!F,withScrollArea:D,maxDropdownHeight:O,filterOptions:!!A&&Ce?.label!==Te,value:be,checkIconPosition:M,withCheckIcon:N,withAlignedLabels:P,nothingFoundMessage:F,unstyled:a,labelId:he.label?`${ye}-label`:void 0,"aria-label":he.label?void 0:he[`aria-label`],renderOption:oe,scrollAreaProps:ce})]}),(0,G.jsx)(Pd.HiddenInput,{value:be,name:I,form:L,disabled:w,...ae})]})});qh.classes={...Vu.classes,...Pd.classes},qh.displayName=`@mantine/core/Select`;var[Jh,Yh]=Ge(`SliderProvider was not found in tree`),Xh={root:`m_dd36362e`,label:`m_c9357328`,thumb:`m_c9a9a60a`,trackContainer:`m_a8645c2`,track:`m_c9ade57f`,bar:`m_38aeed47`,markWrapper:`m_b7b0423a`,mark:`m_dd33bc19`,markLabel:`m_68c77a5b`},Zh=(0,b.forwardRef)(({size:e,disabled:t,variant:n,color:r,thumbSize:i,radius:a,...o},s)=>{let{getStyles:c}=Yh();return(0,G.jsx)(q,{tabIndex:-1,variant:n,size:e,ref:s,...c(`root`),...o})});Zh.displayName=`@mantine/core/SliderRoot`;var Qh=(0,b.forwardRef)(({max:e,min:t,value:n,position:r,label:i,dragging:a,onMouseDown:o,onKeyDownCapture:s,labelTransitionProps:c,labelAlwaysOn:l,thumbLabel:u,onFocus:d,onBlur:f,showLabelOnHover:p,isHovered:m,children:h=null,disabled:g},_)=>{let{getStyles:v}=Yh(),[y,x]=(0,b.useState)(!1),S=l||a||y||p&&m;return(0,G.jsxs)(q,{tabIndex:0,role:`slider`,"aria-label":u,"aria-valuemax":e,"aria-valuemin":t,"aria-valuenow":n,ref:_,__vars:{"--slider-thumb-offset":`${r}%`},...v(`thumb`,{focusable:!0}),mod:{dragging:a,disabled:g},onFocus:e=>{x(!0),typeof d==`function`&&d(e)},onBlur:e=>{x(!1),typeof f==`function`&&f(e)},onTouchStart:o,onMouseDown:o,onKeyDownCapture:s,onClick:e=>e.stopPropagation(),children:[h,(0,G.jsx)(_l,{mounted:i!=null&&!!S,transition:`fade`,duration:0,...c,children:e=>(0,G.jsx)(`div`,{...v(`label`,{style:e}),children:i})})]})});Qh.displayName=`@mantine/core/SliderThumb`;function $h({value:e,min:t,max:n}){let r=(e-t)/(n-t)*100;return Math.min(Math.max(r,0),100)}function eg({mark:e,offset:t,value:n,inverted:r=!1}){return r?typeof t==`number`&&e.value<=t||e.value>=n:typeof t==`number`?e.value>=t&&e.value<=n:e.value<=n}function tg({marks:e,min:t,max:n,disabled:r,value:i,offset:a,inverted:o}){let{getStyles:s}=Yh();return e?(0,G.jsx)(`div`,{children:e.map((e,c)=>(0,b.createElement)(q,{...s(`markWrapper`),__vars:{"--mark-offset":`${$h({value:e.value,min:t,max:n})}%`},key:c},(0,G.jsx)(q,{...s(`mark`),mod:{filled:eg({mark:e,value:i,offset:a,inverted:o}),disabled:r}}),e.label&&(0,G.jsx)(`div`,{...s(`markLabel`),children:e.label})))}):null}tg.displayName=`@mantine/core/SliderMarks`;function ng({filled:e,children:t,offset:n,disabled:r,marksOffset:i,inverted:a,containerProps:o,...s}){let{getStyles:c}=Yh();return(0,G.jsx)(q,{...c(`trackContainer`),mod:{disabled:r},...o,children:(0,G.jsxs)(q,{...c(`track`),mod:{inverted:a,disabled:r},children:[(0,G.jsx)(q,{mod:{inverted:a,disabled:r},__vars:{"--slider-bar-width":`calc(${e}% + 2 * var(--slider-size))`,"--slider-bar-offset":`calc(${n}% - var(--slider-size))`},...c(`bar`)}),t,(0,G.jsx)(tg,{...s,offset:i,disabled:r,inverted:a})]})})}ng.displayName=`@mantine/core/SliderTrack`;function rg({value:e,containerWidth:t,min:n,max:r,step:i,precision:a}){let o=(t?Math.min(Math.max(e,0),t)/t:e)*(r-n),s=(o===0?0:Math.round(o/i)*i)+n,c=Math.max(s,n);return a===void 0?c:Number(c.toFixed(a))}function ig(e,t){return parseFloat(e.toFixed(t))}function ag(e){if(!e)return 0;let t=e.toString().split(`.`);return t.length>1?t[1].length:0}function og(e,t){let n=[...t].sort((e,t)=>e.value-t.value).find(t=>t.value>e);return n?n.value:e}function sg(e,t){let n=[...t].sort((e,t)=>t.value-e.value).find(t=>t.value<e);return n?n.value:e}function cg(e){let t=[...e].sort((e,t)=>e.value-t.value);return t.length>0?t[0].value:0}function lg(e){let t=[...e].sort((e,t)=>e.value-t.value);return t.length>0?t[t.length-1].value:100}var ug={radius:`xl`,min:0,max:100,step:1,marks:[],label:e=>e,labelTransitionProps:{transition:`fade`,duration:0},thumbLabel:``,showLabelOnHover:!0,scale:e=>e,size:`md`},dg=en((e,{size:t,color:n,thumbSize:r,radius:i})=>({root:{"--slider-size":nt(t,`slider-size`),"--slider-color":n?An(n,e):void 0,"--slider-radius":i===void 0?void 0:it(i),"--slider-thumb-size":r===void 0?`calc(var(--slider-size) * 2)`:W(r)}})),fg=_i((e,t)=>{let n=K(`Slider`,ug,e),{classNames:r,styles:i,value:a,onChange:o,onChangeEnd:s,size:c,min:l,max:u,domain:d,step:f,precision:p,defaultValue:m,name:h,marks:g,label:_,labelTransitionProps:v,labelAlwaysOn:y,thumbLabel:x,showLabelOnHover:S,thumbChildren:C,disabled:w,unstyled:T,scale:E,inverted:D,className:O,style:k,vars:A,hiddenInputProps:j,restrictToMarks:M,thumbProps:N,attributes:P,...F}=n,I=jr({name:`Slider`,props:n,classes:Xh,classNames:r,className:O,styles:i,style:k,attributes:P,vars:A,varsResolver:dg,unstyled:T}),{dir:L}=bi(),[R,z]=(0,b.useState)(!1),[B,V]=Vt({value:typeof a==`number`?ut(a,l,u):a,defaultValue:typeof m==`number`?ut(m,l,u):m,finalValue:ut(0,l,u),onChange:o}),ee=(0,b.useRef)(B),te=(0,b.useRef)(s);(0,b.useEffect)(()=>{te.current=s},[s]);let ne=(0,b.useRef)(null),re=(0,b.useRef)(null),[ie,ae]=d||[l,u],oe=$h({value:B,min:ie,max:ae}),se=E(B),H=typeof _==`function`?_(se):_,ce=p??ag(f),{ref:le,active:ue}=Bt((0,b.useCallback)(({x:e})=>{if(!w){let t=ut(rg({value:e,min:ie,max:ae,step:f,precision:ce}),l,u);V(M&&g?.length?Jt(t,g.map(e=>e.value)):t),ee.current=t}},[w,l,u,ie,ae,f,ce,V,g,M]),{onScrubEnd:(0,b.useCallback)(()=>{if(!w&&te.current){let e=M&&g?.length?Jt(ee.current,g.map(e=>e.value)):ee.current;te.current(e)}},[w,g,M])},L),U=(0,b.useCallback)(e=>{!w&&te.current&&te.current(e)},[w]),de=e=>{if(!w)switch(e.key){case`ArrowUp`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=og(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(B+f,l),u),ce);V(t),U(t);break}case`ArrowRight`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=L===`rtl`?sg(B,g):og(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(L===`rtl`?B-f:B+f,l),u),ce);V(t),U(t);break}case`ArrowDown`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=sg(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(B-f,l),u),ce);V(t),U(t);break}case`ArrowLeft`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=L===`rtl`?og(B,g):sg(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(L===`rtl`?B+f:B-f,l),u),ce);V(t),U(t);break}case`Home`:if(e.preventDefault(),re.current?.focus(),M&&g){V(cg(g)),U(cg(g));break}V(l),U(l);break;case`End`:if(e.preventDefault(),re.current?.focus(),M&&g){V(lg(g)),U(lg(g));break}V(u),U(u);break}};return(0,G.jsx)(Jh,{value:{getStyles:I},children:(0,G.jsxs)(Zh,{...F,ref:Rt(t,ne),onKeyDownCapture:de,onMouseDownCapture:()=>ne.current?.focus(),size:c,disabled:w,children:[(0,G.jsx)(ng,{inverted:D,offset:0,filled:oe,marks:g,min:ie,max:ae,value:se,disabled:w,containerProps:{ref:le,onMouseEnter:S?()=>z(!0):void 0,onMouseLeave:S?()=>z(!1):void 0},children:(0,G.jsx)(Qh,{max:ae,min:ie,value:se,position:oe,dragging:ue,label:H,ref:re,labelTransitionProps:v,labelAlwaysOn:y,thumbLabel:x,showLabelOnHover:S,isHovered:R,disabled:w,...N,children:C})}),(0,G.jsx)(`input`,{type:`hidden`,name:h,value:se,...j})]})})});fg.classes=Xh,fg.displayName=`@mantine/core/Slider`;var pg={root:`m_6d731127`},mg={gap:`md`,align:`stretch`,justify:`flex-start`},hg=en((e,{gap:t,align:n,justify:r})=>({root:{"--stack-gap":rt(t),"--stack-align":n,"--stack-justify":r}})),gg=_i((e,t)=>{let n=K(`Stack`,mg,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,align:l,justify:u,gap:d,variant:f,attributes:p,...m}=n;return(0,G.jsx)(q,{ref:t,...jr({name:`Stack`,props:n,classes:pg,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c,varsResolver:hg})(`root`),variant:f,...m})});gg.classes=pg,gg.displayName=`@mantine/core/Stack`;var _g=_i((e,t)=>(0,G.jsx)(Vu,{component:`input`,ref:t,...K(`TextInput`,null,e),__staticSelector:`TextInput`}));_g.classes=Vu.classes,_g.displayName=`@mantine/core/TextInput`;var vg={outline:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},filled:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`currentColor`,stroke:`none`}},yg=(e,t,n,r)=>{let i=(0,b.forwardRef)(({color:n=`currentColor`,size:i=24,stroke:a=2,title:o,className:s,children:c,...l},u)=>(0,b.createElement)(`svg`,{ref:u,...vg[e],width:i,height:i,className:[`tabler-icon`,`tabler-icon-${t}`,s].join(` `),...e===`filled`?{fill:n}:{strokeWidth:a,stroke:n},...l},[o&&(0,b.createElement)(`title`,{key:`svg-title`},o),...r.map(([e,t])=>(0,b.createElement)(e,t)),...Array.isArray(c)?c:[c]]));return i.displayName=`${n}`,i},bg=yg(`outline`,`chevron-down`,`ChevronDown`,[[`path`,{d:`M6 9l6 6l6 -6`,key:`svg-0`}]]),xg=yg(`outline`,`chevron-up`,`ChevronUp`,[[`path`,{d:`M6 15l6 -6l6 6`,key:`svg-0`}]]),Sg=yg(`outline`,`refresh`,`Refresh`,[[`path`,{d:`M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4`,key:`svg-0`}],[`path`,{d:`M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4`,key:`svg-1`}]]),Cg=yg(`outline`,`x`,`X`,[[`path`,{d:`M18 6l-12 12`,key:`svg-0`}],[`path`,{d:`M6 6l12 12`,key:`svg-1`}]]),wg=d(),Tg=`0.8.1-beta.0`,Eg=[{login:`ttktjmt`,html_url:`https://github.com/ttktjmt`},{login:`claude`,html_url:`https://github.com/claude`},{login:`Axellwppr`,html_url:`https://github.com/Axellwppr`},{login:`julien-blanchon`,html_url:`https://github.com/julien-blanchon`},{login:`unmoyai`,html_url:`https://github.com/unmoyai`},{login:`brentyi`,html_url:`https://github.com/brentyi`},{login:`CharlieLeee`,html_url:`https://github.com/CharlieLeee`}],Dg={move:`touchmove`,end:`touchend`},Og={move:`mousemove`,end:`mouseup`};function kg(e){return e.type===`touchmove`}function Ag(e){return e.type===`mousemove`}var jg=b.createContext(null);function Mg({children:e,width:t,visible:n=!0,onVisibleChange:r,hiddenButtonTooltip:i}){let a=b.useRef(null),[o,{toggle:s}]=Ut(!0),[c,l]=b.useState(800),u=b.useRef({dragging:!1,startPosX:0,startPosY:0,startClientX:0,startClientY:0}),d=b.useRef({}),f=(e,t,n)=>Math.abs(e+t/2)<Math.abs(e-n+t/2)?e:e-n;function p(e,t){let n=a.current;if(n===null)return[e,t];let r=n.parentElement;if(r===null)return[e,t];let i=e,o=t;return i=Math.min(i,r.clientWidth-n.clientWidth-15),i=Math.max(i,15),o=Math.min(o,r.clientHeight-n.clientHeight-15),o=Math.max(o,15),n.style.top=`${o.toString()}px`,n.style.left=`${i.toString()}px`,[f(i,n.clientWidth,r.clientWidth),f(o,n.clientHeight,r.clientHeight)]}b.useEffect(()=>{let e=a.current;if(e===null)return;let t=e.parentElement;if(t===null)return;let n=new ResizeObserver(()=>{d.current.x===void 0&&(d.current.x=f(e.offsetLeft,e.clientWidth,t.clientWidth)),d.current.y===void 0&&(d.current.y=f(e.offsetTop,e.clientHeight,t.clientHeight));let n=t.clientHeight-30;c!==n&&l(n);let r=d.current.x,i=d.current.y;for(;r<0;)r+=t.clientWidth;for(;i<0;)i+=t.clientHeight;p(r,i)});return n.observe(e),n.observe(t),()=>{n.disconnect()}});let m=e=>{let t=u.current,n=a.current;if(!n)return;e.type==`touchstart`?(e=e,t.startClientX=e.touches[0].clientX,t.startClientY=e.touches[0].clientY):(e=e,t.startClientX=e.clientX,t.startClientY=e.clientY),t.startPosX=n.offsetLeft,t.startPosY=n.offsetTop;let r=e.type==`touchstart`?Dg:Og;function i(e){let n=0,r=0;if(kg(e)?(e=e,n=e.touches[0].clientX-t.startClientX,r=e.touches[0].clientY-t.startClientY):Ag(e)&&(e=e,n=e.clientX-t.startClientX,r=e.clientY-t.startClientY),Math.abs(n)<=3&&Math.abs(r)<=3)return;t.dragging=!0;let i=t.startPosX+n,a=t.startPosY+r;[d.current.x,d.current.y]=p(i,a)}window.addEventListener(r.move,i),window.addEventListener(r.end,()=>{e.type==`touchstart`&&(t.dragging=!1),window.removeEventListener(r.move,i)},{once:!0})};if(!n){let e=(0,G.jsx)(q,{component:`button`,"aria-label":i??`Show controls`,onClick:()=>r?.(!0),style:{width:`0.85rem`,height:`0.85rem`,minWidth:`0.85rem`,minHeight:`0.85rem`,display:`block`,padding:0,border:`none`,borderRadius:`9999px`,background:`rgba(255, 255, 255, 0.82)`,boxShadow:`0 0 0 1px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.18)`,cursor:`pointer`}});return(0,G.jsx)(q,{style:{zIndex:10,position:`absolute`,top:`1em`,right:`1em`},children:i?(0,G.jsx)(Gh,{label:i,children:(0,G.jsx)(q,{children:e})}):e})}return(0,G.jsx)(jg.Provider,{value:{wrapperRef:a,expanded:o,width:t,maxHeight:c,toggleExpanded:s,dragHandler:m,dragInfo:u},children:(0,G.jsx)(Xc,{radius:`xs`,shadow:`0.1em 0 1em 0 rgba(0,0,0,0.1)`,style:{boxSizing:`border-box`,width:t,zIndex:10,position:`absolute`,top:`1em`,right:`1em`,margin:0,"& .expandIcon":{transform:`rotate(0)`},overflow:`hidden`},ref:a,children:e})})}Mg.Handle=function({children:e}){let t=b.useContext(jg);return(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(q,{style:{borderRadius:`0.2em 0.2em 0 0`,lineHeight:`1.5em`,cursor:`pointer`,position:`relative`,fontWeight:400,userSelect:`none`,display:`flex`,alignItems:`center`,padding:`0 0.75em`,height:`2.75em`},onClick:()=>{let e=t.dragInfo.current;if(e.dragging){e.dragging=!1;return}t.toggleExpanded()},onTouchStart:e=>{t.dragHandler(e)},onMouseDown:e=>{t.dragHandler(e)},children:e})})},Mg.Contents=function({children:e}){let t=b.useContext(jg);return(0,G.jsxs)(ki,{in:t.expanded,children:[(0,G.jsx)(hp,{mx:`xs`}),(0,G.jsx)(Vc.Autosize,{mah:t.maxHeight,children:(0,G.jsx)(q,{style:{width:t.width},children:e})})]})},Mg.HideWhenCollapsed=function({children:e}){return b.useContext(jg)?.expanded??!0?e:null},Mg.HideWhenExpanded=function({children:e}){return b.useContext(jg)?.expanded??!0?null:e};function Ng({id:e,label:t,children:n}){return(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsxs)(Wu,{align:`center`,children:[(0,G.jsx)(q,{pr:`xs`,style:{width:`7.25em`,flexShrink:0,position:`relative`},children:(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`100%`,boxSizing:`content-box`},children:(0,G.jsx)(`label`,{htmlFor:e,children:t})})}),(0,G.jsx)(q,{style:{flexGrow:1},children:n})]})})}function Pg({label:e,expandByDefault:t=!0,children:n}){let[r,{toggle:i}]=Ut(t);return(0,G.jsxs)(Xc,{withBorder:!0,style:{borderWidth:`1px`,position:`relative`,marginLeft:`var(--mantine-spacing-xs)`,marginRight:`var(--mantine-spacing-xs)`,marginTop:`var(--mantine-spacing-xs)`,marginBottom:`var(--mantine-spacing-xs)`,paddingBottom:`calc(var(--mantine-spacing-xs) - 0.5em)`},children:[(0,G.jsxs)(Xc,{onClick:i,style:{fontSize:`0.875em`,position:`absolute`,padding:`0 0.375em`,top:0,left:`0.375em`,transform:`translateY(-50%)`,userSelect:`none`,fontWeight:500,cursor:`pointer`,display:`flex`,alignItems:`center`},children:[e,(0,G.jsx)(r?xg:bg,{style:{width:`0.9em`,height:`0.9em`,strokeWidth:3,top:`0.1em`,position:`relative`,marginLeft:`0.25em`,marginRight:`-0.1em`,opacity:.5}})]}),(0,G.jsx)(ki,{in:r,children:(0,G.jsx)(q,{pt:`1em`,children:n})}),(0,G.jsx)(ki,{in:!r,children:(0,G.jsx)(q,{p:`xs`})})]})}var Fg={fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`4.5em`,flexShrink:0},Ig={root:{padding:`0`},track:{height:4},thumb:{width:12,height:12}},Lg={flex:1,minWidth:0,height:`1.75em`,fontSize:`0.8em`,fontFamily:`inherit`,border:`1px solid var(--mantine-color-default-border)`,borderRadius:`var(--mantine-radius-sm)`,background:`var(--mantine-color-default)`,color:`var(--mantine-color-text)`,textAlign:`right`,padding:`0 0.4em`,outline:`none`,cursor:`ns-resize`,touchAction:`none`};function Rg({axis:e,value:t,min:n=-1/0,max:r=1/0,step:i,onChange:a}){let o=(0,b.useRef)(null),s=(0,b.useRef)(null);(0,b.useEffect)(()=>{let e=o.current;e&&document.activeElement!==e&&(e.value=t.toFixed(2))},[t]);let c=e=>Math.max(n,Math.min(r,parseFloat((Math.round(e/i)*i).toFixed(10))));return(0,G.jsxs)(q,{style:{display:`flex`,alignItems:`center`,gap:`0.25em`,flex:1},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,letterSpacing:`-0.75px`,flexShrink:0},children:e}),(0,G.jsx)(`input`,{ref:o,size:1,defaultValue:t.toFixed(2),onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),s.current={startY:e.clientY,startValue:t,moved:!1}},onPointerMove:e=>{if(!s.current||!(e.buttons&1))return;let t=s.current.startY-e.clientY;if(Math.abs(t)>3&&(s.current.moved=!0),!s.current.moved)return;let n=c(s.current.startValue+t*i);a(n),o.current&&(o.current.value=n.toFixed(2))},onPointerUp:()=>{if(s.current&&!s.current.moved){let e=o.current;e&&(e.focus(),e.select())}s.current=null},onBlur:e=>{let n=parseFloat(e.target.value);isNaN(n)||a(c(n)),e.target.value=t.toFixed(2)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&(o.current&&(o.current.value=t.toFixed(2)),o.current?.blur())},onFocus:e=>e.currentTarget.style.outline=`2px solid var(--mantine-color-blue-5)`,onBlurCapture:e=>e.currentTarget.style.outline=`none`,style:Lg})]})}function zg({label:e,x:t,y:n,z:r,step:i,xLabel:a=`X`,yLabel:o=`Y`,zLabel:s=`Z`,onX:c,onY:l,onZ:u}){return(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`,gap:`0.5em`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:Fg,children:e}),(0,G.jsx)(Rg,{axis:a,value:t,step:i,onChange:c}),(0,G.jsx)(Rg,{axis:o,value:n,step:i,onChange:l}),(0,G.jsx)(Rg,{axis:s,value:r,step:i,onChange:u})]})}function Bg({scale:e,xOffset:t,yOffset:n,zOffset:r,roll:i,pitch:a,yaw:o,onCalibrate:s}){let[c,l]=(0,b.useState)(e),[u,d]=(0,b.useState)(t),[f,p]=(0,b.useState)(n),[m,h]=(0,b.useState)(r),[g,_]=(0,b.useState)(i),[v,y]=(0,b.useState)(a),[x,S]=(0,b.useState)(o);(0,b.useEffect)(()=>{l(e)},[e]),(0,b.useEffect)(()=>{d(t)},[t]),(0,b.useEffect)(()=>{p(n)},[n]),(0,b.useEffect)(()=>{h(r)},[r]),(0,b.useEffect)(()=>{_(i)},[i]),(0,b.useEffect)(()=>{y(a)},[a]),(0,b.useEffect)(()=>{S(o)},[o]);let C=(e,t,n,r,i,a,o)=>s(e,t,n,r,i,a,o);return(0,G.jsxs)(Pg,{label:`Control`,expandByDefault:!0,children:[(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`,gap:`0.5em`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:Fg,children:`Scale`}),(0,G.jsx)(q,{style:{flex:1},children:(0,G.jsx)(fg,{value:c,onChange:e=>{l(e),C(e,u,f,m,g,v,x)},min:.1,max:5,step:.05,size:`xs`,label:e=>e.toFixed(2),styles:Ig})})]}),(0,G.jsx)(zg,{label:`Position`,x:u,y:f,z:m,step:.05,onX:e=>{d(e),C(c,e,f,m,g,v,x)},onY:e=>{p(e),C(c,u,e,m,g,v,x)},onZ:e=>{h(e),C(c,u,f,e,g,v,x)}}),(0,G.jsx)(zg,{label:`Rotation`,x:g,y:v,z:x,step:.5,xLabel:`R`,yLabel:`P`,zLabel:`Y`,onX:e=>{_(e),C(c,u,f,m,e,v,x)},onY:e=>{y(e),C(c,u,f,m,g,e,x)},onZ:e=>{S(e),C(c,u,f,m,g,v,e)}})]})}function Vg(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.closest(`input, textarea, select, [contenteditable], [role="textbox"], [role="searchbox"], [role="combobox"]`)!==null:!1}function Hg(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Ug({command:e,value:t,onChange:n,disabled:r,enabledWhenValue:i}){let a=e.enabledWhen!==void 0&&(i??0)<.5,o=r||a;return(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`50%`,flexShrink:0},children:e.label}),(0,G.jsx)(q,{style:{width:`50%`},children:(0,G.jsx)(fg,{value:t,onChange:t=>n(e.id,t),min:e.min,max:e.max,step:e.step,size:`xs`,disabled:o,styles:{root:{padding:`0`},track:{height:4},thumb:{width:12,height:12}}})})]})}function Wg({command:e,value:t,onChange:n,disabled:r}){return(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsx)(af,{label:e.label,checked:t>=.5,onChange:t=>n(e.id,+!!t.currentTarget.checked),size:`xs`,disabled:r})})}function Gg(e){let{visible:t,onVisibleChange:n,projects:r,projectValue:i,projectLabel:a,onProjectChange:o,scenes:s,sceneValue:c,onSceneChange:l,splats:u,splatSection:d=!1,splatValue:f,onSplatChange:p,splatConfig:m,onCalibrateSplat:h,onSplatUrlLoad:g,policies:_,policyValue:v,onPolicyChange:y,motions:x,motionValue:S,onMotionChange:C,showReferenceMotion:w,onShowReferenceMotionChange:T,commandsEnabled:E=!1,commands:D,commandValues:O,onCommandChange:k,onReset:A}=e,[j,{open:M,close:N}]=Ut(!1),[P,F]=(0,b.useState)(``),[I,L]=(0,b.useState)(null),[R,z]=(0,b.useState)(!1),B=(0,b.useCallback)(async e=>{if(e.key!==`Enter`||!g)return;let t=P.trim();if(!u.some(e=>e.label===t||e.value===t)){if(!t.toLowerCase().endsWith(`.spz`)){L(`URL must end with .spz`);return}await g(t)?(L(null),z(!0)):L(`File not found at the specified URL`)}},[g,P,u]),V=Array.from(new Set(D.map(e=>e.group))),ee=(0,b.useCallback)(()=>{A?.()},[A]);(0,b.useEffect)(()=>{let e=e=>{if(e.defaultPrevented||e.repeat||e.altKey||e.ctrlKey||e.metaKey)return;let r=e.key.toLowerCase();r!==`c`&&r!==`r`||Vg(e.target instanceof Element?e.target:document.activeElement)||(e.preventDefault(),r===`c`?n(!t):ee())};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[t,n,ee]);let te=e=>D.filter(t=>t.group===e&&(t.type===`slider`||t.type===`checkbox`));return!r.length&&!s.length&&!_.length?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Cm,{opened:j,onClose:N,size:`lg`,title:null,centered:!0,styles:{body:{textAlign:`center`}},children:(0,G.jsxs)(gg,{gap:`md`,align:`center`,children:[(0,G.jsx)(vp,{src:`/logo.svg`,style:{width:`8em`,height:`auto`}}),(0,G.jsx)(Zu,{size:`xl`,fw:700,children:`powered by mjswan`}),(0,G.jsxs)(Zu,{size:`sm`,c:`dimmed`,children:[`version `,Tg]}),(0,G.jsx)(Zu,{size:`sm`,c:`dimmed`,children:`MuJoco Simulation on Web Assembly with Neural netwroks`}),(0,G.jsx)(hp,{w:`100%`}),(0,G.jsxs)(q,{children:[(0,G.jsx)(ed,{href:`https://github.com/ttktjmt/mjswan`,target:`_blank`,style:{fontWeight:`600`},children:`GitHub`}),`\xA0\xA0•\xA0\xA0`,(0,G.jsx)(ed,{href:`https://mjswan.readthedocs.io`,target:`_blank`,style:{fontWeight:`600`},children:`Documentation`})]}),(0,G.jsx)(hp,{w:`100%`}),(0,G.jsxs)(q,{style:{textAlign:`left`,maxHeight:`120px`,overflowY:`auto`,lineHeight:`1`,fontSize:`0.8rem`,opacity:`0.75`},px:`md`,children:[`Thanks to our contributors! `,(0,G.jsx)(`br`,{}),Eg.map((e,t)=>(0,G.jsxs)(`span`,{children:[(0,G.jsx)(ed,{href:e.html_url,target:`_blank`,style:{textDecoration:`none`,fontSize:`0.75rem`},children:e.login}),t<Eg.length-1&&`, `]},e.login))]})]})}),(0,G.jsxs)(Mg,{width:`20em`,visible:t,onVisibleChange:n,hiddenButtonTooltip:`Show controls (C)`,children:[(0,G.jsxs)(Mg.Handle,{children:[(0,G.jsx)(Gh,{label:`mjswan ${Tg}`,children:(0,G.jsx)(q,{component:`a`,onClick:e=>{e.stopPropagation(),M()},onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),style:{position:`absolute`,cursor:`pointer`,display:`flex`,top:`0.8em`,left:`0.9em`},children:(0,G.jsx)(vp,{src:`/logo.svg`,style:{width:`1.2em`,height:`auto`}})})}),(0,G.jsx)(`div`,{style:{width:`1.1em`}}),(0,G.jsx)(Mg.HideWhenCollapsed,{children:(0,G.jsxs)(q,{px:`xs`,style:{flexGrow:1,letterSpacing:`-0.5px`,display:`flex`,alignItems:`center`,gap:`0.5em`},pt:`0.1em`,children:[(0,G.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:a}),r.length>1&&(0,G.jsxs)(om,{position:`bottom-start`,offset:5,children:[(0,G.jsx)(om.Target,{children:(0,G.jsx)(q,{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),style:{cursor:`pointer`,display:`flex`,alignItems:`center`,flexShrink:0},children:(0,G.jsx)(bg,{size:16})})}),(0,G.jsx)(om.Dropdown,{onClick:e=>e.stopPropagation(),children:r.map(e=>(0,G.jsx)(om.Item,{onClick:t=>{t.stopPropagation(),o(e.value)},style:{fontWeight:e.value===i?600:400,backgroundColor:e.value===i?`rgba(34, 139, 230, 0.1)`:void 0},children:e.label},e.value))})]})]})}),(0,G.jsx)(Mg.HideWhenExpanded,{children:(0,G.jsx)(q,{px:`xs`,style:{flexGrow:1,letterSpacing:`-0.5px`},pt:`0.1em`,children:a})}),(0,G.jsx)(Gh,{label:`Hide controls (C)`,children:(0,G.jsx)(ql,{variant:`subtle`,color:`gray`,size:`sm`,"aria-label":`Hide controls`,onClick:e=>{e.stopPropagation(),n(!1)},onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:(0,G.jsx)(Cg,{size:14})})})]}),(0,G.jsx)(Mg.Contents,{children:(0,G.jsxs)(q,{pt:`0.375em`,children:[s.length>0&&(0,G.jsx)(Ng,{id:`scene-select`,label:`Scene`,children:(0,G.jsx)(qh,{id:`scene-select`,placeholder:`Select scene`,data:s,value:c,onChange:l,size:`xs`,radius:`xs`,searchable:!0,clearable:!1,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),(u.length>0||d)&&(0,G.jsx)(Ng,{id:`splat-select`,label:`Splat`,children:(0,G.jsx)(Gh,{label:I??``,color:`red`,position:`bottom`,opened:I!==null,withArrow:!0,children:(0,G.jsx)(qh,{id:`splat-select`,placeholder:g===void 0?`Select splat`:`Select splat or paste .spz URL`,data:u,value:f,onChange:e=>{p(e),L(null),z(!1)},searchable:g!==void 0,searchValue:P,onSearchChange:e=>{F(e),e&&L(null)},onKeyDown:B,size:`xs`,radius:`xs`,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})})}),(m?.control&&f!==null||R)&&h&&(0,G.jsx)(Bg,{scale:m?.scale??1,xOffset:m?.xOffset??0,yOffset:m?.yOffset??0,zOffset:m?.zOffset??0,roll:m?.roll??0,pitch:m?.pitch??0,yaw:m?.yaw??0,onCalibrate:h}),_.length>0&&(0,G.jsx)(Ng,{id:`policy-select`,label:`Policy`,children:(0,G.jsx)(qh,{id:`policy-select`,placeholder:`Select policy`,data:_,value:v,onChange:y,size:`xs`,radius:`xs`,searchable:!0,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),x.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ng,{id:`motion-select`,label:`Motion`,children:(0,G.jsx)(qh,{id:`motion-select`,placeholder:`Select motion`,data:x,value:S,onChange:C,size:`xs`,radius:`xs`,searchable:!0,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsx)(af,{label:`Show reference`,checked:w,onChange:e=>T(e.currentTarget.checked),size:`xs`})})]}),V.length>0&&D.some(e=>e.type===`slider`||e.type===`checkbox`)&&(0,G.jsx)(G.Fragment,{children:V.map(e=>{let t=te(e);return t.length===0?null:(0,G.jsx)(Pg,{label:Hg(e),expandByDefault:!0,children:t.map(e=>e.type===`checkbox`?(0,G.jsx)(Wg,{command:e,value:O[e.id]??0,onChange:k,disabled:!E},e.id):e.type===`slider`?(0,G.jsx)(Ug,{command:e,value:O[e.id]??0,onChange:k,disabled:!E,enabledWhenValue:e.enabledWhen?O[`${e.group}:${e.enabledWhen}`]:void 0},e.id):null)},e)})}),(0,G.jsx)(hp,{mb:`xs`,mx:`xs`}),(0,G.jsx)(q,{px:`xs`,pb:`xs`,children:(0,G.jsx)(xf,{variant:`light`,color:`red`,size:`xs`,fullWidth:!0,leftSection:(0,G.jsx)(Sg,{size:14}),onClick:ee,children:`Reset`})})]})})]})]})}function Kg(e,t,n){return Object.keys(e[t]).reduce((e,t)=>(e[t]=`var(--mantine-${n}-${t})`,e),{})}function qg(e,t){return e in t.breakpoints?t.breakpoints[e]:Be(e)}function Jg(e){let t=Wn(Ln,e),n=Kg(t,`fontSizes`,`font-size`),r=Kg(t,`lineHeights`,`line-height`),i=Kg(t,`shadows`,`shadow`),a=Kg(t,`radius`,`radius`),o=Kg(t,`spacing`,`spacing`),s=Object.keys(t.headings.sizes).reduce((e,t)=>(e[t]={fontSize:`var(--mantine-${t}-font-size)`,lineHeight:`var(--mantine-${t}-line-height)`,fontWeight:`var(--mantine-${t}-font-weight)`},e),{}),c=Object.keys(t.colors).reduce((e,t)=>(e[t]={0:`var(--mantine-color-${t}-0)`,1:`var(--mantine-color-${t}-1)`,2:`var(--mantine-color-${t}-2)`,3:`var(--mantine-color-${t}-3)`,4:`var(--mantine-color-${t}-4)`,5:`var(--mantine-color-${t}-5)`,6:`var(--mantine-color-${t}-6)`,7:`var(--mantine-color-${t}-7)`,8:`var(--mantine-color-${t}-8)`,9:`var(--mantine-color-${t}-9)`,filled:`var(--mantine-color-${t}-filled)`,filledHover:`var(--mantine-color-${t}-filled-hover)`,light:`var(--mantine-color-${t}-light)`,lightHover:`var(--mantine-color-${t}-light-hover)`,lightColor:`var(--mantine-color-${t}-light-color)`,outline:`var(--mantine-color-${t}-outline)`,outlineHover:`var(--mantine-color-${t}-outline-hover)`},e),{primary:`var(--mantine-primary-color-filled)`,primaryColors:{0:`var(--mantine-primary-color-0)`,1:`var(--mantine-primary-color-1)`,2:`var(--mantine-primary-color-2)`,3:`var(--mantine-primary-color-3)`,4:`var(--mantine-primary-color-4)`,5:`var(--mantine-primary-color-5)`,6:`var(--mantine-primary-color-6)`,7:`var(--mantine-primary-color-7)`,8:`var(--mantine-primary-color-8)`,9:`var(--mantine-primary-color-9)`,filled:`var(--mantine-primary-color-filled)`,filledHover:`var(--mantine-primary-color-filled-hover)`,light:`var(--mantine-primary-color-light)`,lightHover:`var(--mantine-primary-color-light-hover)`,lightColor:`var(--mantine-primary-color-light-color)`,outline:`var(--mantine-primary-color-outline)`,outlineHover:`var(--mantine-primary-color-outline-hover)`},white:`var(--mantine-color-white)`,black:`var(--mantine-color-black)`,text:`var(--mantine-color-text)`,body:`var(--mantine-color-body)`,error:`var(--mantine-color-error)`,placeholder:`var(--mantine-color-placeholder)`,anchor:`var(--mantine-color-anchor)`,default:`var(--mantine-color-default)`,defaultHover:`var(--mantine-color-default-hover)`,defaultColor:`var(--mantine-color-default-color)`,defaultBorder:`var(--mantine-color-default-border)`,dimmed:`var(--mantine-color-dimmed)`,disabledBody:`var(--mantine-color-disabled)`,disabledText:`var(--mantine-color-disabled-color)`,disabledBorder:`var(--mantine-color-disabled-border)`});return{scale:`var(--mantine-scale)`,cursorType:`var(--mantine-cursor-type)`,webkitFontSmoothing:`var(--mantine-webkit-font-smoothing)`,mozFontSmoothing:`var(--mantine-moz-font-smoothing)`,lineHeight:`var(--mantine-line-height)`,fontFamily:`var(--mantine-font-family)`,fontFamilyMonospace:`var(--mantine-font-family-monospace)`,fontFamilyHeadings:`var(--mantine-font-family-headings)`,headingFontWeight:`var(--mantine-heading-font-weight)`,radiusDefault:`var(--mantine-radius-default)`,breakpoints:t.breakpoints,fontSizes:n,lineHeights:r,shadows:i,radius:a,headings:s,spacing:o,colors:c,rtlSelector:`[dir="rtl"] &`,darkSelector:`[data-mantine-color-scheme="dark"] &`,lightSelector:`[data-mantine-color-scheme="light"] &`,smallerThan:e=>`(max-width: ${qg(e,t)})`,largerThan:e=>`(min-width: ${qg(e,t)})`}}var Yg=Nr({fontFamily:`Inter`,autoContrast:!0,components:{Checkbox:af.extend({defaultProps:{radius:`xs`}}),ColorInput:dp.extend({defaultProps:{radius:`xs`}}),Select:qh.extend({defaultProps:{radius:`sm`}}),Textarea:Hp.extend({defaultProps:{radius:`xs`}}),TextInput:_g.extend({defaultProps:{radius:`xs`}}),NumberInput:Dh.extend({defaultProps:{radius:`xs`}}),Paper:Xc.extend({defaultProps:{radius:`xs`,shadow:`0`}}),ActionIcon:ql.extend({defaultProps:{variant:`subtle`,color:`gray`,radius:`xs`}}),Button:xf.extend({defaultProps:{radius:`xs`,styles:{label:{fontWeight:450}}}})}});Jg(Yg);var Xg=(0,b.createContext)(void 0),Zg=()=>{let e=(0,b.useContext)(Xg);if(!e)throw Error(`useLoading must be used within a LoadingProvider`);return e},Qg=({children:e})=>{let[t,n]=(0,b.useState)(!1),[r,i]=(0,b.useState)(null),a=(0,b.useCallback)(e=>{e!==void 0&&i(e),n(!0)},[]),o=(0,b.useCallback)(e=>{i(e)},[]),s=(0,b.useCallback)(()=>{n(!1),i(null)},[]);return(0,G.jsx)(Xg.Provider,{value:{isLoading:t,loadingMessage:r,showLoading:a,setLoadingMessage:o,hideLoading:s},children:e})},$g=()=>{let{isLoading:e,loadingMessage:t}=Zg();return e?(0,G.jsx)(`div`,{className:`loader-overlay`,children:(0,G.jsxs)(`div`,{className:`loader-content`,children:[(0,G.jsx)(zl,{size:64,type:`bars`}),t&&(0,G.jsx)(`p`,{className:`loader-message`,children:t})]})}):null},e_=!1;function t_(){typeof window>`u`||(window.__mjswanReady=!0,e_||(e_=!0,window.dispatchEvent(new CustomEvent(`mjswan:ready`))))}function n_(){typeof window>`u`||(window.__mjswanError=!0)}var r_={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},i_={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},a_=`attached`,o_=`detached`,s_=1e3,c_=1001,l_=1002,u_=1003,d_=1004,f_=1004,p_=1005,m_=1005,h_=1006,g_=1007,__=1007,v_=1008,y_=1008,b_=1009,x_=1010,S_=1011,C_=1012,w_=1013,T_=1014,E_=1015,D_=1016,O_=1017,k_=1018,A_=1020,j_=35902,M_=35899,N_=1021,P_=1022,F_=1023,I_=1026,L_=1027,R_=1028,z_=1029,B_=1030,V_=1031,H_=1032,U_=1033,W_=33776,G_=33777,K_=33778,q_=33779,J_=35840,Y_=35841,X_=35842,Z_=35843,Q_=36196,$_=37492,ev=37496,tv=37808,nv=37809,rv=37810,iv=37811,av=37812,ov=37813,sv=37814,cv=37815,lv=37816,uv=37817,dv=37818,fv=37819,pv=37820,mv=37821,hv=36492,gv=36494,_v=36495,vv=36283,yv=36284,bv=36285,xv=36286,Sv=2200,Cv=2201,wv=2202,Tv=2300,Ev=2301,Dv=2302,Ov=2400,kv=2401,Av=2402,jv=2500,Mv=2501,Nv=3200,Pv=3201,Fv=3202,Iv=3203,Lv=`srgb`,Rv=`srgb-linear`,zv=`linear`,Bv=`srgb`,Vv=7680,Hv=7681,Uv=7682,Wv=7683,Gv=34055,Kv=34056,qv=5386,Jv=35044,Yv=35048,Xv=35040,Zv=35045,Qv=35049,$v=35041,ey=35046,ty=35050,ny=35042,ry=`300 es`,iy=2e3,ay=2001,oy={COMPUTE:`compute`,RENDER:`render`},sy={PERSPECTIVE:`perspective`,LINEAR:`linear`,FLAT:`flat`},cy={NORMAL:`normal`,CENTROID:`centroid`,SAMPLE:`sample`,FIRST:`first`,EITHER:`either`};function ly(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}var uy={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function dy(e,t){return new uy[e](t)}function fy(e){return document.createElementNS(`http://www.w3.org/1999/xhtml`,e)}function py(){let e=fy(`canvas`);return e.style.display=`block`,e}var my={},hy=null;function gy(e){hy=e}function _y(){return hy}function vy(...e){let t=`THREE.`+e.shift();hy?hy(`log`,t,...e):console.log(t,...e)}function yy(...e){let t=`THREE.`+e.shift();hy?hy(`warn`,t,...e):console.warn(t,...e)}function by(...e){let t=`THREE.`+e.shift();hy?hy(`error`,t,...e):console.error(t,...e)}function xy(...e){let t=e.join(` `);t in my||(my[t]=!0,yy(...e))}function Sy(e,t,n){return new Promise(function(r,i){function a(){switch(e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0)){case e.WAIT_FAILED:i();break;case e.TIMEOUT_EXPIRED:setTimeout(a,n);break;default:r()}}setTimeout(a,n)})}var Cy=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){let n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){let n=this._listeners;if(n===void 0)return;let r=n[e];if(r!==void 0){let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let n=t[e.type];if(n!==void 0){e.target=this;let t=n.slice(0);for(let n=0,r=t.length;n<r;n++)t[n].call(this,e);e.target=null}}},wy=`00.01.02.03.04.05.06.07.08.09.0a.0b.0c.0d.0e.0f.10.11.12.13.14.15.16.17.18.19.1a.1b.1c.1d.1e.1f.20.21.22.23.24.25.26.27.28.29.2a.2b.2c.2d.2e.2f.30.31.32.33.34.35.36.37.38.39.3a.3b.3c.3d.3e.3f.40.41.42.43.44.45.46.47.48.49.4a.4b.4c.4d.4e.4f.50.51.52.53.54.55.56.57.58.59.5a.5b.5c.5d.5e.5f.60.61.62.63.64.65.66.67.68.69.6a.6b.6c.6d.6e.6f.70.71.72.73.74.75.76.77.78.79.7a.7b.7c.7d.7e.7f.80.81.82.83.84.85.86.87.88.89.8a.8b.8c.8d.8e.8f.90.91.92.93.94.95.96.97.98.99.9a.9b.9c.9d.9e.9f.a0.a1.a2.a3.a4.a5.a6.a7.a8.a9.aa.ab.ac.ad.ae.af.b0.b1.b2.b3.b4.b5.b6.b7.b8.b9.ba.bb.bc.bd.be.bf.c0.c1.c2.c3.c4.c5.c6.c7.c8.c9.ca.cb.cc.cd.ce.cf.d0.d1.d2.d3.d4.d5.d6.d7.d8.d9.da.db.dc.dd.de.df.e0.e1.e2.e3.e4.e5.e6.e7.e8.e9.ea.eb.ec.ed.ee.ef.f0.f1.f2.f3.f4.f5.f6.f7.f8.f9.fa.fb.fc.fd.fe.ff`.split(`.`),Ty=1234567,Ey=Math.PI/180,Dy=180/Math.PI;function Oy(){let e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(wy[e&255]+wy[e>>8&255]+wy[e>>16&255]+wy[e>>24&255]+`-`+wy[t&255]+wy[t>>8&255]+`-`+wy[t>>16&15|64]+wy[t>>24&255]+`-`+wy[n&63|128]+wy[n>>8&255]+`-`+wy[n>>16&255]+wy[n>>24&255]+wy[r&255]+wy[r>>8&255]+wy[r>>16&255]+wy[r>>24&255]).toLowerCase()}function ky(e,t,n){return Math.max(t,Math.min(n,e))}function Ay(e,t){return(e%t+t)%t}function jy(e,t,n,r,i){return r+(e-t)*(i-r)/(n-t)}function My(e,t,n){return e===t?0:(n-e)/(t-e)}function Ny(e,t,n){return(1-n)*e+n*t}function Py(e,t,n,r){return Ny(e,t,1-Math.exp(-n*r))}function Fy(e,t=1){return t-Math.abs(Ay(e,t*2)-t)}function Iy(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*(3-2*e))}function Ly(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*e*(e*(e*6-15)+10))}function Ry(e,t){return e+Math.floor(Math.random()*(t-e+1))}function zy(e,t){return e+Math.random()*(t-e)}function By(e){return e*(.5-Math.random())}function Vy(e){e!==void 0&&(Ty=e);let t=Ty+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Hy(e){return e*Ey}function Uy(e){return e*Dy}function Wy(e){return(e&e-1)==0&&e!==0}function Gy(e){return 2**Math.ceil(Math.log(e)/Math.LN2)}function Ky(e){return 2**Math.floor(Math.log(e)/Math.LN2)}function qy(e,t,n,r,i){let a=Math.cos,o=Math.sin,s=a(n/2),c=o(n/2),l=a((t+r)/2),u=o((t+r)/2),d=a((t-r)/2),f=o((t-r)/2),p=a((r-t)/2),m=o((r-t)/2);switch(i){case`XYX`:e.set(s*u,c*d,c*f,s*l);break;case`YZY`:e.set(c*f,s*u,c*d,s*l);break;case`ZXZ`:e.set(c*d,c*f,s*u,s*l);break;case`XZX`:e.set(s*u,c*m,c*p,s*l);break;case`YXY`:e.set(c*p,s*u,c*m,s*l);break;case`ZYZ`:e.set(c*m,c*p,s*u,s*l);break;default:yy(`MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: `+i)}}function Jy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw Error(`Invalid component type.`)}}function Yy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw Error(`Invalid component type.`)}}var Xy={DEG2RAD:Ey,RAD2DEG:Dy,generateUUID:Oy,clamp:ky,euclideanModulo:Ay,mapLinear:jy,inverseLerp:My,lerp:Ny,damp:Py,pingpong:Fy,smoothstep:Iy,smootherstep:Ly,randInt:Ry,randFloat:zy,randFloatSpread:By,seededRandom:Vy,degToRad:Hy,radToDeg:Uy,isPowerOfTwo:Wy,ceilPowerOfTwo:Gy,floorPowerOfTwo:Ky,setQuaternionFromProperEuler:qy,normalize:Yy,denormalize:Jy},J=class e{constructor(t=0,n=0){e.prototype.isVector2=!0,this.x=t,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ky(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),r=Math.sin(t),i=this.x-e.x,a=this.y-e.y;return this.x=i*n-a*r+e.x,this.y=i*r+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Zy=class{constructor(e=0,t=0,n=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=r}static slerpFlat(e,t,n,r,i,a,o){let s=n[r+0],c=n[r+1],l=n[r+2],u=n[r+3],d=i[a+0],f=i[a+1],p=i[a+2],m=i[a+3];if(o<=0){e[t+0]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u;return}if(o>=1){e[t+0]=d,e[t+1]=f,e[t+2]=p,e[t+3]=m;return}if(u!==m||s!==d||c!==f||l!==p){let e=s*d+c*f+l*p+u*m;e<0&&(d=-d,f=-f,p=-p,m=-m,e=-e);let t=1-o;if(e<.9995){let n=Math.acos(e),r=Math.sin(n);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r,s=s*t+d*o,c=c*t+f*o,l=l*t+p*o,u=u*t+m*o}else{s=s*t+d*o,c=c*t+f*o,l=l*t+p*o,u=u*t+m*o;let e=1/Math.sqrt(s*s+c*c+l*l+u*u);s*=e,c*=e,l*=e,u*=e}}e[t]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,r,i,a){let o=n[r],s=n[r+1],c=n[r+2],l=n[r+3],u=i[a],d=i[a+1],f=i[a+2],p=i[a+3];return e[t]=o*p+l*u+s*f-c*d,e[t+1]=s*p+l*d+c*u-o*f,e[t+2]=c*p+l*f+o*d-s*u,e[t+3]=l*p-o*u-s*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,r){return this._x=e,this._y=t,this._z=n,this._w=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let n=e._x,r=e._y,i=e._z,a=e._order,o=Math.cos,s=Math.sin,c=o(n/2),l=o(r/2),u=o(i/2),d=s(n/2),f=s(r/2),p=s(i/2);switch(a){case`XYZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`YXZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`ZXY`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`ZYX`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`YZX`:this._x=d*l*u+c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u-d*f*p;break;case`XZY`:this._x=d*l*u-c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u+d*f*p;break;default:yy(`Quaternion: .setFromEuler() encountered an unknown order: `+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],r=t[4],i=t[8],a=t[1],o=t[5],s=t[9],c=t[2],l=t[6],u=t[10],d=n+o+u;if(d>0){let e=.5/Math.sqrt(d+1);this._w=.25/e,this._x=(l-s)*e,this._y=(i-c)*e,this._z=(a-r)*e}else if(n>o&&n>u){let e=2*Math.sqrt(1+n-o-u);this._w=(l-s)/e,this._x=.25*e,this._y=(r+a)/e,this._z=(i+c)/e}else if(o>u){let e=2*Math.sqrt(1+o-n-u);this._w=(i-c)/e,this._x=(r+a)/e,this._y=.25*e,this._z=(s+l)/e}else{let e=2*Math.sqrt(1+u-n-o);this._w=(a-r)/e,this._x=(i+c)/e,this._y=(s+l)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ky(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let r=Math.min(1,t/n);return this.slerp(e,r),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x*=e,this._y*=e,this._z*=e,this._w*=e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,r=e._y,i=e._z,a=e._w,o=t._x,s=t._y,c=t._z,l=t._w;return this._x=n*l+a*o+r*c-i*s,this._y=r*l+a*s+i*o-n*c,this._z=i*l+a*c+n*s-r*o,this._w=a*l-n*o-r*s-i*c,this._onChangeCallback(),this}slerp(e,t){if(t<=0)return this;if(t>=1)return this.copy(e);let n=e._x,r=e._y,i=e._z,a=e._w,o=this.dot(e);o<0&&(n=-n,r=-r,i=-i,a=-a,o=-o);let s=1-t;if(o<.9995){let e=Math.acos(o),c=Math.sin(e);s=Math.sin(s*e)/c,t=Math.sin(t*e)/c,this._x=this._x*s+n*t,this._y=this._y*s+r*t,this._z=this._z*s+i*t,this._w=this._w*s+a*t,this._onChangeCallback()}else this._x=this._x*s+n*t,this._y=this._y*s+r*t,this._z=this._z*s+i*t,this._w=this._w*s+a*t,this.normalize();return this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),r=Math.sqrt(1-n),i=Math.sqrt(n);return this.set(r*Math.sin(e),r*Math.cos(e),i*Math.sin(t),i*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},Y=class e{constructor(t=0,n=0,r=0){e.prototype.isVector3=!0,this.x=t,this.y=n,this.z=r}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion($y.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion($y.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6]*r,this.y=i[1]*t+i[4]*n+i[7]*r,this.z=i[2]*t+i[5]*n+i[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=e.elements,a=1/(i[3]*t+i[7]*n+i[11]*r+i[15]);return this.x=(i[0]*t+i[4]*n+i[8]*r+i[12])*a,this.y=(i[1]*t+i[5]*n+i[9]*r+i[13])*a,this.z=(i[2]*t+i[6]*n+i[10]*r+i[14])*a,this}applyQuaternion(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z,s=e.w,c=2*(a*r-o*n),l=2*(o*t-i*r),u=2*(i*n-a*t);return this.x=t+s*c+a*u-o*l,this.y=n+s*l+o*c-i*u,this.z=r+s*u+i*l-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[4]*n+i[8]*r,this.y=i[1]*t+i[5]*n+i[9]*r,this.z=i[2]*t+i[6]*n+i[10]*r,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this.z=ky(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this.z=ky(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,r=e.y,i=e.z,a=t.x,o=t.y,s=t.z;return this.x=r*s-i*o,this.y=i*a-n*s,this.z=n*o-r*a,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Qy.copy(this).projectOnVector(e),this.sub(Qy)}reflect(e){return this.sub(Qy.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ky(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Qy=new Y,$y=new Zy,eb=class e{constructor(t,n,r,i,a,o,s,c,l){e.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){let l=this.elements;return l[0]=e,l[1]=r,l[2]=o,l[3]=t,l[4]=i,l[5]=s,l[6]=n,l[7]=a,l[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],l=n[4],u=n[7],d=n[2],f=n[5],p=n[8],m=r[0],h=r[3],g=r[6],_=r[1],v=r[4],y=r[7],b=r[2],x=r[5],S=r[8];return i[0]=a*m+o*_+s*b,i[3]=a*h+o*v+s*x,i[6]=a*g+o*y+s*S,i[1]=c*m+l*_+u*b,i[4]=c*h+l*v+u*x,i[7]=c*g+l*y+u*S,i[2]=d*m+f*_+p*b,i[5]=d*h+f*v+p*x,i[8]=d*g+f*y+p*S,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8];return t*a*l-t*o*c-n*i*l+n*o*s+r*i*c-r*a*s}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=l*a-o*c,d=o*s-l*i,f=c*i-a*s,p=t*u+n*d+r*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/p;return e[0]=u*m,e[1]=(r*c-l*n)*m,e[2]=(o*n-r*a)*m,e[3]=d*m,e[4]=(l*t-r*s)*m,e[5]=(r*i-o*t)*m,e[6]=f*m,e[7]=(n*s-c*t)*m,e[8]=(a*t-n*i)*m,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,r,i,a,o){let s=Math.cos(i),c=Math.sin(i);return this.set(n*s,n*c,-n*(s*a+c*o)+a+e,-r*c,r*s,-r*(-c*a+s*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(tb.makeScale(e,t)),this}rotate(e){return this.premultiply(tb.makeRotation(-e)),this}translate(e,t){return this.premultiply(tb.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<9;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},tb=new eb,nb=new eb().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),rb=new eb().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function ib(){let e={enabled:!0,workingColorSpace:Rv,spaces:{},convert:function(e,t,n){return this.enabled===!1||t===n||!t||!n?e:(this.spaces[t].transfer===`srgb`&&(e.r=ob(e.r),e.g=ob(e.g),e.b=ob(e.b)),this.spaces[t].primaries!==this.spaces[n].primaries&&(e.applyMatrix3(this.spaces[t].toXYZ),e.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===`srgb`&&(e.r=sb(e.r),e.g=sb(e.g),e.b=sb(e.b)),e)},workingToColorSpace:function(e,t){return this.convert(e,this.workingColorSpace,t)},colorSpaceToWorking:function(e,t){return this.convert(e,t,this.workingColorSpace)},getPrimaries:function(e){return this.spaces[e].primaries},getTransfer:function(e){return e===``?zv:this.spaces[e].transfer},getToneMappingMode:function(e){return this.spaces[e].outputColorSpaceConfig.toneMappingMode||`standard`},getLuminanceCoefficients:function(e,t=this.workingColorSpace){return e.fromArray(this.spaces[t].luminanceCoefficients)},define:function(e){Object.assign(this.spaces,e)},_getMatrix:function(e,t,n){return e.copy(this.spaces[t].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(e){return this.spaces[e].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(e=this.workingColorSpace){return this.spaces[e].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(t,n){return xy(`ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace().`),e.workingToColorSpace(t,n)},toWorkingColorSpace:function(t,n){return xy(`ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking().`),e.colorSpaceToWorking(t,n)}},t=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],r=[.3127,.329];return e.define({[Rv]:{primaries:t,whitePoint:r,transfer:zv,toXYZ:nb,fromXYZ:rb,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:Lv},outputColorSpaceConfig:{drawingBufferColorSpace:Lv}},[Lv]:{primaries:t,whitePoint:r,transfer:Bv,toXYZ:nb,fromXYZ:rb,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:Lv}}}),e}var ab=ib();function ob(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}function sb(e){return e<.0031308?e*12.92:1.055*e**.41666-.055}var cb,lb=class{static getDataURL(e,t=`image/png`){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>`u`)return e.src;let n;if(e instanceof HTMLCanvasElement)n=e;else{cb===void 0&&(cb=fy(`canvas`)),cb.width=e.width,cb.height=e.height;let t=cb.getContext(`2d`);e instanceof ImageData?t.putImageData(e,0,0):t.drawImage(e,0,0,e.width,e.height),n=cb}return n.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let t=fy(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);n.drawImage(e,0,0,e.width,e.height);let r=n.getImageData(0,0,e.width,e.height),i=r.data;for(let e=0;e<i.length;e++)i[e]=ob(i[e]/255)*255;return n.putImageData(r,0,0),t}else if(e.data){let t=e.data.slice(0);for(let e=0;e<t.length;e++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[e]=Math.floor(ob(t[e]/255)*255):t[e]=ob(t[e]);return{data:t,width:e.width,height:e.height}}else return yy(`ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.`),e}},ub=0,db=class{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:ub++}),this.uuid=Oy(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<`u`&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):t instanceof VideoFrame?e.set(t.displayHeight,t.displayWidth,0):t===null?e.set(0,0,0):e.set(t.width,t.height,t.depth||0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let n={uuid:this.uuid,url:``},r=this.data;if(r!==null){let e;if(Array.isArray(r)){e=[];for(let t=0,n=r.length;t<n;t++)r[t].isDataTexture?e.push(fb(r[t].image)):e.push(fb(r[t]))}else e=fb(r);n.url=e}return t||(e.images[this.uuid]=n),n}};function fb(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap?lb.getDataURL(e):e.data?{data:Array.from(e.data),width:e.width,height:e.height,type:e.data.constructor.name}:(yy(`Texture: Unable to serialize Texture.`),{})}var pb=0,mb=new Y,hb=class e extends Cy{constructor(t=e.DEFAULT_IMAGE,n=e.DEFAULT_MAPPING,r=c_,i=c_,a=h_,o=v_,s=F_,c=b_,l=e.DEFAULT_ANISOTROPY,u=``){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:pb++}),this.uuid=Oy(),this.name=``,this.source=new db(t),this.mipmaps=[],this.mapping=n,this.channel=0,this.wrapS=r,this.wrapT=i,this.magFilter=a,this.minFilter=o,this.anisotropy=l,this.format=s,this.internalFormat=null,this.type=c,this.offset=new J(0,0),this.repeat=new J(1,1),this.center=new J(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new eb,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(mb).x}get height(){return this.source.getSize(mb).y}get depth(){return this.source.getSize(mb).z}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(let t in e){let n=e[t];if(n===void 0){yy(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){yy(`Texture.setValues(): property '${t}' does not exist.`);continue}r&&n&&r.isVector2&&n.isVector2||r&&n&&r.isVector3&&n.isVector3||r&&n&&r.isMatrix3&&n.isMatrix3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let n={metadata:{version:4.7,type:`Texture`,generator:`Texture.toJSON`},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:`dispose`})}transformUv(e){if(this.mapping!==300)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case s_:e.x-=Math.floor(e.x);break;case c_:e.x=e.x<0?0:1;break;case l_:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x-=Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case s_:e.y-=Math.floor(e.y);break;case c_:e.y=e.y<0?0:1;break;case l_:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y-=Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};hb.DEFAULT_IMAGE=null,hb.DEFAULT_MAPPING=300,hb.DEFAULT_ANISOTROPY=1;var gb=class e{constructor(t=0,n=0,r=0,i=1){e.prototype.isVector4=!0,this.x=t,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w===void 0?1:e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*r+a[12]*i,this.y=a[1]*t+a[5]*n+a[9]*r+a[13]*i,this.z=a[2]*t+a[6]*n+a[10]*r+a[14]*i,this.w=a[3]*t+a[7]*n+a[11]*r+a[15]*i,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,r,i,a=.01,o=.1,s=e.elements,c=s[0],l=s[4],u=s[8],d=s[1],f=s[5],p=s[9],m=s[2],h=s[6],g=s[10];if(Math.abs(l-d)<a&&Math.abs(u-m)<a&&Math.abs(p-h)<a){if(Math.abs(l+d)<o&&Math.abs(u+m)<o&&Math.abs(p+h)<o&&Math.abs(c+f+g-3)<o)return this.set(1,0,0,0),this;t=Math.PI;let e=(c+1)/2,s=(f+1)/2,_=(g+1)/2,v=(l+d)/4,y=(u+m)/4,b=(p+h)/4;return e>s&&e>_?e<a?(n=0,r=.707106781,i=.707106781):(n=Math.sqrt(e),r=v/n,i=y/n):s>_?s<a?(n=.707106781,r=0,i=.707106781):(r=Math.sqrt(s),n=v/r,i=b/r):_<a?(n=.707106781,r=.707106781,i=0):(i=Math.sqrt(_),n=y/i,r=b/i),this.set(n,r,i,t),this}let _=Math.sqrt((h-p)*(h-p)+(u-m)*(u-m)+(d-l)*(d-l));return Math.abs(_)<.001&&(_=1),this.x=(h-p)/_,this.y=(u-m)/_,this.z=(d-l)/_,this.w=Math.acos((c+f+g-1)/2),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this.z=ky(this.z,e.z,t.z),this.w=ky(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this.z=ky(this.z,e,t),this.w=ky(this.w,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},_b=class extends Cy{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:h_,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new gb(0,0,e,t),this.scissorTest=!1,this.viewport=new gb(0,0,e,t);let r=new hb({width:e,height:t,depth:n.depth});this.textures=[];let i=n.count;for(let e=0;e<i;e++)this.textures[e]=r.clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;this._setTextureOptions(n),this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=n.depthTexture,this.samples=n.samples,this.multiview=n.multiview}_setTextureOptions(e={}){let t={minFilter:h_,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let e=0;e<this.textures.length;e++)this.textures[e].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let r=0,i=this.textures.length;r<i;r++)this.textures[r].image.width=e,this.textures[r].image.height=t,this.textures[r].image.depth=n,this.textures[r].isData3DTexture!==!0&&(this.textures[r].isArrayTexture=this.textures[r].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;let n=Object.assign({},e.textures[t].image);this.textures[t].source=new db(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:`dispose`})}},vb=class extends _b{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}},yb=class extends hb{constructor(e=null,t=1,n=1,r=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=u_,this.minFilter=u_,this.wrapR=c_,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}},bb=class extends vb{constructor(e=1,t=1,n=1,r={}){super(e,t,r),this.isWebGLArrayRenderTarget=!0,this.depth=n,this.texture=new yb(null,e,t,n),this._setTextureOptions(r),this.texture.isRenderTargetTexture=!0}},xb=class extends hb{constructor(e=null,t=1,n=1,r=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=u_,this.minFilter=u_,this.wrapR=c_,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},Sb=class extends vb{constructor(e=1,t=1,n=1,r={}){super(e,t,r),this.isWebGL3DRenderTarget=!0,this.depth=n,this.texture=new xb(null,e,t,n),this._setTextureOptions(r),this.texture.isRenderTargetTexture=!0}},Cb=class{constructor(e=new Y(1/0,1/0,1/0),t=new Y(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(Tb.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(Tb.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let n=Tb.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let n=e.geometry;if(n!==void 0){let r=n.getAttribute(`position`);if(t===!0&&r!==void 0&&e.isInstancedMesh!==!0)for(let t=0,n=r.count;t<n;t++)e.isMesh===!0?e.getVertexPosition(t,Tb):Tb.fromBufferAttribute(r,t),Tb.applyMatrix4(e.matrixWorld),this.expandByPoint(Tb);else e.boundingBox===void 0?(n.boundingBox===null&&n.computeBoundingBox(),Eb.copy(n.boundingBox)):(e.boundingBox===null&&e.computeBoundingBox(),Eb.copy(e.boundingBox)),Eb.applyMatrix4(e.matrixWorld),this.union(Eb)}let r=e.children;for(let e=0,n=r.length;e<n;e++)this.expandByObject(r[e],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Tb),Tb.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Nb),Pb.subVectors(this.max,Nb),Db.subVectors(e.a,Nb),Ob.subVectors(e.b,Nb),kb.subVectors(e.c,Nb),Ab.subVectors(Ob,Db),jb.subVectors(kb,Ob),Mb.subVectors(Db,kb);let t=[0,-Ab.z,Ab.y,0,-jb.z,jb.y,0,-Mb.z,Mb.y,Ab.z,0,-Ab.x,jb.z,0,-jb.x,Mb.z,0,-Mb.x,-Ab.y,Ab.x,0,-jb.y,jb.x,0,-Mb.y,Mb.x,0];return!Lb(t,Db,Ob,kb,Pb)||(t=[1,0,0,0,1,0,0,0,1],!Lb(t,Db,Ob,kb,Pb))?!1:(Fb.crossVectors(Ab,jb),t=[Fb.x,Fb.y,Fb.z],Lb(t,Db,Ob,kb,Pb))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Tb).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Tb).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(wb[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),wb[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),wb[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),wb[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),wb[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),wb[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),wb[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),wb[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(wb),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},wb=[new Y,new Y,new Y,new Y,new Y,new Y,new Y,new Y],Tb=new Y,Eb=new Cb,Db=new Y,Ob=new Y,kb=new Y,Ab=new Y,jb=new Y,Mb=new Y,Nb=new Y,Pb=new Y,Fb=new Y,Ib=new Y;function Lb(e,t,n,r,i){for(let a=0,o=e.length-3;a<=o;a+=3){Ib.fromArray(e,a);let o=i.x*Math.abs(Ib.x)+i.y*Math.abs(Ib.y)+i.z*Math.abs(Ib.z),s=t.dot(Ib),c=n.dot(Ib),l=r.dot(Ib);if(Math.max(-Math.max(s,c,l),Math.min(s,c,l))>o)return!1}return!0}var Rb=new Cb,zb=new Y,Bb=new Y,Vb=class{constructor(e=new Y,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t===void 0?Rb.setFromPoints(e).getCenter(n):n.copy(t);let r=0;for(let t=0,i=e.length;t<i;t++)r=Math.max(r,n.distanceToSquared(e[t]));return this.radius=Math.sqrt(r),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius*=e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;zb.subVectors(e,this.center);let t=zb.lengthSq();if(t>this.radius*this.radius){let e=Math.sqrt(t),n=(e-this.radius)*.5;this.center.addScaledVector(zb,n/e),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Bb.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(zb.copy(e.center).add(Bb)),this.expandByPoint(zb.copy(e.center).sub(Bb))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}},Hb=new Y,Ub=new Y,Wb=new Y,Gb=new Y,Kb=new Y,qb=new Y,Jb=new Y,Yb=class{constructor(e=new Y,t=new Y(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Hb)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=Hb.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Hb.copy(this.origin).addScaledVector(this.direction,t),Hb.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){Ub.copy(e).add(t).multiplyScalar(.5),Wb.copy(t).sub(e).normalize(),Gb.copy(this.origin).sub(Ub);let i=e.distanceTo(t)*.5,a=-this.direction.dot(Wb),o=Gb.dot(this.direction),s=-Gb.dot(Wb),c=Gb.lengthSq(),l=Math.abs(1-a*a),u,d,f,p;if(l>0)if(u=a*s-o,d=a*o-s,p=i*l,u>=0)if(d>=-p)if(d<=p){let e=1/l;u*=e,d*=e,f=u*(u+a*d+2*o)+d*(a*u+d+2*s)+c}else d=i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d=-i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d<=-p?(u=Math.max(0,-(-a*i+o)),d=u>0?-i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c):d<=p?(u=0,d=Math.min(Math.max(-i,-s),i),f=d*(d+2*s)+c):(u=Math.max(0,-(a*i+o)),d=u>0?i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c);else d=a>0?-i:i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),r&&r.copy(Ub).addScaledVector(Wb,d),f}intersectSphere(e,t){Hb.subVectors(e.center,this.origin);let n=Hb.dot(this.direction),r=Hb.dot(Hb)-n*n,i=e.radius*e.radius;if(r>i)return null;let a=Math.sqrt(i-r),o=n-a,s=n+a;return s<0?null:o<0?this.at(s,t):this.at(o,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,r,i,a,o,s,c=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,r=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,r=(e.min.x-d.x)*c),l>=0?(i=(e.min.y-d.y)*l,a=(e.max.y-d.y)*l):(i=(e.max.y-d.y)*l,a=(e.min.y-d.y)*l),n>a||i>r||((i>n||isNaN(n))&&(n=i),(a<r||isNaN(r))&&(r=a),u>=0?(o=(e.min.z-d.z)*u,s=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,s=(e.min.z-d.z)*u),n>s||o>r)||((o>n||n!==n)&&(n=o),(s<r||r!==r)&&(r=s),r<0)?null:this.at(n>=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,Hb)!==null}intersectTriangle(e,t,n,r,i){Kb.subVectors(t,e),qb.subVectors(n,e),Jb.crossVectors(Kb,qb);let a=this.direction.dot(Jb),o;if(a>0){if(r)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Gb.subVectors(this.origin,e);let s=o*this.direction.dot(qb.crossVectors(Gb,qb));if(s<0)return null;let c=o*this.direction.dot(Kb.cross(Gb));if(c<0||s+c>a)return null;let l=-o*Gb.dot(Jb);return l<0?null:this.at(l/a,i)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},Xb=class e{constructor(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){e.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this.elements;return g[0]=e,g[4]=t,g[8]=n,g[12]=r,g[1]=i,g[5]=a,g[9]=o,g[13]=s,g[2]=c,g[6]=l,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=m,g[15]=h,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new e().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,r=1/Zb.setFromMatrixColumn(e,0).length(),i=1/Zb.setFromMatrixColumn(e,1).length(),a=1/Zb.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=0,t[4]=n[4]*i,t[5]=n[5]*i,t[6]=n[6]*i,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,r=e.y,i=e.z,a=Math.cos(n),o=Math.sin(n),s=Math.cos(r),c=Math.sin(r),l=Math.cos(i),u=Math.sin(i);if(e.order===`XYZ`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=-s*u,t[8]=c,t[1]=n+r*c,t[5]=e-i*c,t[9]=-o*s,t[2]=i-e*c,t[6]=r+n*c,t[10]=a*s}else if(e.order===`YXZ`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e+i*o,t[4]=r*o-n,t[8]=a*c,t[1]=a*u,t[5]=a*l,t[9]=-o,t[2]=n*o-r,t[6]=i+e*o,t[10]=a*s}else if(e.order===`ZXY`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e-i*o,t[4]=-a*u,t[8]=r+n*o,t[1]=n+r*o,t[5]=a*l,t[9]=i-e*o,t[2]=-a*c,t[6]=o,t[10]=a*s}else if(e.order===`ZYX`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=r*c-n,t[8]=e*c+i,t[1]=s*u,t[5]=i*c+e,t[9]=n*c-r,t[2]=-c,t[6]=o*s,t[10]=a*s}else if(e.order===`YZX`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=i-e*u,t[8]=r*u+n,t[1]=u,t[5]=a*l,t[9]=-o*l,t[2]=-c*l,t[6]=n*u+r,t[10]=e-i*u}else if(e.order===`XZY`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=-u,t[8]=c*l,t[1]=e*u+i,t[5]=a*l,t[9]=n*u-r,t[2]=r*u-n,t[6]=o*l,t[10]=i*u+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose($b,e,ex)}lookAt(e,t,n){let r=this.elements;return rx.subVectors(e,t),rx.lengthSq()===0&&(rx.z=1),rx.normalize(),tx.crossVectors(n,rx),tx.lengthSq()===0&&(Math.abs(n.z)===1?rx.x+=1e-4:rx.z+=1e-4,rx.normalize(),tx.crossVectors(n,rx)),tx.normalize(),nx.crossVectors(rx,tx),r[0]=tx.x,r[4]=nx.x,r[8]=rx.x,r[1]=tx.y,r[5]=nx.y,r[9]=rx.y,r[2]=tx.z,r[6]=nx.z,r[10]=rx.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[4],s=n[8],c=n[12],l=n[1],u=n[5],d=n[9],f=n[13],p=n[2],m=n[6],h=n[10],g=n[14],_=n[3],v=n[7],y=n[11],b=n[15],x=r[0],S=r[4],C=r[8],w=r[12],T=r[1],E=r[5],D=r[9],O=r[13],k=r[2],A=r[6],j=r[10],M=r[14],N=r[3],P=r[7],F=r[11],I=r[15];return i[0]=a*x+o*T+s*k+c*N,i[4]=a*S+o*E+s*A+c*P,i[8]=a*C+o*D+s*j+c*F,i[12]=a*w+o*O+s*M+c*I,i[1]=l*x+u*T+d*k+f*N,i[5]=l*S+u*E+d*A+f*P,i[9]=l*C+u*D+d*j+f*F,i[13]=l*w+u*O+d*M+f*I,i[2]=p*x+m*T+h*k+g*N,i[6]=p*S+m*E+h*A+g*P,i[10]=p*C+m*D+h*j+g*F,i[14]=p*w+m*O+h*M+g*I,i[3]=_*x+v*T+y*k+b*N,i[7]=_*S+v*E+y*A+b*P,i[11]=_*C+v*D+y*j+b*F,i[15]=_*w+v*O+y*M+b*I,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],r=e[8],i=e[12],a=e[1],o=e[5],s=e[9],c=e[13],l=e[2],u=e[6],d=e[10],f=e[14],p=e[3],m=e[7],h=e[11],g=e[15];return p*(+i*s*u-r*c*u-i*o*d+n*c*d+r*o*f-n*s*f)+m*(+t*s*f-t*c*d+i*a*d-r*a*f+r*c*l-i*s*l)+h*(+t*c*u-t*o*f-i*a*u+n*a*f+i*o*l-n*c*l)+g*(-r*o*l-t*s*u+t*o*d+r*a*u-n*a*d+n*s*l)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=u*h*c-m*d*c+m*s*f-o*h*f-u*s*g+o*d*g,v=p*d*c-l*h*c-p*s*f+a*h*f+l*s*g-a*d*g,y=l*m*c-p*u*c+p*o*f-a*m*f-l*o*g+a*u*g,b=p*u*s-l*m*s-p*o*d+a*m*d+l*o*h-a*u*h,x=t*_+n*v+r*y+i*b;if(x===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let S=1/x;return e[0]=_*S,e[1]=(m*d*i-u*h*i-m*r*f+n*h*f+u*r*g-n*d*g)*S,e[2]=(o*h*i-m*s*i+m*r*c-n*h*c-o*r*g+n*s*g)*S,e[3]=(u*s*i-o*d*i-u*r*c+n*d*c+o*r*f-n*s*f)*S,e[4]=v*S,e[5]=(l*h*i-p*d*i+p*r*f-t*h*f-l*r*g+t*d*g)*S,e[6]=(p*s*i-a*h*i-p*r*c+t*h*c+a*r*g-t*s*g)*S,e[7]=(a*d*i-l*s*i+l*r*c-t*d*c-a*r*f+t*s*f)*S,e[8]=y*S,e[9]=(p*u*i-l*m*i-p*n*f+t*m*f+l*n*g-t*u*g)*S,e[10]=(a*m*i-p*o*i+p*n*c-t*m*c-a*n*g+t*o*g)*S,e[11]=(l*o*i-a*u*i-l*n*c+t*u*c+a*n*f-t*o*f)*S,e[12]=b*S,e[13]=(l*m*r-p*u*r+p*n*d-t*m*d-l*n*h+t*u*h)*S,e[14]=(p*o*r-a*m*r-p*n*s+t*m*s+a*n*h-t*o*h)*S,e[15]=(a*u*r-l*o*r+l*n*s-t*u*s-a*n*d+t*o*d)*S,this}scale(e){let t=this.elements,n=e.x,r=e.y,i=e.z;return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),r=Math.sin(t),i=1-n,a=e.x,o=e.y,s=e.z,c=i*a,l=i*o;return this.set(c*a+n,c*o-r*s,c*s+r*o,0,c*o+r*s,l*o+n,l*s-r*a,0,c*s-r*o,l*s+r*a,i*s*s+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,r,i,a){return this.set(1,n,i,0,e,1,a,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){let r=this.elements,i=t._x,a=t._y,o=t._z,s=t._w,c=i+i,l=a+a,u=o+o,d=i*c,f=i*l,p=i*u,m=a*l,h=a*u,g=o*u,_=s*c,v=s*l,y=s*u,b=n.x,x=n.y,S=n.z;return r[0]=(1-(m+g))*b,r[1]=(f+y)*b,r[2]=(p-v)*b,r[3]=0,r[4]=(f-y)*x,r[5]=(1-(d+g))*x,r[6]=(h+_)*x,r[7]=0,r[8]=(p+v)*S,r[9]=(h-_)*S,r[10]=(1-(d+m))*S,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){let r=this.elements,i=Zb.set(r[0],r[1],r[2]).length(),a=Zb.set(r[4],r[5],r[6]).length(),o=Zb.set(r[8],r[9],r[10]).length();this.determinant()<0&&(i=-i),e.x=r[12],e.y=r[13],e.z=r[14],Qb.copy(this);let s=1/i,c=1/a,l=1/o;return Qb.elements[0]*=s,Qb.elements[1]*=s,Qb.elements[2]*=s,Qb.elements[4]*=c,Qb.elements[5]*=c,Qb.elements[6]*=c,Qb.elements[8]*=l,Qb.elements[9]*=l,Qb.elements[10]*=l,t.setFromRotationMatrix(Qb),n.x=i,n.y=a,n.z=o,this}makePerspective(e,t,n,r,i,a,o=iy,s=!1){let c=this.elements,l=2*i/(t-e),u=2*i/(n-r),d=(t+e)/(t-e),f=(n+r)/(n-r),p,m;if(s)p=i/(a-i),m=a*i/(a-i);else if(o===2e3)p=-(a+i)/(a-i),m=-2*a*i/(a-i);else if(o===2001)p=-a/(a-i),m=-a*i/(a-i);else throw Error(`THREE.Matrix4.makePerspective(): Invalid coordinate system: `+o);return c[0]=l,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=u,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,r,i,a,o=iy,s=!1){let c=this.elements,l=2/(t-e),u=2/(n-r),d=-(t+e)/(t-e),f=-(n+r)/(n-r),p,m;if(s)p=1/(a-i),m=a/(a-i);else if(o===2e3)p=-2/(a-i),m=-(a+i)/(a-i);else if(o===2001)p=-1/(a-i),m=-i/(a-i);else throw Error(`THREE.Matrix4.makeOrthographic(): Invalid coordinate system: `+o);return c[0]=l,c[4]=0,c[8]=0,c[12]=d,c[1]=0,c[5]=u,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<16;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Zb=new Y,Qb=new Xb,$b=new Y(0,0,0),ex=new Y(1,1,1),tx=new Y,nx=new Y,rx=new Y,ix=new Xb,ax=new Zy,ox=class e{constructor(t=0,n=0,r=0,i=e.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let r=e.elements,i=r[0],a=r[4],o=r[8],s=r[1],c=r[5],l=r[9],u=r[2],d=r[6],f=r[10];switch(t){case`XYZ`:this._y=Math.asin(ky(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,f),this._z=Math.atan2(-a,i)):(this._x=Math.atan2(d,c),this._z=0);break;case`YXZ`:this._x=Math.asin(-ky(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(s,c)):(this._y=Math.atan2(-u,i),this._z=0);break;case`ZXY`:this._x=Math.asin(ky(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(s,i));break;case`ZYX`:this._y=Math.asin(-ky(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(s,i)):(this._x=0,this._z=Math.atan2(-a,c));break;case`YZX`:this._z=Math.asin(ky(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-l,c),this._y=Math.atan2(-u,i)):(this._x=0,this._y=Math.atan2(o,f));break;case`XZY`:this._z=Math.asin(-ky(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,i)):(this._x=Math.atan2(-l,f),this._y=0);break;default:yy(`Euler: .setFromRotationMatrix() encountered an unknown order: `+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return ix.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ix,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ax.setFromEuler(this),this.setFromQuaternion(ax,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};ox.DEFAULT_ORDER=`XYZ`;var sx=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!=0}},cx=0,lx=new Y,ux=new Zy,dx=new Xb,fx=new Y,px=new Y,mx=new Y,hx=new Zy,gx=new Y(1,0,0),_x=new Y(0,1,0),vx=new Y(0,0,1),yx={type:`added`},bx={type:`removed`},xx={type:`childadded`,child:null},Sx={type:`childremoved`,child:null},Cx=class e extends Cy{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cx++}),this.uuid=Oy(),this.name=``,this.type=`Object3D`,this.parent=null,this.children=[],this.up=e.DEFAULT_UP.clone();let t=new Y,n=new ox,r=new Zy,i=new Y(1,1,1);function a(){r.setFromEuler(n,!1)}function o(){n.setFromQuaternion(r,void 0,!1)}n._onChange(a),r._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:n},quaternion:{configurable:!0,enumerable:!0,value:r},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new Xb},normalMatrix:{value:new eb}}),this.matrix=new Xb,this.matrixWorld=new Xb,this.matrixAutoUpdate=e.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=e.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new sx,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return ux.setFromAxisAngle(e,t),this.quaternion.multiply(ux),this}rotateOnWorldAxis(e,t){return ux.setFromAxisAngle(e,t),this.quaternion.premultiply(ux),this}rotateX(e){return this.rotateOnAxis(gx,e)}rotateY(e){return this.rotateOnAxis(_x,e)}rotateZ(e){return this.rotateOnAxis(vx,e)}translateOnAxis(e,t){return lx.copy(e).applyQuaternion(this.quaternion),this.position.add(lx.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(gx,e)}translateY(e){return this.translateOnAxis(_x,e)}translateZ(e){return this.translateOnAxis(vx,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(dx.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?fx.copy(e):fx.set(e,t,n);let r=this.parent;this.updateWorldMatrix(!0,!1),px.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?dx.lookAt(px,fx,this.up):dx.lookAt(fx,px,this.up),this.quaternion.setFromRotationMatrix(dx),r&&(dx.extractRotation(r.matrixWorld),ux.setFromRotationMatrix(dx),this.quaternion.premultiply(ux.invert()))}add(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return e===this?(by(`Object3D.add: object can't be added as a child of itself.`,e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(yx),xx.child=e,this.dispatchEvent(xx),xx.child=null):by(`Object3D.add: object not an instance of THREE.Object3D.`,e),this)}remove(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.remove(arguments[e]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(bx),Sx.child=e,this.dispatchEvent(Sx),Sx.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),dx.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),dx.multiply(e.parent.matrixWorld)),e.applyMatrix4(dx),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(yx),xx.child=e,this.dispatchEvent(xx),xx.child=null,this}getObjectById(e){return this.getObjectByProperty(`id`,e)}getObjectByName(e){return this.getObjectByProperty(`name`,e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,r=this.children.length;n<r;n++){let r=this.children[n].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);let r=this.children;for(let i=0,a=r.length;i<a;i++)r[i].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(px,e,mx),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(px,hx,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t){let n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),t===!0){let e=this.children;for(let t=0,n=e.length;t<n;t++)e[t].updateWorldMatrix(!1,!0)}}toJSON(e){let t=e===void 0||typeof e==`string`,n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:`Object`,generator:`Object3D.toJSON`});let r={};r.uuid=this.uuid,r.type=this.type,this.name!==``&&(r.name=this.name),this.castShadow===!0&&(r.castShadow=!0),this.receiveShadow===!0&&(r.receiveShadow=!0),this.visible===!1&&(r.visible=!1),this.frustumCulled===!1&&(r.frustumCulled=!1),this.renderOrder!==0&&(r.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.isInstancedMesh&&(r.type=`InstancedMesh`,r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type=`BatchedMesh`,r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.geometryInfo=this._geometryInfo.map(e=>({...e,boundingBox:e.boundingBox?e.boundingBox.toJSON():void 0,boundingSphere:e.boundingSphere?e.boundingSphere.toJSON():void 0})),r.instanceInfo=this._instanceInfo.map(e=>({...e})),r.availableInstanceIds=this._availableInstanceIds.slice(),r.availableGeometryIds=this._availableGeometryIds.slice(),r.nextIndexStart=this._nextIndexStart,r.nextVertexStart=this._nextVertexStart,r.geometryCount=this._geometryCount,r.maxInstanceCount=this._maxInstanceCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.matricesTexture=this._matricesTexture.toJSON(e),r.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(r.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(r.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(r.boundingBox=this.boundingBox.toJSON()));function i(t,n){return t[n.uuid]===void 0&&(t[n.uuid]=n.toJSON(e)),n.uuid}if(this.isScene)this.background&&(this.background.isColor?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.geometry=i(e.geometries,this.geometry);let t=this.geometry.parameters;if(t!==void 0&&t.shapes!==void 0){let n=t.shapes;if(Array.isArray(n))for(let t=0,r=n.length;t<r;t++){let r=n[t];i(e.shapes,r)}else i(e.shapes,n)}}if(this.isSkinnedMesh&&(r.bindMode=this.bindMode,r.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(i(e.skeletons,this.skeleton),r.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let t=[];for(let n=0,r=this.material.length;n<r;n++)t.push(i(e.materials,this.material[n]));r.material=t}else r.material=i(e.materials,this.material);if(this.children.length>0){r.children=[];for(let t=0;t<this.children.length;t++)r.children.push(this.children[t].toJSON(e).object)}if(this.animations.length>0){r.animations=[];for(let t=0;t<this.animations.length;t++){let n=this.animations[t];r.animations.push(i(e.animations,n))}}if(t){let t=a(e.geometries),r=a(e.materials),i=a(e.textures),o=a(e.images),s=a(e.shapes),c=a(e.skeletons),l=a(e.animations),u=a(e.nodes);t.length>0&&(n.geometries=t),r.length>0&&(n.materials=r),i.length>0&&(n.textures=i),o.length>0&&(n.images=o),s.length>0&&(n.shapes=s),c.length>0&&(n.skeletons=c),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=r,n;function a(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let t=0;t<e.children.length;t++){let n=e.children[t];this.add(n.clone())}return this}};Cx.DEFAULT_UP=new Y(0,1,0),Cx.DEFAULT_MATRIX_AUTO_UPDATE=!0,Cx.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var wx=new Y,Tx=new Y,Ex=new Y,Dx=new Y,Ox=new Y,kx=new Y,Ax=new Y,jx=new Y,Mx=new Y,Nx=new Y,Px=new gb,Fx=new gb,Ix=new gb,Lx=class e{constructor(e=new Y,t=new Y,n=new Y){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,r){r.subVectors(n,t),wx.subVectors(e,t),r.cross(wx);let i=r.lengthSq();return i>0?r.multiplyScalar(1/Math.sqrt(i)):r.set(0,0,0)}static getBarycoord(e,t,n,r,i){wx.subVectors(r,t),Tx.subVectors(n,t),Ex.subVectors(e,t);let a=wx.dot(wx),o=wx.dot(Tx),s=wx.dot(Ex),c=Tx.dot(Tx),l=Tx.dot(Ex),u=a*c-o*o;if(u===0)return i.set(0,0,0),null;let d=1/u,f=(c*s-o*l)*d,p=(a*l-o*s)*d;return i.set(1-f-p,p,f)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,Dx)===null?!1:Dx.x>=0&&Dx.y>=0&&Dx.x+Dx.y<=1}static getInterpolation(e,t,n,r,i,a,o,s){return this.getBarycoord(e,t,n,r,Dx)===null?(s.x=0,s.y=0,`z`in s&&(s.z=0),`w`in s&&(s.w=0),null):(s.setScalar(0),s.addScaledVector(i,Dx.x),s.addScaledVector(a,Dx.y),s.addScaledVector(o,Dx.z),s)}static getInterpolatedAttribute(e,t,n,r,i,a){return Px.setScalar(0),Fx.setScalar(0),Ix.setScalar(0),Px.fromBufferAttribute(e,t),Fx.fromBufferAttribute(e,n),Ix.fromBufferAttribute(e,r),a.setScalar(0),a.addScaledVector(Px,i.x),a.addScaledVector(Fx,i.y),a.addScaledVector(Ix,i.z),a}static isFrontFacing(e,t,n,r){return wx.subVectors(n,t),Tx.subVectors(e,t),wx.cross(Tx).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return wx.subVectors(this.c,this.b),Tx.subVectors(this.a,this.b),wx.cross(Tx).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return e.getNormal(this.a,this.b,this.c,t)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,n){return e.getBarycoord(t,this.a,this.b,this.c,n)}getInterpolation(t,n,r,i,a){return e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}containsPoint(t){return e.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return e.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,r=this.b,i=this.c,a,o;Ox.subVectors(r,n),kx.subVectors(i,n),jx.subVectors(e,n);let s=Ox.dot(jx),c=kx.dot(jx);if(s<=0&&c<=0)return t.copy(n);Mx.subVectors(e,r);let l=Ox.dot(Mx),u=kx.dot(Mx);if(l>=0&&u<=l)return t.copy(r);let d=s*u-l*c;if(d<=0&&s>=0&&l<=0)return a=s/(s-l),t.copy(n).addScaledVector(Ox,a);Nx.subVectors(e,i);let f=Ox.dot(Nx),p=kx.dot(Nx);if(p>=0&&f<=p)return t.copy(i);let m=f*c-s*p;if(m<=0&&c>=0&&p<=0)return o=c/(c-p),t.copy(n).addScaledVector(kx,o);let h=l*p-f*u;if(h<=0&&u-l>=0&&f-p>=0)return Ax.subVectors(i,r),o=(u-l)/(u-l+(f-p)),t.copy(r).addScaledVector(Ax,o);let g=1/(h+m+d);return a=m*g,o=d*g,t.copy(n).addScaledVector(Ox,a).addScaledVector(kx,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},Rx={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},zx={h:0,s:0,l:0},Bx={h:0,s:0,l:0};function Vx(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*6*(2/3-n):e}var X=class{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let t=e;t&&t.isColor?this.copy(t):typeof t==`number`?this.setHex(t):typeof t==`string`&&this.setStyle(t)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Lv){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,ab.colorSpaceToWorking(this,t),this}setRGB(e,t,n,r=ab.workingColorSpace){return this.r=e,this.g=t,this.b=n,ab.colorSpaceToWorking(this,r),this}setHSL(e,t,n,r=ab.workingColorSpace){if(e=Ay(e,1),t=ky(t,0,1),n=ky(n,0,1),t===0)this.r=this.g=this.b=n;else{let r=n<=.5?n*(1+t):n+t-n*t,i=2*n-r;this.r=Vx(i,r,e+1/3),this.g=Vx(i,r,e),this.b=Vx(i,r,e-1/3)}return ab.colorSpaceToWorking(this,r),this}setStyle(e,t=Lv){function n(t){t!==void 0&&parseFloat(t)<1&&yy(`Color: Alpha component of `+e+` will be ignored.`)}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let i,a=r[1],o=r[2];switch(a){case`rgb`:case`rgba`:if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,t);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,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(o))return n(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,t);break;default:yy(`Color: Unknown color model `+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){let n=r[1],i=n.length;if(i===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(i===6)return this.setHex(parseInt(n,16),t);yy(`Color: Invalid hex color `+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Lv){let n=Rx[e.toLowerCase()];return n===void 0?yy(`Color: Unknown color `+e):this.setHex(n,t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=ob(e.r),this.g=ob(e.g),this.b=ob(e.b),this}copyLinearToSRGB(e){return this.r=sb(e.r),this.g=sb(e.g),this.b=sb(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Lv){return ab.workingToColorSpace(Hx.copy(this),e),Math.round(ky(Hx.r*255,0,255))*65536+Math.round(ky(Hx.g*255,0,255))*256+Math.round(ky(Hx.b*255,0,255))}getHexString(e=Lv){return(`000000`+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=ab.workingColorSpace){ab.workingToColorSpace(Hx.copy(this),t);let n=Hx.r,r=Hx.g,i=Hx.b,a=Math.max(n,r,i),o=Math.min(n,r,i),s,c,l=(o+a)/2;if(o===a)s=0,c=0;else{let e=a-o;switch(c=l<=.5?e/(a+o):e/(2-a-o),a){case n:s=(r-i)/e+(r<i?6:0);break;case r:s=(i-n)/e+2;break;case i:s=(n-r)/e+4;break}s/=6}return e.h=s,e.s=c,e.l=l,e}getRGB(e,t=ab.workingColorSpace){return ab.workingToColorSpace(Hx.copy(this),t),e.r=Hx.r,e.g=Hx.g,e.b=Hx.b,e}getStyle(e=Lv){ab.workingToColorSpace(Hx.copy(this),e);let t=Hx.r,n=Hx.g,r=Hx.b;return e===`srgb`?`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(r*255)})`:`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${r.toFixed(3)})`}offsetHSL(e,t,n){return this.getHSL(zx),this.setHSL(zx.h+e,zx.s+t,zx.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(zx),e.getHSL(Bx);let n=Ny(zx.h,Bx.h,t),r=Ny(zx.s,Bx.s,t),i=Ny(zx.l,Bx.l,t);return this.setHSL(n,r,i),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,n=this.g,r=this.b,i=e.elements;return this.r=i[0]*t+i[3]*n+i[6]*r,this.g=i[1]*t+i[4]*n+i[7]*r,this.b=i[2]*t+i[5]*n+i[8]*r,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},Hx=new X;X.NAMES=Rx;var Ux=0,Wx=class extends Cy{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Ux++}),this.uuid=Oy(),this.name=``,this.type=`Material`,this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=204,this.blendDst=205,this.blendEquation=100,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new X(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Vv,this.stencilZFail=Vv,this.stencilZPass=Vv,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let n=e[t];if(n===void 0){yy(`Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){yy(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector3&&n&&n.isVector3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;t&&(e={textures:{},images:{}});let n={metadata:{version:4.7,type:`Material`,generator:`Material.toJSON`}};n.uuid=this.uuid,n.type=this.type,this.name!==``&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==1&&(n.blending=this.blending),this.side!==0&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==204&&(n.blendSrc=this.blendSrc),this.blendDst!==205&&(n.blendDst=this.blendDst),this.blendEquation!==100&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==3&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==519&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==7680&&(n.stencilFail=this.stencilFail),this.stencilZFail!==7680&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==7680&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!==`round`&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!==`round`&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}if(t){let t=r(e.textures),i=r(e.images);t.length>0&&(n.textures=t),i.length>0&&(n.images=i)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let e=t.length;n=Array(e);for(let r=0;r!==e;++r)n[r]=t[r].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:`dispose`})}set needsUpdate(e){e===!0&&this.version++}},Gx=class extends Wx{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type=`MeshBasicMaterial`,this.color=new X(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ox,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Kx=qx();function qx(){let e=new ArrayBuffer(4),t=new Float32Array(e),n=new Uint32Array(e),r=new Uint32Array(512),i=new Uint32Array(512);for(let e=0;e<256;++e){let t=e-127;t<-27?(r[e]=0,r[e|256]=32768,i[e]=24,i[e|256]=24):t<-14?(r[e]=1024>>-t-14,r[e|256]=1024>>-t-14|32768,i[e]=-t-1,i[e|256]=-t-1):t<=15?(r[e]=t+15<<10,r[e|256]=t+15<<10|32768,i[e]=13,i[e|256]=13):t<128?(r[e]=31744,r[e|256]=64512,i[e]=24,i[e|256]=24):(r[e]=31744,r[e|256]=64512,i[e]=13,i[e|256]=13)}let a=new Uint32Array(2048),o=new Uint32Array(64),s=new Uint32Array(64);for(let e=1;e<1024;++e){let t=e<<13,n=0;for(;!(t&8388608);)t<<=1,n-=8388608;t&=-8388609,n+=947912704,a[e]=t|n}for(let e=1024;e<2048;++e)a[e]=939524096+(e-1024<<13);for(let e=1;e<31;++e)o[e]=e<<23;o[31]=1199570944,o[32]=2147483648;for(let e=33;e<63;++e)o[e]=2147483648+(e-32<<23);o[63]=3347054592;for(let e=1;e<64;++e)e!==32&&(s[e]=1024);return{floatView:t,uint32View:n,baseTable:r,shiftTable:i,mantissaTable:a,exponentTable:o,offsetTable:s}}function Jx(e){Math.abs(e)>65504&&yy(`DataUtils.toHalfFloat(): Value out of range.`),e=ky(e,-65504,65504),Kx.floatView[0]=e;let t=Kx.uint32View[0],n=t>>23&511;return Kx.baseTable[n]+((t&8388607)>>Kx.shiftTable[n])}function Yx(e){let t=e>>10;return Kx.uint32View[0]=Kx.mantissaTable[Kx.offsetTable[t]+(e&1023)]+Kx.exponentTable[t],Kx.floatView[0]}var Xx=class{static toHalfFloat(e){return Jx(e)}static fromHalfFloat(e){return Yx(e)}},Zx=new Y,Qx=new J,$x=0,eS=class{constructor(e,t,n=!1){if(Array.isArray(e))throw TypeError(`THREE.BufferAttribute: array should be a Typed Array.`);this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:$x++}),this.name=``,this.array=e,this.itemSize=t,this.count=e===void 0?0:e.length/t,this.normalized=n,this.usage=Jv,this.updateRanges=[],this.gpuType=E_,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,i=this.itemSize;r<i;r++)this.array[e+r]=t.array[n+r];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)Qx.fromBufferAttribute(this,t),Qx.applyMatrix3(e),this.setXY(t,Qx.x,Qx.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyMatrix3(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyMatrix4(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyNormalMatrix(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.transformDirection(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=Jy(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=Yy(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=Jy(t,this.array)),t}setX(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=Jy(t,this.array)),t}setY(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=Jy(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=Jy(t,this.array)),t}setW(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this}setXYZW(e,t,n,r,i){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array),i=Yy(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this.array[e+3]=i,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==``&&(e.name=this.name),this.usage!==35044&&(e.usage=this.usage),e}},tS=class extends eS{constructor(e,t,n){super(new Int8Array(e),t,n)}},nS=class extends eS{constructor(e,t,n){super(new Uint8Array(e),t,n)}},rS=class extends eS{constructor(e,t,n){super(new Uint8ClampedArray(e),t,n)}},iS=class extends eS{constructor(e,t,n){super(new Int16Array(e),t,n)}},aS=class extends eS{constructor(e,t,n){super(new Uint16Array(e),t,n)}},oS=class extends eS{constructor(e,t,n){super(new Int32Array(e),t,n)}},sS=class extends eS{constructor(e,t,n){super(new Uint32Array(e),t,n)}},cS=class extends eS{constructor(e,t,n){super(new Uint16Array(e),t,n),this.isFloat16BufferAttribute=!0}getX(e){let t=Yx(this.array[e*this.itemSize]);return this.normalized&&(t=Jy(t,this.array)),t}setX(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize]=Jx(t),this}getY(e){let t=Yx(this.array[e*this.itemSize+1]);return this.normalized&&(t=Jy(t,this.array)),t}setY(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+1]=Jx(t),this}getZ(e){let t=Yx(this.array[e*this.itemSize+2]);return this.normalized&&(t=Jy(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+2]=Jx(t),this}getW(e){let t=Yx(this.array[e*this.itemSize+3]);return this.normalized&&(t=Jy(t,this.array)),t}setW(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+3]=Jx(t),this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this.array[e+2]=Jx(r),this}setXYZW(e,t,n,r,i){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array),i=Yy(i,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this.array[e+2]=Jx(r),this.array[e+3]=Jx(i),this}},lS=class extends eS{constructor(e,t,n){super(new Float32Array(e),t,n)}},uS=0,dS=new Xb,fS=new Cx,pS=new Y,mS=new Cb,hS=new Cb,gS=new Y,_S=class e extends Cy{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:uS++}),this.uuid=Oy(),this.name=``,this.type=`BufferGeometry`,this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(ly(e)?sS:aS)(e,1):this.index=e,this}setIndirect(e){return this.indirect=e,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let t=new eb().getNormalMatrix(e);n.applyNormalMatrix(t),n.needsUpdate=!0}let r=this.attributes.tangent;return r!==void 0&&(r.transformDirection(e),r.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return dS.makeRotationFromQuaternion(e),this.applyMatrix4(dS),this}rotateX(e){return dS.makeRotationX(e),this.applyMatrix4(dS),this}rotateY(e){return dS.makeRotationY(e),this.applyMatrix4(dS),this}rotateZ(e){return dS.makeRotationZ(e),this.applyMatrix4(dS),this}translate(e,t,n){return dS.makeTranslation(e,t,n),this.applyMatrix4(dS),this}scale(e,t,n){return dS.makeScale(e,t,n),this.applyMatrix4(dS),this}lookAt(e){return fS.lookAt(e),fS.updateMatrix(),this.applyMatrix4(fS.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(pS).negate(),this.translate(pS.x,pS.y,pS.z),this}setFromPoints(e){let t=this.getAttribute(`position`);if(t===void 0){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];t.push(r.x,r.y,r.z||0)}this.setAttribute(`position`,new lS(t,3))}else{let n=Math.min(e.length,t.count);for(let r=0;r<n;r++){let n=e[r];t.setXYZ(r,n.x,n.y,n.z||0)}e.length>t.count&&yy(`BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.`),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Cb);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){by(`BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.`,this),this.boundingBox.set(new Y(-1/0,-1/0,-1/0),new Y(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];mS.setFromBufferAttribute(n),this.morphTargetsRelative?(gS.addVectors(this.boundingBox.min,mS.min),this.boundingBox.expandByPoint(gS),gS.addVectors(this.boundingBox.max,mS.max),this.boundingBox.expandByPoint(gS)):(this.boundingBox.expandByPoint(mS.min),this.boundingBox.expandByPoint(mS.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&by(`BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.`,this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Vb);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){by(`BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.`,this),this.boundingSphere.set(new Y,1/0);return}if(e){let n=this.boundingSphere.center;if(mS.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];hS.setFromBufferAttribute(n),this.morphTargetsRelative?(gS.addVectors(mS.min,hS.min),mS.expandByPoint(gS),gS.addVectors(mS.max,hS.max),mS.expandByPoint(gS)):(mS.expandByPoint(hS.min),mS.expandByPoint(hS.max))}mS.getCenter(n);let r=0;for(let t=0,i=e.count;t<i;t++)gS.fromBufferAttribute(e,t),r=Math.max(r,n.distanceToSquared(gS));if(t)for(let i=0,a=t.length;i<a;i++){let a=t[i],o=this.morphTargetsRelative;for(let t=0,i=a.count;t<i;t++)gS.fromBufferAttribute(a,t),o&&(pS.fromBufferAttribute(e,t),gS.add(pS)),r=Math.max(r,n.distanceToSquared(gS))}this.boundingSphere.radius=Math.sqrt(r),isNaN(this.boundingSphere.radius)&&by(`BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.`,this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){by(`BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)`);return}let n=t.position,r=t.normal,i=t.uv;this.hasAttribute(`tangent`)===!1&&this.setAttribute(`tangent`,new eS(new Float32Array(4*n.count),4));let a=this.getAttribute(`tangent`),o=[],s=[];for(let e=0;e<n.count;e++)o[e]=new Y,s[e]=new Y;let c=new Y,l=new Y,u=new Y,d=new J,f=new J,p=new J,m=new Y,h=new Y;function g(e,t,r){c.fromBufferAttribute(n,e),l.fromBufferAttribute(n,t),u.fromBufferAttribute(n,r),d.fromBufferAttribute(i,e),f.fromBufferAttribute(i,t),p.fromBufferAttribute(i,r),l.sub(c),u.sub(c),f.sub(d),p.sub(d);let a=1/(f.x*p.y-p.x*f.y);isFinite(a)&&(m.copy(l).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(a),h.copy(u).multiplyScalar(f.x).addScaledVector(l,-p.x).multiplyScalar(a),o[e].add(m),o[t].add(m),o[r].add(m),s[e].add(h),s[t].add(h),s[r].add(h))}let _=this.groups;_.length===0&&(_=[{start:0,count:e.count}]);for(let t=0,n=_.length;t<n;++t){let n=_[t],r=n.start,i=n.count;for(let t=r,n=r+i;t<n;t+=3)g(e.getX(t+0),e.getX(t+1),e.getX(t+2))}let v=new Y,y=new Y,b=new Y,x=new Y;function S(e){b.fromBufferAttribute(r,e),x.copy(b);let t=o[e];v.copy(t),v.sub(b.multiplyScalar(b.dot(t))).normalize(),y.crossVectors(x,t);let n=y.dot(s[e])<0?-1:1;a.setXYZW(e,v.x,v.y,v.z,n)}for(let t=0,n=_.length;t<n;++t){let n=_[t],r=n.start,i=n.count;for(let t=r,n=r+i;t<n;t+=3)S(e.getX(t+0)),S(e.getX(t+1)),S(e.getX(t+2))}}computeVertexNormals(){let e=this.index,t=this.getAttribute(`position`);if(t!==void 0){let n=this.getAttribute(`normal`);if(n===void 0)n=new eS(new Float32Array(t.count*3),3),this.setAttribute(`normal`,n);else for(let e=0,t=n.count;e<t;e++)n.setXYZ(e,0,0,0);let r=new Y,i=new Y,a=new Y,o=new Y,s=new Y,c=new Y,l=new Y,u=new Y;if(e)for(let d=0,f=e.count;d<f;d+=3){let f=e.getX(d+0),p=e.getX(d+1),m=e.getX(d+2);r.fromBufferAttribute(t,f),i.fromBufferAttribute(t,p),a.fromBufferAttribute(t,m),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),o.fromBufferAttribute(n,f),s.fromBufferAttribute(n,p),c.fromBufferAttribute(n,m),o.add(l),s.add(l),c.add(l),n.setXYZ(f,o.x,o.y,o.z),n.setXYZ(p,s.x,s.y,s.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let e=0,o=t.count;e<o;e+=3)r.fromBufferAttribute(t,e+0),i.fromBufferAttribute(t,e+1),a.fromBufferAttribute(t,e+2),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),n.setXYZ(e+0,l.x,l.y,l.z),n.setXYZ(e+1,l.x,l.y,l.z),n.setXYZ(e+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)gS.fromBufferAttribute(e,t),gS.normalize(),e.setXYZ(t,gS.x,gS.y,gS.z)}toNonIndexed(){function t(e,t){let n=e.array,r=e.itemSize,i=e.normalized,a=new n.constructor(t.length*r),o=0,s=0;for(let i=0,c=t.length;i<c;i++){o=e.isInterleavedBufferAttribute?t[i]*e.data.stride+e.offset:t[i]*r;for(let e=0;e<r;e++)a[s++]=n[o++]}return new eS(a,r,i)}if(this.index===null)return yy(`BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.`),this;let n=new e,r=this.index.array,i=this.attributes;for(let e in i){let a=i[e],o=t(a,r);n.setAttribute(e,o)}let a=this.morphAttributes;for(let e in a){let i=[],o=a[e];for(let e=0,n=o.length;e<n;e++){let n=o[e],a=t(n,r);i.push(a)}n.morphAttributes[e]=i}n.morphTargetsRelative=this.morphTargetsRelative;let o=this.groups;for(let e=0,t=o.length;e<t;e++){let t=o[e];n.addGroup(t.start,t.count,t.materialIndex)}return n}toJSON(){let e={metadata:{version:4.7,type:`BufferGeometry`,generator:`BufferGeometry.toJSON`}};if(e.uuid=this.uuid,e.type=this.type,this.name!==``&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){let t=this.parameters;for(let n in t)t[n]!==void 0&&(e[n]=t[n]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let n=this.attributes;for(let t in n){let r=n[t];e.data.attributes[t]=r.toJSON(e.data)}let r={},i=!1;for(let t in this.morphAttributes){let n=this.morphAttributes[t],a=[];for(let t=0,r=n.length;t<r;t++){let r=n[t];a.push(r.toJSON(e.data))}a.length>0&&(r[t]=a,i=!0)}i&&(e.data.morphAttributes=r,e.data.morphTargetsRelative=this.morphTargetsRelative);let a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));let o=this.boundingSphere;return o!==null&&(e.data.boundingSphere=o.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let n=e.index;n!==null&&this.setIndex(n.clone());let r=e.attributes;for(let e in r){let n=r[e];this.setAttribute(e,n.clone(t))}let i=e.morphAttributes;for(let e in i){let n=[],r=i[e];for(let e=0,i=r.length;e<i;e++)n.push(r[e].clone(t));this.morphAttributes[e]=n}this.morphTargetsRelative=e.morphTargetsRelative;let a=e.groups;for(let e=0,t=a.length;e<t;e++){let t=a[e];this.addGroup(t.start,t.count,t.materialIndex)}let o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());let s=e.boundingSphere;return s!==null&&(this.boundingSphere=s.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:`dispose`})}},vS=new Xb,yS=new Yb,bS=new Vb,xS=new Y,SS=new Y,CS=new Y,wS=new Y,TS=new Y,ES=new Y,DS=new Y,OS=new Y,kS=class extends Cx{constructor(e=new _S,t=new Gx){super(),this.isMesh=!0,this.type=`Mesh`,this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;e<t;e++){let t=n[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}getVertexPosition(e,t){let n=this.geometry,r=n.attributes.position,i=n.morphAttributes.position,a=n.morphTargetsRelative;t.fromBufferAttribute(r,e);let o=this.morphTargetInfluences;if(i&&o){ES.set(0,0,0);for(let n=0,r=i.length;n<r;n++){let r=o[n],s=i[n];r!==0&&(TS.fromBufferAttribute(s,e),a?ES.addScaledVector(TS,r):ES.addScaledVector(TS.sub(t),r))}t.add(ES)}return t}raycast(e,t){let n=this.geometry,r=this.material,i=this.matrixWorld;r!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),bS.copy(n.boundingSphere),bS.applyMatrix4(i),yS.copy(e.ray).recast(e.near),!(bS.containsPoint(yS.origin)===!1&&(yS.intersectSphere(bS,xS)===null||yS.origin.distanceToSquared(xS)>(e.far-e.near)**2))&&(vS.copy(i).invert(),yS.copy(e.ray).applyMatrix4(vS),!(n.boundingBox!==null&&yS.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,yS)))}_computeIntersections(e,t,n){let r,i=this.geometry,a=this.material,o=i.index,s=i.attributes.position,c=i.attributes.uv,l=i.attributes.uv1,u=i.attributes.normal,d=i.groups,f=i.drawRange;if(o!==null)if(Array.isArray(a))for(let i=0,s=d.length;i<s;i++){let s=d[i],p=a[s.materialIndex],m=Math.max(s.start,f.start),h=Math.min(o.count,Math.min(s.start+s.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=o.getX(i),d=o.getX(i+1),f=o.getX(i+2);r=jS(this,p,e,n,c,l,u,a,d,f),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=s.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),s=Math.min(o.count,f.start+f.count);for(let d=i,f=s;d<f;d+=3){let i=o.getX(d),s=o.getX(d+1),f=o.getX(d+2);r=jS(this,a,e,n,c,l,u,i,s,f),r&&(r.faceIndex=Math.floor(d/3),t.push(r))}}else if(s!==void 0)if(Array.isArray(a))for(let i=0,o=d.length;i<o;i++){let o=d[i],p=a[o.materialIndex],m=Math.max(o.start,f.start),h=Math.min(s.count,Math.min(o.start+o.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=i,s=i+1,d=i+2;r=jS(this,p,e,n,c,l,u,a,s,d),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=o.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),o=Math.min(s.count,f.start+f.count);for(let s=i,d=o;s<d;s+=3){let i=s,o=s+1,d=s+2;r=jS(this,a,e,n,c,l,u,i,o,d),r&&(r.faceIndex=Math.floor(s/3),t.push(r))}}}};function AS(e,t,n,r,i,a,o,s){let c;if(c=t.side===1?r.intersectTriangle(o,a,i,!0,s):r.intersectTriangle(i,a,o,t.side===0,s),c===null)return null;OS.copy(s),OS.applyMatrix4(e.matrixWorld);let l=n.ray.origin.distanceTo(OS);return l<n.near||l>n.far?null:{distance:l,point:OS.clone(),object:e}}function jS(e,t,n,r,i,a,o,s,c,l){e.getVertexPosition(s,SS),e.getVertexPosition(c,CS),e.getVertexPosition(l,wS);let u=AS(e,t,n,r,SS,CS,wS,DS);if(u){let e=new Y;Lx.getBarycoord(DS,SS,CS,wS,e),i&&(u.uv=Lx.getInterpolatedAttribute(i,s,c,l,e,new J)),a&&(u.uv1=Lx.getInterpolatedAttribute(a,s,c,l,e,new J)),o&&(u.normal=Lx.getInterpolatedAttribute(o,s,c,l,e,new Y),u.normal.dot(r.direction)>0&&u.normal.multiplyScalar(-1));let t={a:s,b:c,c:l,normal:new Y,materialIndex:0};Lx.getNormal(SS,CS,wS,t.normal),u.face=t,u.barycoord=e}return u}var MS=class e extends _S{constructor(e=1,t=1,n=1,r=1,i=1,a=1){super(),this.type=`BoxGeometry`,this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:i,depthSegments:a};let o=this;r=Math.floor(r),i=Math.floor(i),a=Math.floor(a);let s=[],c=[],l=[],u=[],d=0,f=0;p(`z`,`y`,`x`,-1,-1,n,t,e,a,i,0),p(`z`,`y`,`x`,1,-1,n,t,-e,a,i,1),p(`x`,`z`,`y`,1,1,e,n,t,r,a,2),p(`x`,`z`,`y`,1,-1,e,n,-t,r,a,3),p(`x`,`y`,`z`,1,-1,e,t,n,r,i,4),p(`x`,`y`,`z`,-1,-1,e,t,-n,r,i,5),this.setIndex(s),this.setAttribute(`position`,new lS(c,3)),this.setAttribute(`normal`,new lS(l,3)),this.setAttribute(`uv`,new lS(u,2));function p(e,t,n,r,i,a,p,m,h,g,_){let v=a/h,y=p/g,b=a/2,x=p/2,S=m/2,C=h+1,w=g+1,T=0,E=0,D=new Y;for(let a=0;a<w;a++){let o=a*y-x;for(let s=0;s<C;s++)D[e]=(s*v-b)*r,D[t]=o*i,D[n]=S,c.push(D.x,D.y,D.z),D[e]=0,D[t]=0,D[n]=m>0?1:-1,l.push(D.x,D.y,D.z),u.push(s/h),u.push(1-a/g),T+=1}for(let e=0;e<g;e++)for(let t=0;t<h;t++){let n=d+t+C*e,r=d+t+C*(e+1),i=d+(t+1)+C*(e+1),a=d+(t+1)+C*e;s.push(n,r,a),s.push(r,i,a),E+=6}o.addGroup(f,E,_),f+=E,d+=T}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}};function NS(e){let t={};for(let n in e){t[n]={};for(let r in e[n]){let i=e[n][r];i&&(i.isColor||i.isMatrix3||i.isMatrix4||i.isVector2||i.isVector3||i.isVector4||i.isTexture||i.isQuaternion)?i.isRenderTargetTexture?(yy(`UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().`),t[n][r]=null):t[n][r]=i.clone():Array.isArray(i)?t[n][r]=i.slice():t[n][r]=i}}return t}function PS(e){let t={};for(let n=0;n<e.length;n++){let r=NS(e[n]);for(let e in r)t[e]=r[e]}return t}function FS(e){let t=[];for(let n=0;n<e.length;n++)t.push(e[n].clone());return t}function IS(e){let t=e.getRenderTarget();return t===null?e.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:ab.workingColorSpace}var LS={clone:NS,merge:PS},RS=`void main() {
61
+ `),a=!1),Object.assign(Object.assign({},e),{allowNegative:a})}function dh(e){e=uh(e),e.decimalSeparator,e.allowedDecimalSeparators,e.thousandsGroupStyle;var t=e.suffix,n=e.allowNegative,r=e.allowLeadingZeros,i=e.onKeyDown;i===void 0&&(i=Em);var a=e.onBlur;a===void 0&&(a=Em);var o=e.thousandSeparator,s=e.decimalScale,c=e.fixedDecimalScale,l=e.prefix;l===void 0&&(l=``);var u=e.defaultValue,d=e.value,f=e.valueIsNumericString,p=e.onValueChange,m=wm(e,[`decimalSeparator`,`allowedDecimalSeparators`,`thousandsGroupStyle`,`suffix`,`allowNegative`,`allowLeadingZeros`,`onKeyDown`,`onBlur`,`thousandSeparator`,`decimalScale`,`fixedDecimalScale`,`prefix`,`defaultValue`,`value`,`valueIsNumericString`,`onValueChange`]),h=ih(e),g=h.decimalSeparator,_=h.allowedDecimalSeparators,v=function(t){return rh(t,e)},y=function(t,n){return ch(t,n,e)},b=km(d)?u:d,x=f??sh(b,l,t);km(d)?km(u)||(x||=typeof u==`number`):x||=typeof d==`number`;var S=function(e){return jm(e)?e:(typeof e==`number`&&(e=Bm(e)),x&&typeof s==`number`?Vm(e,s,!!c):e)},C=$m(S(d),S(u),!!x,v,y,p),w=C[0],T=w.numAsString,E=w.formattedValue,D=C[1];return Object.assign(Object.assign({},m),{value:E,valueIsNumericString:!1,isValidInputCharacter:function(e){return e===g?!0:Om(e)},isCharacterSame:function(e){var t=e.currentValue,n=e.lastValue,r=e.formattedValue,i=e.currentValueIndex,a=e.formattedValueIndex,o=t[i],u=r[a],f=Um(n,t).to,p=function(e){return y(e).indexOf(`.`)+l.length};return d===0&&c&&s&&t[f.start]===g&&p(t)<i&&p(r)>a?!1:i>=f.start&&i<f.end&&_&&_.includes(o)&&u===g?!0:o===u},onValueChange:D,format:v,removeFormatting:y,getCaretBoundary:function(t){return lh(t,e)},onKeyDown:function(e){var t=e.target,r=e.key,a=t.selectionStart,u=t.selectionEnd,d=t.value;if(d===void 0&&(d=``),(r===`Backspace`||r===`Delete`)&&u<l.length&&d!==`-`){e.preventDefault();return}if(a!==u){i(e);return}r===`Backspace`&&d[0]===`-`&&a===l.length+1&&n&&Hm(t,1),s&&c&&(r===`Backspace`&&d[a-1]===g?(Hm(t,a-1),e.preventDefault()):r===`Delete`&&d[a]===g&&e.preventDefault()),_?.includes(r)&&d[a]===g&&Hm(t,a+1);var f=o===!0?`,`:o;r===`Backspace`&&d[a-1]===f&&Hm(t,a-1),r===`Delete`&&d[a]===f&&Hm(t,a+1),i(e)},onBlur:function(t){var n=T;n.match(/\d/g)||(n=``),r||(n=Lm(n)),c&&s&&(n=Vm(n,s,c)),n!==T&&D({formattedValue:rh(n,e),value:n,floatValue:parseFloat(n)},{event:t,source:Tm.event}),a(t)}})}function fh(e){var t=dh(e);return b.createElement(nh,Object.assign({},t))}var ph={root:`m_e2f5cd4e`,controls:`m_95e17d22`,control:`m_80b4b171`};function mh({direction:e,style:t,...n}){return(0,G.jsx)(`svg`,{style:{width:`var(--ni-chevron-size)`,height:`var(--ni-chevron-size)`,transform:e===`up`?`rotate(180deg)`:void 0,...t},viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...n,children:(0,G.jsx)(`path`,{d:`M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})}var hh=/^(0\.0*|-0(\.0*)?)$/,gh=/^-?0\d+(\.\d+)?\.?$/,_h=/\.\d*0$/,vh=/^-?\d+\.$/;function yh(e){return typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))}function bh(e){return typeof e==`number`?e<2**53-1:e===``||yh(e)&&Number(e)<2**53-1}function xh(e){return e.toString().replace(`.`,``).length}function Sh(e,t){return(typeof e==`number`?e<2**53-1:!Number.isNaN(Number(e)))&&!Number.isNaN(e)&&xh(t)<14&&t!==``}function Ch(e,t,n){return e===void 0?!0:(t===void 0||e>=t)&&(n===void 0||e<=n)}var wh={step:1,clampBehavior:`blur`,allowDecimal:!0,allowNegative:!0,withKeyboardEvents:!0,allowLeadingZeros:!0,trimLeadingZeroesOnBlur:!0,startValue:0,allowedDecimalSeparators:[`.`,`,`]},Th=en((e,{size:t})=>({controls:{"--ni-chevron-size":nt(t,`ni-chevron-size`)}}));function Eh(e,t,n){let r=e.toString(),i=vh.test(r),a=r.replace(/^0+(?=\d)/,``),o=parseFloat(a);if(Number.isNaN(o))return a;if(o>2**53-1)return t===void 0?a:t;let s=ut(o,n,t);return i?`${s.toString().replace(/^0+(?=\d)/,``)}.`:s}var Dh=_i((e,t)=>{let n=K(`NumberInput`,wh,e),{className:r,classNames:i,styles:a,unstyled:o,vars:s,onChange:c,onValueChange:l,value:u,defaultValue:d,max:f,min:p,step:m,hideControls:h,rightSection:g,isAllowed:_,clampBehavior:v,onBlur:y,allowDecimal:x,decimalScale:S,onKeyDown:C,onKeyDownCapture:w,handlersRef:T,startValue:E,disabled:D,rightSectionPointerEvents:O,allowNegative:k,readOnly:A,size:j,rightSectionWidth:M,stepHoldInterval:N,stepHoldDelay:P,allowLeadingZeros:F,withKeyboardEvents:I,trimLeadingZeroesOnBlur:L,allowedDecimalSeparators:R,attributes:z,...B}=n,V=jr({name:`NumberInput`,classes:ph,props:n,classNames:i,styles:a,unstyled:o,attributes:z,vars:s,varsResolver:Th}),{resolvedClassNames:ee,resolvedStyles:te}=mr({classNames:i,styles:a,props:n}),[ne,re]=Vt({value:u,defaultValue:d,finalValue:``,onChange:c}),ie=P!==void 0&&N!==void 0,ae=(0,b.useRef)(null),oe=(0,b.useRef)(null),se=(0,b.useRef)(0),H=(e,t)=>{t.source===`event`&&re(Sh(e.floatValue,e.value)&&!hh.test(e.value)&&!(F&&gh.test(e.value))&&!_h.test(e.value)&&!vh.test(e.value)?e.floatValue:e.value),l?.(e,t)},ce=e=>{let t=String(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0},le=e=>{ae.current&&e!==void 0&&ae.current.setSelectionRange(e,e)},ue=(0,b.useRef)(et);ue.current=()=>{if(!bh(ne))return;let e,t=ce(ne),n=ce(m),r=Math.max(t,n),i=10**r;if(!yh(ne)&&(typeof ne!=`number`||Number.isNaN(ne)))e=ut(E,p,f);else if(f!==void 0){let t=(Math.round(Number(ne)*i)+Math.round(m*i))/i;e=t<=f?t:f}else e=(Math.round(Number(ne)*i)+Math.round(m*i))/i;let a=e.toFixed(r);re(parseFloat(a)),l?.({floatValue:parseFloat(a),formattedValue:a,value:a},{source:`increment`}),setTimeout(()=>le(ae.current?.value.length),0)};let U=(0,b.useRef)(et);U.current=()=>{if(!bh(ne))return;let e,t=p===void 0?k?-(2**53-1):0:p,n=ce(ne),r=ce(m),i=Math.max(n,r),a=10**i;if(!yh(ne)&&typeof ne!=`number`||Number.isNaN(ne))e=ut(E,t,f);else{let n=(Math.round(Number(ne)*a)-Math.round(m*a))/a;e=t!==void 0&&n<t?t:n}let o=e.toFixed(i);re(parseFloat(o)),l?.({floatValue:parseFloat(o),formattedValue:o,value:o},{source:`decrement`}),setTimeout(()=>le(ae.current?.value.length),0)};let de=e=>{let t=e.clipboardData.getData(`text`),n=B.decimalSeparator||`.`,r=(R||[`.`,`,`]).filter(e=>e!==n);if(r.some(e=>t.includes(e))){e.preventDefault();let i=t;r.forEach(e=>{i=i.split(e).join(n)});let a=ae.current;if(a){let e=a.selectionStart??0,t=a.selectionEnd??0,n=a.value,r=n.substring(0,e)+i+n.substring(t);(Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set)?.call(a,r),a.dispatchEvent(new Event(`change`,{bubbles:!0}));let o=e+i.length;setTimeout(()=>le(o),0)}}B.onPaste?.(e)},fe=e=>{C?.(e),!(A||!I)&&(e.key===`ArrowUp`&&(e.preventDefault(),ue.current?.()),e.key===`ArrowDown`&&(e.preventDefault(),U.current?.()))},pe=e=>{if(w?.(e),e.key===`Backspace`){let t=ae.current;t&&t.selectionStart===0&&t.selectionStart===t.selectionEnd&&(e.preventDefault(),window.setTimeout(()=>le(0),0))}},me=e=>{let t=ne;v===`blur`&&typeof t==`number`&&(t=ut(t,p,f)),L&&typeof t==`string`&&ce(t)<15&&(t=Eh(t,f,p)),ne!==t&&re(t),y?.(e)};It(T,{increment:ue.current,decrement:U.current});let he=e=>{e?ue.current?.():U.current?.(),se.current+=1},ge=e=>{if(he(e),ie){let t=typeof N==`number`?N:N(se.current);oe.current=window.setTimeout(()=>ge(e),t)}},_e=(e,t)=>{e.preventDefault(),ae.current?.focus(),he(t),ie&&(oe.current=window.setTimeout(()=>ge(t),P))},ve=()=>{oe.current&&window.clearTimeout(oe.current),oe.current=null,se.current=0},ye=(0,G.jsxs)(`div`,{...V(`controls`),children:[(0,G.jsx)(Gc,{...V(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof ne==`number`&&f!==void 0&&ne>=f,mod:{direction:`up`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{_e(e,!0)},onPointerUp:ve,onPointerLeave:ve,children:(0,G.jsx)(mh,{direction:`up`})}),(0,G.jsx)(Gc,{...V(`control`),tabIndex:-1,"aria-hidden":!0,disabled:D||typeof ne==`number`&&p!==void 0&&ne<=p,mod:{direction:`down`},onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{_e(e,!1)},onPointerUp:ve,onPointerLeave:ve,children:(0,G.jsx)(mh,{direction:`down`})})]});return(0,G.jsx)(Vu,{component:fh,allowNegative:k,className:nn(ph.root,r),size:j,inputMode:`decimal`,...B,readOnly:A,disabled:D,value:ne,getInputRef:Rt(t,ae),onValueChange:H,rightSection:h||A||!bh(ne)?g:g||ye,classNames:ee,styles:te,unstyled:o,__staticSelector:`NumberInput`,decimalScale:x?S:0,onPaste:de,onKeyDown:fe,onKeyDownCapture:pe,rightSectionPointerEvents:O??(D?`none`:void 0),rightSectionWidth:M??`var(--ni-right-section-width-${j||`sm`})`,allowLeadingZeros:F,allowedDecimalSeparators:R,onBlur:me,attributes:z,isAllowed:e=>v===`strict`?_?_(e)&&Ch(e.floatValue,p,f):Ch(e.floatValue,p,f):_?_(e):!0})});Dh.classes={...Vu.classes,...ph},Dh.displayName=`@mantine/core/NumberInput`;var Oh={duration:100,transition:`fade`};function kh(e,t){return{...Oh,...t,...e}}var Ah={tooltip:`m_1b3c8819`,arrow:`m_f898399f`};function jh({offset:e,position:t,defaultOpened:n}){let[r,i]=(0,b.useState)(n),a=(0,b.useRef)(null),{x:o,y:s,elements:c,refs:l,update:u,placement:d}=tc({placement:t,middleware:[ds({crossAxis:!0,padding:5,rootBoundary:`document`})]}),f=d.includes(`right`)?e:t.includes(`left`)?e*-1:0,p=d.includes(`bottom`)?e:t.includes(`top`)?e*-1:0,m=(0,b.useCallback)(({clientX:e,clientY:t})=>{l.setPositionReference({getBoundingClientRect(){return{width:0,height:0,x:e,y:t,left:e+f,top:t+p,right:e,bottom:t}}})},[c.reference]);return(0,b.useEffect)(()=>{if(l.floating.current){let e=a.current;e.addEventListener(`mousemove`,m);let t=$i(l.floating.current);return t.forEach(e=>{e.addEventListener(`scroll`,u)}),()=>{e.removeEventListener(`mousemove`,m),t.forEach(e=>{e.removeEventListener(`scroll`,u)})}}},[c.reference,l.floating.current,u,m,r]),{handleMouseMove:m,x:o,y:s,opened:r,setOpened:i,boundaryRef:a,floating:l.setFloating}}var Mh={refProp:`ref`,withinPortal:!0,offset:10,position:`right`,zIndex:$e(`popover`)},Nh=en((e,{radius:t,color:n})=>({tooltip:{"--tooltip-radius":t===void 0?void 0:it(t),"--tooltip-bg":n?An(n,e):void 0,"--tooltip-color":n?`var(--mantine-color-white)`:void 0}})),Ph=_i((e,t)=>{let n=K(`TooltipFloating`,Mh,e),{children:r,refProp:i,withinPortal:a,style:o,className:s,classNames:c,styles:l,unstyled:u,radius:d,color:f,label:p,offset:m,position:h,multiline:g,zIndex:_,disabled:v,defaultOpened:y,variant:x,vars:S,portalProps:C,attributes:w,...T}=n,E=qn(),D=jr({name:`TooltipFloating`,props:n,classes:Ah,className:s,style:o,classNames:c,styles:l,unstyled:u,attributes:w,rootSelector:`tooltip`,vars:S,varsResolver:Nh}),{handleMouseMove:O,x:k,y:A,opened:j,boundaryRef:M,floating:N,setOpened:P}=jh({offset:m,position:h,defaultOpened:y}),F=$t(r);if(!F)throw Error(`[@mantine/core] Tooltip.Floating component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);let I=Rt(M,Yt(F),t),L=F.props,R=e=>{L.onMouseEnter?.(e),O(e),P(!0)},z=e=>{L.onMouseLeave?.(e),P(!1)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dl,{...C,withinPortal:a,children:(0,G.jsx)(q,{...T,...D(`tooltip`,{style:{...si(o,E),zIndex:_,display:!v&&j?`block`:`none`,top:(A&&Math.round(A))??``,left:(k&&Math.round(k))??``}}),variant:x,ref:N,mod:{multiline:g},children:p})}),(0,b.cloneElement)(F,{...L,[i]:I,onMouseEnter:R,onMouseLeave:z})]})});Ph.classes=Ah,Ph.displayName=`@mantine/core/TooltipFloating`;var Fh=(0,b.createContext)(!1),Ih=Fh.Provider,Lh=()=>(0,b.useContext)(Fh),Rh={openDelay:0,closeDelay:0};function zh(e){let{openDelay:t,closeDelay:n,children:r}=K(`TooltipGroup`,Rh,e);return(0,G.jsx)(Ih,{value:!0,children:(0,G.jsx)(Js,{delay:{open:t,close:n},children:r})})}zh.displayName=`@mantine/core/TooltipGroup`,zh.extend=e=>e;function Bh(e){if(e===void 0)return{shift:!0,flip:!0};let t={...e};return e.shift===void 0&&(t.shift=!0),e.flip===void 0&&(t.flip=!0),t}function Vh(e){let t=Bh(e.middlewares),n=[us(e.offset)];return t.shift&&n.push(ds(typeof t.shift==`boolean`?{padding:8}:{padding:8,...t.shift})),t.flip&&n.push(typeof t.flip==`boolean`?ps():ps(t.flip)),n.push(_s({element:e.arrowRef,padding:e.arrowOffset})),t.inline?n.push(typeof t.inline==`boolean`?gs():gs(t.inline)):e.inline&&n.push(gs()),n}function Hh(e){let[t,n]=(0,b.useState)(e.defaultOpened),r=typeof e.opened==`boolean`?e.opened:t,i=Lh(),a=Pt(),o=(0,b.useCallback)(e=>{n(e),e&&g(a)},[a]),{x:s,y:c,context:l,refs:u,placement:d,middlewareData:{arrow:{x:f,y:p}={}}}=tc({strategy:e.strategy,placement:e.position,open:r,onOpenChange:o,middleware:Vh(e),whileElementsMounted:qo}),{delay:m,currentId:h,setCurrentId:g}=Ys(l,{id:a}),{getReferenceProps:_,getFloatingProps:v}=ac([Ws(l,{enabled:e.events?.hover,delay:i?m:{open:e.openDelay,close:e.closeDelay},mouseOnly:!e.events?.touch}),rc(l,{enabled:e.events?.focus,visibleOnly:!0}),sc(l,{role:`tooltip`}),$s(l,{enabled:e.opened===void 0})]);bt(()=>{e.onPositionChange?.(d)},[d]);let y=r&&h&&h!==a;return{x:s,y:c,arrowX:f,arrowY:p,reference:u.setReference,floating:u.setFloating,getFloatingProps:v,getReferenceProps:_,isGroupPhase:y,opened:r,placement:d}}var Uh={position:`top`,refProp:`ref`,withinPortal:!0,arrowSize:4,arrowOffset:5,arrowRadius:0,arrowPosition:`side`,offset:5,transitionProps:{duration:100,transition:`fade`},events:{hover:!0,focus:!1,touch:!1},zIndex:$e(`popover`),positionDependencies:[],middlewares:{flip:!0,shift:!0,inline:!1}},Wh=en((e,{radius:t,color:n,variant:r,autoContrast:i})=>{let a=e.variantColorResolver({theme:e,color:n||e.primaryColor,autoContrast:i,variant:r||`filled`});return{tooltip:{"--tooltip-radius":t===void 0?void 0:it(t),"--tooltip-bg":n?a.background:void 0,"--tooltip-color":n?a.color:void 0}}}),Gh=_i((e,t)=>{let n=K(`Tooltip`,Uh,e),{children:r,position:i,refProp:a,label:o,openDelay:s,closeDelay:c,onPositionChange:l,opened:u,defaultOpened:d,withinPortal:f,radius:p,color:m,classNames:h,styles:g,unstyled:_,style:v,className:y,withArrow:x,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,offset:E,transitionProps:D,multiline:O,events:k,zIndex:A,disabled:j,positionDependencies:M,onClick:N,onMouseEnter:P,onMouseLeave:F,inline:I,variant:L,keepMounted:R,vars:z,portalProps:B,mod:V,floatingStrategy:ee,middlewares:te,autoContrast:ne,attributes:re,target:ie,...ae}=K(`Tooltip`,Uh,n),{dir:oe}=bi(),se=(0,b.useRef)(null),H=Hh({position:nl(oe,i),closeDelay:c,openDelay:s,onPositionChange:l,opened:u,defaultOpened:d,events:k,arrowRef:se,arrowOffset:C,offset:typeof E==`number`?E+(x?S/2:0):E,positionDependencies:[...M,ie??r],inline:I,strategy:ee,middlewares:te});(0,b.useEffect)(()=>{let e=ie instanceof HTMLElement?ie:typeof ie==`string`?document.querySelector(ie):ie?.current||null;e&&H.reference(e)},[ie,H]);let ce=jr({name:`Tooltip`,props:n,classes:Ah,className:y,style:v,classNames:h,styles:g,unstyled:_,attributes:re,rootSelector:`tooltip`,vars:z,varsResolver:Wh}),le=$t(r);if(!ie&&!le)throw Error(`[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported`);if(ie){let e=kh(D,{duration:100,transition:`fade`});return(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(dl,{...B,withinPortal:f,children:(0,G.jsx)(_l,{...e,keepMounted:R,mounted:!j&&!!H.opened,duration:H.isGroupPhase?10:e.duration,children:e=>(0,G.jsxs)(q,{...ae,"data-fixed":ee===`fixed`||void 0,variant:L,mod:[{multiline:O},V],...H.getFloatingProps({ref:H.floating,className:ce(`tooltip`).className,style:{...ce(`tooltip`).style,...e,zIndex:A,top:H.y??0,left:H.x??0}}),children:[o,(0,G.jsx)(tl,{ref:se,arrowX:H.arrowX,arrowY:H.arrowY,visible:x,position:H.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ce(`arrow`)})]})})})})}let ue=le.props,U=Rt(H.reference,Yt(le),t),de=kh(D,{duration:100,transition:`fade`});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(dl,{...B,withinPortal:f,children:(0,G.jsx)(_l,{...de,keepMounted:R,mounted:!j&&!!H.opened,duration:H.isGroupPhase?10:de.duration,children:e=>(0,G.jsxs)(q,{...ae,"data-fixed":ee===`fixed`||void 0,variant:L,mod:[{multiline:O},V],...H.getFloatingProps({ref:H.floating,className:ce(`tooltip`).className,style:{...ce(`tooltip`).style,...e,zIndex:A,top:H.y??0,left:H.x??0}}),children:[o,(0,G.jsx)(tl,{ref:se,arrowX:H.arrowX,arrowY:H.arrowY,visible:x,position:H.placement,arrowSize:S,arrowOffset:C,arrowRadius:w,arrowPosition:T,...ce(`arrow`)})]})})}),(0,b.cloneElement)(le,H.getReferenceProps({onClick:N,onMouseEnter:P,onMouseLeave:F,onMouseMove:n.onMouseMove,onPointerDown:n.onPointerDown,onPointerEnter:n.onPointerEnter,...ue,className:nn(y,ue.className),[a]:U}))]})});Gh.classes=Ah,Gh.displayName=`@mantine/core/Tooltip`,Gh.Floating=Ph,Gh.Group=zh;var Kh={withCheckIcon:!0,allowDeselect:!0,checkIconPosition:`left`,openOnFocus:!0},qh=_i((e,t)=>{let n=K(`Select`,Kh,e),{classNames:r,styles:i,unstyled:a,vars:o,dropdownOpened:s,defaultDropdownOpened:c,onDropdownClose:l,onDropdownOpen:u,onFocus:d,onBlur:f,onClick:p,onChange:m,data:h,value:g,defaultValue:_,selectFirstOptionOnChange:v,selectFirstOptionOnDropdownOpen:y,onOptionSubmit:x,comboboxProps:S,readOnly:C,disabled:w,filter:T,limit:E,withScrollArea:D,maxDropdownHeight:O,size:k,searchable:A,rightSection:j,checkIconPosition:M,withCheckIcon:N,withAlignedLabels:P,nothingFoundMessage:F,name:I,form:L,searchValue:R,defaultSearchValue:z,onSearchChange:B,allowDeselect:V,error:ee,rightSectionPointerEvents:te,id:ne,clearable:re,clearButtonProps:ie,hiddenInputProps:ae,renderOption:oe,onClear:se,autoComplete:H,scrollAreaProps:ce,__defaultRightSection:le,__clearSection:ue,__clearable:U,chevronColor:de,autoSelectOnBlur:fe,openOnFocus:pe,attributes:me,...he}=n,ge=(0,b.useMemo)(()=>nd(h),[h]),_e=(0,b.useRef)({}),ve=(0,b.useMemo)(()=>rd(ge),[ge]),ye=Pt(ne),[be,xe,Se]=Vt({value:g,defaultValue:_,finalValue:null,onChange:m}),Ce=typeof be==`string`?be in ve?ve[be]:_e.current[be]:void 0,we=Wt(Ce),[Te,Ee,De]=Vt({value:R,defaultValue:z,finalValue:Ce?Ce.label:``,onChange:B}),Oe=jd({opened:s,defaultOpened:c,onDropdownOpen:()=>{u?.(),y?Oe.selectFirstOption():Oe.updateSelectedOptionIndex(`active`,{scrollIntoView:!0})},onDropdownClose:()=>{l?.(),setTimeout(Oe.resetSelectedOption,0)}}),ke=e=>{Ee(e),Oe.resetSelectedOption()},{resolvedClassNames:Ae,resolvedStyles:je}=mr({props:n,styles:i,classNames:r});(0,b.useEffect)(()=>{v&&Oe.selectFirstOption()},[v,Te]),(0,b.useEffect)(()=>{g===null&&ke(``),typeof g==`string`&&Ce&&(we?.value!==Ce.value||we?.label!==Ce.label)&&ke(Ce.label)},[g,Ce]),(0,b.useEffect)(()=>{!Se&&!De&&ke(typeof be==`string`?be in ve?ve[be]?.label:_e.current[be]?.label||``:``)},[ve,be]),(0,b.useEffect)(()=>{be&&be in ve&&(_e.current[be]=ve[be])},[ve,be]);let Me=(0,G.jsx)(Pd.ClearButton,{...ie,onClear:()=>{xe(null,null),ke(``),se?.()}}),Ne=re&&!!be&&!w&&!C;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Pd,{store:Oe,__staticSelector:`Select`,classNames:Ae,styles:je,unstyled:a,readOnly:C,size:k,attributes:me,keepMounted:fe,onOptionSubmit:e=>{x?.(e);let t=V&&ve[e].value===be?null:ve[e],n=t?t.value:null;n!==be&&xe(n,t),!Se&&ke(typeof n==`string`&&t?.label||``),Oe.closeDropdown()},...S,children:[(0,G.jsx)(Pd.Target,{targetType:A?`input`:`button`,autoComplete:H,children:(0,G.jsx)(Vu,{id:ye,ref:t,__defaultRightSection:(0,G.jsx)(Pd.Chevron,{size:k,error:ee,unstyled:a,color:de}),__clearSection:Me,__clearable:Ne,rightSection:j,rightSectionPointerEvents:te||`none`,...he,size:k,__staticSelector:`Select`,disabled:w,readOnly:C||!A,value:Te,onChange:e=>{ke(e.currentTarget.value),Oe.openDropdown(),v&&Oe.selectFirstOption()},onFocus:e=>{pe&&A&&Oe.openDropdown(),d?.(e)},onBlur:e=>{fe&&Oe.clickSelectedOption(),A&&Oe.closeDropdown();let t=typeof be==`string`&&(be in ve?ve[be]:_e.current[be]);ke(t&&t.label||``),f?.(e)},onClick:e=>{A?Oe.openDropdown():Oe.toggleDropdown(),p?.(e)},classNames:Ae,styles:je,unstyled:a,pointer:!A,error:ee,attributes:me})}),(0,G.jsx)(ff,{data:ge,hidden:C||w,filter:T,search:Te,limit:E,hiddenWhenEmpty:!F,withScrollArea:D,maxDropdownHeight:O,filterOptions:!!A&&Ce?.label!==Te,value:be,checkIconPosition:M,withCheckIcon:N,withAlignedLabels:P,nothingFoundMessage:F,unstyled:a,labelId:he.label?`${ye}-label`:void 0,"aria-label":he.label?void 0:he[`aria-label`],renderOption:oe,scrollAreaProps:ce})]}),(0,G.jsx)(Pd.HiddenInput,{value:be,name:I,form:L,disabled:w,...ae})]})});qh.classes={...Vu.classes,...Pd.classes},qh.displayName=`@mantine/core/Select`;var[Jh,Yh]=Ge(`SliderProvider was not found in tree`),Xh={root:`m_dd36362e`,label:`m_c9357328`,thumb:`m_c9a9a60a`,trackContainer:`m_a8645c2`,track:`m_c9ade57f`,bar:`m_38aeed47`,markWrapper:`m_b7b0423a`,mark:`m_dd33bc19`,markLabel:`m_68c77a5b`},Zh=(0,b.forwardRef)(({size:e,disabled:t,variant:n,color:r,thumbSize:i,radius:a,...o},s)=>{let{getStyles:c}=Yh();return(0,G.jsx)(q,{tabIndex:-1,variant:n,size:e,ref:s,...c(`root`),...o})});Zh.displayName=`@mantine/core/SliderRoot`;var Qh=(0,b.forwardRef)(({max:e,min:t,value:n,position:r,label:i,dragging:a,onMouseDown:o,onKeyDownCapture:s,labelTransitionProps:c,labelAlwaysOn:l,thumbLabel:u,onFocus:d,onBlur:f,showLabelOnHover:p,isHovered:m,children:h=null,disabled:g},_)=>{let{getStyles:v}=Yh(),[y,x]=(0,b.useState)(!1),S=l||a||y||p&&m;return(0,G.jsxs)(q,{tabIndex:0,role:`slider`,"aria-label":u,"aria-valuemax":e,"aria-valuemin":t,"aria-valuenow":n,ref:_,__vars:{"--slider-thumb-offset":`${r}%`},...v(`thumb`,{focusable:!0}),mod:{dragging:a,disabled:g},onFocus:e=>{x(!0),typeof d==`function`&&d(e)},onBlur:e=>{x(!1),typeof f==`function`&&f(e)},onTouchStart:o,onMouseDown:o,onKeyDownCapture:s,onClick:e=>e.stopPropagation(),children:[h,(0,G.jsx)(_l,{mounted:i!=null&&!!S,transition:`fade`,duration:0,...c,children:e=>(0,G.jsx)(`div`,{...v(`label`,{style:e}),children:i})})]})});Qh.displayName=`@mantine/core/SliderThumb`;function $h({value:e,min:t,max:n}){let r=(e-t)/(n-t)*100;return Math.min(Math.max(r,0),100)}function eg({mark:e,offset:t,value:n,inverted:r=!1}){return r?typeof t==`number`&&e.value<=t||e.value>=n:typeof t==`number`?e.value>=t&&e.value<=n:e.value<=n}function tg({marks:e,min:t,max:n,disabled:r,value:i,offset:a,inverted:o}){let{getStyles:s}=Yh();return e?(0,G.jsx)(`div`,{children:e.map((e,c)=>(0,b.createElement)(q,{...s(`markWrapper`),__vars:{"--mark-offset":`${$h({value:e.value,min:t,max:n})}%`},key:c},(0,G.jsx)(q,{...s(`mark`),mod:{filled:eg({mark:e,value:i,offset:a,inverted:o}),disabled:r}}),e.label&&(0,G.jsx)(`div`,{...s(`markLabel`),children:e.label})))}):null}tg.displayName=`@mantine/core/SliderMarks`;function ng({filled:e,children:t,offset:n,disabled:r,marksOffset:i,inverted:a,containerProps:o,...s}){let{getStyles:c}=Yh();return(0,G.jsx)(q,{...c(`trackContainer`),mod:{disabled:r},...o,children:(0,G.jsxs)(q,{...c(`track`),mod:{inverted:a,disabled:r},children:[(0,G.jsx)(q,{mod:{inverted:a,disabled:r},__vars:{"--slider-bar-width":`calc(${e}% + 2 * var(--slider-size))`,"--slider-bar-offset":`calc(${n}% - var(--slider-size))`},...c(`bar`)}),t,(0,G.jsx)(tg,{...s,offset:i,disabled:r,inverted:a})]})})}ng.displayName=`@mantine/core/SliderTrack`;function rg({value:e,containerWidth:t,min:n,max:r,step:i,precision:a}){let o=(t?Math.min(Math.max(e,0),t)/t:e)*(r-n),s=(o===0?0:Math.round(o/i)*i)+n,c=Math.max(s,n);return a===void 0?c:Number(c.toFixed(a))}function ig(e,t){return parseFloat(e.toFixed(t))}function ag(e){if(!e)return 0;let t=e.toString().split(`.`);return t.length>1?t[1].length:0}function og(e,t){let n=[...t].sort((e,t)=>e.value-t.value).find(t=>t.value>e);return n?n.value:e}function sg(e,t){let n=[...t].sort((e,t)=>t.value-e.value).find(t=>t.value<e);return n?n.value:e}function cg(e){let t=[...e].sort((e,t)=>e.value-t.value);return t.length>0?t[0].value:0}function lg(e){let t=[...e].sort((e,t)=>e.value-t.value);return t.length>0?t[t.length-1].value:100}var ug={radius:`xl`,min:0,max:100,step:1,marks:[],label:e=>e,labelTransitionProps:{transition:`fade`,duration:0},thumbLabel:``,showLabelOnHover:!0,scale:e=>e,size:`md`},dg=en((e,{size:t,color:n,thumbSize:r,radius:i})=>({root:{"--slider-size":nt(t,`slider-size`),"--slider-color":n?An(n,e):void 0,"--slider-radius":i===void 0?void 0:it(i),"--slider-thumb-size":r===void 0?`calc(var(--slider-size) * 2)`:W(r)}})),fg=_i((e,t)=>{let n=K(`Slider`,ug,e),{classNames:r,styles:i,value:a,onChange:o,onChangeEnd:s,size:c,min:l,max:u,domain:d,step:f,precision:p,defaultValue:m,name:h,marks:g,label:_,labelTransitionProps:v,labelAlwaysOn:y,thumbLabel:x,showLabelOnHover:S,thumbChildren:C,disabled:w,unstyled:T,scale:E,inverted:D,className:O,style:k,vars:A,hiddenInputProps:j,restrictToMarks:M,thumbProps:N,attributes:P,...F}=n,I=jr({name:`Slider`,props:n,classes:Xh,classNames:r,className:O,styles:i,style:k,attributes:P,vars:A,varsResolver:dg,unstyled:T}),{dir:L}=bi(),[R,z]=(0,b.useState)(!1),[B,V]=Vt({value:typeof a==`number`?ut(a,l,u):a,defaultValue:typeof m==`number`?ut(m,l,u):m,finalValue:ut(0,l,u),onChange:o}),ee=(0,b.useRef)(B),te=(0,b.useRef)(s);(0,b.useEffect)(()=>{te.current=s},[s]);let ne=(0,b.useRef)(null),re=(0,b.useRef)(null),[ie,ae]=d||[l,u],oe=$h({value:B,min:ie,max:ae}),se=E(B),H=typeof _==`function`?_(se):_,ce=p??ag(f),{ref:le,active:ue}=Bt((0,b.useCallback)(({x:e})=>{if(!w){let t=ut(rg({value:e,min:ie,max:ae,step:f,precision:ce}),l,u);V(M&&g?.length?Jt(t,g.map(e=>e.value)):t),ee.current=t}},[w,l,u,ie,ae,f,ce,V,g,M]),{onScrubEnd:(0,b.useCallback)(()=>{if(!w&&te.current){let e=M&&g?.length?Jt(ee.current,g.map(e=>e.value)):ee.current;te.current(e)}},[w,g,M])},L),U=(0,b.useCallback)(e=>{!w&&te.current&&te.current(e)},[w]),de=e=>{if(!w)switch(e.key){case`ArrowUp`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=og(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(B+f,l),u),ce);V(t),U(t);break}case`ArrowRight`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=L===`rtl`?sg(B,g):og(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(L===`rtl`?B-f:B+f,l),u),ce);V(t),U(t);break}case`ArrowDown`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=sg(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(B-f,l),u),ce);V(t),U(t);break}case`ArrowLeft`:{if(e.preventDefault(),re.current?.focus(),M&&g){let e=L===`rtl`?og(B,g):sg(B,g);V(e),U(e);break}let t=ig(Math.min(Math.max(L===`rtl`?B+f:B-f,l),u),ce);V(t),U(t);break}case`Home`:if(e.preventDefault(),re.current?.focus(),M&&g){V(cg(g)),U(cg(g));break}V(l),U(l);break;case`End`:if(e.preventDefault(),re.current?.focus(),M&&g){V(lg(g)),U(lg(g));break}V(u),U(u);break}};return(0,G.jsx)(Jh,{value:{getStyles:I},children:(0,G.jsxs)(Zh,{...F,ref:Rt(t,ne),onKeyDownCapture:de,onMouseDownCapture:()=>ne.current?.focus(),size:c,disabled:w,children:[(0,G.jsx)(ng,{inverted:D,offset:0,filled:oe,marks:g,min:ie,max:ae,value:se,disabled:w,containerProps:{ref:le,onMouseEnter:S?()=>z(!0):void 0,onMouseLeave:S?()=>z(!1):void 0},children:(0,G.jsx)(Qh,{max:ae,min:ie,value:se,position:oe,dragging:ue,label:H,ref:re,labelTransitionProps:v,labelAlwaysOn:y,thumbLabel:x,showLabelOnHover:S,isHovered:R,disabled:w,...N,children:C})}),(0,G.jsx)(`input`,{type:`hidden`,name:h,value:se,...j})]})})});fg.classes=Xh,fg.displayName=`@mantine/core/Slider`;var pg={root:`m_6d731127`},mg={gap:`md`,align:`stretch`,justify:`flex-start`},hg=en((e,{gap:t,align:n,justify:r})=>({root:{"--stack-gap":rt(t),"--stack-align":n,"--stack-justify":r}})),gg=_i((e,t)=>{let n=K(`Stack`,mg,e),{classNames:r,className:i,style:a,styles:o,unstyled:s,vars:c,align:l,justify:u,gap:d,variant:f,attributes:p,...m}=n;return(0,G.jsx)(q,{ref:t,...jr({name:`Stack`,props:n,classes:pg,className:i,style:a,classNames:r,styles:o,unstyled:s,attributes:p,vars:c,varsResolver:hg})(`root`),variant:f,...m})});gg.classes=pg,gg.displayName=`@mantine/core/Stack`;var _g=_i((e,t)=>(0,G.jsx)(Vu,{component:`input`,ref:t,...K(`TextInput`,null,e),__staticSelector:`TextInput`}));_g.classes=Vu.classes,_g.displayName=`@mantine/core/TextInput`;var vg={outline:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},filled:{xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`currentColor`,stroke:`none`}},yg=(e,t,n,r)=>{let i=(0,b.forwardRef)(({color:n=`currentColor`,size:i=24,stroke:a=2,title:o,className:s,children:c,...l},u)=>(0,b.createElement)(`svg`,{ref:u,...vg[e],width:i,height:i,className:[`tabler-icon`,`tabler-icon-${t}`,s].join(` `),...e===`filled`?{fill:n}:{strokeWidth:a,stroke:n},...l},[o&&(0,b.createElement)(`title`,{key:`svg-title`},o),...r.map(([e,t])=>(0,b.createElement)(e,t)),...Array.isArray(c)?c:[c]]));return i.displayName=`${n}`,i},bg=yg(`outline`,`chevron-down`,`ChevronDown`,[[`path`,{d:`M6 9l6 6l6 -6`,key:`svg-0`}]]),xg=yg(`outline`,`chevron-up`,`ChevronUp`,[[`path`,{d:`M6 15l6 -6l6 6`,key:`svg-0`}]]),Sg=yg(`outline`,`refresh`,`Refresh`,[[`path`,{d:`M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4`,key:`svg-0`}],[`path`,{d:`M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4`,key:`svg-1`}]]),Cg=yg(`outline`,`x`,`X`,[[`path`,{d:`M18 6l-12 12`,key:`svg-0`}],[`path`,{d:`M6 6l12 12`,key:`svg-1`}]]),wg=d(),Tg=`0.8.1`,Eg=[{login:`ttktjmt`,html_url:`https://github.com/ttktjmt`},{login:`claude`,html_url:`https://github.com/claude`},{login:`Axellwppr`,html_url:`https://github.com/Axellwppr`},{login:`julien-blanchon`,html_url:`https://github.com/julien-blanchon`},{login:`unmoyai`,html_url:`https://github.com/unmoyai`},{login:`brentyi`,html_url:`https://github.com/brentyi`},{login:`CharlieLeee`,html_url:`https://github.com/CharlieLeee`}],Dg={move:`touchmove`,end:`touchend`},Og={move:`mousemove`,end:`mouseup`};function kg(e){return e.type===`touchmove`}function Ag(e){return e.type===`mousemove`}var jg=b.createContext(null);function Mg({children:e,width:t,visible:n=!0,onVisibleChange:r,hiddenButtonTooltip:i}){let a=b.useRef(null),[o,{toggle:s}]=Ut(!0),[c,l]=b.useState(800),u=b.useRef({dragging:!1,startPosX:0,startPosY:0,startClientX:0,startClientY:0}),d=b.useRef({}),f=(e,t,n)=>Math.abs(e+t/2)<Math.abs(e-n+t/2)?e:e-n;function p(e,t){let n=a.current;if(n===null)return[e,t];let r=n.parentElement;if(r===null)return[e,t];let i=e,o=t;return i=Math.min(i,r.clientWidth-n.clientWidth-15),i=Math.max(i,15),o=Math.min(o,r.clientHeight-n.clientHeight-15),o=Math.max(o,15),n.style.top=`${o.toString()}px`,n.style.left=`${i.toString()}px`,[f(i,n.clientWidth,r.clientWidth),f(o,n.clientHeight,r.clientHeight)]}b.useEffect(()=>{let e=a.current;if(e===null)return;let t=e.parentElement;if(t===null)return;let n=new ResizeObserver(()=>{d.current.x===void 0&&(d.current.x=f(e.offsetLeft,e.clientWidth,t.clientWidth)),d.current.y===void 0&&(d.current.y=f(e.offsetTop,e.clientHeight,t.clientHeight));let n=t.clientHeight-30;c!==n&&l(n);let r=d.current.x,i=d.current.y;for(;r<0;)r+=t.clientWidth;for(;i<0;)i+=t.clientHeight;p(r,i)});return n.observe(e),n.observe(t),()=>{n.disconnect()}});let m=e=>{let t=u.current,n=a.current;if(!n)return;e.type==`touchstart`?(e=e,t.startClientX=e.touches[0].clientX,t.startClientY=e.touches[0].clientY):(e=e,t.startClientX=e.clientX,t.startClientY=e.clientY),t.startPosX=n.offsetLeft,t.startPosY=n.offsetTop;let r=e.type==`touchstart`?Dg:Og;function i(e){let n=0,r=0;if(kg(e)?(e=e,n=e.touches[0].clientX-t.startClientX,r=e.touches[0].clientY-t.startClientY):Ag(e)&&(e=e,n=e.clientX-t.startClientX,r=e.clientY-t.startClientY),Math.abs(n)<=3&&Math.abs(r)<=3)return;t.dragging=!0;let i=t.startPosX+n,a=t.startPosY+r;[d.current.x,d.current.y]=p(i,a)}window.addEventListener(r.move,i),window.addEventListener(r.end,()=>{e.type==`touchstart`&&(t.dragging=!1),window.removeEventListener(r.move,i)},{once:!0})};if(!n){let e=(0,G.jsx)(q,{component:`button`,"aria-label":i??`Show controls`,onClick:()=>r?.(!0),style:{width:`0.85rem`,height:`0.85rem`,minWidth:`0.85rem`,minHeight:`0.85rem`,display:`block`,padding:0,border:`none`,borderRadius:`9999px`,background:`rgba(255, 255, 255, 0.82)`,boxShadow:`0 0 0 1px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.18)`,cursor:`pointer`}});return(0,G.jsx)(q,{style:{zIndex:10,position:`absolute`,top:`1em`,right:`1em`},children:i?(0,G.jsx)(Gh,{label:i,children:(0,G.jsx)(q,{children:e})}):e})}return(0,G.jsx)(jg.Provider,{value:{wrapperRef:a,expanded:o,width:t,maxHeight:c,toggleExpanded:s,dragHandler:m,dragInfo:u},children:(0,G.jsx)(Xc,{radius:`xs`,shadow:`0.1em 0 1em 0 rgba(0,0,0,0.1)`,style:{boxSizing:`border-box`,width:t,zIndex:10,position:`absolute`,top:`1em`,right:`1em`,margin:0,"& .expandIcon":{transform:`rotate(0)`},overflow:`hidden`},ref:a,children:e})})}Mg.Handle=function({children:e}){let t=b.useContext(jg);return(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(q,{style:{borderRadius:`0.2em 0.2em 0 0`,lineHeight:`1.5em`,cursor:`pointer`,position:`relative`,fontWeight:400,userSelect:`none`,display:`flex`,alignItems:`center`,padding:`0 0.75em`,height:`2.75em`},onClick:()=>{let e=t.dragInfo.current;if(e.dragging){e.dragging=!1;return}t.toggleExpanded()},onTouchStart:e=>{t.dragHandler(e)},onMouseDown:e=>{t.dragHandler(e)},children:e})})},Mg.Contents=function({children:e}){let t=b.useContext(jg);return(0,G.jsxs)(ki,{in:t.expanded,children:[(0,G.jsx)(hp,{mx:`xs`}),(0,G.jsx)(Vc.Autosize,{mah:t.maxHeight,children:(0,G.jsx)(q,{style:{width:t.width},children:e})})]})},Mg.HideWhenCollapsed=function({children:e}){return b.useContext(jg)?.expanded??!0?e:null},Mg.HideWhenExpanded=function({children:e}){return b.useContext(jg)?.expanded??!0?null:e};function Ng({id:e,label:t,children:n}){return(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsxs)(Wu,{align:`center`,children:[(0,G.jsx)(q,{pr:`xs`,style:{width:`7.25em`,flexShrink:0,position:`relative`},children:(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`100%`,boxSizing:`content-box`},children:(0,G.jsx)(`label`,{htmlFor:e,children:t})})}),(0,G.jsx)(q,{style:{flexGrow:1},children:n})]})})}function Pg({label:e,expandByDefault:t=!0,children:n}){let[r,{toggle:i}]=Ut(t);return(0,G.jsxs)(Xc,{withBorder:!0,style:{borderWidth:`1px`,position:`relative`,marginLeft:`var(--mantine-spacing-xs)`,marginRight:`var(--mantine-spacing-xs)`,marginTop:`var(--mantine-spacing-xs)`,marginBottom:`var(--mantine-spacing-xs)`,paddingBottom:`calc(var(--mantine-spacing-xs) - 0.5em)`},children:[(0,G.jsxs)(Xc,{onClick:i,style:{fontSize:`0.875em`,position:`absolute`,padding:`0 0.375em`,top:0,left:`0.375em`,transform:`translateY(-50%)`,userSelect:`none`,fontWeight:500,cursor:`pointer`,display:`flex`,alignItems:`center`},children:[e,(0,G.jsx)(r?xg:bg,{style:{width:`0.9em`,height:`0.9em`,strokeWidth:3,top:`0.1em`,position:`relative`,marginLeft:`0.25em`,marginRight:`-0.1em`,opacity:.5}})]}),(0,G.jsx)(ki,{in:r,children:(0,G.jsx)(q,{pt:`1em`,children:n})}),(0,G.jsx)(ki,{in:!r,children:(0,G.jsx)(q,{p:`xs`})})]})}var Fg={fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`4.5em`,flexShrink:0},Ig={root:{padding:`0`},track:{height:4},thumb:{width:12,height:12}},Lg={flex:1,minWidth:0,height:`1.75em`,fontSize:`0.8em`,fontFamily:`inherit`,border:`1px solid var(--mantine-color-default-border)`,borderRadius:`var(--mantine-radius-sm)`,background:`var(--mantine-color-default)`,color:`var(--mantine-color-text)`,textAlign:`right`,padding:`0 0.4em`,outline:`none`,cursor:`ns-resize`,touchAction:`none`};function Rg({axis:e,value:t,min:n=-1/0,max:r=1/0,step:i,onChange:a}){let o=(0,b.useRef)(null),s=(0,b.useRef)(null);(0,b.useEffect)(()=>{let e=o.current;e&&document.activeElement!==e&&(e.value=t.toFixed(2))},[t]);let c=e=>Math.max(n,Math.min(r,parseFloat((Math.round(e/i)*i).toFixed(10))));return(0,G.jsxs)(q,{style:{display:`flex`,alignItems:`center`,gap:`0.25em`,flex:1},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,letterSpacing:`-0.75px`,flexShrink:0},children:e}),(0,G.jsx)(`input`,{ref:o,size:1,defaultValue:t.toFixed(2),onPointerDown:e=>{e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),s.current={startY:e.clientY,startValue:t,moved:!1}},onPointerMove:e=>{if(!s.current||!(e.buttons&1))return;let t=s.current.startY-e.clientY;if(Math.abs(t)>3&&(s.current.moved=!0),!s.current.moved)return;let n=c(s.current.startValue+t*i);a(n),o.current&&(o.current.value=n.toFixed(2))},onPointerUp:()=>{if(s.current&&!s.current.moved){let e=o.current;e&&(e.focus(),e.select())}s.current=null},onBlur:e=>{let n=parseFloat(e.target.value);isNaN(n)||a(c(n)),e.target.value=t.toFixed(2)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&(o.current&&(o.current.value=t.toFixed(2)),o.current?.blur())},onFocus:e=>e.currentTarget.style.outline=`2px solid var(--mantine-color-blue-5)`,onBlurCapture:e=>e.currentTarget.style.outline=`none`,style:Lg})]})}function zg({label:e,x:t,y:n,z:r,step:i,xLabel:a=`X`,yLabel:o=`Y`,zLabel:s=`Z`,onX:c,onY:l,onZ:u}){return(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`,gap:`0.5em`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:Fg,children:e}),(0,G.jsx)(Rg,{axis:a,value:t,step:i,onChange:c}),(0,G.jsx)(Rg,{axis:o,value:n,step:i,onChange:l}),(0,G.jsx)(Rg,{axis:s,value:r,step:i,onChange:u})]})}function Bg({scale:e,xOffset:t,yOffset:n,zOffset:r,roll:i,pitch:a,yaw:o,onCalibrate:s}){let[c,l]=(0,b.useState)(e),[u,d]=(0,b.useState)(t),[f,p]=(0,b.useState)(n),[m,h]=(0,b.useState)(r),[g,_]=(0,b.useState)(i),[v,y]=(0,b.useState)(a),[x,S]=(0,b.useState)(o);(0,b.useEffect)(()=>{l(e)},[e]),(0,b.useEffect)(()=>{d(t)},[t]),(0,b.useEffect)(()=>{p(n)},[n]),(0,b.useEffect)(()=>{h(r)},[r]),(0,b.useEffect)(()=>{_(i)},[i]),(0,b.useEffect)(()=>{y(a)},[a]),(0,b.useEffect)(()=>{S(o)},[o]);let C=(e,t,n,r,i,a,o)=>s(e,t,n,r,i,a,o);return(0,G.jsxs)(Pg,{label:`Control`,expandByDefault:!0,children:[(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`,gap:`0.5em`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:Fg,children:`Scale`}),(0,G.jsx)(q,{style:{flex:1},children:(0,G.jsx)(fg,{value:c,onChange:e=>{l(e),C(e,u,f,m,g,v,x)},min:.1,max:5,step:.05,size:`xs`,label:e=>e.toFixed(2),styles:Ig})})]}),(0,G.jsx)(zg,{label:`Position`,x:u,y:f,z:m,step:.05,onX:e=>{d(e),C(c,e,f,m,g,v,x)},onY:e=>{p(e),C(c,u,e,m,g,v,x)},onZ:e=>{h(e),C(c,u,f,e,g,v,x)}}),(0,G.jsx)(zg,{label:`Rotation`,x:g,y:v,z:x,step:.5,xLabel:`R`,yLabel:`P`,zLabel:`Y`,onX:e=>{_(e),C(c,u,f,m,e,v,x)},onY:e=>{y(e),C(c,u,f,m,g,e,x)},onZ:e=>{S(e),C(c,u,f,m,g,v,e)}})]})}function Vg(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.closest(`input, textarea, select, [contenteditable], [role="textbox"], [role="searchbox"], [role="combobox"]`)!==null:!1}function Hg(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Ug({command:e,value:t,onChange:n,disabled:r,enabledWhenValue:i}){let a=e.enabledWhen!==void 0&&(i??0)<.5,o=r||a;return(0,G.jsxs)(q,{pb:`0.5em`,px:`xs`,style:{display:`flex`,alignItems:`center`},children:[(0,G.jsx)(Zu,{c:`dimmed`,style:{fontSize:`0.875em`,fontWeight:450,lineHeight:`1.375em`,letterSpacing:`-0.75px`,width:`50%`,flexShrink:0},children:e.label}),(0,G.jsx)(q,{style:{width:`50%`},children:(0,G.jsx)(fg,{value:t,onChange:t=>n(e.id,t),min:e.min,max:e.max,step:e.step,size:`xs`,disabled:o,styles:{root:{padding:`0`},track:{height:4},thumb:{width:12,height:12}}})})]})}function Wg({command:e,value:t,onChange:n,disabled:r}){return(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsx)(af,{label:e.label,checked:t>=.5,onChange:t=>n(e.id,+!!t.currentTarget.checked),size:`xs`,disabled:r})})}function Gg(e){let{visible:t,onVisibleChange:n,projects:r,projectValue:i,projectLabel:a,onProjectChange:o,scenes:s,sceneValue:c,onSceneChange:l,splats:u,splatSection:d=!1,splatValue:f,onSplatChange:p,splatConfig:m,onCalibrateSplat:h,onSplatUrlLoad:g,policies:_,policyValue:v,onPolicyChange:y,motions:x,motionValue:S,onMotionChange:C,showReferenceMotion:w,onShowReferenceMotionChange:T,commandsEnabled:E=!1,commands:D,commandValues:O,onCommandChange:k,onReset:A}=e,[j,{open:M,close:N}]=Ut(!1),[P,F]=(0,b.useState)(``),[I,L]=(0,b.useState)(null),[R,z]=(0,b.useState)(!1),B=(0,b.useCallback)(async e=>{if(e.key!==`Enter`||!g)return;let t=P.trim();if(!u.some(e=>e.label===t||e.value===t)){if(!t.toLowerCase().endsWith(`.spz`)){L(`URL must end with .spz`);return}await g(t)?(L(null),z(!0)):L(`File not found at the specified URL`)}},[g,P,u]),V=Array.from(new Set(D.map(e=>e.group))),ee=(0,b.useCallback)(()=>{A?.()},[A]);(0,b.useEffect)(()=>{let e=e=>{if(e.defaultPrevented||e.repeat||e.altKey||e.ctrlKey||e.metaKey)return;let r=e.key.toLowerCase();r!==`c`&&r!==`r`||Vg(e.target instanceof Element?e.target:document.activeElement)||(e.preventDefault(),r===`c`?n(!t):ee())};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[t,n,ee]);let te=e=>D.filter(t=>t.group===e&&(t.type===`slider`||t.type===`checkbox`));return!r.length&&!s.length&&!_.length?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Cm,{opened:j,onClose:N,size:`lg`,title:null,centered:!0,styles:{body:{textAlign:`center`}},children:(0,G.jsxs)(gg,{gap:`md`,align:`center`,children:[(0,G.jsx)(vp,{src:`/logo.svg`,style:{width:`8em`,height:`auto`}}),(0,G.jsx)(Zu,{size:`xl`,fw:700,children:`powered by mjswan`}),(0,G.jsxs)(Zu,{size:`sm`,c:`dimmed`,children:[`version `,Tg]}),(0,G.jsx)(Zu,{size:`sm`,c:`dimmed`,children:`MuJoco Simulation on Web Assembly with Neural netwroks`}),(0,G.jsx)(hp,{w:`100%`}),(0,G.jsxs)(q,{children:[(0,G.jsx)(ed,{href:`https://github.com/ttktjmt/mjswan`,target:`_blank`,style:{fontWeight:`600`},children:`GitHub`}),`\xA0\xA0•\xA0\xA0`,(0,G.jsx)(ed,{href:`https://mjswan.readthedocs.io`,target:`_blank`,style:{fontWeight:`600`},children:`Documentation`})]}),(0,G.jsx)(hp,{w:`100%`}),(0,G.jsxs)(q,{style:{textAlign:`left`,maxHeight:`120px`,overflowY:`auto`,lineHeight:`1`,fontSize:`0.8rem`,opacity:`0.75`},px:`md`,children:[`Thanks to our contributors! `,(0,G.jsx)(`br`,{}),Eg.map((e,t)=>(0,G.jsxs)(`span`,{children:[(0,G.jsx)(ed,{href:e.html_url,target:`_blank`,style:{textDecoration:`none`,fontSize:`0.75rem`},children:e.login}),t<Eg.length-1&&`, `]},e.login))]})]})}),(0,G.jsxs)(Mg,{width:`20em`,visible:t,onVisibleChange:n,hiddenButtonTooltip:`Show controls (C)`,children:[(0,G.jsxs)(Mg.Handle,{children:[(0,G.jsx)(Gh,{label:`mjswan ${Tg}`,children:(0,G.jsx)(q,{component:`a`,onClick:e=>{e.stopPropagation(),M()},onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),style:{position:`absolute`,cursor:`pointer`,display:`flex`,top:`0.8em`,left:`0.9em`},children:(0,G.jsx)(vp,{src:`/logo.svg`,style:{width:`1.2em`,height:`auto`}})})}),(0,G.jsx)(`div`,{style:{width:`1.1em`}}),(0,G.jsx)(Mg.HideWhenCollapsed,{children:(0,G.jsxs)(q,{px:`xs`,style:{flexGrow:1,letterSpacing:`-0.5px`,display:`flex`,alignItems:`center`,gap:`0.5em`},pt:`0.1em`,children:[(0,G.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:a}),r.length>1&&(0,G.jsxs)(om,{position:`bottom-start`,offset:5,children:[(0,G.jsx)(om.Target,{children:(0,G.jsx)(q,{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),style:{cursor:`pointer`,display:`flex`,alignItems:`center`,flexShrink:0},children:(0,G.jsx)(bg,{size:16})})}),(0,G.jsx)(om.Dropdown,{onClick:e=>e.stopPropagation(),children:r.map(e=>(0,G.jsx)(om.Item,{onClick:t=>{t.stopPropagation(),o(e.value)},style:{fontWeight:e.value===i?600:400,backgroundColor:e.value===i?`rgba(34, 139, 230, 0.1)`:void 0},children:e.label},e.value))})]})]})}),(0,G.jsx)(Mg.HideWhenExpanded,{children:(0,G.jsx)(q,{px:`xs`,style:{flexGrow:1,letterSpacing:`-0.5px`},pt:`0.1em`,children:a})}),(0,G.jsx)(Gh,{label:`Hide controls (C)`,children:(0,G.jsx)(ql,{variant:`subtle`,color:`gray`,size:`sm`,"aria-label":`Hide controls`,onClick:e=>{e.stopPropagation(),n(!1)},onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:(0,G.jsx)(Cg,{size:14})})})]}),(0,G.jsx)(Mg.Contents,{children:(0,G.jsxs)(q,{pt:`0.375em`,children:[s.length>0&&(0,G.jsx)(Ng,{id:`scene-select`,label:`Scene`,children:(0,G.jsx)(qh,{id:`scene-select`,placeholder:`Select scene`,data:s,value:c,onChange:l,size:`xs`,radius:`xs`,searchable:!0,clearable:!1,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),(u.length>0||d)&&(0,G.jsx)(Ng,{id:`splat-select`,label:`Splat`,children:(0,G.jsx)(Gh,{label:I??``,color:`red`,position:`bottom`,opened:I!==null,withArrow:!0,children:(0,G.jsx)(qh,{id:`splat-select`,placeholder:g===void 0?`Select splat`:`Select splat or paste .spz URL`,data:u,value:f,onChange:e=>{p(e),L(null),z(!1)},searchable:g!==void 0,searchValue:P,onSearchChange:e=>{F(e),e&&L(null)},onKeyDown:B,size:`xs`,radius:`xs`,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})})}),(m?.control&&f!==null||R)&&h&&(0,G.jsx)(Bg,{scale:m?.scale??1,xOffset:m?.xOffset??0,yOffset:m?.yOffset??0,zOffset:m?.zOffset??0,roll:m?.roll??0,pitch:m?.pitch??0,yaw:m?.yaw??0,onCalibrate:h}),_.length>0&&(0,G.jsx)(Ng,{id:`policy-select`,label:`Policy`,children:(0,G.jsx)(qh,{id:`policy-select`,placeholder:`Select policy`,data:_,value:v,onChange:y,size:`xs`,radius:`xs`,searchable:!0,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),x.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ng,{id:`motion-select`,label:`Motion`,children:(0,G.jsx)(qh,{id:`motion-select`,placeholder:`Select motion`,data:x,value:S,onChange:C,size:`xs`,radius:`xs`,searchable:!0,clearable:!0,styles:{input:{minHeight:`1.625rem`,height:`1.625rem`,padding:`0.5em`}},comboboxProps:{zIndex:1e3}})}),(0,G.jsx)(q,{pb:`0.5em`,px:`xs`,children:(0,G.jsx)(af,{label:`Show reference`,checked:w,onChange:e=>T(e.currentTarget.checked),size:`xs`})})]}),V.length>0&&D.some(e=>e.type===`slider`||e.type===`checkbox`)&&(0,G.jsx)(G.Fragment,{children:V.map(e=>{let t=te(e);return t.length===0?null:(0,G.jsx)(Pg,{label:Hg(e),expandByDefault:!0,children:t.map(e=>e.type===`checkbox`?(0,G.jsx)(Wg,{command:e,value:O[e.id]??0,onChange:k,disabled:!E},e.id):e.type===`slider`?(0,G.jsx)(Ug,{command:e,value:O[e.id]??0,onChange:k,disabled:!E,enabledWhenValue:e.enabledWhen?O[`${e.group}:${e.enabledWhen}`]:void 0},e.id):null)},e)})}),(0,G.jsx)(hp,{mb:`xs`,mx:`xs`}),(0,G.jsx)(q,{px:`xs`,pb:`xs`,children:(0,G.jsx)(xf,{variant:`light`,color:`red`,size:`xs`,fullWidth:!0,leftSection:(0,G.jsx)(Sg,{size:14}),onClick:ee,children:`Reset`})})]})})]})]})}function Kg(e,t,n){return Object.keys(e[t]).reduce((e,t)=>(e[t]=`var(--mantine-${n}-${t})`,e),{})}function qg(e,t){return e in t.breakpoints?t.breakpoints[e]:Be(e)}function Jg(e){let t=Wn(Ln,e),n=Kg(t,`fontSizes`,`font-size`),r=Kg(t,`lineHeights`,`line-height`),i=Kg(t,`shadows`,`shadow`),a=Kg(t,`radius`,`radius`),o=Kg(t,`spacing`,`spacing`),s=Object.keys(t.headings.sizes).reduce((e,t)=>(e[t]={fontSize:`var(--mantine-${t}-font-size)`,lineHeight:`var(--mantine-${t}-line-height)`,fontWeight:`var(--mantine-${t}-font-weight)`},e),{}),c=Object.keys(t.colors).reduce((e,t)=>(e[t]={0:`var(--mantine-color-${t}-0)`,1:`var(--mantine-color-${t}-1)`,2:`var(--mantine-color-${t}-2)`,3:`var(--mantine-color-${t}-3)`,4:`var(--mantine-color-${t}-4)`,5:`var(--mantine-color-${t}-5)`,6:`var(--mantine-color-${t}-6)`,7:`var(--mantine-color-${t}-7)`,8:`var(--mantine-color-${t}-8)`,9:`var(--mantine-color-${t}-9)`,filled:`var(--mantine-color-${t}-filled)`,filledHover:`var(--mantine-color-${t}-filled-hover)`,light:`var(--mantine-color-${t}-light)`,lightHover:`var(--mantine-color-${t}-light-hover)`,lightColor:`var(--mantine-color-${t}-light-color)`,outline:`var(--mantine-color-${t}-outline)`,outlineHover:`var(--mantine-color-${t}-outline-hover)`},e),{primary:`var(--mantine-primary-color-filled)`,primaryColors:{0:`var(--mantine-primary-color-0)`,1:`var(--mantine-primary-color-1)`,2:`var(--mantine-primary-color-2)`,3:`var(--mantine-primary-color-3)`,4:`var(--mantine-primary-color-4)`,5:`var(--mantine-primary-color-5)`,6:`var(--mantine-primary-color-6)`,7:`var(--mantine-primary-color-7)`,8:`var(--mantine-primary-color-8)`,9:`var(--mantine-primary-color-9)`,filled:`var(--mantine-primary-color-filled)`,filledHover:`var(--mantine-primary-color-filled-hover)`,light:`var(--mantine-primary-color-light)`,lightHover:`var(--mantine-primary-color-light-hover)`,lightColor:`var(--mantine-primary-color-light-color)`,outline:`var(--mantine-primary-color-outline)`,outlineHover:`var(--mantine-primary-color-outline-hover)`},white:`var(--mantine-color-white)`,black:`var(--mantine-color-black)`,text:`var(--mantine-color-text)`,body:`var(--mantine-color-body)`,error:`var(--mantine-color-error)`,placeholder:`var(--mantine-color-placeholder)`,anchor:`var(--mantine-color-anchor)`,default:`var(--mantine-color-default)`,defaultHover:`var(--mantine-color-default-hover)`,defaultColor:`var(--mantine-color-default-color)`,defaultBorder:`var(--mantine-color-default-border)`,dimmed:`var(--mantine-color-dimmed)`,disabledBody:`var(--mantine-color-disabled)`,disabledText:`var(--mantine-color-disabled-color)`,disabledBorder:`var(--mantine-color-disabled-border)`});return{scale:`var(--mantine-scale)`,cursorType:`var(--mantine-cursor-type)`,webkitFontSmoothing:`var(--mantine-webkit-font-smoothing)`,mozFontSmoothing:`var(--mantine-moz-font-smoothing)`,lineHeight:`var(--mantine-line-height)`,fontFamily:`var(--mantine-font-family)`,fontFamilyMonospace:`var(--mantine-font-family-monospace)`,fontFamilyHeadings:`var(--mantine-font-family-headings)`,headingFontWeight:`var(--mantine-heading-font-weight)`,radiusDefault:`var(--mantine-radius-default)`,breakpoints:t.breakpoints,fontSizes:n,lineHeights:r,shadows:i,radius:a,headings:s,spacing:o,colors:c,rtlSelector:`[dir="rtl"] &`,darkSelector:`[data-mantine-color-scheme="dark"] &`,lightSelector:`[data-mantine-color-scheme="light"] &`,smallerThan:e=>`(max-width: ${qg(e,t)})`,largerThan:e=>`(min-width: ${qg(e,t)})`}}var Yg=Nr({fontFamily:`Inter`,autoContrast:!0,components:{Checkbox:af.extend({defaultProps:{radius:`xs`}}),ColorInput:dp.extend({defaultProps:{radius:`xs`}}),Select:qh.extend({defaultProps:{radius:`sm`}}),Textarea:Hp.extend({defaultProps:{radius:`xs`}}),TextInput:_g.extend({defaultProps:{radius:`xs`}}),NumberInput:Dh.extend({defaultProps:{radius:`xs`}}),Paper:Xc.extend({defaultProps:{radius:`xs`,shadow:`0`}}),ActionIcon:ql.extend({defaultProps:{variant:`subtle`,color:`gray`,radius:`xs`}}),Button:xf.extend({defaultProps:{radius:`xs`,styles:{label:{fontWeight:450}}}})}});Jg(Yg);var Xg=(0,b.createContext)(void 0),Zg=()=>{let e=(0,b.useContext)(Xg);if(!e)throw Error(`useLoading must be used within a LoadingProvider`);return e},Qg=({children:e})=>{let[t,n]=(0,b.useState)(!1),[r,i]=(0,b.useState)(null),a=(0,b.useCallback)(e=>{e!==void 0&&i(e),n(!0)},[]),o=(0,b.useCallback)(e=>{i(e)},[]),s=(0,b.useCallback)(()=>{n(!1),i(null)},[]);return(0,G.jsx)(Xg.Provider,{value:{isLoading:t,loadingMessage:r,showLoading:a,setLoadingMessage:o,hideLoading:s},children:e})},$g=()=>{let{isLoading:e,loadingMessage:t}=Zg();return e?(0,G.jsx)(`div`,{className:`loader-overlay`,children:(0,G.jsxs)(`div`,{className:`loader-content`,children:[(0,G.jsx)(zl,{size:64,type:`bars`}),t&&(0,G.jsx)(`p`,{className:`loader-message`,children:t})]})}):null},e_=!1;function t_(){typeof window>`u`||(window.__mjswanReady=!0,e_||(e_=!0,window.dispatchEvent(new CustomEvent(`mjswan:ready`))))}function n_(){typeof window>`u`||(window.__mjswanError=!0)}var r_={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},i_={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},a_=`attached`,o_=`detached`,s_=1e3,c_=1001,l_=1002,u_=1003,d_=1004,f_=1004,p_=1005,m_=1005,h_=1006,g_=1007,__=1007,v_=1008,y_=1008,b_=1009,x_=1010,S_=1011,C_=1012,w_=1013,T_=1014,E_=1015,D_=1016,O_=1017,k_=1018,A_=1020,j_=35902,M_=35899,N_=1021,P_=1022,F_=1023,I_=1026,L_=1027,R_=1028,z_=1029,B_=1030,V_=1031,H_=1032,U_=1033,W_=33776,G_=33777,K_=33778,q_=33779,J_=35840,Y_=35841,X_=35842,Z_=35843,Q_=36196,$_=37492,ev=37496,tv=37808,nv=37809,rv=37810,iv=37811,av=37812,ov=37813,sv=37814,cv=37815,lv=37816,uv=37817,dv=37818,fv=37819,pv=37820,mv=37821,hv=36492,gv=36494,_v=36495,vv=36283,yv=36284,bv=36285,xv=36286,Sv=2200,Cv=2201,wv=2202,Tv=2300,Ev=2301,Dv=2302,Ov=2400,kv=2401,Av=2402,jv=2500,Mv=2501,Nv=3200,Pv=3201,Fv=3202,Iv=3203,Lv=`srgb`,Rv=`srgb-linear`,zv=`linear`,Bv=`srgb`,Vv=7680,Hv=7681,Uv=7682,Wv=7683,Gv=34055,Kv=34056,qv=5386,Jv=35044,Yv=35048,Xv=35040,Zv=35045,Qv=35049,$v=35041,ey=35046,ty=35050,ny=35042,ry=`300 es`,iy=2e3,ay=2001,oy={COMPUTE:`compute`,RENDER:`render`},sy={PERSPECTIVE:`perspective`,LINEAR:`linear`,FLAT:`flat`},cy={NORMAL:`normal`,CENTROID:`centroid`,SAMPLE:`sample`,FIRST:`first`,EITHER:`either`};function ly(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}var uy={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function dy(e,t){return new uy[e](t)}function fy(e){return document.createElementNS(`http://www.w3.org/1999/xhtml`,e)}function py(){let e=fy(`canvas`);return e.style.display=`block`,e}var my={},hy=null;function gy(e){hy=e}function _y(){return hy}function vy(...e){let t=`THREE.`+e.shift();hy?hy(`log`,t,...e):console.log(t,...e)}function yy(...e){let t=`THREE.`+e.shift();hy?hy(`warn`,t,...e):console.warn(t,...e)}function by(...e){let t=`THREE.`+e.shift();hy?hy(`error`,t,...e):console.error(t,...e)}function xy(...e){let t=e.join(` `);t in my||(my[t]=!0,yy(...e))}function Sy(e,t,n){return new Promise(function(r,i){function a(){switch(e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0)){case e.WAIT_FAILED:i();break;case e.TIMEOUT_EXPIRED:setTimeout(a,n);break;default:r()}}setTimeout(a,n)})}var Cy=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){let n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){let n=this._listeners;if(n===void 0)return;let r=n[e];if(r!==void 0){let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let n=t[e.type];if(n!==void 0){e.target=this;let t=n.slice(0);for(let n=0,r=t.length;n<r;n++)t[n].call(this,e);e.target=null}}},wy=`00.01.02.03.04.05.06.07.08.09.0a.0b.0c.0d.0e.0f.10.11.12.13.14.15.16.17.18.19.1a.1b.1c.1d.1e.1f.20.21.22.23.24.25.26.27.28.29.2a.2b.2c.2d.2e.2f.30.31.32.33.34.35.36.37.38.39.3a.3b.3c.3d.3e.3f.40.41.42.43.44.45.46.47.48.49.4a.4b.4c.4d.4e.4f.50.51.52.53.54.55.56.57.58.59.5a.5b.5c.5d.5e.5f.60.61.62.63.64.65.66.67.68.69.6a.6b.6c.6d.6e.6f.70.71.72.73.74.75.76.77.78.79.7a.7b.7c.7d.7e.7f.80.81.82.83.84.85.86.87.88.89.8a.8b.8c.8d.8e.8f.90.91.92.93.94.95.96.97.98.99.9a.9b.9c.9d.9e.9f.a0.a1.a2.a3.a4.a5.a6.a7.a8.a9.aa.ab.ac.ad.ae.af.b0.b1.b2.b3.b4.b5.b6.b7.b8.b9.ba.bb.bc.bd.be.bf.c0.c1.c2.c3.c4.c5.c6.c7.c8.c9.ca.cb.cc.cd.ce.cf.d0.d1.d2.d3.d4.d5.d6.d7.d8.d9.da.db.dc.dd.de.df.e0.e1.e2.e3.e4.e5.e6.e7.e8.e9.ea.eb.ec.ed.ee.ef.f0.f1.f2.f3.f4.f5.f6.f7.f8.f9.fa.fb.fc.fd.fe.ff`.split(`.`),Ty=1234567,Ey=Math.PI/180,Dy=180/Math.PI;function Oy(){let e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(wy[e&255]+wy[e>>8&255]+wy[e>>16&255]+wy[e>>24&255]+`-`+wy[t&255]+wy[t>>8&255]+`-`+wy[t>>16&15|64]+wy[t>>24&255]+`-`+wy[n&63|128]+wy[n>>8&255]+`-`+wy[n>>16&255]+wy[n>>24&255]+wy[r&255]+wy[r>>8&255]+wy[r>>16&255]+wy[r>>24&255]).toLowerCase()}function ky(e,t,n){return Math.max(t,Math.min(n,e))}function Ay(e,t){return(e%t+t)%t}function jy(e,t,n,r,i){return r+(e-t)*(i-r)/(n-t)}function My(e,t,n){return e===t?0:(n-e)/(t-e)}function Ny(e,t,n){return(1-n)*e+n*t}function Py(e,t,n,r){return Ny(e,t,1-Math.exp(-n*r))}function Fy(e,t=1){return t-Math.abs(Ay(e,t*2)-t)}function Iy(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*(3-2*e))}function Ly(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*e*(e*(e*6-15)+10))}function Ry(e,t){return e+Math.floor(Math.random()*(t-e+1))}function zy(e,t){return e+Math.random()*(t-e)}function By(e){return e*(.5-Math.random())}function Vy(e){e!==void 0&&(Ty=e);let t=Ty+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Hy(e){return e*Ey}function Uy(e){return e*Dy}function Wy(e){return(e&e-1)==0&&e!==0}function Gy(e){return 2**Math.ceil(Math.log(e)/Math.LN2)}function Ky(e){return 2**Math.floor(Math.log(e)/Math.LN2)}function qy(e,t,n,r,i){let a=Math.cos,o=Math.sin,s=a(n/2),c=o(n/2),l=a((t+r)/2),u=o((t+r)/2),d=a((t-r)/2),f=o((t-r)/2),p=a((r-t)/2),m=o((r-t)/2);switch(i){case`XYX`:e.set(s*u,c*d,c*f,s*l);break;case`YZY`:e.set(c*f,s*u,c*d,s*l);break;case`ZXZ`:e.set(c*d,c*f,s*u,s*l);break;case`XZX`:e.set(s*u,c*m,c*p,s*l);break;case`YXY`:e.set(c*p,s*u,c*m,s*l);break;case`ZYZ`:e.set(c*m,c*p,s*u,s*l);break;default:yy(`MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: `+i)}}function Jy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw Error(`Invalid component type.`)}}function Yy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw Error(`Invalid component type.`)}}var Xy={DEG2RAD:Ey,RAD2DEG:Dy,generateUUID:Oy,clamp:ky,euclideanModulo:Ay,mapLinear:jy,inverseLerp:My,lerp:Ny,damp:Py,pingpong:Fy,smoothstep:Iy,smootherstep:Ly,randInt:Ry,randFloat:zy,randFloatSpread:By,seededRandom:Vy,degToRad:Hy,radToDeg:Uy,isPowerOfTwo:Wy,ceilPowerOfTwo:Gy,floorPowerOfTwo:Ky,setQuaternionFromProperEuler:qy,normalize:Yy,denormalize:Jy},J=class e{constructor(t=0,n=0){e.prototype.isVector2=!0,this.x=t,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ky(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),r=Math.sin(t),i=this.x-e.x,a=this.y-e.y;return this.x=i*n-a*r+e.x,this.y=i*r+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Zy=class{constructor(e=0,t=0,n=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=r}static slerpFlat(e,t,n,r,i,a,o){let s=n[r+0],c=n[r+1],l=n[r+2],u=n[r+3],d=i[a+0],f=i[a+1],p=i[a+2],m=i[a+3];if(o<=0){e[t+0]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u;return}if(o>=1){e[t+0]=d,e[t+1]=f,e[t+2]=p,e[t+3]=m;return}if(u!==m||s!==d||c!==f||l!==p){let e=s*d+c*f+l*p+u*m;e<0&&(d=-d,f=-f,p=-p,m=-m,e=-e);let t=1-o;if(e<.9995){let n=Math.acos(e),r=Math.sin(n);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r,s=s*t+d*o,c=c*t+f*o,l=l*t+p*o,u=u*t+m*o}else{s=s*t+d*o,c=c*t+f*o,l=l*t+p*o,u=u*t+m*o;let e=1/Math.sqrt(s*s+c*c+l*l+u*u);s*=e,c*=e,l*=e,u*=e}}e[t]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,r,i,a){let o=n[r],s=n[r+1],c=n[r+2],l=n[r+3],u=i[a],d=i[a+1],f=i[a+2],p=i[a+3];return e[t]=o*p+l*u+s*f-c*d,e[t+1]=s*p+l*d+c*u-o*f,e[t+2]=c*p+l*f+o*d-s*u,e[t+3]=l*p-o*u-s*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,r){return this._x=e,this._y=t,this._z=n,this._w=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let n=e._x,r=e._y,i=e._z,a=e._order,o=Math.cos,s=Math.sin,c=o(n/2),l=o(r/2),u=o(i/2),d=s(n/2),f=s(r/2),p=s(i/2);switch(a){case`XYZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`YXZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`ZXY`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`ZYX`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`YZX`:this._x=d*l*u+c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u-d*f*p;break;case`XZY`:this._x=d*l*u-c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u+d*f*p;break;default:yy(`Quaternion: .setFromEuler() encountered an unknown order: `+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],r=t[4],i=t[8],a=t[1],o=t[5],s=t[9],c=t[2],l=t[6],u=t[10],d=n+o+u;if(d>0){let e=.5/Math.sqrt(d+1);this._w=.25/e,this._x=(l-s)*e,this._y=(i-c)*e,this._z=(a-r)*e}else if(n>o&&n>u){let e=2*Math.sqrt(1+n-o-u);this._w=(l-s)/e,this._x=.25*e,this._y=(r+a)/e,this._z=(i+c)/e}else if(o>u){let e=2*Math.sqrt(1+o-n-u);this._w=(i-c)/e,this._x=(r+a)/e,this._y=.25*e,this._z=(s+l)/e}else{let e=2*Math.sqrt(1+u-n-o);this._w=(a-r)/e,this._x=(i+c)/e,this._y=(s+l)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ky(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let r=Math.min(1,t/n);return this.slerp(e,r),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x*=e,this._y*=e,this._z*=e,this._w*=e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,r=e._y,i=e._z,a=e._w,o=t._x,s=t._y,c=t._z,l=t._w;return this._x=n*l+a*o+r*c-i*s,this._y=r*l+a*s+i*o-n*c,this._z=i*l+a*c+n*s-r*o,this._w=a*l-n*o-r*s-i*c,this._onChangeCallback(),this}slerp(e,t){if(t<=0)return this;if(t>=1)return this.copy(e);let n=e._x,r=e._y,i=e._z,a=e._w,o=this.dot(e);o<0&&(n=-n,r=-r,i=-i,a=-a,o=-o);let s=1-t;if(o<.9995){let e=Math.acos(o),c=Math.sin(e);s=Math.sin(s*e)/c,t=Math.sin(t*e)/c,this._x=this._x*s+n*t,this._y=this._y*s+r*t,this._z=this._z*s+i*t,this._w=this._w*s+a*t,this._onChangeCallback()}else this._x=this._x*s+n*t,this._y=this._y*s+r*t,this._z=this._z*s+i*t,this._w=this._w*s+a*t,this.normalize();return this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),r=Math.sqrt(1-n),i=Math.sqrt(n);return this.set(r*Math.sin(e),r*Math.cos(e),i*Math.sin(t),i*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},Y=class e{constructor(t=0,n=0,r=0){e.prototype.isVector3=!0,this.x=t,this.y=n,this.z=r}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion($y.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion($y.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6]*r,this.y=i[1]*t+i[4]*n+i[7]*r,this.z=i[2]*t+i[5]*n+i[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=e.elements,a=1/(i[3]*t+i[7]*n+i[11]*r+i[15]);return this.x=(i[0]*t+i[4]*n+i[8]*r+i[12])*a,this.y=(i[1]*t+i[5]*n+i[9]*r+i[13])*a,this.z=(i[2]*t+i[6]*n+i[10]*r+i[14])*a,this}applyQuaternion(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z,s=e.w,c=2*(a*r-o*n),l=2*(o*t-i*r),u=2*(i*n-a*t);return this.x=t+s*c+a*u-o*l,this.y=n+s*l+o*c-i*u,this.z=r+s*u+i*l-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[4]*n+i[8]*r,this.y=i[1]*t+i[5]*n+i[9]*r,this.z=i[2]*t+i[6]*n+i[10]*r,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this.z=ky(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this.z=ky(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,r=e.y,i=e.z,a=t.x,o=t.y,s=t.z;return this.x=r*s-i*o,this.y=i*a-n*s,this.z=n*o-r*a,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Qy.copy(this).projectOnVector(e),this.sub(Qy)}reflect(e){return this.sub(Qy.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ky(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Qy=new Y,$y=new Zy,eb=class e{constructor(t,n,r,i,a,o,s,c,l){e.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){let l=this.elements;return l[0]=e,l[1]=r,l[2]=o,l[3]=t,l[4]=i,l[5]=s,l[6]=n,l[7]=a,l[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],l=n[4],u=n[7],d=n[2],f=n[5],p=n[8],m=r[0],h=r[3],g=r[6],_=r[1],v=r[4],y=r[7],b=r[2],x=r[5],S=r[8];return i[0]=a*m+o*_+s*b,i[3]=a*h+o*v+s*x,i[6]=a*g+o*y+s*S,i[1]=c*m+l*_+u*b,i[4]=c*h+l*v+u*x,i[7]=c*g+l*y+u*S,i[2]=d*m+f*_+p*b,i[5]=d*h+f*v+p*x,i[8]=d*g+f*y+p*S,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8];return t*a*l-t*o*c-n*i*l+n*o*s+r*i*c-r*a*s}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=l*a-o*c,d=o*s-l*i,f=c*i-a*s,p=t*u+n*d+r*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/p;return e[0]=u*m,e[1]=(r*c-l*n)*m,e[2]=(o*n-r*a)*m,e[3]=d*m,e[4]=(l*t-r*s)*m,e[5]=(r*i-o*t)*m,e[6]=f*m,e[7]=(n*s-c*t)*m,e[8]=(a*t-n*i)*m,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,r,i,a,o){let s=Math.cos(i),c=Math.sin(i);return this.set(n*s,n*c,-n*(s*a+c*o)+a+e,-r*c,r*s,-r*(-c*a+s*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(tb.makeScale(e,t)),this}rotate(e){return this.premultiply(tb.makeRotation(-e)),this}translate(e,t){return this.premultiply(tb.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<9;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},tb=new eb,nb=new eb().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),rb=new eb().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function ib(){let e={enabled:!0,workingColorSpace:Rv,spaces:{},convert:function(e,t,n){return this.enabled===!1||t===n||!t||!n?e:(this.spaces[t].transfer===`srgb`&&(e.r=ob(e.r),e.g=ob(e.g),e.b=ob(e.b)),this.spaces[t].primaries!==this.spaces[n].primaries&&(e.applyMatrix3(this.spaces[t].toXYZ),e.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===`srgb`&&(e.r=sb(e.r),e.g=sb(e.g),e.b=sb(e.b)),e)},workingToColorSpace:function(e,t){return this.convert(e,this.workingColorSpace,t)},colorSpaceToWorking:function(e,t){return this.convert(e,t,this.workingColorSpace)},getPrimaries:function(e){return this.spaces[e].primaries},getTransfer:function(e){return e===``?zv:this.spaces[e].transfer},getToneMappingMode:function(e){return this.spaces[e].outputColorSpaceConfig.toneMappingMode||`standard`},getLuminanceCoefficients:function(e,t=this.workingColorSpace){return e.fromArray(this.spaces[t].luminanceCoefficients)},define:function(e){Object.assign(this.spaces,e)},_getMatrix:function(e,t,n){return e.copy(this.spaces[t].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(e){return this.spaces[e].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(e=this.workingColorSpace){return this.spaces[e].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(t,n){return xy(`ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace().`),e.workingToColorSpace(t,n)},toWorkingColorSpace:function(t,n){return xy(`ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking().`),e.colorSpaceToWorking(t,n)}},t=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],r=[.3127,.329];return e.define({[Rv]:{primaries:t,whitePoint:r,transfer:zv,toXYZ:nb,fromXYZ:rb,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:Lv},outputColorSpaceConfig:{drawingBufferColorSpace:Lv}},[Lv]:{primaries:t,whitePoint:r,transfer:Bv,toXYZ:nb,fromXYZ:rb,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:Lv}}}),e}var ab=ib();function ob(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}function sb(e){return e<.0031308?e*12.92:1.055*e**.41666-.055}var cb,lb=class{static getDataURL(e,t=`image/png`){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>`u`)return e.src;let n;if(e instanceof HTMLCanvasElement)n=e;else{cb===void 0&&(cb=fy(`canvas`)),cb.width=e.width,cb.height=e.height;let t=cb.getContext(`2d`);e instanceof ImageData?t.putImageData(e,0,0):t.drawImage(e,0,0,e.width,e.height),n=cb}return n.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let t=fy(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);n.drawImage(e,0,0,e.width,e.height);let r=n.getImageData(0,0,e.width,e.height),i=r.data;for(let e=0;e<i.length;e++)i[e]=ob(i[e]/255)*255;return n.putImageData(r,0,0),t}else if(e.data){let t=e.data.slice(0);for(let e=0;e<t.length;e++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[e]=Math.floor(ob(t[e]/255)*255):t[e]=ob(t[e]);return{data:t,width:e.width,height:e.height}}else return yy(`ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.`),e}},ub=0,db=class{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:ub++}),this.uuid=Oy(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<`u`&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):t instanceof VideoFrame?e.set(t.displayHeight,t.displayWidth,0):t===null?e.set(0,0,0):e.set(t.width,t.height,t.depth||0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let n={uuid:this.uuid,url:``},r=this.data;if(r!==null){let e;if(Array.isArray(r)){e=[];for(let t=0,n=r.length;t<n;t++)r[t].isDataTexture?e.push(fb(r[t].image)):e.push(fb(r[t]))}else e=fb(r);n.url=e}return t||(e.images[this.uuid]=n),n}};function fb(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap?lb.getDataURL(e):e.data?{data:Array.from(e.data),width:e.width,height:e.height,type:e.data.constructor.name}:(yy(`Texture: Unable to serialize Texture.`),{})}var pb=0,mb=new Y,hb=class e extends Cy{constructor(t=e.DEFAULT_IMAGE,n=e.DEFAULT_MAPPING,r=c_,i=c_,a=h_,o=v_,s=F_,c=b_,l=e.DEFAULT_ANISOTROPY,u=``){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:pb++}),this.uuid=Oy(),this.name=``,this.source=new db(t),this.mipmaps=[],this.mapping=n,this.channel=0,this.wrapS=r,this.wrapT=i,this.magFilter=a,this.minFilter=o,this.anisotropy=l,this.format=s,this.internalFormat=null,this.type=c,this.offset=new J(0,0),this.repeat=new J(1,1),this.center=new J(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new eb,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(mb).x}get height(){return this.source.getSize(mb).y}get depth(){return this.source.getSize(mb).z}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(let t in e){let n=e[t];if(n===void 0){yy(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){yy(`Texture.setValues(): property '${t}' does not exist.`);continue}r&&n&&r.isVector2&&n.isVector2||r&&n&&r.isVector3&&n.isVector3||r&&n&&r.isMatrix3&&n.isMatrix3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let n={metadata:{version:4.7,type:`Texture`,generator:`Texture.toJSON`},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:`dispose`})}transformUv(e){if(this.mapping!==300)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case s_:e.x-=Math.floor(e.x);break;case c_:e.x=e.x<0?0:1;break;case l_:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x-=Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case s_:e.y-=Math.floor(e.y);break;case c_:e.y=e.y<0?0:1;break;case l_:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y-=Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};hb.DEFAULT_IMAGE=null,hb.DEFAULT_MAPPING=300,hb.DEFAULT_ANISOTROPY=1;var gb=class e{constructor(t=0,n=0,r=0,i=1){e.prototype.isVector4=!0,this.x=t,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w===void 0?1:e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*r+a[12]*i,this.y=a[1]*t+a[5]*n+a[9]*r+a[13]*i,this.z=a[2]*t+a[6]*n+a[10]*r+a[14]*i,this.w=a[3]*t+a[7]*n+a[11]*r+a[15]*i,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,r,i,a=.01,o=.1,s=e.elements,c=s[0],l=s[4],u=s[8],d=s[1],f=s[5],p=s[9],m=s[2],h=s[6],g=s[10];if(Math.abs(l-d)<a&&Math.abs(u-m)<a&&Math.abs(p-h)<a){if(Math.abs(l+d)<o&&Math.abs(u+m)<o&&Math.abs(p+h)<o&&Math.abs(c+f+g-3)<o)return this.set(1,0,0,0),this;t=Math.PI;let e=(c+1)/2,s=(f+1)/2,_=(g+1)/2,v=(l+d)/4,y=(u+m)/4,b=(p+h)/4;return e>s&&e>_?e<a?(n=0,r=.707106781,i=.707106781):(n=Math.sqrt(e),r=v/n,i=y/n):s>_?s<a?(n=.707106781,r=0,i=.707106781):(r=Math.sqrt(s),n=v/r,i=b/r):_<a?(n=.707106781,r=.707106781,i=0):(i=Math.sqrt(_),n=y/i,r=b/i),this.set(n,r,i,t),this}let _=Math.sqrt((h-p)*(h-p)+(u-m)*(u-m)+(d-l)*(d-l));return Math.abs(_)<.001&&(_=1),this.x=(h-p)/_,this.y=(u-m)/_,this.z=(d-l)/_,this.w=Math.acos((c+f+g-1)/2),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ky(this.x,e.x,t.x),this.y=ky(this.y,e.y,t.y),this.z=ky(this.z,e.z,t.z),this.w=ky(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ky(this.x,e,t),this.y=ky(this.y,e,t),this.z=ky(this.z,e,t),this.w=ky(this.w,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ky(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},_b=class extends Cy{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:h_,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new gb(0,0,e,t),this.scissorTest=!1,this.viewport=new gb(0,0,e,t);let r=new hb({width:e,height:t,depth:n.depth});this.textures=[];let i=n.count;for(let e=0;e<i;e++)this.textures[e]=r.clone(),this.textures[e].isRenderTargetTexture=!0,this.textures[e].renderTarget=this;this._setTextureOptions(n),this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=n.depthTexture,this.samples=n.samples,this.multiview=n.multiview}_setTextureOptions(e={}){let t={minFilter:h_,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let e=0;e<this.textures.length;e++)this.textures[e].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let r=0,i=this.textures.length;r<i;r++)this.textures[r].image.width=e,this.textures[r].image.height=t,this.textures[r].image.depth=n,this.textures[r].isData3DTexture!==!0&&(this.textures[r].isArrayTexture=this.textures[r].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;let n=Object.assign({},e.textures[t].image);this.textures[t].source=new db(n)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:`dispose`})}},vb=class extends _b{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}},yb=class extends hb{constructor(e=null,t=1,n=1,r=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=u_,this.minFilter=u_,this.wrapR=c_,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}},bb=class extends vb{constructor(e=1,t=1,n=1,r={}){super(e,t,r),this.isWebGLArrayRenderTarget=!0,this.depth=n,this.texture=new yb(null,e,t,n),this._setTextureOptions(r),this.texture.isRenderTargetTexture=!0}},xb=class extends hb{constructor(e=null,t=1,n=1,r=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=u_,this.minFilter=u_,this.wrapR=c_,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},Sb=class extends vb{constructor(e=1,t=1,n=1,r={}){super(e,t,r),this.isWebGL3DRenderTarget=!0,this.depth=n,this.texture=new xb(null,e,t,n),this._setTextureOptions(r),this.texture.isRenderTargetTexture=!0}},Cb=class{constructor(e=new Y(1/0,1/0,1/0),t=new Y(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(Tb.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(Tb.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let n=Tb.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let n=e.geometry;if(n!==void 0){let r=n.getAttribute(`position`);if(t===!0&&r!==void 0&&e.isInstancedMesh!==!0)for(let t=0,n=r.count;t<n;t++)e.isMesh===!0?e.getVertexPosition(t,Tb):Tb.fromBufferAttribute(r,t),Tb.applyMatrix4(e.matrixWorld),this.expandByPoint(Tb);else e.boundingBox===void 0?(n.boundingBox===null&&n.computeBoundingBox(),Eb.copy(n.boundingBox)):(e.boundingBox===null&&e.computeBoundingBox(),Eb.copy(e.boundingBox)),Eb.applyMatrix4(e.matrixWorld),this.union(Eb)}let r=e.children;for(let e=0,n=r.length;e<n;e++)this.expandByObject(r[e],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Tb),Tb.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Nb),Pb.subVectors(this.max,Nb),Db.subVectors(e.a,Nb),Ob.subVectors(e.b,Nb),kb.subVectors(e.c,Nb),Ab.subVectors(Ob,Db),jb.subVectors(kb,Ob),Mb.subVectors(Db,kb);let t=[0,-Ab.z,Ab.y,0,-jb.z,jb.y,0,-Mb.z,Mb.y,Ab.z,0,-Ab.x,jb.z,0,-jb.x,Mb.z,0,-Mb.x,-Ab.y,Ab.x,0,-jb.y,jb.x,0,-Mb.y,Mb.x,0];return!Lb(t,Db,Ob,kb,Pb)||(t=[1,0,0,0,1,0,0,0,1],!Lb(t,Db,Ob,kb,Pb))?!1:(Fb.crossVectors(Ab,jb),t=[Fb.x,Fb.y,Fb.z],Lb(t,Db,Ob,kb,Pb))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Tb).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Tb).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(wb[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),wb[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),wb[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),wb[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),wb[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),wb[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),wb[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),wb[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(wb),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},wb=[new Y,new Y,new Y,new Y,new Y,new Y,new Y,new Y],Tb=new Y,Eb=new Cb,Db=new Y,Ob=new Y,kb=new Y,Ab=new Y,jb=new Y,Mb=new Y,Nb=new Y,Pb=new Y,Fb=new Y,Ib=new Y;function Lb(e,t,n,r,i){for(let a=0,o=e.length-3;a<=o;a+=3){Ib.fromArray(e,a);let o=i.x*Math.abs(Ib.x)+i.y*Math.abs(Ib.y)+i.z*Math.abs(Ib.z),s=t.dot(Ib),c=n.dot(Ib),l=r.dot(Ib);if(Math.max(-Math.max(s,c,l),Math.min(s,c,l))>o)return!1}return!0}var Rb=new Cb,zb=new Y,Bb=new Y,Vb=class{constructor(e=new Y,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t===void 0?Rb.setFromPoints(e).getCenter(n):n.copy(t);let r=0;for(let t=0,i=e.length;t<i;t++)r=Math.max(r,n.distanceToSquared(e[t]));return this.radius=Math.sqrt(r),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius*=e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;zb.subVectors(e,this.center);let t=zb.lengthSq();if(t>this.radius*this.radius){let e=Math.sqrt(t),n=(e-this.radius)*.5;this.center.addScaledVector(zb,n/e),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Bb.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(zb.copy(e.center).add(Bb)),this.expandByPoint(zb.copy(e.center).sub(Bb))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}},Hb=new Y,Ub=new Y,Wb=new Y,Gb=new Y,Kb=new Y,qb=new Y,Jb=new Y,Yb=class{constructor(e=new Y,t=new Y(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Hb)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=Hb.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Hb.copy(this.origin).addScaledVector(this.direction,t),Hb.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){Ub.copy(e).add(t).multiplyScalar(.5),Wb.copy(t).sub(e).normalize(),Gb.copy(this.origin).sub(Ub);let i=e.distanceTo(t)*.5,a=-this.direction.dot(Wb),o=Gb.dot(this.direction),s=-Gb.dot(Wb),c=Gb.lengthSq(),l=Math.abs(1-a*a),u,d,f,p;if(l>0)if(u=a*s-o,d=a*o-s,p=i*l,u>=0)if(d>=-p)if(d<=p){let e=1/l;u*=e,d*=e,f=u*(u+a*d+2*o)+d*(a*u+d+2*s)+c}else d=i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d=-i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d<=-p?(u=Math.max(0,-(-a*i+o)),d=u>0?-i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c):d<=p?(u=0,d=Math.min(Math.max(-i,-s),i),f=d*(d+2*s)+c):(u=Math.max(0,-(a*i+o)),d=u>0?i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c);else d=a>0?-i:i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),r&&r.copy(Ub).addScaledVector(Wb,d),f}intersectSphere(e,t){Hb.subVectors(e.center,this.origin);let n=Hb.dot(this.direction),r=Hb.dot(Hb)-n*n,i=e.radius*e.radius;if(r>i)return null;let a=Math.sqrt(i-r),o=n-a,s=n+a;return s<0?null:o<0?this.at(s,t):this.at(o,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,r,i,a,o,s,c=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,r=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,r=(e.min.x-d.x)*c),l>=0?(i=(e.min.y-d.y)*l,a=(e.max.y-d.y)*l):(i=(e.max.y-d.y)*l,a=(e.min.y-d.y)*l),n>a||i>r||((i>n||isNaN(n))&&(n=i),(a<r||isNaN(r))&&(r=a),u>=0?(o=(e.min.z-d.z)*u,s=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,s=(e.min.z-d.z)*u),n>s||o>r)||((o>n||n!==n)&&(n=o),(s<r||r!==r)&&(r=s),r<0)?null:this.at(n>=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,Hb)!==null}intersectTriangle(e,t,n,r,i){Kb.subVectors(t,e),qb.subVectors(n,e),Jb.crossVectors(Kb,qb);let a=this.direction.dot(Jb),o;if(a>0){if(r)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Gb.subVectors(this.origin,e);let s=o*this.direction.dot(qb.crossVectors(Gb,qb));if(s<0)return null;let c=o*this.direction.dot(Kb.cross(Gb));if(c<0||s+c>a)return null;let l=-o*Gb.dot(Jb);return l<0?null:this.at(l/a,i)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},Xb=class e{constructor(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){e.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this.elements;return g[0]=e,g[4]=t,g[8]=n,g[12]=r,g[1]=i,g[5]=a,g[9]=o,g[13]=s,g[2]=c,g[6]=l,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=m,g[15]=h,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new e().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,r=1/Zb.setFromMatrixColumn(e,0).length(),i=1/Zb.setFromMatrixColumn(e,1).length(),a=1/Zb.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=0,t[4]=n[4]*i,t[5]=n[5]*i,t[6]=n[6]*i,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,r=e.y,i=e.z,a=Math.cos(n),o=Math.sin(n),s=Math.cos(r),c=Math.sin(r),l=Math.cos(i),u=Math.sin(i);if(e.order===`XYZ`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=-s*u,t[8]=c,t[1]=n+r*c,t[5]=e-i*c,t[9]=-o*s,t[2]=i-e*c,t[6]=r+n*c,t[10]=a*s}else if(e.order===`YXZ`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e+i*o,t[4]=r*o-n,t[8]=a*c,t[1]=a*u,t[5]=a*l,t[9]=-o,t[2]=n*o-r,t[6]=i+e*o,t[10]=a*s}else if(e.order===`ZXY`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e-i*o,t[4]=-a*u,t[8]=r+n*o,t[1]=n+r*o,t[5]=a*l,t[9]=i-e*o,t[2]=-a*c,t[6]=o,t[10]=a*s}else if(e.order===`ZYX`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=r*c-n,t[8]=e*c+i,t[1]=s*u,t[5]=i*c+e,t[9]=n*c-r,t[2]=-c,t[6]=o*s,t[10]=a*s}else if(e.order===`YZX`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=i-e*u,t[8]=r*u+n,t[1]=u,t[5]=a*l,t[9]=-o*l,t[2]=-c*l,t[6]=n*u+r,t[10]=e-i*u}else if(e.order===`XZY`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=-u,t[8]=c*l,t[1]=e*u+i,t[5]=a*l,t[9]=n*u-r,t[2]=r*u-n,t[6]=o*l,t[10]=i*u+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose($b,e,ex)}lookAt(e,t,n){let r=this.elements;return rx.subVectors(e,t),rx.lengthSq()===0&&(rx.z=1),rx.normalize(),tx.crossVectors(n,rx),tx.lengthSq()===0&&(Math.abs(n.z)===1?rx.x+=1e-4:rx.z+=1e-4,rx.normalize(),tx.crossVectors(n,rx)),tx.normalize(),nx.crossVectors(rx,tx),r[0]=tx.x,r[4]=nx.x,r[8]=rx.x,r[1]=tx.y,r[5]=nx.y,r[9]=rx.y,r[2]=tx.z,r[6]=nx.z,r[10]=rx.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[4],s=n[8],c=n[12],l=n[1],u=n[5],d=n[9],f=n[13],p=n[2],m=n[6],h=n[10],g=n[14],_=n[3],v=n[7],y=n[11],b=n[15],x=r[0],S=r[4],C=r[8],w=r[12],T=r[1],E=r[5],D=r[9],O=r[13],k=r[2],A=r[6],j=r[10],M=r[14],N=r[3],P=r[7],F=r[11],I=r[15];return i[0]=a*x+o*T+s*k+c*N,i[4]=a*S+o*E+s*A+c*P,i[8]=a*C+o*D+s*j+c*F,i[12]=a*w+o*O+s*M+c*I,i[1]=l*x+u*T+d*k+f*N,i[5]=l*S+u*E+d*A+f*P,i[9]=l*C+u*D+d*j+f*F,i[13]=l*w+u*O+d*M+f*I,i[2]=p*x+m*T+h*k+g*N,i[6]=p*S+m*E+h*A+g*P,i[10]=p*C+m*D+h*j+g*F,i[14]=p*w+m*O+h*M+g*I,i[3]=_*x+v*T+y*k+b*N,i[7]=_*S+v*E+y*A+b*P,i[11]=_*C+v*D+y*j+b*F,i[15]=_*w+v*O+y*M+b*I,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],r=e[8],i=e[12],a=e[1],o=e[5],s=e[9],c=e[13],l=e[2],u=e[6],d=e[10],f=e[14],p=e[3],m=e[7],h=e[11],g=e[15];return p*(+i*s*u-r*c*u-i*o*d+n*c*d+r*o*f-n*s*f)+m*(+t*s*f-t*c*d+i*a*d-r*a*f+r*c*l-i*s*l)+h*(+t*c*u-t*o*f-i*a*u+n*a*f+i*o*l-n*c*l)+g*(-r*o*l-t*s*u+t*o*d+r*a*u-n*a*d+n*s*l)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=u*h*c-m*d*c+m*s*f-o*h*f-u*s*g+o*d*g,v=p*d*c-l*h*c-p*s*f+a*h*f+l*s*g-a*d*g,y=l*m*c-p*u*c+p*o*f-a*m*f-l*o*g+a*u*g,b=p*u*s-l*m*s-p*o*d+a*m*d+l*o*h-a*u*h,x=t*_+n*v+r*y+i*b;if(x===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let S=1/x;return e[0]=_*S,e[1]=(m*d*i-u*h*i-m*r*f+n*h*f+u*r*g-n*d*g)*S,e[2]=(o*h*i-m*s*i+m*r*c-n*h*c-o*r*g+n*s*g)*S,e[3]=(u*s*i-o*d*i-u*r*c+n*d*c+o*r*f-n*s*f)*S,e[4]=v*S,e[5]=(l*h*i-p*d*i+p*r*f-t*h*f-l*r*g+t*d*g)*S,e[6]=(p*s*i-a*h*i-p*r*c+t*h*c+a*r*g-t*s*g)*S,e[7]=(a*d*i-l*s*i+l*r*c-t*d*c-a*r*f+t*s*f)*S,e[8]=y*S,e[9]=(p*u*i-l*m*i-p*n*f+t*m*f+l*n*g-t*u*g)*S,e[10]=(a*m*i-p*o*i+p*n*c-t*m*c-a*n*g+t*o*g)*S,e[11]=(l*o*i-a*u*i-l*n*c+t*u*c+a*n*f-t*o*f)*S,e[12]=b*S,e[13]=(l*m*r-p*u*r+p*n*d-t*m*d-l*n*h+t*u*h)*S,e[14]=(p*o*r-a*m*r-p*n*s+t*m*s+a*n*h-t*o*h)*S,e[15]=(a*u*r-l*o*r+l*n*s-t*u*s-a*n*d+t*o*d)*S,this}scale(e){let t=this.elements,n=e.x,r=e.y,i=e.z;return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),r=Math.sin(t),i=1-n,a=e.x,o=e.y,s=e.z,c=i*a,l=i*o;return this.set(c*a+n,c*o-r*s,c*s+r*o,0,c*o+r*s,l*o+n,l*s-r*a,0,c*s-r*o,l*s+r*a,i*s*s+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,r,i,a){return this.set(1,n,i,0,e,1,a,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){let r=this.elements,i=t._x,a=t._y,o=t._z,s=t._w,c=i+i,l=a+a,u=o+o,d=i*c,f=i*l,p=i*u,m=a*l,h=a*u,g=o*u,_=s*c,v=s*l,y=s*u,b=n.x,x=n.y,S=n.z;return r[0]=(1-(m+g))*b,r[1]=(f+y)*b,r[2]=(p-v)*b,r[3]=0,r[4]=(f-y)*x,r[5]=(1-(d+g))*x,r[6]=(h+_)*x,r[7]=0,r[8]=(p+v)*S,r[9]=(h-_)*S,r[10]=(1-(d+m))*S,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){let r=this.elements,i=Zb.set(r[0],r[1],r[2]).length(),a=Zb.set(r[4],r[5],r[6]).length(),o=Zb.set(r[8],r[9],r[10]).length();this.determinant()<0&&(i=-i),e.x=r[12],e.y=r[13],e.z=r[14],Qb.copy(this);let s=1/i,c=1/a,l=1/o;return Qb.elements[0]*=s,Qb.elements[1]*=s,Qb.elements[2]*=s,Qb.elements[4]*=c,Qb.elements[5]*=c,Qb.elements[6]*=c,Qb.elements[8]*=l,Qb.elements[9]*=l,Qb.elements[10]*=l,t.setFromRotationMatrix(Qb),n.x=i,n.y=a,n.z=o,this}makePerspective(e,t,n,r,i,a,o=iy,s=!1){let c=this.elements,l=2*i/(t-e),u=2*i/(n-r),d=(t+e)/(t-e),f=(n+r)/(n-r),p,m;if(s)p=i/(a-i),m=a*i/(a-i);else if(o===2e3)p=-(a+i)/(a-i),m=-2*a*i/(a-i);else if(o===2001)p=-a/(a-i),m=-a*i/(a-i);else throw Error(`THREE.Matrix4.makePerspective(): Invalid coordinate system: `+o);return c[0]=l,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=u,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,r,i,a,o=iy,s=!1){let c=this.elements,l=2/(t-e),u=2/(n-r),d=-(t+e)/(t-e),f=-(n+r)/(n-r),p,m;if(s)p=1/(a-i),m=a/(a-i);else if(o===2e3)p=-2/(a-i),m=-(a+i)/(a-i);else if(o===2001)p=-1/(a-i),m=-i/(a-i);else throw Error(`THREE.Matrix4.makeOrthographic(): Invalid coordinate system: `+o);return c[0]=l,c[4]=0,c[8]=0,c[12]=d,c[1]=0,c[5]=u,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<16;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Zb=new Y,Qb=new Xb,$b=new Y(0,0,0),ex=new Y(1,1,1),tx=new Y,nx=new Y,rx=new Y,ix=new Xb,ax=new Zy,ox=class e{constructor(t=0,n=0,r=0,i=e.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let r=e.elements,i=r[0],a=r[4],o=r[8],s=r[1],c=r[5],l=r[9],u=r[2],d=r[6],f=r[10];switch(t){case`XYZ`:this._y=Math.asin(ky(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,f),this._z=Math.atan2(-a,i)):(this._x=Math.atan2(d,c),this._z=0);break;case`YXZ`:this._x=Math.asin(-ky(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(s,c)):(this._y=Math.atan2(-u,i),this._z=0);break;case`ZXY`:this._x=Math.asin(ky(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(s,i));break;case`ZYX`:this._y=Math.asin(-ky(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(s,i)):(this._x=0,this._z=Math.atan2(-a,c));break;case`YZX`:this._z=Math.asin(ky(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-l,c),this._y=Math.atan2(-u,i)):(this._x=0,this._y=Math.atan2(o,f));break;case`XZY`:this._z=Math.asin(-ky(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,i)):(this._x=Math.atan2(-l,f),this._y=0);break;default:yy(`Euler: .setFromRotationMatrix() encountered an unknown order: `+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return ix.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ix,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ax.setFromEuler(this),this.setFromQuaternion(ax,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};ox.DEFAULT_ORDER=`XYZ`;var sx=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!=0}},cx=0,lx=new Y,ux=new Zy,dx=new Xb,fx=new Y,px=new Y,mx=new Y,hx=new Zy,gx=new Y(1,0,0),_x=new Y(0,1,0),vx=new Y(0,0,1),yx={type:`added`},bx={type:`removed`},xx={type:`childadded`,child:null},Sx={type:`childremoved`,child:null},Cx=class e extends Cy{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cx++}),this.uuid=Oy(),this.name=``,this.type=`Object3D`,this.parent=null,this.children=[],this.up=e.DEFAULT_UP.clone();let t=new Y,n=new ox,r=new Zy,i=new Y(1,1,1);function a(){r.setFromEuler(n,!1)}function o(){n.setFromQuaternion(r,void 0,!1)}n._onChange(a),r._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:n},quaternion:{configurable:!0,enumerable:!0,value:r},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new Xb},normalMatrix:{value:new eb}}),this.matrix=new Xb,this.matrixWorld=new Xb,this.matrixAutoUpdate=e.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=e.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new sx,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return ux.setFromAxisAngle(e,t),this.quaternion.multiply(ux),this}rotateOnWorldAxis(e,t){return ux.setFromAxisAngle(e,t),this.quaternion.premultiply(ux),this}rotateX(e){return this.rotateOnAxis(gx,e)}rotateY(e){return this.rotateOnAxis(_x,e)}rotateZ(e){return this.rotateOnAxis(vx,e)}translateOnAxis(e,t){return lx.copy(e).applyQuaternion(this.quaternion),this.position.add(lx.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(gx,e)}translateY(e){return this.translateOnAxis(_x,e)}translateZ(e){return this.translateOnAxis(vx,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(dx.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?fx.copy(e):fx.set(e,t,n);let r=this.parent;this.updateWorldMatrix(!0,!1),px.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?dx.lookAt(px,fx,this.up):dx.lookAt(fx,px,this.up),this.quaternion.setFromRotationMatrix(dx),r&&(dx.extractRotation(r.matrixWorld),ux.setFromRotationMatrix(dx),this.quaternion.premultiply(ux.invert()))}add(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return e===this?(by(`Object3D.add: object can't be added as a child of itself.`,e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(yx),xx.child=e,this.dispatchEvent(xx),xx.child=null):by(`Object3D.add: object not an instance of THREE.Object3D.`,e),this)}remove(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.remove(arguments[e]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(bx),Sx.child=e,this.dispatchEvent(Sx),Sx.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),dx.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),dx.multiply(e.parent.matrixWorld)),e.applyMatrix4(dx),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(yx),xx.child=e,this.dispatchEvent(xx),xx.child=null,this}getObjectById(e){return this.getObjectByProperty(`id`,e)}getObjectByName(e){return this.getObjectByProperty(`name`,e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,r=this.children.length;n<r;n++){let r=this.children[n].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);let r=this.children;for(let i=0,a=r.length;i<a;i++)r[i].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(px,e,mx),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(px,hx,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t){let n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),t===!0){let e=this.children;for(let t=0,n=e.length;t<n;t++)e[t].updateWorldMatrix(!1,!0)}}toJSON(e){let t=e===void 0||typeof e==`string`,n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:`Object`,generator:`Object3D.toJSON`});let r={};r.uuid=this.uuid,r.type=this.type,this.name!==``&&(r.name=this.name),this.castShadow===!0&&(r.castShadow=!0),this.receiveShadow===!0&&(r.receiveShadow=!0),this.visible===!1&&(r.visible=!1),this.frustumCulled===!1&&(r.frustumCulled=!1),this.renderOrder!==0&&(r.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.isInstancedMesh&&(r.type=`InstancedMesh`,r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type=`BatchedMesh`,r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.geometryInfo=this._geometryInfo.map(e=>({...e,boundingBox:e.boundingBox?e.boundingBox.toJSON():void 0,boundingSphere:e.boundingSphere?e.boundingSphere.toJSON():void 0})),r.instanceInfo=this._instanceInfo.map(e=>({...e})),r.availableInstanceIds=this._availableInstanceIds.slice(),r.availableGeometryIds=this._availableGeometryIds.slice(),r.nextIndexStart=this._nextIndexStart,r.nextVertexStart=this._nextVertexStart,r.geometryCount=this._geometryCount,r.maxInstanceCount=this._maxInstanceCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.matricesTexture=this._matricesTexture.toJSON(e),r.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(r.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(r.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(r.boundingBox=this.boundingBox.toJSON()));function i(t,n){return t[n.uuid]===void 0&&(t[n.uuid]=n.toJSON(e)),n.uuid}if(this.isScene)this.background&&(this.background.isColor?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.geometry=i(e.geometries,this.geometry);let t=this.geometry.parameters;if(t!==void 0&&t.shapes!==void 0){let n=t.shapes;if(Array.isArray(n))for(let t=0,r=n.length;t<r;t++){let r=n[t];i(e.shapes,r)}else i(e.shapes,n)}}if(this.isSkinnedMesh&&(r.bindMode=this.bindMode,r.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(i(e.skeletons,this.skeleton),r.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let t=[];for(let n=0,r=this.material.length;n<r;n++)t.push(i(e.materials,this.material[n]));r.material=t}else r.material=i(e.materials,this.material);if(this.children.length>0){r.children=[];for(let t=0;t<this.children.length;t++)r.children.push(this.children[t].toJSON(e).object)}if(this.animations.length>0){r.animations=[];for(let t=0;t<this.animations.length;t++){let n=this.animations[t];r.animations.push(i(e.animations,n))}}if(t){let t=a(e.geometries),r=a(e.materials),i=a(e.textures),o=a(e.images),s=a(e.shapes),c=a(e.skeletons),l=a(e.animations),u=a(e.nodes);t.length>0&&(n.geometries=t),r.length>0&&(n.materials=r),i.length>0&&(n.textures=i),o.length>0&&(n.images=o),s.length>0&&(n.shapes=s),c.length>0&&(n.skeletons=c),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=r,n;function a(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let t=0;t<e.children.length;t++){let n=e.children[t];this.add(n.clone())}return this}};Cx.DEFAULT_UP=new Y(0,1,0),Cx.DEFAULT_MATRIX_AUTO_UPDATE=!0,Cx.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var wx=new Y,Tx=new Y,Ex=new Y,Dx=new Y,Ox=new Y,kx=new Y,Ax=new Y,jx=new Y,Mx=new Y,Nx=new Y,Px=new gb,Fx=new gb,Ix=new gb,Lx=class e{constructor(e=new Y,t=new Y,n=new Y){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,r){r.subVectors(n,t),wx.subVectors(e,t),r.cross(wx);let i=r.lengthSq();return i>0?r.multiplyScalar(1/Math.sqrt(i)):r.set(0,0,0)}static getBarycoord(e,t,n,r,i){wx.subVectors(r,t),Tx.subVectors(n,t),Ex.subVectors(e,t);let a=wx.dot(wx),o=wx.dot(Tx),s=wx.dot(Ex),c=Tx.dot(Tx),l=Tx.dot(Ex),u=a*c-o*o;if(u===0)return i.set(0,0,0),null;let d=1/u,f=(c*s-o*l)*d,p=(a*l-o*s)*d;return i.set(1-f-p,p,f)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,Dx)===null?!1:Dx.x>=0&&Dx.y>=0&&Dx.x+Dx.y<=1}static getInterpolation(e,t,n,r,i,a,o,s){return this.getBarycoord(e,t,n,r,Dx)===null?(s.x=0,s.y=0,`z`in s&&(s.z=0),`w`in s&&(s.w=0),null):(s.setScalar(0),s.addScaledVector(i,Dx.x),s.addScaledVector(a,Dx.y),s.addScaledVector(o,Dx.z),s)}static getInterpolatedAttribute(e,t,n,r,i,a){return Px.setScalar(0),Fx.setScalar(0),Ix.setScalar(0),Px.fromBufferAttribute(e,t),Fx.fromBufferAttribute(e,n),Ix.fromBufferAttribute(e,r),a.setScalar(0),a.addScaledVector(Px,i.x),a.addScaledVector(Fx,i.y),a.addScaledVector(Ix,i.z),a}static isFrontFacing(e,t,n,r){return wx.subVectors(n,t),Tx.subVectors(e,t),wx.cross(Tx).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return wx.subVectors(this.c,this.b),Tx.subVectors(this.a,this.b),wx.cross(Tx).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return e.getNormal(this.a,this.b,this.c,t)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,n){return e.getBarycoord(t,this.a,this.b,this.c,n)}getInterpolation(t,n,r,i,a){return e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}containsPoint(t){return e.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return e.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,r=this.b,i=this.c,a,o;Ox.subVectors(r,n),kx.subVectors(i,n),jx.subVectors(e,n);let s=Ox.dot(jx),c=kx.dot(jx);if(s<=0&&c<=0)return t.copy(n);Mx.subVectors(e,r);let l=Ox.dot(Mx),u=kx.dot(Mx);if(l>=0&&u<=l)return t.copy(r);let d=s*u-l*c;if(d<=0&&s>=0&&l<=0)return a=s/(s-l),t.copy(n).addScaledVector(Ox,a);Nx.subVectors(e,i);let f=Ox.dot(Nx),p=kx.dot(Nx);if(p>=0&&f<=p)return t.copy(i);let m=f*c-s*p;if(m<=0&&c>=0&&p<=0)return o=c/(c-p),t.copy(n).addScaledVector(kx,o);let h=l*p-f*u;if(h<=0&&u-l>=0&&f-p>=0)return Ax.subVectors(i,r),o=(u-l)/(u-l+(f-p)),t.copy(r).addScaledVector(Ax,o);let g=1/(h+m+d);return a=m*g,o=d*g,t.copy(n).addScaledVector(Ox,a).addScaledVector(kx,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},Rx={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},zx={h:0,s:0,l:0},Bx={h:0,s:0,l:0};function Vx(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*6*(2/3-n):e}var X=class{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let t=e;t&&t.isColor?this.copy(t):typeof t==`number`?this.setHex(t):typeof t==`string`&&this.setStyle(t)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Lv){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,ab.colorSpaceToWorking(this,t),this}setRGB(e,t,n,r=ab.workingColorSpace){return this.r=e,this.g=t,this.b=n,ab.colorSpaceToWorking(this,r),this}setHSL(e,t,n,r=ab.workingColorSpace){if(e=Ay(e,1),t=ky(t,0,1),n=ky(n,0,1),t===0)this.r=this.g=this.b=n;else{let r=n<=.5?n*(1+t):n+t-n*t,i=2*n-r;this.r=Vx(i,r,e+1/3),this.g=Vx(i,r,e),this.b=Vx(i,r,e-1/3)}return ab.colorSpaceToWorking(this,r),this}setStyle(e,t=Lv){function n(t){t!==void 0&&parseFloat(t)<1&&yy(`Color: Alpha component of `+e+` will be ignored.`)}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let i,a=r[1],o=r[2];switch(a){case`rgb`:case`rgba`:if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,t);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,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(o))return n(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,t);break;default:yy(`Color: Unknown color model `+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){let n=r[1],i=n.length;if(i===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(i===6)return this.setHex(parseInt(n,16),t);yy(`Color: Invalid hex color `+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Lv){let n=Rx[e.toLowerCase()];return n===void 0?yy(`Color: Unknown color `+e):this.setHex(n,t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=ob(e.r),this.g=ob(e.g),this.b=ob(e.b),this}copyLinearToSRGB(e){return this.r=sb(e.r),this.g=sb(e.g),this.b=sb(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Lv){return ab.workingToColorSpace(Hx.copy(this),e),Math.round(ky(Hx.r*255,0,255))*65536+Math.round(ky(Hx.g*255,0,255))*256+Math.round(ky(Hx.b*255,0,255))}getHexString(e=Lv){return(`000000`+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=ab.workingColorSpace){ab.workingToColorSpace(Hx.copy(this),t);let n=Hx.r,r=Hx.g,i=Hx.b,a=Math.max(n,r,i),o=Math.min(n,r,i),s,c,l=(o+a)/2;if(o===a)s=0,c=0;else{let e=a-o;switch(c=l<=.5?e/(a+o):e/(2-a-o),a){case n:s=(r-i)/e+(r<i?6:0);break;case r:s=(i-n)/e+2;break;case i:s=(n-r)/e+4;break}s/=6}return e.h=s,e.s=c,e.l=l,e}getRGB(e,t=ab.workingColorSpace){return ab.workingToColorSpace(Hx.copy(this),t),e.r=Hx.r,e.g=Hx.g,e.b=Hx.b,e}getStyle(e=Lv){ab.workingToColorSpace(Hx.copy(this),e);let t=Hx.r,n=Hx.g,r=Hx.b;return e===`srgb`?`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(r*255)})`:`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${r.toFixed(3)})`}offsetHSL(e,t,n){return this.getHSL(zx),this.setHSL(zx.h+e,zx.s+t,zx.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(zx),e.getHSL(Bx);let n=Ny(zx.h,Bx.h,t),r=Ny(zx.s,Bx.s,t),i=Ny(zx.l,Bx.l,t);return this.setHSL(n,r,i),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,n=this.g,r=this.b,i=e.elements;return this.r=i[0]*t+i[3]*n+i[6]*r,this.g=i[1]*t+i[4]*n+i[7]*r,this.b=i[2]*t+i[5]*n+i[8]*r,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},Hx=new X;X.NAMES=Rx;var Ux=0,Wx=class extends Cy{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Ux++}),this.uuid=Oy(),this.name=``,this.type=`Material`,this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=204,this.blendDst=205,this.blendEquation=100,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new X(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Vv,this.stencilZFail=Vv,this.stencilZPass=Vv,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let n=e[t];if(n===void 0){yy(`Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){yy(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector3&&n&&n.isVector3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;t&&(e={textures:{},images:{}});let n={metadata:{version:4.7,type:`Material`,generator:`Material.toJSON`}};n.uuid=this.uuid,n.type=this.type,this.name!==``&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==1&&(n.blending=this.blending),this.side!==0&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==204&&(n.blendSrc=this.blendSrc),this.blendDst!==205&&(n.blendDst=this.blendDst),this.blendEquation!==100&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==3&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==519&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==7680&&(n.stencilFail=this.stencilFail),this.stencilZFail!==7680&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==7680&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!==`round`&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!==`round`&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}if(t){let t=r(e.textures),i=r(e.images);t.length>0&&(n.textures=t),i.length>0&&(n.images=i)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let e=t.length;n=Array(e);for(let r=0;r!==e;++r)n[r]=t[r].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:`dispose`})}set needsUpdate(e){e===!0&&this.version++}},Gx=class extends Wx{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type=`MeshBasicMaterial`,this.color=new X(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ox,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Kx=qx();function qx(){let e=new ArrayBuffer(4),t=new Float32Array(e),n=new Uint32Array(e),r=new Uint32Array(512),i=new Uint32Array(512);for(let e=0;e<256;++e){let t=e-127;t<-27?(r[e]=0,r[e|256]=32768,i[e]=24,i[e|256]=24):t<-14?(r[e]=1024>>-t-14,r[e|256]=1024>>-t-14|32768,i[e]=-t-1,i[e|256]=-t-1):t<=15?(r[e]=t+15<<10,r[e|256]=t+15<<10|32768,i[e]=13,i[e|256]=13):t<128?(r[e]=31744,r[e|256]=64512,i[e]=24,i[e|256]=24):(r[e]=31744,r[e|256]=64512,i[e]=13,i[e|256]=13)}let a=new Uint32Array(2048),o=new Uint32Array(64),s=new Uint32Array(64);for(let e=1;e<1024;++e){let t=e<<13,n=0;for(;!(t&8388608);)t<<=1,n-=8388608;t&=-8388609,n+=947912704,a[e]=t|n}for(let e=1024;e<2048;++e)a[e]=939524096+(e-1024<<13);for(let e=1;e<31;++e)o[e]=e<<23;o[31]=1199570944,o[32]=2147483648;for(let e=33;e<63;++e)o[e]=2147483648+(e-32<<23);o[63]=3347054592;for(let e=1;e<64;++e)e!==32&&(s[e]=1024);return{floatView:t,uint32View:n,baseTable:r,shiftTable:i,mantissaTable:a,exponentTable:o,offsetTable:s}}function Jx(e){Math.abs(e)>65504&&yy(`DataUtils.toHalfFloat(): Value out of range.`),e=ky(e,-65504,65504),Kx.floatView[0]=e;let t=Kx.uint32View[0],n=t>>23&511;return Kx.baseTable[n]+((t&8388607)>>Kx.shiftTable[n])}function Yx(e){let t=e>>10;return Kx.uint32View[0]=Kx.mantissaTable[Kx.offsetTable[t]+(e&1023)]+Kx.exponentTable[t],Kx.floatView[0]}var Xx=class{static toHalfFloat(e){return Jx(e)}static fromHalfFloat(e){return Yx(e)}},Zx=new Y,Qx=new J,$x=0,eS=class{constructor(e,t,n=!1){if(Array.isArray(e))throw TypeError(`THREE.BufferAttribute: array should be a Typed Array.`);this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:$x++}),this.name=``,this.array=e,this.itemSize=t,this.count=e===void 0?0:e.length/t,this.normalized=n,this.usage=Jv,this.updateRanges=[],this.gpuType=E_,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,i=this.itemSize;r<i;r++)this.array[e+r]=t.array[n+r];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)Qx.fromBufferAttribute(this,t),Qx.applyMatrix3(e),this.setXY(t,Qx.x,Qx.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyMatrix3(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyMatrix4(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.applyNormalMatrix(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)Zx.fromBufferAttribute(this,t),Zx.transformDirection(e),this.setXYZ(t,Zx.x,Zx.y,Zx.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=Jy(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=Yy(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=Jy(t,this.array)),t}setX(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=Jy(t,this.array)),t}setY(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=Jy(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=Jy(t,this.array)),t}setW(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this}setXYZW(e,t,n,r,i){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array),i=Yy(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this.array[e+3]=i,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==``&&(e.name=this.name),this.usage!==35044&&(e.usage=this.usage),e}},tS=class extends eS{constructor(e,t,n){super(new Int8Array(e),t,n)}},nS=class extends eS{constructor(e,t,n){super(new Uint8Array(e),t,n)}},rS=class extends eS{constructor(e,t,n){super(new Uint8ClampedArray(e),t,n)}},iS=class extends eS{constructor(e,t,n){super(new Int16Array(e),t,n)}},aS=class extends eS{constructor(e,t,n){super(new Uint16Array(e),t,n)}},oS=class extends eS{constructor(e,t,n){super(new Int32Array(e),t,n)}},sS=class extends eS{constructor(e,t,n){super(new Uint32Array(e),t,n)}},cS=class extends eS{constructor(e,t,n){super(new Uint16Array(e),t,n),this.isFloat16BufferAttribute=!0}getX(e){let t=Yx(this.array[e*this.itemSize]);return this.normalized&&(t=Jy(t,this.array)),t}setX(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize]=Jx(t),this}getY(e){let t=Yx(this.array[e*this.itemSize+1]);return this.normalized&&(t=Jy(t,this.array)),t}setY(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+1]=Jx(t),this}getZ(e){let t=Yx(this.array[e*this.itemSize+2]);return this.normalized&&(t=Jy(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+2]=Jx(t),this}getW(e){let t=Yx(this.array[e*this.itemSize+3]);return this.normalized&&(t=Jy(t,this.array)),t}setW(e,t){return this.normalized&&(t=Yy(t,this.array)),this.array[e*this.itemSize+3]=Jx(t),this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this.array[e+2]=Jx(r),this}setXYZW(e,t,n,r,i){return e*=this.itemSize,this.normalized&&(t=Yy(t,this.array),n=Yy(n,this.array),r=Yy(r,this.array),i=Yy(i,this.array)),this.array[e+0]=Jx(t),this.array[e+1]=Jx(n),this.array[e+2]=Jx(r),this.array[e+3]=Jx(i),this}},lS=class extends eS{constructor(e,t,n){super(new Float32Array(e),t,n)}},uS=0,dS=new Xb,fS=new Cx,pS=new Y,mS=new Cb,hS=new Cb,gS=new Y,_S=class e extends Cy{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:uS++}),this.uuid=Oy(),this.name=``,this.type=`BufferGeometry`,this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(ly(e)?sS:aS)(e,1):this.index=e,this}setIndirect(e){return this.indirect=e,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let t=new eb().getNormalMatrix(e);n.applyNormalMatrix(t),n.needsUpdate=!0}let r=this.attributes.tangent;return r!==void 0&&(r.transformDirection(e),r.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return dS.makeRotationFromQuaternion(e),this.applyMatrix4(dS),this}rotateX(e){return dS.makeRotationX(e),this.applyMatrix4(dS),this}rotateY(e){return dS.makeRotationY(e),this.applyMatrix4(dS),this}rotateZ(e){return dS.makeRotationZ(e),this.applyMatrix4(dS),this}translate(e,t,n){return dS.makeTranslation(e,t,n),this.applyMatrix4(dS),this}scale(e,t,n){return dS.makeScale(e,t,n),this.applyMatrix4(dS),this}lookAt(e){return fS.lookAt(e),fS.updateMatrix(),this.applyMatrix4(fS.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(pS).negate(),this.translate(pS.x,pS.y,pS.z),this}setFromPoints(e){let t=this.getAttribute(`position`);if(t===void 0){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];t.push(r.x,r.y,r.z||0)}this.setAttribute(`position`,new lS(t,3))}else{let n=Math.min(e.length,t.count);for(let r=0;r<n;r++){let n=e[r];t.setXYZ(r,n.x,n.y,n.z||0)}e.length>t.count&&yy(`BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.`),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Cb);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){by(`BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.`,this),this.boundingBox.set(new Y(-1/0,-1/0,-1/0),new Y(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];mS.setFromBufferAttribute(n),this.morphTargetsRelative?(gS.addVectors(this.boundingBox.min,mS.min),this.boundingBox.expandByPoint(gS),gS.addVectors(this.boundingBox.max,mS.max),this.boundingBox.expandByPoint(gS)):(this.boundingBox.expandByPoint(mS.min),this.boundingBox.expandByPoint(mS.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&by(`BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.`,this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Vb);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){by(`BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.`,this),this.boundingSphere.set(new Y,1/0);return}if(e){let n=this.boundingSphere.center;if(mS.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];hS.setFromBufferAttribute(n),this.morphTargetsRelative?(gS.addVectors(mS.min,hS.min),mS.expandByPoint(gS),gS.addVectors(mS.max,hS.max),mS.expandByPoint(gS)):(mS.expandByPoint(hS.min),mS.expandByPoint(hS.max))}mS.getCenter(n);let r=0;for(let t=0,i=e.count;t<i;t++)gS.fromBufferAttribute(e,t),r=Math.max(r,n.distanceToSquared(gS));if(t)for(let i=0,a=t.length;i<a;i++){let a=t[i],o=this.morphTargetsRelative;for(let t=0,i=a.count;t<i;t++)gS.fromBufferAttribute(a,t),o&&(pS.fromBufferAttribute(e,t),gS.add(pS)),r=Math.max(r,n.distanceToSquared(gS))}this.boundingSphere.radius=Math.sqrt(r),isNaN(this.boundingSphere.radius)&&by(`BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.`,this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){by(`BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)`);return}let n=t.position,r=t.normal,i=t.uv;this.hasAttribute(`tangent`)===!1&&this.setAttribute(`tangent`,new eS(new Float32Array(4*n.count),4));let a=this.getAttribute(`tangent`),o=[],s=[];for(let e=0;e<n.count;e++)o[e]=new Y,s[e]=new Y;let c=new Y,l=new Y,u=new Y,d=new J,f=new J,p=new J,m=new Y,h=new Y;function g(e,t,r){c.fromBufferAttribute(n,e),l.fromBufferAttribute(n,t),u.fromBufferAttribute(n,r),d.fromBufferAttribute(i,e),f.fromBufferAttribute(i,t),p.fromBufferAttribute(i,r),l.sub(c),u.sub(c),f.sub(d),p.sub(d);let a=1/(f.x*p.y-p.x*f.y);isFinite(a)&&(m.copy(l).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(a),h.copy(u).multiplyScalar(f.x).addScaledVector(l,-p.x).multiplyScalar(a),o[e].add(m),o[t].add(m),o[r].add(m),s[e].add(h),s[t].add(h),s[r].add(h))}let _=this.groups;_.length===0&&(_=[{start:0,count:e.count}]);for(let t=0,n=_.length;t<n;++t){let n=_[t],r=n.start,i=n.count;for(let t=r,n=r+i;t<n;t+=3)g(e.getX(t+0),e.getX(t+1),e.getX(t+2))}let v=new Y,y=new Y,b=new Y,x=new Y;function S(e){b.fromBufferAttribute(r,e),x.copy(b);let t=o[e];v.copy(t),v.sub(b.multiplyScalar(b.dot(t))).normalize(),y.crossVectors(x,t);let n=y.dot(s[e])<0?-1:1;a.setXYZW(e,v.x,v.y,v.z,n)}for(let t=0,n=_.length;t<n;++t){let n=_[t],r=n.start,i=n.count;for(let t=r,n=r+i;t<n;t+=3)S(e.getX(t+0)),S(e.getX(t+1)),S(e.getX(t+2))}}computeVertexNormals(){let e=this.index,t=this.getAttribute(`position`);if(t!==void 0){let n=this.getAttribute(`normal`);if(n===void 0)n=new eS(new Float32Array(t.count*3),3),this.setAttribute(`normal`,n);else for(let e=0,t=n.count;e<t;e++)n.setXYZ(e,0,0,0);let r=new Y,i=new Y,a=new Y,o=new Y,s=new Y,c=new Y,l=new Y,u=new Y;if(e)for(let d=0,f=e.count;d<f;d+=3){let f=e.getX(d+0),p=e.getX(d+1),m=e.getX(d+2);r.fromBufferAttribute(t,f),i.fromBufferAttribute(t,p),a.fromBufferAttribute(t,m),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),o.fromBufferAttribute(n,f),s.fromBufferAttribute(n,p),c.fromBufferAttribute(n,m),o.add(l),s.add(l),c.add(l),n.setXYZ(f,o.x,o.y,o.z),n.setXYZ(p,s.x,s.y,s.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let e=0,o=t.count;e<o;e+=3)r.fromBufferAttribute(t,e+0),i.fromBufferAttribute(t,e+1),a.fromBufferAttribute(t,e+2),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),n.setXYZ(e+0,l.x,l.y,l.z),n.setXYZ(e+1,l.x,l.y,l.z),n.setXYZ(e+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)gS.fromBufferAttribute(e,t),gS.normalize(),e.setXYZ(t,gS.x,gS.y,gS.z)}toNonIndexed(){function t(e,t){let n=e.array,r=e.itemSize,i=e.normalized,a=new n.constructor(t.length*r),o=0,s=0;for(let i=0,c=t.length;i<c;i++){o=e.isInterleavedBufferAttribute?t[i]*e.data.stride+e.offset:t[i]*r;for(let e=0;e<r;e++)a[s++]=n[o++]}return new eS(a,r,i)}if(this.index===null)return yy(`BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.`),this;let n=new e,r=this.index.array,i=this.attributes;for(let e in i){let a=i[e],o=t(a,r);n.setAttribute(e,o)}let a=this.morphAttributes;for(let e in a){let i=[],o=a[e];for(let e=0,n=o.length;e<n;e++){let n=o[e],a=t(n,r);i.push(a)}n.morphAttributes[e]=i}n.morphTargetsRelative=this.morphTargetsRelative;let o=this.groups;for(let e=0,t=o.length;e<t;e++){let t=o[e];n.addGroup(t.start,t.count,t.materialIndex)}return n}toJSON(){let e={metadata:{version:4.7,type:`BufferGeometry`,generator:`BufferGeometry.toJSON`}};if(e.uuid=this.uuid,e.type=this.type,this.name!==``&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){let t=this.parameters;for(let n in t)t[n]!==void 0&&(e[n]=t[n]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let n=this.attributes;for(let t in n){let r=n[t];e.data.attributes[t]=r.toJSON(e.data)}let r={},i=!1;for(let t in this.morphAttributes){let n=this.morphAttributes[t],a=[];for(let t=0,r=n.length;t<r;t++){let r=n[t];a.push(r.toJSON(e.data))}a.length>0&&(r[t]=a,i=!0)}i&&(e.data.morphAttributes=r,e.data.morphTargetsRelative=this.morphTargetsRelative);let a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));let o=this.boundingSphere;return o!==null&&(e.data.boundingSphere=o.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let n=e.index;n!==null&&this.setIndex(n.clone());let r=e.attributes;for(let e in r){let n=r[e];this.setAttribute(e,n.clone(t))}let i=e.morphAttributes;for(let e in i){let n=[],r=i[e];for(let e=0,i=r.length;e<i;e++)n.push(r[e].clone(t));this.morphAttributes[e]=n}this.morphTargetsRelative=e.morphTargetsRelative;let a=e.groups;for(let e=0,t=a.length;e<t;e++){let t=a[e];this.addGroup(t.start,t.count,t.materialIndex)}let o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());let s=e.boundingSphere;return s!==null&&(this.boundingSphere=s.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:`dispose`})}},vS=new Xb,yS=new Yb,bS=new Vb,xS=new Y,SS=new Y,CS=new Y,wS=new Y,TS=new Y,ES=new Y,DS=new Y,OS=new Y,kS=class extends Cx{constructor(e=new _S,t=new Gx){super(),this.isMesh=!0,this.type=`Mesh`,this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;e<t;e++){let t=n[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}getVertexPosition(e,t){let n=this.geometry,r=n.attributes.position,i=n.morphAttributes.position,a=n.morphTargetsRelative;t.fromBufferAttribute(r,e);let o=this.morphTargetInfluences;if(i&&o){ES.set(0,0,0);for(let n=0,r=i.length;n<r;n++){let r=o[n],s=i[n];r!==0&&(TS.fromBufferAttribute(s,e),a?ES.addScaledVector(TS,r):ES.addScaledVector(TS.sub(t),r))}t.add(ES)}return t}raycast(e,t){let n=this.geometry,r=this.material,i=this.matrixWorld;r!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),bS.copy(n.boundingSphere),bS.applyMatrix4(i),yS.copy(e.ray).recast(e.near),!(bS.containsPoint(yS.origin)===!1&&(yS.intersectSphere(bS,xS)===null||yS.origin.distanceToSquared(xS)>(e.far-e.near)**2))&&(vS.copy(i).invert(),yS.copy(e.ray).applyMatrix4(vS),!(n.boundingBox!==null&&yS.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,yS)))}_computeIntersections(e,t,n){let r,i=this.geometry,a=this.material,o=i.index,s=i.attributes.position,c=i.attributes.uv,l=i.attributes.uv1,u=i.attributes.normal,d=i.groups,f=i.drawRange;if(o!==null)if(Array.isArray(a))for(let i=0,s=d.length;i<s;i++){let s=d[i],p=a[s.materialIndex],m=Math.max(s.start,f.start),h=Math.min(o.count,Math.min(s.start+s.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=o.getX(i),d=o.getX(i+1),f=o.getX(i+2);r=jS(this,p,e,n,c,l,u,a,d,f),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=s.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),s=Math.min(o.count,f.start+f.count);for(let d=i,f=s;d<f;d+=3){let i=o.getX(d),s=o.getX(d+1),f=o.getX(d+2);r=jS(this,a,e,n,c,l,u,i,s,f),r&&(r.faceIndex=Math.floor(d/3),t.push(r))}}else if(s!==void 0)if(Array.isArray(a))for(let i=0,o=d.length;i<o;i++){let o=d[i],p=a[o.materialIndex],m=Math.max(o.start,f.start),h=Math.min(s.count,Math.min(o.start+o.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=i,s=i+1,d=i+2;r=jS(this,p,e,n,c,l,u,a,s,d),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=o.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),o=Math.min(s.count,f.start+f.count);for(let s=i,d=o;s<d;s+=3){let i=s,o=s+1,d=s+2;r=jS(this,a,e,n,c,l,u,i,o,d),r&&(r.faceIndex=Math.floor(s/3),t.push(r))}}}};function AS(e,t,n,r,i,a,o,s){let c;if(c=t.side===1?r.intersectTriangle(o,a,i,!0,s):r.intersectTriangle(i,a,o,t.side===0,s),c===null)return null;OS.copy(s),OS.applyMatrix4(e.matrixWorld);let l=n.ray.origin.distanceTo(OS);return l<n.near||l>n.far?null:{distance:l,point:OS.clone(),object:e}}function jS(e,t,n,r,i,a,o,s,c,l){e.getVertexPosition(s,SS),e.getVertexPosition(c,CS),e.getVertexPosition(l,wS);let u=AS(e,t,n,r,SS,CS,wS,DS);if(u){let e=new Y;Lx.getBarycoord(DS,SS,CS,wS,e),i&&(u.uv=Lx.getInterpolatedAttribute(i,s,c,l,e,new J)),a&&(u.uv1=Lx.getInterpolatedAttribute(a,s,c,l,e,new J)),o&&(u.normal=Lx.getInterpolatedAttribute(o,s,c,l,e,new Y),u.normal.dot(r.direction)>0&&u.normal.multiplyScalar(-1));let t={a:s,b:c,c:l,normal:new Y,materialIndex:0};Lx.getNormal(SS,CS,wS,t.normal),u.face=t,u.barycoord=e}return u}var MS=class e extends _S{constructor(e=1,t=1,n=1,r=1,i=1,a=1){super(),this.type=`BoxGeometry`,this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:i,depthSegments:a};let o=this;r=Math.floor(r),i=Math.floor(i),a=Math.floor(a);let s=[],c=[],l=[],u=[],d=0,f=0;p(`z`,`y`,`x`,-1,-1,n,t,e,a,i,0),p(`z`,`y`,`x`,1,-1,n,t,-e,a,i,1),p(`x`,`z`,`y`,1,1,e,n,t,r,a,2),p(`x`,`z`,`y`,1,-1,e,n,-t,r,a,3),p(`x`,`y`,`z`,1,-1,e,t,n,r,i,4),p(`x`,`y`,`z`,-1,-1,e,t,-n,r,i,5),this.setIndex(s),this.setAttribute(`position`,new lS(c,3)),this.setAttribute(`normal`,new lS(l,3)),this.setAttribute(`uv`,new lS(u,2));function p(e,t,n,r,i,a,p,m,h,g,_){let v=a/h,y=p/g,b=a/2,x=p/2,S=m/2,C=h+1,w=g+1,T=0,E=0,D=new Y;for(let a=0;a<w;a++){let o=a*y-x;for(let s=0;s<C;s++)D[e]=(s*v-b)*r,D[t]=o*i,D[n]=S,c.push(D.x,D.y,D.z),D[e]=0,D[t]=0,D[n]=m>0?1:-1,l.push(D.x,D.y,D.z),u.push(s/h),u.push(1-a/g),T+=1}for(let e=0;e<g;e++)for(let t=0;t<h;t++){let n=d+t+C*e,r=d+t+C*(e+1),i=d+(t+1)+C*(e+1),a=d+(t+1)+C*e;s.push(n,r,a),s.push(r,i,a),E+=6}o.addGroup(f,E,_),f+=E,d+=T}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}};function NS(e){let t={};for(let n in e){t[n]={};for(let r in e[n]){let i=e[n][r];i&&(i.isColor||i.isMatrix3||i.isMatrix4||i.isVector2||i.isVector3||i.isVector4||i.isTexture||i.isQuaternion)?i.isRenderTargetTexture?(yy(`UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().`),t[n][r]=null):t[n][r]=i.clone():Array.isArray(i)?t[n][r]=i.slice():t[n][r]=i}}return t}function PS(e){let t={};for(let n=0;n<e.length;n++){let r=NS(e[n]);for(let e in r)t[e]=r[e]}return t}function FS(e){let t=[];for(let n=0;n<e.length;n++)t.push(e[n].clone());return t}function IS(e){let t=e.getRenderTarget();return t===null?e.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:ab.workingColorSpace}var LS={clone:NS,merge:PS},RS=`void main() {
62
62
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
63
63
  }`,zS=`void main() {
64
64
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
@@ -15594,4 +15594,4 @@ fn calculateOutputIndex(index: u32) -> u32 {
15594
15594
  }`},RQ=e=>{let t=e[1].dims,n=e[2].dims,r=e[0].dims,i=e[1].dataType,a=!(Q.areEqual(t,n)&&Q.areEqual(n,r)),o=t,s=Q.size(t);if(a){let e=$U.calcShape($U.calcShape(t,n,!1),r,!1);if(!e)throw Error(`Can't perform where op on the given tensors`);o=e,s=Q.size(o)}let c=Math.ceil(s/4);return{name:`Where`,shaderCache:{inputDependencies:[`rank`,`rank`,`rank`]},getShaderSource:t=>LQ(t,e,o,a,i),getRunData:()=>({outputs:[{dims:o,dataType:i}],dispatchGroup:{x:Math.ceil(s/64/4)},programUniforms:[{type:12,data:c},...VW(r,t,n,o)]})}},zQ=e=>{e.compute(RQ(e.inputs))}}),VQ,HQ=Z(()=>{lK(),vK(),CK(),DK(),Cq(),Lq(),Wq(),LJ(),YJ(),$J(),aY(),_Y(),CY(),EY(),jY(),FY(),BY(),GY(),XY(),dX(),LX(),HX(),KX(),YX(),tZ(),yX(),dZ(),jZ(),IZ(),BZ(),GZ(),iK(),fQ(),jX(),gQ(),TQ(),AQ(),DX(),IQ(),lG(),yq(),BQ(),VQ=new Map([[`Abs`,[AK]],[`Acos`,[jK]],[`Acosh`,[MK]],[`Add`,[Dq]],[`ArgMax`,[sK,cK]],[`ArgMin`,[oK,cK]],[`Asin`,[NK]],[`Asinh`,[PK]],[`Atan`,[FK]],[`Atanh`,[IK]],[`Attention`,[_K]],[`AveragePool`,[SZ,xZ]],[`BatchNormalization`,[SK]],[`BiasAdd`,[EK]],[`BiasSplitGelu`,[Sq]],[`Cast`,[RK,LK]],[`Ceil`,[VK]],[`Clip`,[BK]],[`Concat`,[Hq,Uq]],[`Conv`,[IJ,MJ]],[`ConvTranspose`,[JJ,WJ]],[`Cos`,[HK]],[`Cosh`,[UK]],[`CumSum`,[ZJ,QJ]],[`DepthToSpace`,[rY,iY]],[`DequantizeLinear`,[PZ,FZ]],[`Div`,[Oq]],[`Einsum`,[hY,gY]],[`Elu`,[GK,WK]],[`Equal`,[kq]],[`Erf`,[qK]],[`Exp`,[JK]],[`Expand`,[SY]],[`FastGelu`,[TY]],[`Floor`,[YK]],[`FusedConv`,[IJ,MJ]],[`Gather`,[AY,kY]],[`GatherElements`,[WY,UY]],[`GatherBlockQuantized`,[RY,zY]],[`GatherND`,[NY,PY]],[`Gelu`,[XK]],[`Gemm`,[YY,JY]],[`GlobalAveragePool`,[TZ,wZ]],[`GlobalMaxPool`,[AZ,kZ]],[`Greater`,[Nq]],[`GreaterOrEqual`,[Fq]],[`GridSample`,[lX,uX]],[`GroupQueryAttention`,[IX]],[`HardSigmoid`,[iq,rq]],[`InstanceNormalization`,[VX]],[`LayerNormalization`,[GX]],[`LeakyRelu`,[ZK,WK]],[`Less`,[Pq]],[`LessOrEqual`,[Iq]],[`Log`,[hq]],[`MatMul`,[JX]],[`MatMulNBits`,[$X,eZ]],[`MaxPool`,[DZ,OZ]],[`Mul`,[Aq]],[`MultiHeadAttention`,[vX,mX]],[`Neg`,[$K]],[`Not`,[QK]],[`Pad`,[uZ]],[`Pow`,[jq]],[`QuickGelu`,[vq,WK]],[`Range`,[zZ]],[`Reciprocal`,[eq]],[`ReduceMin`,[$G]],[`ReduceMean`,[JG]],[`ReduceMax`,[QG]],[`ReduceSum`,[tK]],[`ReduceProd`,[eK]],[`ReduceL1`,[YG]],[`ReduceL2`,[XG]],[`ReduceLogSum`,[rK]],[`ReduceLogSumExp`,[ZG]],[`ReduceSumSquare`,[nK]],[`Relu`,[tq]],[`Resize`,[uQ,dQ]],[`RotaryEmbedding`,[AX]],[`ScatterND`,[WZ,UZ]],[`Sigmoid`,[nq]],[`Sin`,[aq]],[`Sinh`,[oq]],[`Slice`,[CQ,wQ]],[`SkipLayerNormalization`,[hQ]],[`Split`,[TX,EX]],[`Sqrt`,[sq]],[`Softmax`,[OQ,kQ]],[`Sub`,[Mq]],[`Tan`,[cq]],[`Tanh`,[uq]],[`ThresholdedRelu`,[mq,WK]],[`Tile`,[FQ]],[`Transpose`,[sG,cG]],[`Where`,[zQ]]])}),UQ,WQ=Z(()=>{LH(),ZU(),$W(),UQ=class{constructor(e){this.backend=e,this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,t){this.repo.set(e,t)}run(e,t,n,r,i){wH(e.programInfo.name);let a=this.backend.device,o=this.backend.getComputePassEncoder();this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2);let s=[];for(let e of t)s.push({binding:s.length,resource:{buffer:e.buffer}});for(let e of n)s.push({binding:s.length,resource:{buffer:e.buffer}});i&&s.push({binding:s.length,resource:i});let c=a.createBindGroup({layout:e.computePipeline.getBindGroupLayout(0),entries:s,label:e.programInfo.name});if(this.backend.sessionStatus===`capturing`){let t={kernelId:this.backend.currentKernelId,computePipeline:e.computePipeline,bindGroup:c,dispatchGroup:r};this.backend.capturedCommandList.get(this.backend.currentSessionId).push(t)}o.setPipeline(e.computePipeline),o.setBindGroup(0,c),o.dispatchWorkgroups(...r),this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2+1),this.backend.pendingDispatchNumber++,(this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber||this.backend.queryType===`at-passes`)&&this.backend.endComputePass(),this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber&&this.backend.flush(),TH(e.programInfo.name)}dispose(){}build(e,t){wH(e.name);let n=this.backend.device,r=[];[{feature:`shader-f16`,extension:`f16`},{feature:`subgroups`,extension:`subgroups`}].forEach(e=>{n.features.has(e.feature)&&r.push(`enable ${e.extension};`)});let i=QW(t,this.backend.device.limits),a=e.getShaderSource(i),o=`${r.join(`
15595
15595
  `)}
15596
15596
  ${i.additionalImplementations}
15597
- ${a}`,s=n.createShaderModule({code:o,label:e.name});XU(`verbose`,()=>`[WebGPU] ${e.name} shader code: ${o}`);let c=n.createComputePipeline({compute:{module:s,entryPoint:`main`},layout:`auto`,label:e.name});return TH(e.name),{programInfo:e,computePipeline:c,uniformVariablesInfo:i.variablesInfo}}normalizeDispatchGroupSize(e){let t=typeof e==`number`?e:e.x,n=typeof e==`number`?1:e.y||1,r=typeof e==`number`?1:e.z||1,i=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(t<=i&&n<=i&&r<=i)return[t,n,r];let a=t*n*r,o=Math.ceil(Math.sqrt(a));if(o>i){if(o=Math.ceil(Math.cbrt(a)),o>i)throw Error(`Total dispatch size exceeds WebGPU maximum.`);return[o,o,o]}else return[o,o,1]}}}),GQ={};LV(GQ,{WebGpuBackend:()=>YQ});var KQ,qQ,JQ,YQ,XQ=Z(()=>{LH(),VU(),ZU(),oW(),NW(),HQ(),WQ(),KQ=(e,t)=>{if(t.length!==e.length)throw Error(`inputDependencies length ${t.length} is not equal to inputTensors length ${e.length}.`);let n=[];for(let r=0;r<e.length;++r){let i=e[r].dataType;switch(t[r]){case`none`:n.push(``);break;case`type`:n.push(`${i}`);break;case`rank`:{let t=e[r].dims.length;n.push(`${i};${t}`);break}case`dims`:{let t=e[r].dims.join(`,`);n.push(`${i};${t}`);break}default:throw Error(`unsupported input dependency: ${t[r]}`)}}return n.join(`|`)},qQ=(e,t,n)=>{let r=e.name;return e.shaderCache?.hint&&(r+=`[`+e.shaderCache.hint+`]`),r+=`:`+n+`:${KQ(t,e.shaderCache?.inputDependencies??Array(t.length).fill(`dims`))}`,r},JQ=class{constructor(e){e&&(this.architecture=e.architecture,this.vendor=e.vendor)}isArchitecture(e){return this.architecture===e}isVendor(e){return this.vendor===e}},YQ=class{constructor(){this.currentSessionId=null,this.currentKernelId=null,this.commandEncoder=null,this.computePassEncoder=null,this.maxDispatchNumber=16,this.pendingDispatchNumber=0,this.pendingKernels=[],this.pendingQueries=new Map,this.sessionStatus=`default`,this.capturedCommandList=new Map,this.capturedPendingKernels=new Map,this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(this.currentKernelId===null)throw Error(`currentKernelCustomData(): currentKernelId is null. (should not happen)`);let e=this.kernelCustomData.get(this.currentKernelId);return e||(e={},this.kernelCustomData.set(this.currentKernelId,e)),e}async initialize(e,t){this.env=e;let n=[],r={requiredLimits:{maxComputeWorkgroupStorageSize:t.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:t.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:t.limits.maxStorageBufferBindingSize,maxBufferSize:t.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:t.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:t.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:t.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:t.limits.maxComputeWorkgroupSizeZ},requiredFeatures:n},i=e=>t.features.has(e)&&n.push(e)&&!0;i(`chromium-experimental-timestamp-query-inside-passes`)||i(`timestamp-query`),i(`shader-f16`),i(`subgroups`),this.device=await t.requestDevice(r),this.adapterInfo=new JQ(t.info||await t.requestAdapterInfo()),this.gpuDataManager=MW(this),this.programManager=new UQ(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,JU(e.logLevel,!!e.debug),this.device.onuncapturederror=e=>{e.error instanceof GPUValidationError&&console.error(`An uncaught WebGPU validation error was raised: ${e.error.message}`)},Object.defineProperty(this.env.webgpu,"device",{value:this.device,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(this.env.webgpu,"adapter",{value:t,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<`u`&&this.querySet.destroy(),this.gpuDataManager.dispose()}getCommandEncoder(){return this.commandEncoder||=this.device.createCommandEncoder(),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let e=this.getCommandEncoder(),t={};this.queryType===`at-passes`&&(t.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:this.pendingDispatchNumber*2,endOfPassWriteIndex:this.pendingDispatchNumber*2+1}),this.computePassEncoder=e.beginComputePass(t)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&=(this.computePassEncoder.end(),null)}flush(){if(!this.commandEncoder)return;wH(),this.endComputePass();let e;this.queryType!==`none`&&(this.commandEncoder.resolveQuerySet(this.querySet,0,this.pendingDispatchNumber*2,this.queryResolveBuffer,0),e=this.device.createBuffer({size:this.pendingDispatchNumber*2*8,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(e,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,e,0,this.pendingDispatchNumber*2*8)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,this.queryType!==`none`&&e.mapAsync(GPUMapMode.READ).then(()=>{let t=new BigUint64Array(e.getMappedRange()),n=this.pendingQueries.get(e);for(let e=0;e<t.length/2;e++){let r=n[e],i=r.kernelId,a=this.kernels.get(i),o=a.kernelType,s=a.kernelName,c=r.programName,l=r.inputTensorViews,u=r.outputTensorViews,d=t[e*2],f=t[e*2+1];typeof this.queryTimeBase>`u`&&(this.queryTimeBase=d);let p=Number(d-this.queryTimeBase),m=Number(f-this.queryTimeBase);if(!Number.isSafeInteger(p)||!Number.isSafeInteger(m))throw RangeError(`incorrect timestamp range`);if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:l.map(e=>({dims:e.dims,dataType:PU(e.dataType)})),outputsMetadata:u.map(e=>({dims:e.dims,dataType:PU(e.dataType)})),kernelId:i,kernelType:o,kernelName:s,programName:c,startTime:p,endTime:m});else{let e=``;l.forEach((t,n)=>{e+=`input[${n}]: [${t.dims}] | ${PU(t.dataType)}, `});let t=``;u.forEach((e,n)=>{t+=`output[${n}]: [${e.dims}] | ${PU(e.dataType)}, `}),console.log(`[profiling] kernel "${i}|${o}|${s}|${c}" ${e}${t}start time: ${p} ns, execution time: ${m-p} ns`)}SH(`GPU`,`${c}::${d}::${f}`)}e.unmap(),this.pendingQueries.delete(e)}),TH()}run(e,t,n,r,i,a){wH(e.name);let o=[];for(let e=0;e<t.length;++e){let n=t[e].data;if(n===0)continue;let r=this.gpuDataManager.get(n);if(!r)throw Error(`no GPU data for input: ${n}`);o.push(r)}let{outputs:s,dispatchGroup:c,programUniforms:l}=e.getRunData(t),u=n.length===0?s.map((e,t)=>t):n;if(u.length!==s.length)throw Error(`Output size ${u.length} must be equal to ${s.length}.`);let d=[],f=[];for(let e=0;e<s.length;++e){if(!Number.isInteger(u[e])||u[e]<-3||u[e]>=a)throw Error(`Invalid output index: ${u[e]}`);if(u[e]===-3)continue;let t=u[e]===-1,n=u[e]===-2,o=t||n?i(s[e].dataType,s[e].dims):r(u[e],s[e].dataType,s[e].dims);if(d.push(o),o.data===0)continue;let c=this.gpuDataManager.get(o.data);if(!c)throw Error(`no GPU data for output: ${o.data}`);if(t&&this.temporaryData.push(c),n){let e=this.kernelPersistentData.get(this.currentKernelId);e||(e=[],this.kernelPersistentData.set(this.currentKernelId,e)),e.push(c)}f.push(c)}if(o.length!==t.length||f.length!==d.length){if(f.length===0)return TH(e.name),d;throw Error(`Program ${e.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}let p;if(l){let e=0,t=[];l.forEach(n=>{let r=typeof n.data==`number`?[n.data]:n.data;if(r.length===0)return;let i=n.type===10?2:4,a,o;n.type===10?(o=r.length>4?16:r.length>2?8:r.length*i,a=r.length>4?16:i*r.length):(o=r.length<=2?r.length*i:16,a=16),e=Math.ceil(e/o)*o,t.push(e);let s=n.type===10?8:4;e+=r.length>4?Math.ceil(r.length/s)*a:r.length*i}),e=Math.ceil(e/16)*16;let n=new ArrayBuffer(e);l.forEach((e,r)=>{let i=t[r],a=typeof e.data==`number`?[e.data]:e.data;if(e.type===6)new Int32Array(n,i,a.length).set(a);else if(e.type===12)new Uint32Array(n,i,a.length).set(a);else if(e.type===10)new Uint16Array(n,i,a.length).set(a);else if(e.type===1)new Float32Array(n,i,a.length).set(a);else throw Error(`Unsupported uniform type: ${PU(e.type)}`)});let r=this.gpuDataManager.create(e,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(r.buffer,0,n,0,e),this.gpuDataManager.release(r.id),p={offset:0,size:e,buffer:r.buffer}}let m=this.programManager.normalizeDispatchGroupSize(c),h=m[1]===1&&m[2]===1,g=qQ(e,t,h),_=this.programManager.getArtifact(g);if(_||(_=this.programManager.build(e,m),this.programManager.setArtifact(g,_),XU(`info`,()=>`[artifact] key: ${g}, programName: ${e.name}`)),l&&_.uniformVariablesInfo){if(l.length!==_.uniformVariablesInfo.length)throw Error(`Uniform variables count mismatch: expect ${_.uniformVariablesInfo.length}, got ${l.length} in program "${_.programInfo.name}".`);for(let e=0;e<l.length;e++){let t=l[e],n=t.type,r=typeof t.data==`number`?1:t.data.length,[i,a]=_.uniformVariablesInfo[e];if(n!==i||r!==a)throw Error(`Uniform variable ${e} mismatch: expect type ${i} with size ${a}, got type ${n} with size ${r} in program "${_.programInfo.name}".`)}}if(XU(`info`,()=>`[ProgramManager] run "${e.name}" (key=${g}) with ${m[0]}x${m[1]}x${m[2]}`),this.queryType!==`none`||this.sessionStatus===`capturing`){let e={kernelId:this.currentKernelId,programName:_.programInfo.name,inputTensorViews:t,outputTensorViews:d};this.pendingKernels.push(e),this.sessionStatus===`capturing`&&this.capturedPendingKernels.get(this.currentSessionId).push(e)}return this.programManager.run(_,o,f,m,p),TH(e.name),d}upload(e,t){this.gpuDataManager.upload(e,t)}memcpy(e,t){this.gpuDataManager.memcpy(e,t)}async download(e,t){await this.gpuDataManager.download(e,t)}alloc(e){return this.gpuDataManager.create(e).id}free(e){return this.gpuDataManager.release(e)}createKernel(e,t,n,r){let i=VQ.get(e);if(!i)throw Error(`kernel not implemented: ${e}`);let a={kernelType:e,kernelName:r,kernelEntry:i[0],attributes:[i[1],n]};this.kernels.set(t,a)}releaseKernel(e){let t=this.kernelPersistentData.get(e);if(t){for(let e of t)this.gpuDataManager.release(e.id);this.kernelPersistentData.delete(e)}this.kernelCustomData.delete(e),this.kernels.delete(e)}computeKernel(e,t,n){let r=this.kernels.get(e);if(!r)throw Error(`kernel not created: ${e}`);let i=r.kernelType,a=r.kernelName,o=r.kernelEntry,s=r.attributes;if(this.currentKernelId!==null)throw Error(`kernel "[${i}] ${a}" is not allowed to be called recursively`);this.currentKernelId=e,s[0]&&=(s[1]=s[0](s[1]),void 0),XU(`info`,()=>`[WebGPU] Start to run kernel "[${i}] ${a}"...`);let c=this.env.debug;this.temporaryData=[];try{return c&&this.device.pushErrorScope(`validation`),o(t,s[1]),0}catch(e){return n.push(Promise.resolve(`[WebGPU] Kernel "[${i}] ${a}" failed. ${e}`)),1}finally{c&&n.push(this.device.popErrorScope().then(e=>e?`GPU validation error for kernel "[${i}] ${a}": ${e.message}`:null));for(let e of this.temporaryData)this.gpuDataManager.release(e.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(e,t,n,r){let i=this.sessionExternalDataMapping.get(e);i||(i=new Map,this.sessionExternalDataMapping.set(e,i));let a=i.get(t),o=this.gpuDataManager.registerExternalBuffer(n,r,a);return i.set(t,[o,n]),o}unregisterBuffers(e){let t=this.sessionExternalDataMapping.get(e);t&&(t.forEach(e=>this.gpuDataManager.unregisterExternalBuffer(e[0])),this.sessionExternalDataMapping.delete(e))}getBuffer(e){let t=this.gpuDataManager.get(e);if(!t)throw Error(`no GPU data for buffer: ${e}`);return t.buffer}createDownloader(e,t,n){return async()=>{let r=await AW(this,e,t);return aW(r.buffer,n)}}writeTimestamp(e){this.queryType===`inside-passes`&&this.computePassEncoder.writeTimestamp(this.querySet,e)}setQueryType(){this.queryType=`none`,(this.env.webgpu.profiling?.mode==="default"||(typeof this.env.trace>`u`?this.env.wasm.trace:this.env.trace))&&(this.device.features.has(`chromium-experimental-timestamp-query-inside-passes`)?this.queryType=`inside-passes`:this.device.features.has(`timestamp-query`)&&(this.queryType=`at-passes`),this.queryType!==`none`&&typeof this.querySet>`u`&&(this.querySet=this.device.createQuerySet({type:`timestamp`,count:this.maxDispatchNumber*2}),this.queryResolveBuffer=this.device.createBuffer({size:this.maxDispatchNumber*2*8,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){XU(`info`,`captureBegin`),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus=`capturing`}captureEnd(){XU(`info`,`captureEnd`),this.flush(),this.sessionStatus=`default`}replay(){XU(`info`,`replay`),this.sessionStatus=`replaying`;let e=this.capturedCommandList.get(this.currentSessionId),t=this.capturedPendingKernels.get(this.currentSessionId),n=e.length;this.pendingKernels=[];for(let r=0;r<n;r++){let n=this.getComputePassEncoder(),i=e[r];this.writeTimestamp(this.pendingDispatchNumber*2),n.setPipeline(i.computePipeline),n.setBindGroup(0,i.bindGroup),n.dispatchWorkgroups(...i.dispatchGroup),this.writeTimestamp(this.pendingDispatchNumber*2+1),this.pendingDispatchNumber++,this.queryType!==`none`&&this.pendingKernels.push(t[r]),(this.pendingDispatchNumber>=this.maxDispatchNumber||this.queryType===`at-passes`)&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus=`default`}onCreateSession(){this.gpuDataManager.onCreateSession()}onReleaseSession(e){this.unregisterBuffers(e),this.capturedCommandList.has(e)&&this.capturedCommandList.delete(e),this.capturedPendingKernels.has(e)&&this.capturedPendingKernels.delete(e),this.gpuDataManager.onReleaseSession(e)}onRunStart(e){this.currentSessionId=e,this.setQueryType()}}}),ZQ={};LV(ZQ,{init:()=>e$});var QQ,$Q,e$,t$=Z(()=>{VU(),ZU(),iW(),SW(),QQ=class e{constructor(e,t,n,r){this.module=e,this.dataType=t,this.data=n,this.dims=r}getFloat32Array(){if(this.dataType!==1)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,e)}getBigInt64Array(){if(this.dataType!==7)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,e)}getInt32Array(){if(this.dataType!==6)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,e)}getUint16Array(){if(this.dataType!==10&&this.dataType!==4)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Uint16Array:new Uint16Array(this.module.HEAP8.buffer,this.data,e)}reshape(t){if(Q.size(t)!==Q.size(this.dims))throw Error(`Invalid new shape`);return new e(this.module,this.dataType,this.data,t)}},$Q=class{constructor(e,t,n){this.module=e,this.backend=t,this.customDataOffset=0,this.customDataSize=0,this.adapterInfo=t.adapterInfo;let r=e.PTR_SIZE,i=n/e.PTR_SIZE,a=r===4?`i32`:`i64`;this.opKernelContext=Number(e.getValue(r*i++,a));let o=Number(e.getValue(r*i++,a));this.outputCount=Number(e.getValue(r*i++,a)),this.customDataOffset=Number(e.getValue(r*i++,`*`)),this.customDataSize=Number(e.getValue(r*i++,a));let s=[];for(let t=0;t<o;t++){let t=Number(e.getValue(r*i++,a)),n=Number(e.getValue(r*i++,`*`)),o=Number(e.getValue(r*i++,a)),c=[];for(let t=0;t<o;t++)c.push(Number(e.getValue(r*i++,a)));s.push(new QQ(e,t,n,c))}this.inputs=s}get kernelCustomData(){return this.backend.currentKernelCustomData}get customDataBuffer(){return this.module.HEAPU8.subarray(this.customDataOffset,this.customDataOffset+this.customDataSize)}compute(e,t){let n=t?.inputs?.map(e=>typeof e==`number`?this.inputs[e]:e)??this.inputs,r=t?.outputs??[];return this.backend.run(e,n,r,(e,t,n)=>new QQ(this.module,t,this.output(e,n),n),(e,t)=>{let n=FU(e,t);if(!n)throw Error(`Unsupported data type: ${e}`);let r=n>0?this.backend.gpuDataManager.create(n).id:0;return new QQ(this.module,e,r,t)},this.outputCount)}output(e,t){let n=this.module.stackSave();try{let n=this.module.PTR_SIZE,r=n===4?`i32`:`i64`,i=this.module.stackAlloc((1+t.length)*n);this.module.setValue(i,t.length,r);for(let e=0;e<t.length;e++)this.module.setValue(i+n*(e+1),t[e],r);return this.module._JsepOutput(this.opKernelContext,e,i)}catch(n){throw Error(`Failed to generate kernel's output[${e}] with dims [${t}]. If you are running with pre-allocated output, please make sure the output type/dims are correct. Error: ${n}`)}finally{this.module.stackRestore(n)}}},e$=async(e,t,n,r)=>{let i=t.jsepInit;if(!i)throw Error(`Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.`);if(e===`webgpu`){let e=(XQ(),zV(GQ)).WebGpuBackend,a=new e;await a.initialize(n,r),i(`webgpu`,[a,e=>a.alloc(Number(e)),e=>a.free(e),(e,n,r,i=!1)=>{if(i)XU(`verbose`,()=>`[WebGPU] jsepCopyGpuToGpu: src=${Number(e)}, dst=${Number(n)}, size=${Number(r)}`),a.memcpy(Number(e),Number(n));else{XU(`verbose`,()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${Number(e)}, gpuDataId=${Number(n)}, size=${Number(r)}`);let i=t.HEAPU8.subarray(Number(e>>>0),Number(e>>>0)+Number(r));a.upload(Number(n),i)}},async(e,n,r)=>{XU(`verbose`,()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${e}, dataOffset=${n}, size=${r}`),await a.download(Number(e),()=>t.HEAPU8.subarray(Number(n)>>>0,Number(n+r)>>>0))},(e,n,r)=>a.createKernel(e,Number(n),r,t.UTF8ToString(t._JsepGetNodeName(Number(n)))),e=>a.releaseKernel(e),(e,n,r,i)=>{XU(`verbose`,()=>`[WebGPU] jsepRun: sessionHandle=${r}, kernel=${e}, contextDataOffset=${n}`);let o=new $Q(t,a,Number(n));return a.computeKernel(Number(e),o,i)},()=>a.captureBegin(),()=>a.captureEnd(),()=>a.replay()])}else{let e=new xW(n);i(`webnn`,[e,()=>e.reserveTensorId(),t=>e.releaseTensorId(t),async(t,n,r,i,a)=>e.ensureTensor(t,n,r,i,a),(t,n)=>{e.uploadTensor(t,n)},async(t,n)=>e.downloadTensor(t,n),(t,n)=>e.registerMLContext(t,n),!!n.trace])}}}),n$,r$,i$,a$,o$,s$,c$,l$,u$,d$,f$,p$,m$,h$=Z(()=>{LH(),TU(),MU(),VU(),yU(),CU(),UU(),n$=(e,t)=>{vU()._OrtInit(e,t)!==0&&SU(`Can't initialize onnxruntime.`)},r$=async e=>{n$(e.wasm.numThreads,LU(e.logLevel))},i$=async(e,t)=>{vU().asyncInit?.();let n=e.webgpu.adapter;if(t===`webgpu`){if(typeof navigator>`u`||!navigator.gpu)throw Error(`WebGPU is not supported in current environment`);if(n){if(typeof n.limits!=`object`||typeof n.features!=`object`||typeof n.requestDevice!=`function`)throw Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let t=e.webgpu.powerPreference;if(t!==void 0&&t!==`low-power`&&t!==`high-performance`)throw Error(`Invalid powerPreference setting: "${t}"`);let r=e.webgpu.forceFallbackAdapter;if(r!==void 0&&typeof r!=`boolean`)throw Error(`Invalid forceFallbackAdapter setting: "${r}"`);if(n=await navigator.gpu.requestAdapter({powerPreference:t,forceFallbackAdapter:r}),!n)throw Error(`Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.`)}}if(t===`webnn`&&(typeof navigator>`u`||!navigator.ml))throw Error(`WebNN is not supported in current environment`);{let r=(t$(),zV(ZQ)).init;t===`webgpu`&&await r(`webgpu`,vU(),e,n),t===`webnn`&&await r(`webnn`,vU(),e)}},a$=new Map,o$=e=>{let t=vU(),n=t.stackSave();try{let n=t.PTR_SIZE,r=t.stackAlloc(2*n);t._OrtGetInputOutputCount(e,r,r+n)!==0&&SU(`Can't get session input/output count.`);let i=n===4?`i32`:`i64`;return[Number(t.getValue(r,i)),Number(t.getValue(r+n,i))]}finally{t.stackRestore(n)}},s$=(e,t)=>{let n=vU(),r=n.stackSave(),i=0;try{let r=n.PTR_SIZE,a=n.stackAlloc(2*r);n._OrtGetInputOutputMetadata(e,t,a,a+r)!==0&&SU(`Can't get session input/output metadata.`);let o=Number(n.getValue(a,`*`));i=Number(n.getValue(a+r,`*`));let s=n.HEAP32[i/4];if(s===0)return[o,0];let c=n.HEAPU32[i/4+1],l=[];for(let e=0;e<c;e++){let t=Number(n.getValue(i+8+e*r,`*`));l.push(t===0?Number(n.getValue(i+8+(e+c)*r,`*`)):n.UTF8ToString(t))}return[o,s,l]}finally{n.stackRestore(r),i!==0&&n._OrtFree(i)}},c$=e=>{let t=vU(),n=t._malloc(e.byteLength);if(n===0)throw Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},l$=async(e,t)=>{let n,r,i=vU();Array.isArray(e)?[n,r]=e:e.buffer===i.HEAPU8.buffer?[n,r]=[e.byteOffset,e.byteLength]:[n,r]=c$(e);let a=0,o=0,s=0,c=[],l=[],u=[];try{if([o,c]=await jU(t),t?.externalData&&i.mountExternalData){let e=[];for(let n of t.externalData){let t=typeof n==`string`?n:n.path;e.push(HU(typeof n==`string`?n:n.data).then(e=>{i.mountExternalData(t,e)}))}await Promise.all(e)}for(let e of t?.executionProviders??[])if((typeof e==`string`?e:e.name)===`webnn`){if(i.shouldTransferToMLTensor=!1,typeof e!=`string`){let t=e,n=t?.context,r=t?.gpuDevice,a=t?.deviceType,o=t?.powerPreference;n?i.currentContext=n:r?i.currentContext=await i.webnnCreateMLContext(r):i.currentContext=await i.webnnCreateMLContext({deviceType:a,powerPreference:o})}else i.currentContext=await i.webnnCreateMLContext();break}a=await i._OrtCreateSession(n,r,o),i.webgpuOnCreateSession?.(a),a===0&&SU(`Can't create a session.`),i.jsepOnCreateSession?.(),i.currentContext&&(i.webnnRegisterMLContext(a,i.currentContext),i.currentContext=void 0,i.shouldTransferToMLTensor=!0);let[e,d]=o$(a),f=!!t?.enableGraphCapture,p=[],m=[],h=[],g=[],_=[];for(let t=0;t<e;t++){let[e,n,r]=s$(a,t);e===0&&SU(`Can't get an input name.`),l.push(e);let o=i.UTF8ToString(e);p.push(o),h.push(n===0?{name:o,isTensor:!1}:{name:o,isTensor:!0,type:PU(n),shape:r})}for(let n=0;n<d;n++){let[r,o,s]=s$(a,n+e);r===0&&SU(`Can't get an output name.`),u.push(r);let c=i.UTF8ToString(r);m.push(c),g.push(o===0?{name:c,isTensor:!1}:{name:c,isTensor:!0,type:PU(o),shape:s});{if(f&&t?.preferredOutputLocation===void 0){_.push(`gpu-buffer`);continue}let e=typeof t?.preferredOutputLocation==`string`?t.preferredOutputLocation:t?.preferredOutputLocation?.[c]??`cpu`,n=i.webnnIsGraphOutput;if(e===`cpu`&&n&&n(a,c)){_.push(`ml-tensor-cpu-output`);continue}if(e!==`cpu`&&e!==`cpu-pinned`&&e!==`gpu-buffer`&&e!==`ml-tensor`)throw Error(`Not supported preferred output location: ${e}.`);if(f&&e!==`gpu-buffer`)throw Error(`Not supported preferred output location: ${e}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);_.push(e)}}let v=null;return _.some(e=>e===`gpu-buffer`||e===`ml-tensor`||e===`ml-tensor-cpu-output`)&&(s=i._OrtCreateBinding(a),s===0&&SU(`Can't create IO binding.`),v={handle:s,outputPreferredLocations:_,outputPreferredLocationsEncoded:_.map(e=>e===`ml-tensor-cpu-output`?`ml-tensor`:e).map(e=>BU(e))}),a$.set(a,[a,l,u,v,f,!1]),[a,p,m,h,g]}catch(e){throw l.forEach(e=>i._OrtFree(e)),u.forEach(e=>i._OrtFree(e)),s!==0&&i._OrtReleaseBinding(s)!==0&&SU(`Can't release IO binding.`),a!==0&&i._OrtReleaseSession(a)!==0&&SU(`Can't release session.`),e}finally{i._free(n),o!==0&&i._OrtReleaseSessionOptions(o)!==0&&SU(`Can't release session options.`),c.forEach(e=>i._free(e)),i.unmountExternalData?.()}},u$=e=>{let t=vU(),n=a$.get(e);if(!n)throw Error(`cannot release session. invalid session id: ${e}`);let[r,i,a,o,s]=n;o&&(s&&t._OrtClearBoundOutputs(o.handle)!==0&&SU(`Can't clear bound outputs.`),t._OrtReleaseBinding(o.handle)!==0&&SU(`Can't release IO binding.`)),t.jsepOnReleaseSession?.(e),t.webnnOnReleaseSession?.(e),t.webgpuOnReleaseSession?.(e),i.forEach(e=>t._OrtFree(e)),a.forEach(e=>t._OrtFree(e)),t._OrtReleaseSession(r)!==0&&SU(`Can't release session.`),a$.delete(e)},d$=async(e,t,n,r,i,a,o=!1)=>{if(!e){t.push(0);return}let s=vU(),c=s.PTR_SIZE,l=e[0],u=e[1],d=e[3],f=d,p,m;if(l===`string`&&(d===`gpu-buffer`||d===`ml-tensor`))throw Error(`String tensor is not supported on GPU.`);if(o&&d!==`gpu-buffer`)throw Error(`External buffer must be provided for input/output index ${a} when enableGraphCapture is true.`);if(d===`gpu-buffer`){let t=e[2].gpuBuffer;m=FU(NU(l),u);{let e=s.jsepRegisterBuffer;if(!e)throw Error(`Tensor location "gpu-buffer" is not supported without using WebGPU.`);p=e(r,a,t,m)}}else if(d===`ml-tensor`){let t=e[2].mlTensor;m=FU(NU(l),u);let n=s.webnnRegisterMLTensor;if(!n)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);p=n(r,t,NU(l),u)}else{let t=e[2];if(Array.isArray(t)){m=c*t.length,p=s._malloc(m),n.push(p);for(let e=0;e<t.length;e++){if(typeof t[e]!=`string`)throw TypeError(`tensor data at index ${e} is not a string`);s.setValue(p+e*c,bU(t[e],n),`*`)}}else{let e=s.webnnIsGraphInput,a=s.webnnIsGraphOutput;if(l!==`string`&&e&&a){let o=s.UTF8ToString(i);if(e(r,o)||a(r,o)){let e=NU(l);m=FU(e,u),f=`ml-tensor`;let n=s.webnnCreateTemporaryTensor,i=s.webnnUploadTensor;if(!n||!i)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);let a=await n(r,e,u);i(a,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),p=a}else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p)}else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p)}}let h=s.stackSave(),g=s.stackAlloc(4*u.length);try{u.forEach((e,t)=>s.setValue(g+t*c,e,c===4?`i32`:`i64`));let e=s._OrtCreateTensor(NU(l),p,m,g,u.length,BU(f));e===0&&SU(`Can't create tensor for input/output. session=${r}, index=${a}.`),t.push(e)}finally{s.stackRestore(h)}},f$=async(e,t,n,r,i,a)=>{let o=vU(),s=o.PTR_SIZE,c=a$.get(e);if(!c)throw Error(`cannot run inference. invalid session id: ${e}`);let l=c[0],u=c[1],d=c[2],f=c[3],p=c[4],m=c[5],h=t.length,g=r.length,_=0,v=[],y=[],b=[],x=[],S=[],C=o.stackSave(),w=o.stackAlloc(h*s),T=o.stackAlloc(h*s),E=o.stackAlloc(g*s),D=o.stackAlloc(g*s);try{[_,v]=wU(a),EH(`wasm prepareInputOutputTensor`);for(let r=0;r<h;r++)await d$(n[r],y,x,e,u[t[r]],t[r],p);for(let t=0;t<g;t++)await d$(i[t],b,x,e,d[r[t]],h+r[t],p);DH(`wasm prepareInputOutputTensor`);for(let e=0;e<h;e++)o.setValue(w+e*s,y[e],`*`),o.setValue(T+e*s,u[t[e]],`*`);for(let e=0;e<g;e++)o.setValue(E+e*s,b[e],`*`),o.setValue(D+e*s,d[r[e]],`*`);if(f&&!m){let{handle:n,outputPreferredLocations:a,outputPreferredLocationsEncoded:s}=f;if(u.length!==h)throw Error(`input count from feeds (${h}) is expected to be always equal to model's input count (${u.length}).`);EH(`wasm bindInputsOutputs`);for(let r=0;r<h;r++){let i=t[r];await o._OrtBindInput(n,u[i],y[r])!==0&&SU(`Can't bind input[${r}] for session=${e}.`)}for(let t=0;t<g;t++){let c=r[t];i[t]?.[3]?(S.push(b[t]),o._OrtBindOutput(n,d[c],b[t],0)!==0&&SU(`Can't bind pre-allocated output[${t}] for session=${e}.`)):o._OrtBindOutput(n,d[c],0,s[c])!==0&&SU(`Can't bind output[${t}] to ${a[t]} for session=${e}.`)}DH(`wasm bindInputsOutputs`),a$.set(e,[l,u,d,f,p,!0])}o.jsepOnRunStart?.(l),o.webnnOnRunStart?.(l);let c;c=f?await o._OrtRunWithBinding(l,f.handle,g,E,_):await o._OrtRun(l,T,w,h,D,g,E,_),c!==0&&SU(`failed to call OrtRun().`);let C=[],O=[];EH(`wasm ProcessOutputTensor`);for(let t=0;t<g;t++){let n=Number(o.getValue(E+t*s,`*`));if(n===b[t]||S.includes(b[t])){C.push(i[t]),n!==b[t]&&o._OrtReleaseTensor(n)!==0&&SU(`Can't release tensor.`);continue}let a=o.stackSave(),c=o.stackAlloc(4*s),l=!1,u,d=0;try{o._OrtGetTensorData(n,c,c+s,c+2*s,c+3*s)!==0&&SU(`Can't access output tensor data on index ${t}.`);let i=s===4?`i32`:`i64`,a=Number(o.getValue(c,i));d=o.getValue(c+s,`*`);let p=o.getValue(c+s*2,`*`),m=Number(o.getValue(c+s*3,i)),h=[];for(let e=0;e<m;e++)h.push(Number(o.getValue(p+e*s,i)));o._OrtFree(p)!==0&&SU(`Can't free memory for tensor dims.`);let g=h.reduce((e,t)=>e*t,1);u=PU(a);let _=f?.outputPreferredLocations[r[t]];if(u===`string`){if(_===`gpu-buffer`||_===`ml-tensor`)throw Error(`String tensor is not supported on GPU.`);let e=[];for(let t=0;t<g;t++){let n=o.getValue(d+t*s,`*`),r=o.getValue(d+(t+1)*s,`*`),i=t===g-1?void 0:r-n;e.push(o.UTF8ToString(n,i))}C.push([u,h,e,`cpu`])}else if(_===`gpu-buffer`&&g>0){let e=o.jsepGetBuffer;if(!e)throw Error(`preferredLocation "gpu-buffer" is not supported without using WebGPU.`);let t=e(d),r=FU(a,g);if(r===void 0||!RU(u))throw Error(`Unsupported data type: ${u}`);l=!0,C.push([u,h,{gpuBuffer:t,download:o.jsepCreateDownloader(t,r,u),dispose:()=>{o._OrtReleaseTensor(n)!==0&&SU(`Can't release tensor.`)}},`gpu-buffer`])}else if(_===`ml-tensor`&&g>0){let t=o.webnnEnsureTensor,r=o.webnnIsGraphInputOutputTypeSupported;if(!t||!r)throw Error(`preferredLocation "ml-tensor" is not supported without using WebNN.`);if(FU(a,g)===void 0||!zU(u))throw Error(`Unsupported data type: ${u}`);if(!r(e,u,!1))throw Error(`preferredLocation "ml-tensor" for ${u} output is not supported by current WebNN Context.`);let i=await t(e,d,a,h,!1);l=!0,C.push([u,h,{mlTensor:i,download:o.webnnCreateMLTensorDownloader(d,u),dispose:()=>{o.webnnReleaseTensorId(d),o._OrtReleaseTensor(n)}},`ml-tensor`])}else if(_===`ml-tensor-cpu-output`&&g>0){let e=o.webnnCreateMLTensorDownloader(d,u)(),t=C.length;l=!0,O.push((async()=>{let r=[t,await e];return o.webnnReleaseTensorId(d),o._OrtReleaseTensor(n),r})()),C.push([u,h,[],`cpu`])}else{let e=new(IU(u))(g);new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(o.HEAPU8.subarray(d,d+e.byteLength)),C.push([u,h,e,`cpu`])}}finally{o.stackRestore(a),u===`string`&&d&&o._free(d),l||o._OrtReleaseTensor(n)}}f&&!p&&(o._OrtClearBoundOutputs(f.handle)!==0&&SU(`Can't clear bound outputs.`),a$.set(e,[l,u,d,f,p,!1]));for(let[e,t]of await Promise.all(O))C[e][2]=t;return DH(`wasm ProcessOutputTensor`),C}finally{o.webnnOnRunEnd?.(l),o.stackRestore(C),y.forEach(e=>o._OrtReleaseTensor(e)),b.forEach(e=>o._OrtReleaseTensor(e)),x.forEach(e=>o._free(e)),_!==0&&o._OrtReleaseRunOptions(_),v.forEach(e=>o._free(e))}},p$=e=>{let t=vU(),n=a$.get(e);if(!n)throw Error(`invalid session id`);let r=n[0],i=t._OrtEndProfiling(r);i===0&&SU(`Can't get an profile file name.`),t._OrtFree(i)},m$=e=>{let t=[];for(let n of e){let e=n[2];!Array.isArray(e)&&`buffer`in e&&t.push(e.buffer)}return t}}),g$,_$,v$,y$,b$,x$,S$,C$,w$,T$,E$,D$,O$,k$,A$,j$,M$,N$,P$=Z(()=>{LH(),h$(),yU(),lU(),g$=()=>!!QV.wasm.proxy&&typeof document<`u`,v$=!1,y$=!1,b$=!1,C$=new Map,w$=(e,t)=>{let n=C$.get(e);n?n.push(t):C$.set(e,[t])},T$=()=>{if(v$||!y$||b$||!_$)throw Error(`worker not ready`)},E$=e=>{switch(e.data.type){case`init-wasm`:v$=!1,e.data.err?(b$=!0,S$[1](e.data.err)):(y$=!0,S$[0]()),x$&&=(URL.revokeObjectURL(x$),void 0);break;case`init-ep`:case`copy-from`:case`create`:case`release`:case`run`:case`end-profiling`:{let t=C$.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}default:}},D$=async()=>{if(!y$){if(v$)throw Error(`multiple calls to 'initWasm()' detected.`);if(b$)throw Error(`previous call to 'initWasm()' failed.`);if(v$=!0,g$())return new Promise((e,t)=>{_$?.terminate(),oU().then(([n,r])=>{try{_$=r,_$.onerror=e=>t(e),_$.onmessage=E$,S$=[e,t];let i={type:`init-wasm`,in:QV};!i.in.wasm.wasmPaths&&(n||XH)&&(i.in.wasm.wasmPaths={wasm:new URL(`/assets/ort-wasm-simd-threaded.jsep-C887KxcQ.wasm`,``+import.meta.url).href}),_$.postMessage(i),x$=n}catch(e){t(e)}},t)});try{await _U(QV.wasm),await r$(QV),y$=!0}catch(e){throw b$=!0,e}finally{v$=!1}}},O$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`init-ep`,[t,n]);let r={type:`init-ep`,in:{epName:e,env:QV}};_$.postMessage(r)});await i$(QV,e)},k$=async e=>g$()?(T$(),new Promise((t,n)=>{w$(`copy-from`,[t,n]);let r={type:`copy-from`,in:{buffer:e}};_$.postMessage(r,[e.buffer])})):c$(e),A$=async(e,t)=>{if(g$()){if(t?.preferredOutputLocation)throw Error(`session option "preferredOutputLocation" is not supported for proxy.`);return T$(),new Promise((n,r)=>{w$(`create`,[n,r]);let i={type:`create`,in:{model:e,options:{...t}}},a=[];e instanceof Uint8Array&&a.push(e.buffer),_$.postMessage(i,a)})}else return l$(e,t)},j$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`release`,[t,n]);let r={type:`release`,in:e};_$.postMessage(r)});u$(e)},M$=async(e,t,n,r,i,a)=>{if(g$()){if(n.some(e=>e[3]!==`cpu`))throw Error(`input tensor on GPU is not supported for proxy.`);if(i.some(e=>e))throw Error(`pre-allocated output tensor is not supported for proxy.`);return T$(),new Promise((i,o)=>{w$(`run`,[i,o]);let s=n,c={type:`run`,in:{sessionId:e,inputIndices:t,inputs:s,outputIndices:r,options:a}};_$.postMessage(c,m$(s))})}else return f$(e,t,n,r,i,a)},N$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`end-profiling`,[t,n]);let r={type:`end-profiling`,in:e};_$.postMessage(r)});p$(e)}}),F$,I$,L$,R$=Z(()=>{LH(),P$(),VU(),RH(),UU(),F$=(e,t)=>{switch(e.location){case`cpu`:return[e.type,e.dims,e.data,`cpu`];case`gpu-buffer`:return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},`gpu-buffer`];case`ml-tensor`:return[e.type,e.dims,{mlTensor:e.mlTensor},`ml-tensor`];default:throw Error(`invalid data location: ${e.location} for ${t()}`)}},I$=e=>{switch(e[3]){case`cpu`:return new bH(e[0],e[2],e[1]);case`gpu-buffer`:{let t=e[0];if(!RU(t))throw Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:r,dispose:i}=e[2];return bH.fromGpuBuffer(n,{dataType:t,dims:e[1],download:r,dispose:i})}case`ml-tensor`:{let t=e[0];if(!zU(t))throw Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:r,dispose:i}=e[2];return bH.fromMLTensor(n,{dataType:t,dims:e[1],download:r,dispose:i})}default:throw Error(`invalid data location: ${e[3]}`)}},L$=class{async fetchModelAndCopyToWasmMemory(e){return k$(await HU(e))}async loadModel(e,t){wH();let n;n=typeof e==`string`?await this.fetchModelAndCopyToWasmMemory(e):e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await A$(n,t),TH()}async dispose(){return j$(this.sessionId)}async run(e,t,n){wH();let r=[],i=[];Object.entries(e).forEach(e=>{let t=e[0],n=e[1],a=this.inputNames.indexOf(t);if(a===-1)throw Error(`invalid input '${t}'`);r.push(n),i.push(a)});let a=[],o=[];Object.entries(t).forEach(e=>{let t=e[0],n=e[1],r=this.outputNames.indexOf(t);if(r===-1)throw Error(`invalid output '${t}'`);a.push(n),o.push(r)});let s=r.map((e,t)=>F$(e,()=>`input "${this.inputNames[i[t]]}"`)),c=a.map((e,t)=>e?F$(e,()=>`output "${this.outputNames[o[t]]}"`):null),l=await M$(this.sessionId,i,s,o,c,n),u={};for(let e=0;e<l.length;e++)u[this.outputNames[o[e]]]=a[e]??I$(l[e]);return TH(),u}startProfiling(){}endProfiling(){N$(this.sessionId)}}}),z$={};LV(z$,{OnnxruntimeWebAssemblyBackend:()=>V$,initializeFlags:()=>B$,wasmBackend:()=>H$});var B$,V$,H$,U$=Z(()=>{LH(),P$(),R$(),B$=()=>{(typeof QV.wasm.initTimeout!=`number`||QV.wasm.initTimeout<0)&&(QV.wasm.initTimeout=0);let e=QV.wasm.simd;if(typeof e!=`boolean`&&e!==void 0&&e!==`fixed`&&e!==`relaxed`&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`),QV.wasm.simd=!1),typeof QV.wasm.proxy!=`boolean`&&(QV.wasm.proxy=!1),typeof QV.wasm.trace!=`boolean`&&(QV.wasm.trace=!1),typeof QV.wasm.numThreads!=`number`||!Number.isInteger(QV.wasm.numThreads)||QV.wasm.numThreads<=0)if(typeof self<`u`&&!self.crossOriginIsolated)QV.wasm.numThreads=1;else{let e=typeof navigator>`u`?IV(`node:os`).cpus().length:navigator.hardwareConcurrency;QV.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},V$=class{async init(e){B$(),await D$(),await O$(e)}async createInferenceSessionHandler(e,t){let n=new L$;return await n.loadModel(e,t),n}},H$=new V$});LH(),LH(),LH();var W$=`1.24.3`;{let e=(U$(),zV(z$)).wasmBackend;HV(`webgpu`,e,5),HV(`webnn`,e,5),HV(`cpu`,e,10),HV(`wasm`,e,10)}Object.defineProperty(QV.versions,"web",{value:W$,enumerable:!0});var G$=class{constructor(e,t){this.runner=e,this.config=t}},K$=class extends G${constructor(e,t){super(e,t),this.store=new EV,this.cachedSize=null,this.graph=t.graph,this.params=t.params??{}}get size(){return this.cachedSize??this.inferSize()}reset(e){this.store.reset()}compute(e){let t=this.evaluate(e);if(this.cachedSize===null)return this.cachedSize=t.length,t;if(t.length===this.cachedSize)return t;let n=new Float32Array(this.cachedSize);return n.set(t.subarray(0,Math.min(t.length,this.cachedSize))),n}evaluate(e){let t=DV(this.graph,{runner:this.runner,state:e,params:this.params},this.store);if(t instanceof Float32Array)return t;if(typeof t==`number`)return new Float32Array([t]);if(typeof t==`boolean`)return new Float32Array([+!!t]);if(t instanceof Uint8Array){let e=new Float32Array(t.length);for(let n=0;n<t.length;n++)e[n]=t[n];return e}return new Float32Array}inferSize(){this.runner.getContext();let e={jointPos:new Float32Array(this.runner.getNumActions())};return this.compute(e),this.cachedSize??0}},q$=class{constructor(e,t={}){this.motionCache=new Map,this.config=e,this.options=t,this.policyModule=null,this.obsGroups={},this.obsLayouts={},this.obsSizes={},this.historyConfig={},this.historyBuffers={},this.defaultObsKey=null,this.context=null,this.policyJointNames=(e.policy_joint_names??[]).slice(),this.numActions=e.policy_num_actions??this.policyJointNames.length,this.lastActions=new Float32Array(this.numActions),this.defaultJointPos=this.normalizeArray(e.default_joint_pos??[],this.numActions,0),this.encoderBias=this.normalizeArray(e.encoder_bias??[],this.numActions,0)}async init(e){this.context=e,this.policyModule=await this.buildPolicyModule(e),this.buildObservationGroups()}reset(e){this.lastActions.fill(0),this.policyModule?.reset();for(let t of Object.values(this.obsGroups))for(let n of t)n.reset&&n.reset(e);if(e){for(let[t,n]of Object.entries(this.historyConfig))if(n.steps>1){let r=this.buildFrame(this.obsGroups[t]??[],e),i=this.historyBuffers[t];for(let e=0;e<n.steps;e++)i.set(r,e*r.length)}}}update(e){this.policyModule?.update();for(let t of Object.values(this.obsGroups))for(let n of t)n.update&&n.update(e)}collectObservationsByKey(e){this.update(e);let t={};for(let[n,r]of Object.entries(this.obsGroups)){let i=this.historyConfig[n];if(i&&i.steps>1){let i=this.buildFrame(r,e),a=this.historyBuffers[n];for(let e=a.length-1;e>=i.length;e--)a[e]=a[e-i.length];a.set(i,0),t[n]=new Float32Array(a)}else t[n]=this.buildFrame(r,e)}return t}collectObservations(e){let t=this.collectObservationsByKey(e);if(this.defaultObsKey&&t[this.defaultObsKey])return t[this.defaultObsKey];let n=Object.keys(t)[0];return n?t[n]:new Float32Array}async preloadAll(){let e=[];for(let t of Object.values(this.obsGroups))for(let n of t)typeof n.preload==`function`&&e.push(n.preload());await Promise.all(e)}getObservationSize(){if(this.defaultObsKey&&this.obsSizes[this.defaultObsKey]!==void 0)return this.obsSizes[this.defaultObsKey];let e=Object.keys(this.obsSizes)[0];return e?this.obsSizes[e]:0}getObservationLayout(){if(this.defaultObsKey&&this.obsLayouts[this.defaultObsKey])return this.obsLayouts[this.defaultObsKey].map(e=>({...e}));let e=Object.keys(this.obsLayouts)[0];return e?this.obsLayouts[e].map(e=>({...e})):[]}getPolicyModuleContext(){return this.policyModule?.getContext()??{}}getPolicyModule(){return this.policyModule}getContext(){return this.context}getPolicyJointNames(){return this.policyJointNames.slice()}getNumActions(){return this.numActions}getDefaultJointPos(){return new Float32Array(this.defaultJointPos)}getEncoderBias(){return new Float32Array(this.encoderBias)}getLastActions(){return new Float32Array(this.lastActions)}getConfig(){return this.config}getMotionData(e){let t=this.motionCache.get(e);if(t)return t;let n=this.options.motions?.find(t=>t.name===e),r=n?UB(n.data):Promise.resolve(null);return this.motionCache.set(e,r),r}setLastActions(e){if(e.length!==this.lastActions.length){this.lastActions=new Float32Array(e);return}this.lastActions.set(e)}async buildPolicyModule(e){let t=this.options.policyModules??{},n=this.config.policy_module,r=n?t[n]:t.default;if(n&&!r)throw Error(`Unknown policy module: ${n}`);if(!r)return null;let i=new r(this.config);return await i.init(e),i}buildObservationGroups(){let e=this.options.observations??{},t=this.config.observations??{};this.obsGroups={},this.obsLayouts={},this.obsSizes={},this.historyConfig={},this.historyBuffers={},this.defaultObsKey=null;let n=t=>{let n=t;if(n.kind===`observation`&&Array.isArray(n.nodes))return new K$(this,{name:`DslObservation`,graph:{kind:`observation`,nodes:n.nodes,output:n.output??``},params:n.params});let r=e[t.name];if(!r)throw Error(`Unknown observation type: ${t.name}`);return new r(this,t)};for(let[r,i]of Object.entries(t)){if(Array.isArray(i)){let e=i.map(n);this.registerGroup(r,e,i);continue}if(i&&typeof i==`object`){let t=i;if(Array.isArray(t.components)){let n=t.components.map(t=>{let n=t;if(n.kind===`observation`&&Array.isArray(n.nodes))return new K$(this,{name:`DslObservation`,graph:{kind:`observation`,nodes:n.nodes,output:n.output??``},params:n.params});let r=e[t.name];if(!r)throw Error(`Unknown observation type: ${t.name}`);let i={...t,history_steps:1};return new r(this,i)}),i=Math.max(1,Math.floor(t.history_steps??1)),a=!!t.interleaved;this.registerGroup(r,n,t.components,{steps:i,interleaved:a})}}}this.obsGroups.policy?this.defaultObsKey=`policy`:this.obsGroups.observation?this.defaultObsKey=`observation`:this.obsGroups.obs_history?this.defaultObsKey=`obs_history`:this.defaultObsKey=Object.keys(this.obsGroups)[0]??null}registerGroup(e,t,n,r){this.obsGroups[e]=t,this.obsLayouts[e]=t.map((e,t)=>({name:n[t]?.name??`obs_${t}`,size:e.size}));let i=this.obsLayouts[e].reduce((e,t)=>e+t.size,0);r&&r.steps>1?(this.historyConfig[e]=r,this.historyBuffers[e]=new Float32Array(i*r.steps),this.obsSizes[e]=i*r.steps):this.obsSizes[e]=i}buildFrame(e,t){let n=e.map(e=>{let n=e.compute(t),r=n instanceof Float32Array?n:Float32Array.from(n);if(r.length!==e.size)throw Error(`Observation size mismatch: expected ${e.size}, got ${r.length}`);return r}),r=n.reduce((e,t)=>e+t.length,0),i=new Float32Array(r),a=0;for(let e of n)i.set(e,a),a+=e.length;return i}normalizeArray(e,t,n){let r=new Float32Array(t);for(let i=0;i<t;i++)r[i]=typeof e[i]==`number`?e[i]:n;return r}};QV.wasm.proxy=!1,QV.wasm.numThreads=1,typeof __ORT_CDN_BASE__<`u`&&(QV.wasm.wasmPaths=__ORT_CDN_BASE__);var J$=class{constructor(e,t){this.bytes=e,this.session=null;let n=t?.in_keys??[`policy`],r=t?.out_keys??[`action`];this.configuredInKeys=n.map(e=>Array.isArray(e)?e.join(`,`):e),this.inKeys=[...this.configuredInKeys],this.outKeys=r.map(e=>Array.isArray(e)?e.join(`,`):e),this.isRecurrent=this.inKeys.includes(`adapt_hx`)}async init(){this.session=await jH.create(this.bytes,{executionProviders:[`wasm`],graphOptimizationLevel:`all`}),this.inferInputKeys(),this.isRecurrent=this.inKeys.includes(`adapt_hx`)}initInput(){let e={};return this.isRecurrent&&(e.is_init=new bH(`bool`,[!0],[1]),e.adapt_hx=new bH(`float32`,new Float32Array(128),[1,128])),this.inKeys.includes(`time_step`)&&(e.time_step=new bH(`float32`,new Float32Array([0]),[1,1])),e}async runInference(e){if(!this.session)throw Error(`OnnxModule not initialized.`);let t={};for(let n=0;n<this.inKeys.length;n++){let r=this.inKeys[n],i=this.session.inputNames[n];if(!i||!e[r])throw Error(`Missing ONNX input for key: ${r}`);t[i]=e[r]}let n=await this.session.run(t),r={};for(let e=0;e<this.outKeys.length;e++){let t=this.outKeys[e],i=this.session.outputNames[e];i&&n[i]&&(r[t]=n[i])}let i={};return this.isRecurrent&&r[`next,adapt_hx`]&&(i.is_init=new bH(`bool`,[!1],[1]),i.adapt_hx=r[`next,adapt_hx`]),[r,i]}dispose(){this.session?.release?.(),this.session=null}inferInputKeys(){if(!this.session)return;let e=this.session.inputNames;if(e.length<=1){this.inKeys=[...this.configuredInKeys];return}if(this.configuredInKeys.length===e.length){this.inKeys=[...this.configuredInKeys];return}this.inKeys=e.map(e=>this.configuredInKeys.includes(e)?e:e===`obs`&&this.configuredInKeys.includes(`policy`)?`policy`:e)}},Y$=class{constructor(e,t,n,r){this.mujoco=e,this.mjModel=t,this.mjData=n;let i=this.getJointNames(t);this.qposAdr=[],this.qvelAdr=[],this.jointIndices=[],this.ctrlAdr=null;for(let e of r){let n=i.indexOf(e);if(n<0)throw Error(`Joint "${e}" not found in MuJoCo model`);this.qposAdr.push(t.jnt_qposadr[n]),this.qvelAdr.push(t.jnt_dofadr[n]),this.jointIndices.push(n)}this.numActions=r.length,this.ctrlAdr=this.buildCtrlAdr()}build(){let e=this.mjData.qpos,t=this.mjData.qvel,n=new Float32Array(this.numActions),r=new Float32Array(this.numActions);for(let i=0;i<this.numActions;i++)n[i]=e[this.qposAdr[i]],r[i]=t[this.qvelAdr[i]];return{jointPos:n,jointVel:r,rootPos:new Float32Array([e[0],e[1],e[2]]),rootQuat:new Float32Array([e[3],e[4],e[5],e[6]]),rootLinVel:new Float32Array([t[0],t[1],t[2]]),rootAngVel:new Float32Array([t[3],t[4],t[5]])}}getControlMapping(){return this.ctrlAdr?{ctrlAdr:this.ctrlAdr.slice(),qposAdr:this.qposAdr.slice(),qvelAdr:this.qvelAdr.slice()}:null}getControlMappingFor(e,t){if(!this.ctrlAdr)return null;let n=e.map(e=>RegExp(`^(?:${e})$`)),r=e=>n.some(t=>t.test(e)),i=[],a=[],o=[],s=[];for(let e=0;e<t.length;e++)r(t[e])&&(i.push(this.ctrlAdr[e]),a.push(this.qposAdr[e]),o.push(this.qvelAdr[e]),s.push(e));return i.length===0?null:{ctrlAdr:i,qposAdr:a,qvelAdr:o,actionIndices:s}}getCtrlMappingByActuatorNames(e){let t=this.getActuatorNames(this.mjModel),n=e.map(e=>RegExp(`^(?:${e})$`)),r=e=>n.some(t=>t.test(e)),i=[],a=[];for(let e=0;e<t.length;e++)r(t[e])&&(i.push(e),a.push(i.length-1));return i.length>0?{ctrlAdr:i,actionIndices:a}:null}getActuatorNames(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.nu;i++){let a=e.name_actuatoradr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;r.push(n.decode(t.subarray(a,o)))}return r}buildCtrlAdr(){if(this.mjModel.nu<=0)return null;let e=this.mujoco.mjtTrn?.mjTRN_JOINT?.value,t=[];for(let n=0;n<this.mjModel.nu;n++){let r=this.mjModel.actuator_trntype[n];e===void 0||r===e?t.push(this.mjModel.actuator_trnid[2*n]):t.push(-1)}let n=[];for(let e of this.jointIndices){let r=t.findIndex(t=>t===e);if(r<0)return null;n.push(r)}return n}getJointNames(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.njnt;i++){let a=e.name_jntadr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;let s=n.decode(t.subarray(a,o));!s&&i===0&&(s=`floating_base_joint`),r.push(s)}return r}},X$=class{constructor(e){this.config=e,this.context=null}init(e){this.context=e}reset(){}update(){}getContext(){return{}}},Z$=class{constructor(e){this.policyJointNames=(e.policy_joint_names??[]).slice(),this.datasetJointNames=(e.dataset_joint_names??[]).slice(),this.nJoints=this.datasetJointNames.length||this.policyJointNames.length||0,this.refJointPos=[],this.refRootPos=[],this.refRootQuat=[],this.refIdx=0,this.refLen=0,this.currentName=`default`,this.currentDone=!0}reset(e){let t=e?.jointPos??new Float32Array(this.nJoints),n=e?.rootPos??new Float32Array([0,0,0]),r=e?.rootQuat??new Float32Array([1,0,0,0]);this.refJointPos=[Float32Array.from(t)],this.refRootPos=[Float32Array.from(n)],this.refRootQuat=[Float32Array.from(r)],this.refIdx=0,this.refLen=1,this.currentDone=!0,this.currentName=`default`}advance(){this.refLen<=1||this.refIdx<this.refLen-1&&(this.refIdx+=1,this.refIdx===this.refLen-1&&(this.currentDone=!0))}isReady(){return this.refLen>0}},Q$=class extends X${constructor(e){super(e),this.tracking=null}async init(e){await super.init(e);let t=this.config.policy_joint_names??[],n={...this.config.tracking,policy_joint_names:t};this.tracking=new Z$(n)}reset(e){this.tracking?.reset(e)}update(){this.tracking?.advance()}getContext(){return{tracking:this.tracking}}},$$=class{constructor(e){this.policyJointNames=(e.policy_joint_names??[]).slice(),this.datasetJointNames=(e.dataset_joint_names??[]).slice(),this.nJoints=this.datasetJointNames.length||this.policyJointNames.length||0,this.refJointPos=[],this.refRootPos=[],this.refRootQuat=[],this.refIdx=0,this.refLen=0,this.currentName=`default`,this.currentDone=!0}reset(e){let t=e?.jointPos??new Float32Array(this.nJoints),n=e?.rootPos??new Float32Array([0,0,0]),r=e?.rootQuat??new Float32Array([1,0,0,0]);this.refJointPos=[Float32Array.from(t)],this.refRootPos=[Float32Array.from(n)],this.refRootQuat=[Float32Array.from(r)],this.refIdx=0,this.refLen=1,this.currentDone=!0,this.currentName=`default`}advance(){this.refLen<=1||this.refIdx<this.refLen-1&&(this.refIdx+=1,this.refIdx===this.refLen-1&&(this.currentDone=!0))}isReady(){return this.refLen>0}},e1=class extends X${constructor(e){super(e),this.locomotion=null}async init(e){await super.init(e);let t=this.config.policy_joint_names??[],n={...this.config.tracking,policy_joint_names:t};this.locomotion=new $$(n)}reset(e){this.locomotion?.reset(e)}update(){this.locomotion?.advance()}getContext(){return{tracking:this.locomotion}}},t1=class{constructor(e){this.config=e}};function n1(e,t){return e+Math.random()*(t-e)}function r1(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.njnt;i++){let a=e.name_jntadr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;r.push(n.decode(t.subarray(a,o)))}return r}function i1(e){for(let t=0;t<e.njnt;t++)if(e.jnt_type[t]===0)return t;return-1}var a1=class extends t1{constructor(e){super(e),this.mutations=e.mutations??[]}onReset(e){let{mjModel:t,mjData:n}=e;if(!(!t||!n))for(let e of this.mutations)switch(e.target){case`joint_qpos`:this.applyJointOffset(t,n,e,`qpos`);break;case`joint_qvel`:this.applyJointOffset(t,n,e,`qvel`);break;case`freejoint_pos`:this.applyFreejointPos(t,n,e);break;case`freejoint_yaw`:this.applyFreejointYaw(t,n,e);break}}resolveJointIndices(e,t){let n=t.select??{};if(n.joint_ids&&n.joint_ids.length>0)return n.joint_ids.filter(t=>t>=0&&t<e.njnt);let r=r1(e);return n.joint_names&&n.joint_names.length>0?n.joint_names.map(e=>this.findJointIndex(r,e,n.entity_name)).filter(e=>e!==null):r.map((e,t)=>({name:e,idx:t})).filter(({name:t,idx:r})=>e.jnt_type[r]===0?!1:n.entity_name?t===n.entity_name||t.startsWith(`${n.entity_name}/`):!0).map(({idx:e})=>e)}findJointIndex(e,t,n){let r=e.indexOf(t);if(r>=0)return r;if(n){let r=e.indexOf(`${n}/${t}`);if(r>=0)return r}let i=e.map((e,t)=>({name:e,idx:t})).filter(({name:e})=>e===t||e.endsWith(`/${t}`));if(i.length===1)return i[0].idx;if(n){let e=i.find(({name:e})=>e===n||e.startsWith(`${n}/`));if(e)return e.idx}return null}applyJointOffset(e,t,n,r){if(n.sample.dist!==`uniform`)return;let{low:i,high:a}=n.sample;for(let o of this.resolveJointIndices(e,n)){let s=e.jnt_type[o];if(!(s!==2&&s!==3))if(r===`qpos`){let r=e.jnt_qposadr[o];if(t.qpos[r]+=n1(i,a),n.clip_to_limits&&e.jnt_limited[o]){let n=e.jnt_range[o*2],i=e.jnt_range[o*2+1];t.qpos[r]=Math.min(Math.max(t.qpos[r],n),i)}}else t.qvel[e.jnt_dofadr[o]]+=n1(i,a)}}applyFreejointPos(e,t,n){if(n.sample.dist!==`uniform_xyz`)return;let r=i1(e);if(r<0)return;let i=e.jnt_qposadr[r];t.qpos[i]+=n1(n.sample.x[0],n.sample.x[1]),t.qpos[i+1]+=n1(n.sample.y[0],n.sample.y[1]),t.qpos[i+2]+=n1(n.sample.z[0],n.sample.z[1])}applyFreejointYaw(e,t,n){if(n.sample.dist!==`uniform`)return;let r=i1(e);if(r<0)return;let i=e.jnt_qposadr[r]+3,a=n1(n.sample.low,n.sample.high),o=Math.cos(a/2),s=Math.sin(a/2),c=t.qpos[i],l=t.qpos[i+1],u=t.qpos[i+2],d=t.qpos[i+3];t.qpos[i]=o*c-s*d,t.qpos[i+1]=o*l+s*u,t.qpos[i+2]=o*u-s*l,t.qpos[i+3]=o*d+s*c}};function o1(e){return`kind`in e&&e.kind===`event`&&Array.isArray(e.mutations)}var s1=class{constructor(e,t){this.terms=[];for(let n of e){if(o1(n)){this.terms.push(new a1(n));continue}let e=t[n.name];if(!e){console.warn(`[EventManager] Unknown event type: ${n.name}`);continue}this.terms.push(new e(n))}}onReset(e){for(let t of this.terms)t.onReset(e)}get size(){return this.terms.length}},c1={};function l1(e){return typeof e==`object`&&!!e&&typeof e.setSelectedMotion==`function`}var u1=class extends Error{constructor(){super(`This scene cannot be loaded because it exceeds the browser's WebAssembly 2 GB memory limit. Try closing other browser tabs or reloading the page to free memory.`),this.name=`WasmMemoryLimitError`}};function d1(e){let t=e instanceof Error?e.message:String(e);return t.includes(`MjModel loading returned null`)||t.includes(`Could not allocate memory`)||t.includes(`memory allocation failed`)||t.includes(`bad_alloc`)}var f1=class{constructor(e,t){this.render=()=>{if(this.commandManager.updateDebugVisuals(),this.mjData&&AB(this.mjData,this.camera,this.controls,this.cameraState),this.controls.update(),this.mjModel&&this.mjData&&this.bodies){WN(this.camera,this.lights);for(let[e,t]of this.lastSimState.bodies){let n=this.bodies[e];n&&(n.position.copy(t.position),n.quaternion.copy(t.quaternion))}UN(this.mujoco,this.mjData,this.lights),this.mujocoRoot&&this.mujocoRoot.cylinders&&QN({cylinders:this.mujocoRoot.cylinders,spheres:this.mujocoRoot.spheres},this.lastSimState.tendons)}this.renderer.render(this.scene,this.camera)},this.onWindowResize=()=>{let{width:e,height:t}=this.getSize();this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)},this.mujoco=e,this.container=t,this.commandManager=new rV,this.scenePlugins={},this.policyPlugins={};let n=`/working`;try{this.mujoco.FS.mkdir(n)}catch(e){e&&typeof e==`object`&&`code`in e&&e.code!==`EEXIST`&&console.warn(`Failed to create /working directory:`,e)}try{this.mujoco.FS.mount(this.mujoco.MEMFS,{root:`.`},n)}catch(e){e&&typeof e==`object`&&`code`in e&&e.code!==`EEXIST`&&e.code!==`EBUSY`&&console.warn(`Failed to mount MEMFS at /working:`,e)}let{width:r,height:i}=this.getSize();this.scene=new nC,this.scene.name=`scene`,this.camera=new GS(45,r/i,.001,1e3),this.camera.name=`PerspectiveCamera`,this.camera.position.set(2,1.7,1.7),this.scene.add(this.camera),this.renderer=new hN({antialias:!0}),this.renderer.xr.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(r,i),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=2,this.renderer.outputColorSpace=Rv,this.renderer.toneMapping=4,this.renderer.toneMappingExposure=1,this.container.appendChild(this.renderer.domElement),this.vrButton=null,navigator.xr?.isSessionSupported(`immersive-vr`).then(e=>{e&&(this.vrButton=zN.createButton(this.renderer),document.body.appendChild(this.vrButton))}),this.controls=new EN(this.camera,this.renderer.domElement),this.controls.target.set(0,.2,0),this.controls.panSpeed=2,this.controls.zoomSpeed=1,this.controls.enableDamping=!0,this.controls.dampingFactor=.1,this.controls.screenSpacePanning=!0,this.controls.update(),this.renderer.setAnimationLoop(this.render),window.addEventListener(`resize`,this.onWindowResize),`ResizeObserver`in window?(this.resizeObserver=new ResizeObserver(()=>this.onWindowResize()),this.resizeObserver.observe(this.container)):this.resizeObserver=null,this.lastSimState={bodies:new Map,tendons:$N()},this.dynamicBodyIds=null,this.mjModel=null,this.mjData=null,this.bodies=null,this.lights=[],this.mujocoRoot=null,this.loopPromise=null,this.running=!1,this.timestep=.001,this.decimation=1,this.policyCtrlDt=null,this.loadingScene=null,this.dragStateManager=null,this.dragForceScale=100,this.policyRunner=null,this.policyStateBuilder=null,this.initialQpos=null,this.initialQvel=null,this.policyControl=null,this.onnxModule=null,this.onnxInputDict=null,this.onnxInferencing=!1,this.onnxTimeStep=0,this.terminationManager=null,this.eventManager=null,this.terrainData=null,this.splatMesh=null,this.colliderMesh=null,this.currentSplatTransform={},this.cameraState={trackBodyId:null,prevBodyPos:null}}async loadEnvironment(e){this.scenePlugins=e.plugins??{},this.terrainData=e.terrainData??null,e.events&&e.events.length>0?(this.eventManager=new s1(e.events,{...c1,...this.scenePlugins.events}),console.log(`[EventManager] ${this.eventManager.size} reset event(s) loaded`)):this.eventManager=null,await this.stop(),this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),this.initializeCommands(),this.mjModel=null,this.mjData=null,this.bodies=null,this.lights=[],this.mujocoRoot=null,this.dynamicBodyIds=null,await this.buildSceneFromMjz(e.model),e.splat&&await this.applySplat(e.splat),await this.loadPolicyConfig(e.policy??null),this.applyViewerConfig(e.viewer??null),this.running=!0,this.startLoop()}initializeCommands(){this.commandManager.clear()}initializeCommandsFromConfig(e,t){this.commandManager.initialize(e,t,this.policyPlugins.commands),console.log(`[mjswanRuntime] Commands loaded from policy config:`,Object.keys(e))}resetSimulation(){if(this.resetSimulationState(),this.policyRunner&&this.policyStateBuilder){let e=this.policyStateBuilder.build();this.policyRunner.reset(e)}console.log(`[mjswanRuntime] Simulation reset`)}async setSelectedMotion(e){let t=this.commandManager.getTerm(`motion`);if(!l1(t))return!1;let n=await t.setSelectedMotion(e);return n&&this.resetSimulation(),n}getSelectedMotionName(){let e=this.commandManager.getTerm(`motion`);return l1(e)?e.getSelectedMotionName?.()??null:null}setReferenceVisible(e){let t=this.commandManager.getTerm(`motion`);!l1(t)||typeof t.setReferenceVisible!=`function`||t.setReferenceVisible(e)}async buildScene(e){this.loadingScene&&await this.loadingScene,this.loadingScene=(async()=>{let t=this.scene.getObjectByName(`MuJoCo Root`);t&&this.scene.remove(t);let n={mjModel:this.mjModel,mjData:this.mjData,scene:this.scene};if([this.mjModel,this.mjData,this.bodies,this.lights]=await rP(this.mujoco,e,n),!this.mjModel||!this.mjData)throw Error(`Failed to load MuJoCo model.`);this.mujocoRoot=this.scene.getObjectByName(`MuJoCo Root`),this.mujoco.mj_forward(this.mjModel,this.mjData),UN(this.mujoco,this.mjData,this.lights),WN(this.camera,this.lights),this.dynamicBodyIds=this.computeDynamicBodyIds(this.mjModel),this.syncStaticBodiesFromData(),this.timestep=this.mjModel.opt.timestep||.001;let r=this.policyCtrlDt??.02;this.decimation=Math.max(1,Math.round(r/this.timestep)),this.lastSimState.bodies.clear(),this.updateCachedState(),this.dragStateManager?this.dragStateManager.setDraggableBodyIds(this.dynamicBodyIds):this.dragStateManager=new EB({scene:this.scene,renderer:this.renderer,camera:this.camera,container:this.container,controls:this.controls,draggableBodyIds:this.dynamicBodyIds}),this.loadingScene=null})(),await this.loadingScene}async buildSceneFromMjz(e){try{let t=await cP(this.mujoco,e);await this.buildScene(t)}catch(e){throw this.loadingScene=null,d1(e)?new u1:e}}async startLoop(){return this.loopPromise?this.loopPromise:(this.running=!0,this.loopPromise=this.mainLoop(),this.loopPromise)}async setSplat(e){this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),e&&await this.applySplat(e)}async applySplat(e){this.currentSplatTransform=e.transform??{},this.splatMesh=Sz(e.data,this.currentSplatTransform,this.scene),e.collider&&(this.colliderMesh=await wB(e.collider,this.scene))}calibrateSplat(e){this.currentSplatTransform=e,this.splatMesh&&xz(this.splatMesh,e)}setSplatVisible(e){this.splatMesh&&(this.splatMesh.visible=e)}get commands(){return this.commandManager}play(){this.running=!0,this.startLoop()}pause(){this.stop()}get isRunning(){return this.running}getCameraView(){let e=this.camera.position.clone().sub(this.controls.target),t=e.length(),n=VN(e),r=VN(this.controls.target.clone()),i=180/Math.PI,a=t>1e-9?Math.asin(-n.z/t)*i:0,o=Math.atan2(n.y,n.x)*i;return{lookat:[r.x,r.y,r.z],distance:t,azimuth:o,elevation:a,fovy:this.camera.fov}}setCameraView(e){let t=this.getCameraView(),n=e.lookat??t.lookat,r=e.distance??t.distance,i=e.elevation??t.elevation,a=e.azimuth??t.azimuth;this.camera.fov=e.fovy??t.fovy,this.camera.updateProjectionMatrix(),this.camera.position.copy(OB(n,r,i,a)),this.controls.target.copy(BN(n)),this.controls.update()}frameCamera(){if(!this.mujocoRoot)return;let e=new Cb().setFromObject(this.mujocoRoot);if(e.isEmpty())return;let t=e.getCenter(new Y),n=e.getSize(new Y).length(),r=this.camera.fov*Math.PI/180,i=n/(2*Math.tan(r/2)),a=this.getCameraView(),o=VN(t);this.setCameraView({lookat:[o.x,o.y,o.z],distance:i>0?i:a.distance})}async stop(){this.running=!1;let e=this.loopPromise;e&&await e,this.loopPromise=null}async mainLoop(){for(;this.running;){let e=performance.now(),t=this.timestep*this.decimation;if(this.mjModel&&this.mjData){if(this.mujoco.mj_forward(this.mjModel,this.mjData),this.policyRunner&&this.policyStateBuilder){let e=this.policyStateBuilder.build(),t=this.policyRunner.collectObservationsByKey(e);await this.runOnnxInference(t)}if(this.executeSimulationSteps(),this.updateCachedState(),this.terminationManager&&this.policyStateBuilder){let e=this.policyStateBuilder.build();if(this.terminationManager.evaluate(e).done&&(this.resetSimulationState(),this.terminationManager.reset(),this.policyRunner)){let e=this.policyStateBuilder.build();this.policyRunner.reset(e)}}this.commandManager.update(t),this.commandManager.updateDebugVisuals()}let n=(performance.now()-e)/1e3,r=Math.max(0,t-n);r>0&&await new Promise(e=>setTimeout(e,r*1e3))}this.loopPromise=null}async loadPolicyConfig(e){if(this.policyPlugins=e?.plugins??{},this.policyRunner=null,this.policyStateBuilder=null,this.policyControl=null,this.onnxModule=null,this.onnxInputDict=null,this.onnxInferencing=!1,this.onnxTimeStep=0,this.terminationManager=null,this.commandManager.clear(),e){if(!this.mjModel||!this.mjData){console.warn(`Policy config loaded before MuJoCo model is ready.`);return}this.resetSimulationState();try{let t=e.config;if(Array.isArray(t.motions)){let n=new Map(e.motions.map(e=>[e.name,e.data]));t.motions=t.motions.map(e=>({...e,data:n.get(e.name)}))}if(t.commands?.motion&&Array.isArray(t.motions)&&(t.commands.motion={...t.commands.motion,motions:t.motions}),this.initialQpos=Array.isArray(t.initial_qpos)?t.initial_qpos:null,this.initialQvel=Array.isArray(t.initial_qvel)?t.initial_qvel:null,this.resetSimulationState(),this.mujoco.mj_forward(this.mjModel,this.mjData),this.updateCachedState(),t.commands&&typeof t.commands==`object`){this.initializeCommandsFromConfig(t.commands,{mujoco:this.mujoco,mjModel:this.mjModel,mjData:this.mjData,scene:this.scene,bodies:this.bodies,mujocoRoot:this.mujocoRoot,requestReset:()=>this.resetSimulation()}),this.commandManager.resetTerms();let e=this.commandManager.getTerm(`motion`);l1(e)&&(await e.setSelectedMotion(t.motions?.find(e=>e.default)?.name??t.motions?.[0]?.name??null),e.setReferenceVisible?.(!0)),this.mujoco.mj_forward(this.mjModel,this.mjData),this.updateCachedState()}if(!t.policy_num_actions&&(!t.policy_joint_names||t.policy_joint_names.length===0))throw Error(`Policy config missing policy_joint_names.`);let n=new q$(t,{policyModules:{tracking:Q$,locomotion:e1},observations:{...jB,...this.policyPlugins.observations},motions:e.motions});await n.init({mujoco:this.mujoco,mjModel:this.mjModel,mjData:this.mjData,scene:this.scene,commandManager:this.commandManager}),await n.preloadAll(),this.policyRunner=n,this.policyStateBuilder=new Y$(this.mujoco,this.mjModel,this.mjData,n.getPolicyJointNames());let r=this.policyStateBuilder.build();this.policyRunner.reset(r),this.policyControl=this.buildPolicyControl(t,n,this.policyStateBuilder);{let e=t.observations,n=[];if(Array.isArray(e))n.push(...e);else if(e&&typeof e==`object`)for(let t of Object.values(e))Array.isArray(t)&&n.push(...t);for(let e of n)if(!(!e||this.timestep<=0)&&typeof e.fps==`number`&&e.fps>0){this.policyCtrlDt=1/e.fps;let t=Math.max(1,Math.round(this.policyCtrlDt/this.timestep));t!==this.decimation&&(console.log(`[PolicyRunner] Decimation updated: ${this.decimation} → ${t} (fps=${e.fps}, sim_dt=${this.timestep})`),this.decimation=t);break}}t.terminations&&Object.keys(t.terminations).length>0&&(this.terminationManager=new AV(t.terminations,{...jV,...this.policyPlugins.terminations},n),console.log(`[TerminationManager] ${this.terminationManager.size} termination term(s) loaded`));let i=new J$(e.onnx,t.onnx?.meta);await i.init(),this.onnxModule=i,this.onnxInputDict=i.initInput(),console.log(`[PolicyRunner] config loaded`,{obsSize:n.getObservationSize(),obsLayout:n.getObservationLayout(),pdEnabled:this.policyControl!==null})}catch(e){console.warn(`Failed to load policy config:`,e)}}}buildPolicyControl(e,t,n){let r=t.getPolicyJointNames(),i=this.mujoco.mjtBias?.mjBIAS_AFFINE?.value??1,a=(n,a,o,s,c,l,u,d)=>{let f=o.qposAdr.length,p=o.actionIndices.map(e=>r[e]),m=this.normalizeControlArray(s,f,1,p),h=this.normalizeControlArray(c,f,0,p),g=d?t.getDefaultJointPos():new Float32Array(r.length),_=new Float32Array(f);for(let e=0;e<f;e++)_[e]=g[o.actionIndices[e]];let v=Array.isArray(e.encoder_bias)?Float32Array.from(e.encoder_bias):new Float32Array(r.length),y=new Float32Array(f);for(let e=0;e<f;e++)y[e]=v[o.actionIndices[e]]??0;let b=this.normalizeControlArray(l,f,0,p),x=this.normalizeControlArray(u,f,0,p),S=o.ctrlAdr.map(e=>e<0||!this.mjModel?!1:this.mjModel.actuator_biastype[e]===i),C=S.some(Boolean),w=S.some(e=>!e);return C&&w&&console.warn(`[PolicyRunner] Action term "${n}": mixed actuator types detected.`),console.log(`[PolicyRunner] Action term "${n}" (${a}): ${f} joint(s), mode: ${C?`position (ctrl=target_pos)`:`motor (ctrl=torque, external PD)`}`),{controlType:a,ctrlAdr:o.ctrlAdr,qposAdr:o.qposAdr,qvelAdr:o.qvelAdr,actionIndices:o.actionIndices,actionScale:m,actionOffset:h,defaultJointPos:_,encoderBias:y,positionActuator:S,kp:b,kd:x,muscleNormalize:!1}},o=e.actions;if(!o||Object.keys(o).length===0){let t=e.control_type??`joint_position`;if(t!==`joint_position`&&t!==`torque`)return console.warn(`[PolicyRunner] Unsupported control_type: ${t}`),null;let r=n.getControlMapping();return r?[a(`legacy`,t,{...r,actionIndices:Array.from({length:r.qposAdr.length},(e,t)=>t)},e.action_scale,void 0,e.stiffness,e.damping,!0)]:(console.warn(`[PolicyRunner] Failed to build control mapping.`),null)}let s=[];for(let[e,t]of Object.entries(o)){let i=t.type??`joint_position`;if(i!==`joint_position`&&i!==`torque`&&i!==`muscle_activation`){console.warn(`[PolicyRunner] Action term "${e}": unsupported type "${i}", skipping.`);continue}let o=t.actuator_names??[`.*`];if(i===`muscle_activation`){let r=n.getCtrlMappingByActuatorNames(o);if(!r){console.warn(`[PolicyRunner] Action term "${e}": no actuators matched patterns [${o.join(`, `)}], skipping.`);continue}let a=r.ctrlAdr.length,c=this.normalizeControlArray(t.scale,a,1),l=this.normalizeControlArray(t.offset,a,0),u=t.normalize??!0;console.log(`[PolicyRunner] Action term "${e}" (muscle_activation): ${a} actuator(s), normalize=${u}`),s.push({controlType:i,ctrlAdr:r.ctrlAdr,qposAdr:[],qvelAdr:[],actionIndices:r.actionIndices,actionScale:c,actionOffset:l,defaultJointPos:new Float32Array(a),encoderBias:new Float32Array(a),positionActuator:Array(a).fill(!1),kp:new Float32Array(a),kd:new Float32Array(a),muscleNormalize:u});continue}let c=o.length===1&&o[0]===`.*`,l;if(c){let t=n.getControlMapping();if(!t){console.warn(`[PolicyRunner] Action term "${e}": failed to build control mapping, skipping.`);continue}l={...t,actionIndices:Array.from({length:t.qposAdr.length},(e,t)=>t)}}else if(l=n.getControlMappingFor(o,r),!l){console.warn(`[PolicyRunner] Action term "${e}": no joints matched patterns [${o.join(`, `)}], skipping.`);continue}let u=t.use_default_offset===void 0?i===`joint_position`:t.use_default_offset;s.push(a(e,i,l,t.scale,t.offset,t.stiffness,t.damping,u))}return s.length===0?(console.warn(`[PolicyRunner] No valid action terms found in config.actions.`),null):s}normalizeControlArray(e,t,n,r){let i=new Float32Array(t);if(i.fill(n),typeof e==`number`)return i.fill(e),i;if(Array.isArray(e)){for(let r=0;r<t;r++)i[r]=typeof e[r]==`number`?e[r]:n;return i}if(typeof e==`object`&&e&&r){for(let[n,a]of Object.entries(e)){let e=r.indexOf(n);e>=0&&e<t?i[e]=a:console.warn(`[PolicyRunner] Joint name "${n}" not found in policy_joint_names; skipping.`)}return i}return i}resetSimulationState(){if(!(!this.mjModel||!this.mjData)){if(this.mjModel.nkey>0?this.mujoco.mj_resetDataKeyframe(this.mjModel,this.mjData,0):this.mujoco.mj_resetData(this.mjModel,this.mjData),this.initialQpos){let e=this.mjData.qpos;for(let t=0;t<Math.min(this.initialQpos.length,this.mjModel.nq);t++)e[t]=this.initialQpos[t]}if(this.initialQvel){let e=this.mjData.qvel;for(let t=0;t<Math.min(this.initialQvel.length,this.mjModel.nv);t++)e[t]=this.initialQvel[t]}this.eventManager&&this.eventManager.onReset({mjModel:this.mjModel,mjData:this.mjData,terrainData:this.terrainData}),this.commandManager.resetTerms(),this.onnxModule&&(this.onnxInputDict=this.onnxModule.initInput()),this.onnxTimeStep=0,this.mujoco.mj_forward(this.mjModel,this.mjData),this.lastSimState.bodies.clear(),this.updateCachedState()}}executeSimulationSteps(){if(!(!this.mjModel||!this.mjData)){this.applyDragForces();for(let e=0;e<this.decimation;e++)this.applyPolicyControl(),this.mujoco.mj_step(this.mjModel,this.mjData)}}applyPolicyControl(){if(!this.policyControl||!this.mjData)return;let e=this.mjData.ctrl;e.fill(0);let t=this.policyRunner?.getLastActions()??new Float32Array;for(let n of this.policyControl){let{controlType:r,ctrlAdr:i,qposAdr:a,qvelAdr:o,actionIndices:s,actionScale:c,actionOffset:l,defaultJointPos:u,encoderBias:d,positionActuator:f,kp:p,kd:m,muscleNormalize:h}=n,g=i.length;if(r===`joint_position`)for(let n=0;n<g;n++){let r=i[n];if(r<0)continue;let h=t[s[n]]??0,g=u[n]+l[n]+c[n]*h-d[n];if(f[n])e[r]=g;else{let t=this.mjData.qpos[a[n]],i=this.mjData.qvel[o[n]];e[r]=p[n]*(g-t)+m[n]*(0-i)}}else if(r===`torque`)for(let n=0;n<g;n++){let r=i[n];r>=0&&(e[r]=c[n]*(t[s[n]]??0))}else if(r===`muscle_activation`)for(let n=0;n<g;n++){let r=i[n];if(r<0)continue;let a=(t[s[n]]??0)*c[n]+l[n];h?e[r]=1/(1+Math.exp(-5*(a-.5))):e[r]=a<0?0:a>1?1:a}}}async runOnnxInference(e){if(!(!this.onnxModule||!this.policyRunner||this.onnxInferencing)){this.onnxInferencing=!0;try{this.onnxInputDict||=this.onnxModule.initInput();let t={...this.onnxInputDict};this.onnxModule.inKeys.includes(`time_step`)&&(t.time_step=new bH(`float32`,new Float32Array([this.onnxTimeStep]),[1,1]));for(let[n,r]of Object.entries(e))t[n]=new bH(`float32`,r,[1,r.length]);for(let e of this.onnxModule.inKeys)if(!t[e]){console.warn(`[PolicyRunner] Missing ONNX input:`,{key:e,available:Object.keys(t)});return}let[n,r]=await this.onnxModule.runInference(t);Object.keys(r).length>0&&(this.onnxInputDict={...this.onnxInputDict,...r}),this.onnxModule.inKeys.includes(`time_step`)&&(this.onnxTimeStep+=1);let i=this.onnxModule.outKeys[0],a=n.action??(i?n[i]:null)??n.policy??null;if(!a)return;let o=a.data,s=ArrayBuffer.isView(o)?new Float32Array(o):Float32Array.from(o),c=this.policyRunner?.getNumActions()??0;if(this.policyControl&&s.length!==c){console.warn(`[PolicyRunner] Action size mismatch:`,{expected:c,got:s.length});return}this.policyRunner.setLastActions(s)}catch(e){console.warn(`[PolicyRunner] ONNX inference failed:`,e)}finally{this.onnxInferencing=!1}}}applyDragForces(){if(!this.dragStateManager||!this.mjModel||!this.mjData||!this.bodies)return;for(let e=0;e<this.mjData.xfrc_applied.length;e++)this.mjData.xfrc_applied[e]=0;let e=this.dragStateManager.physicsObject;if(!e||!(`bodyID`in e)||typeof e.bodyID!=`number`||e.bodyID<=0)return;let t=e.bodyID;if(this.dynamicBodyIds&&!this.dynamicBodyIds.has(t))return;for(let e=0;e<this.mjModel.nbody;e++)this.bodies[e]&&(aP(this.mjData.xpos,e,this.bodies[e].position),oP(this.mjData.xquat,e,this.bodies[e].quaternion),this.bodies[e].updateWorldMatrix(!0,!1));this.dragStateManager.update();let n=VN(this.dragStateManager.offset.clone().multiplyScalar(this.dragForceScale)),r=VN(this.dragStateManager.worldHit.clone()),i=new Y(this.mjData.xpos[t*3+0],this.mjData.xpos[t*3+1],this.mjData.xpos[t*3+2]),a=new Y(r.x-i.x,r.y-i.y,r.z-i.z),o=new Y(n.x,n.y,n.z),s=new Y().crossVectors(a,o),c=t*6;this.mjData.xfrc_applied[c+0]=n.x,this.mjData.xfrc_applied[c+1]=n.y,this.mjData.xfrc_applied[c+2]=n.z,this.mjData.xfrc_applied[c+3]=s.x,this.mjData.xfrc_applied[c+4]=s.y,this.mjData.xfrc_applied[c+5]=s.z}updateCachedState(){if(!this.mjModel||!this.mjData||!this.bodies)return;let e=this.dynamicBodyIds;for(let t=0;t<this.mjModel.nbody;t++)if(!(e&&!e.has(t))&&this.bodies[t]){this.lastSimState.bodies.has(t)||this.lastSimState.bodies.set(t,{position:new Y,quaternion:new Zy});let e=this.lastSimState.bodies.get(t);aP(this.mjData.xpos,t,e.position),oP(this.mjData.xquat,t,e.quaternion)}this.mujocoRoot&&this.mujocoRoot.cylinders&&ZN(this.mjModel,this.mjData,{cylinders:this.mujocoRoot.cylinders,spheres:this.mujocoRoot.spheres},this.lastSimState.tendons)}applyViewerConfig(e){this.cameraState=kB(e,this.camera,this.controls,this.mjModel,this.mjData)}computeDynamicBodyIds(e){let t=new Set;for(let n=1;n<e.nbody;n++){let r=n;for(;r>0;){if(e.body_jntnum[r]>0){t.add(n);break}r=e.body_parentid[r]}}return t}syncStaticBodiesFromData(){if(!this.mjModel||!this.mjData||!this.bodies)return;let e=this.dynamicBodyIds;for(let t=0;t<this.mjModel.nbody;t++){if(e?.has(t))continue;let n=this.bodies[t];n&&(aP(this.mjData.xpos,t,n.position),oP(this.mjData.xquat,t,n.quaternion))}}async captureThumbnail(e={}){let{maxDim:t=1280,quality:n=.85}=e,r=this.renderer.domElement;this.renderer.render(this.scene,this.camera);let i=r.width,a=r.height;if(!i||!a)throw Error(`mjswan: canvas has zero size; nothing to capture.`);let o=Math.min(1,t/Math.max(i,a)),s=Math.max(1,Math.round(i*o)),c=Math.max(1,Math.round(a*o)),l=document.createElement(`canvas`);l.width=s,l.height=c;let u=l.getContext(`2d`);if(!u)throw Error(`mjswan: failed to get a 2D context for thumbnail capture.`);return u.drawImage(r,0,0,s,c),await new Promise((e,t)=>{l.toBlob(n=>n?e(n):t(Error(`mjswan: toBlob returned null.`)),`image/jpeg`,n)})}async dispose(){await this.stop(),this.policyRunner=null,this.policyStateBuilder=null,this.onnxModule&&=(this.onnxModule.dispose(),null),this.onnxInputDict=null,this.onnxInferencing=!1,this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),this.dragStateManager&&=(this.dragStateManager.dispose(),null),this.mjData=null,this.mjModel=null,window.removeEventListener(`resize`,this.onWindowResize),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.controls.dispose(),this.renderer.setAnimationLoop(null),this.renderer.dispose(),this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this.vrButton?.parentElement&&(this.vrButton.parentElement.removeChild(this.vrButton),this.vrButton=null),this.bodies=null,this.lights=[],this.mujocoRoot=null,this.dynamicBodyIds=null,this.lastSimState.bodies.clear(),this.commandManager.dispose()}disposeThreeJSResources(){if(this.scene)for(this.scene.traverse(e=>{`geometry`in e&&e.geometry&&e.geometry.dispose(),`material`in e&&e.material&&(Array.isArray(e.material)?e.material.forEach(e=>this.disposeMaterial(e)):this.disposeMaterial(e.material))});this.scene.children.length>0;)this.scene.remove(this.scene.children[0])}disposeMaterial(e){let t=e;t.map&&t.map.dispose(),t.aoMap&&t.aoMap.dispose(),t.emissiveMap&&t.emissiveMap.dispose(),t.metalnessMap&&t.metalnessMap.dispose(),t.normalMap&&t.normalMap.dispose(),t.roughnessMap&&t.roughnessMap.dispose(),e.dispose()}getSize(){let e=this.container.clientWidth||window.innerWidth,t=this.container.clientHeight||window.innerHeight;return{width:Math.max(1,e),height:Math.max(1,t)}}};function p1(e){let t=e.config,n={id:e.id,group:e.groupName,type:t.type,label:t.label};return t.type===`slider`?{...n,min:t.min,max:t.max,step:t.step,enabledWhen:t.enabled_when}:n}async function m1(e){return{config:e.config,onnx:await UB(e.onnx),motions:(e.motions??[]).map(e=>({name:e.name,data:e.data,default:e.default})),plugins:e.plugins}}async function h1(e){return{data:await UB(e.data),collider:e.collider?await UB(e.collider):null,transform:e.transform}}var g1=class{constructor(e){this.phase=`paused`,this.loading=!1,this.loadingMessage=null,this.error=null,this.listeners=new Set,this.onCommandEvent=()=>this.refresh(),this.runtime=e,this.state=this.buildState(),this.runtime.commands.addEventListener(this.onCommandEvent),this.camera={set:e=>this.runtime.setCameraView(e),get:()=>this.runtime.getCameraView(),frame:()=>this.runtime.frameCamera()},this.commands={set:(e,t)=>this.runtime.commands.setValue(e,t),trigger:e=>this.runtime.commands.triggerButton(e)}}buildState(){let e=this.runtime.commands;return{phase:this.phase,loading:this.loading,loadingMessage:this.loadingMessage,error:this.error,commands:e.getCommands().map(p1),commandValues:e.getValues()}}refresh(){this.state=this.buildState();for(let e of this.listeners)try{e(this.state)}catch(e){console.warn(`[mjswan] subscribe listener error:`,e)}}async loadScene(e){this.loading=!0,this.loadingMessage=`Loading scene…`,this.error=null,this.refresh();try{let t={model:await UB(e.model),policy:e.policy?await m1(e.policy):null,splat:e.splat?await h1(e.splat):null,viewer:e.viewer??null,events:e.events??null,terrainData:e.terrainData??null,plugins:e.plugins};await this.runtime.loadEnvironment(t),this.phase=this.runtime.isRunning?`running`:`paused`}catch(e){throw this.error=e instanceof Error?e:Error(String(e)),e}finally{this.loading=!1,this.loadingMessage=null,this.refresh()}}async setPolicy(e){await this.runtime.loadPolicyConfig(e?await m1(e):null),this.refresh()}async setSplat(e){await this.runtime.setSplat(e?await h1(e):null)}setMotion(e){return this.runtime.setSelectedMotion(e)}setReferenceVisible(e){this.runtime.setReferenceVisible(e)}calibrateSplat(e){this.runtime.calibrateSplat(e)}play(){this.runtime.play(),this.phase=`running`,this.refresh()}pause(){this.runtime.pause(),this.phase=`paused`,this.refresh()}reset(){this.runtime.resetSimulation()}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}captureThumbnail(e){return this.runtime.captureThumbnail(e)}dispose(){this.runtime.commands.removeEventListener(this.onCommandEvent),this.listeners.clear(),this.runtime.dispose()}};async function _1(e,t={}){return new g1(new f1(await(t.multithreaded?await i(()=>import(`./mujoco-Bacjb_-g.js`),__vite__mapDeps([0,1,2])):await i(()=>import(`./mujoco-CKOf6FiF.js`),__vite__mapDeps([3,1,2]))).default(),e))}globalThis.__mjswanThree=lA;function v1(e){return e.toLowerCase().replace(/ /g,`_`).replace(/-/g,`_`)}function y1(e){return e.id?e.id:`main`}function b1(e,t){let n=t.path?t.path:`scene/${v1(t.name)}/scene.mjz`;return`${y1(e)}/assets/${n}`.replace(/\/+/g,`/`)}function x1(e,t){return`${y1(e)}/assets/${t}`.replace(/\/+/g,`/`)}function S1(e,t){let n=e.lastIndexOf(`/`);return`${n>=0?e.slice(0,n+1):``}${t}`.replace(/\/+/g,`/`)}function C1(e){return async()=>{let t=await fetch(e);if(!t.ok)throw Error(`mjswan/manifest: failed to fetch ${e}: ${t.status}`);return t.arrayBuffer()}}async function w1(e){let t=typeof e==`function`?await e():e;return JSON.parse(new TextDecoder().decode(t))}function T1(e){return{scale:e.scale,xOffset:e.xOffset,yOffset:e.yOffset,zOffset:e.zOffset,roll:e.roll,pitch:e.pitch,yaw:e.yaw}}function E1(e,t,n){return{data:t.path?n(x1(e,t.path)):C1(t.url),collider:t.colliderUrl?/^[a-z]+:\/\//i.test(t.colliderUrl)?C1(t.colliderUrl):n(x1(e,t.colliderUrl)):void 0,transform:T1(t)}}async function D1(e,t,n){if(!t.config)throw Error(`mjswan/manifest: policy "${t.name}" has no config path.`);let r=x1(e,t.config),i=await w1(n(r)),a=i.onnx?.path;if(!a)throw Error(`mjswan/manifest: policy "${t.name}" config missing onnx.path.`);return{config:i,onnx:n(S1(r,a)),motions:Array.isArray(i.motions)?i.motions.map(e=>({name:e.name,data:n(S1(r,e.path)),default:e.default})):[]}}function O1(e,t,n){let r=t.policies.map(t=>({name:t.name,default:t.default??!1,motions:(t.motions??[]).map(e=>({name:e.name,default:e.default??!1})),build:()=>D1(e,t,n)})),i=(t.splats??[]).map(t=>({name:t.name,control:t.control??!1,transform:T1(t),build:async()=>E1(e,t,n)}));return{name:t.name,camera:t.camera,splatSection:t.splatSection??!1,policies:r,splats:i,buildScene:async r=>{let i=r?.policy,a=i==null?t.policies.find(e=>e.default)??t.policies[0]:t.policies.find(e=>e.name===i),o=r?.splat,s=o==null?void 0:t.splats?.find(e=>e.name===o);return{model:n(b1(e,t)),policy:a?await D1(e,a,n):null,splat:s?E1(e,s,n):null,viewer:t.camera,events:t.events,terrainData:t.terrainData}}}}function k1(e,t){let n=typeof e==`string`?JSON.parse(e):e,r=n.projects.find(e=>e.id===null)??n.projects[0];if(!r)throw Error(`mjswan/manifest: config.json has no projects.`);return{name:r.name,scenes:r.scenes.map(e=>O1(r,e,t)),pluginsPath:n.plugins}}var A1=`panel`,j1=`ref`;function M1(e){return new URLSearchParams(window.location.search).get(e)!==`0`}function N1(e){return t=>async()=>{let n=`${e}${t}`.replace(/([^:])\/{2,}/g,`$1/`),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch ${n}: ${r.status}`);return r.arrayBuffer()}}async function P1(e){let t=new URLSearchParams(window.location.search).get(`config`),n=t?new URL(t,window.location.href).toString():`${e}assets/config.json`.replace(/([^:])\/{2,}/g,`$1/`),r=await fetch(n,{cache:`no-store`});if(!r.ok)throw Error(`Failed to fetch ${n}: ${r.status}`);return k1(await r.text(),N1(e))}function F1(e,t,n){if(!t)return n;let r=t.trim().toLowerCase();return e.find(e=>e.name.toLowerCase()===r)??e.find(e=>v1(e.name)===r)??n}function I1(){let[e,t]=(0,b.useState)(null),[n,r]=(0,b.useState)(null),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(null),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(()=>M1(j1)),[h,g]=(0,b.useState)(()=>M1(A1)),[_,v]=(0,b.useState)(null),y=(0,b.useRef)(null),x=(0,b.useRef)(null),S=(0,b.useRef)(null),{showLoading:C,hideLoading:w,setLoadingMessage:T}=Zg(),E=(0,b.useCallback)(e=>{let t=S.current;return t?(e.plugins=t,e.policy&&(e.policy.plugins=t),e):e},[]);(0,b.useEffect)(()=>{C(`Loading…`),P1(`/`).then(async e=>{if(e.pluginsPath){let t=`/${e.pluginsPath}`.replace(/([^:])\/{2,}/g,`$1/`);S.current=await i(()=>import(t),[])}let n=new URLSearchParams(window.location.search),r=F1(e.scenes,n.get(`scene`),e.scenes[0]),a=r?F1(r.policies,n.get(`policy`),r.policies.find(e=>e.default)??r.policies[0]):void 0,s=a?.motions.find(e=>e.default)??a?.motions[0];t(e),o(r?.name??null),c(a?.name??null),u(s?.name??null),f(r?.splats[0]?.name??null)}).catch(e=>{r(e instanceof Error?e.message:String(e)),w(),n_()})},[]);let D=(0,b.useMemo)(()=>e?.scenes.find(e=>e.name===a)??null,[e,a]);(0,b.useEffect)(()=>{let t=y.current;if(!e||!D||!t)return;let n=!1;return(async()=>{C(`Loading MuJoCo…`);let e=await _1(t,{multithreaded:!1});if(n){e.dispose();return}x.current=e,e.subscribe(v);try{T(`Loading scene…`);let t=await D.buildScene({policy:s,splat:d});await e.loadScene(E(t)),l&&await e.setMotion(l),e.setReferenceVisible(p),w(),t_()}catch(e){r(e instanceof Error?e.message:String(e)),w(),n_()}})(),()=>{n=!0,x.current?.dispose(),x.current=null}},[e]),(0,b.useEffect)(()=>{_&&(_.loading?C(_.loadingMessage??`Loading…`):_.error||w(),_.error&&(r(_.error.message),w(),n_()))},[_,C,w]);let O=(0,b.useCallback)(e=>{let t=new URLSearchParams(window.location.search),n=(e,n,r)=>n!=null&&r?t.set(e,n):t.delete(e);n(`scene`,e.scene??a,!0),n(`policy`,e.policy??s,!0),t.delete(A1),(e.panel??h)||t.set(A1,`0`),t.delete(j1),(e.ref??p)||t.set(j1,`0`);let r=t.toString();window.history.replaceState({},``,`${window.location.pathname}${r?`?${r}`:``}${window.location.hash}`)},[a,s,h,p]),k=(0,b.useCallback)(async t=>{let n=x.current,r=e?.scenes.find(e=>e.name===t);if(!n||!r)return;let i=r.policies.find(e=>e.default)??r.policies[0],a=i?.motions.find(e=>e.default)??i?.motions[0],s=r.splats[0]?.name??null;o(r.name),c(i?.name??null),u(a?.name??null),f(s),O({scene:r.name,policy:i?.name??null}),C(`Loading scene "${r.name}"…`);try{await n.loadScene(E(await r.buildScene({policy:i?.name,splat:s}))),a&&await n.setMotion(a.name),n.setReferenceVisible(p)}catch(e){console.error(`Failed to load scene:`,e)}finally{w()}},[e,p,O,C,w]),A=(0,b.useCallback)(async e=>{let t=x.current,n=D?.policies.find(t=>t.name===e)??null;c(e);let r=n?.motions.find(e=>e.default)??n?.motions[0];if(u(r?.name??null),O({policy:e}),t){C(e?`Loading policy "${e}"…`:`Clearing policy…`);try{let e=n?await n.build():null;e&&S.current&&(e.plugins=S.current),await t.setPolicy(e),r&&await t.setMotion(r.name),t.setReferenceVisible(p)}catch(e){console.error(`Failed to load policy:`,e)}finally{w()}}},[D,p,O,C,w]),j=(0,b.useCallback)(async e=>{let t=x.current,n=l;if(u(e),t){C(e===null?`Clearing motion…`:`Loading motion "${e}"…`);try{!await t.setMotion(e)&&e!==null&&u(n)}catch(e){console.error(`Failed to load motion:`,e)}finally{w()}}},[l,C,w]),M=(0,b.useCallback)(async e=>{let t=x.current,n=e===null?null:D?.splats.find(t=>t.name===e)??null;if(f(e),!(!t||e!==null&&!n)){C(e===null?`Removing splat…`:`Loading splat "${e}"…`);try{await t.setSplat(n?await n.build():null)}catch(e){console.error(`Failed to load splat:`,e)}finally{w()}}},[D,C,w]),N=(0,b.useCallback)(e=>{m(e),x.current?.setReferenceVisible(e),O({ref:e})},[O]),P=(0,b.useCallback)(e=>{g(e),O({panel:e})},[O]),F=(0,b.useCallback)(e=>e.map(e=>({value:e.name,label:e.name})),[]);return n?(0,G.jsx)(fr,{theme:Yg,defaultColorScheme:`auto`,children:(0,G.jsx)(`div`,{className:`app`,children:(0,G.jsxs)(`div`,{className:`hud hud-error`,children:[(0,G.jsx)(`h1`,{className:`hud-title`,children:`mjswan`}),(0,G.jsx)(`p`,{className:`hud-message`,children:n})]})})}):(0,G.jsx)(fr,{theme:Yg,defaultColorScheme:`auto`,children:(0,G.jsxs)(`div`,{className:`app`,children:[(0,G.jsx)($g,{}),e&&D&&(0,G.jsx)(Gg,{visible:h,onVisibleChange:P,projects:[{value:e.name,label:e.name}],projectValue:e.name,projectLabel:e.name,onProjectChange:()=>{},scenes:F(e.scenes),sceneValue:a,onSceneChange:k,splats:F(D.splats),splatSection:D.splatSection,splatValue:d,onSplatChange:M,splatConfig:(()=>{let e=D.splats.find(e=>e.name===d);return e?{name:e.name,control:e.control,...e.transform}:null})(),onCalibrateSplat:(e,t,n,r,i,a,o)=>x.current?.calibrateSplat({scale:e,xOffset:t,yOffset:n,zOffset:r,roll:i,pitch:a,yaw:o}),policies:F(D.policies),policyValue:s,onPolicyChange:A,motions:F(D.policies.find(e=>e.name===s)?.motions??[]),motionValue:l,onMotionChange:j,showReferenceMotion:p,onShowReferenceMotionChange:N,commandsEnabled:!!s,commands:_?.commands?[..._.commands]:[],commandValues:_?.commandValues??{},onCommandChange:(e,t)=>x.current?.commands.set(e,t),onReset:()=>x.current?.reset()}),(0,G.jsx)(`div`,{ref:y,className:`viewer`})]})})}function L1(){return(0,G.jsx)(Qg,{children:(0,G.jsx)(I1,{})})}var R1=document.getElementById(`root`);R1&&(0,wg.createRoot)(R1).render((0,G.jsx)(b.StrictMode,{children:(0,G.jsx)(L1,{})}));
15597
+ ${a}`,s=n.createShaderModule({code:o,label:e.name});XU(`verbose`,()=>`[WebGPU] ${e.name} shader code: ${o}`);let c=n.createComputePipeline({compute:{module:s,entryPoint:`main`},layout:`auto`,label:e.name});return TH(e.name),{programInfo:e,computePipeline:c,uniformVariablesInfo:i.variablesInfo}}normalizeDispatchGroupSize(e){let t=typeof e==`number`?e:e.x,n=typeof e==`number`?1:e.y||1,r=typeof e==`number`?1:e.z||1,i=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(t<=i&&n<=i&&r<=i)return[t,n,r];let a=t*n*r,o=Math.ceil(Math.sqrt(a));if(o>i){if(o=Math.ceil(Math.cbrt(a)),o>i)throw Error(`Total dispatch size exceeds WebGPU maximum.`);return[o,o,o]}else return[o,o,1]}}}),GQ={};LV(GQ,{WebGpuBackend:()=>YQ});var KQ,qQ,JQ,YQ,XQ=Z(()=>{LH(),VU(),ZU(),oW(),NW(),HQ(),WQ(),KQ=(e,t)=>{if(t.length!==e.length)throw Error(`inputDependencies length ${t.length} is not equal to inputTensors length ${e.length}.`);let n=[];for(let r=0;r<e.length;++r){let i=e[r].dataType;switch(t[r]){case`none`:n.push(``);break;case`type`:n.push(`${i}`);break;case`rank`:{let t=e[r].dims.length;n.push(`${i};${t}`);break}case`dims`:{let t=e[r].dims.join(`,`);n.push(`${i};${t}`);break}default:throw Error(`unsupported input dependency: ${t[r]}`)}}return n.join(`|`)},qQ=(e,t,n)=>{let r=e.name;return e.shaderCache?.hint&&(r+=`[`+e.shaderCache.hint+`]`),r+=`:`+n+`:${KQ(t,e.shaderCache?.inputDependencies??Array(t.length).fill(`dims`))}`,r},JQ=class{constructor(e){e&&(this.architecture=e.architecture,this.vendor=e.vendor)}isArchitecture(e){return this.architecture===e}isVendor(e){return this.vendor===e}},YQ=class{constructor(){this.currentSessionId=null,this.currentKernelId=null,this.commandEncoder=null,this.computePassEncoder=null,this.maxDispatchNumber=16,this.pendingDispatchNumber=0,this.pendingKernels=[],this.pendingQueries=new Map,this.sessionStatus=`default`,this.capturedCommandList=new Map,this.capturedPendingKernels=new Map,this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(this.currentKernelId===null)throw Error(`currentKernelCustomData(): currentKernelId is null. (should not happen)`);let e=this.kernelCustomData.get(this.currentKernelId);return e||(e={},this.kernelCustomData.set(this.currentKernelId,e)),e}async initialize(e,t){this.env=e;let n=[],r={requiredLimits:{maxComputeWorkgroupStorageSize:t.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:t.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:t.limits.maxStorageBufferBindingSize,maxBufferSize:t.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:t.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:t.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:t.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:t.limits.maxComputeWorkgroupSizeZ},requiredFeatures:n},i=e=>t.features.has(e)&&n.push(e)&&!0;i(`chromium-experimental-timestamp-query-inside-passes`)||i(`timestamp-query`),i(`shader-f16`),i(`subgroups`),this.device=await t.requestDevice(r),this.adapterInfo=new JQ(t.info||await t.requestAdapterInfo()),this.gpuDataManager=MW(this),this.programManager=new UQ(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,JU(e.logLevel,!!e.debug),this.device.onuncapturederror=e=>{e.error instanceof GPUValidationError&&console.error(`An uncaught WebGPU validation error was raised: ${e.error.message}`)},Object.defineProperty(this.env.webgpu,"device",{value:this.device,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(this.env.webgpu,"adapter",{value:t,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<`u`&&this.querySet.destroy(),this.gpuDataManager.dispose()}getCommandEncoder(){return this.commandEncoder||=this.device.createCommandEncoder(),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let e=this.getCommandEncoder(),t={};this.queryType===`at-passes`&&(t.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:this.pendingDispatchNumber*2,endOfPassWriteIndex:this.pendingDispatchNumber*2+1}),this.computePassEncoder=e.beginComputePass(t)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&=(this.computePassEncoder.end(),null)}flush(){if(!this.commandEncoder)return;wH(),this.endComputePass();let e;this.queryType!==`none`&&(this.commandEncoder.resolveQuerySet(this.querySet,0,this.pendingDispatchNumber*2,this.queryResolveBuffer,0),e=this.device.createBuffer({size:this.pendingDispatchNumber*2*8,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(e,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,e,0,this.pendingDispatchNumber*2*8)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,this.queryType!==`none`&&e.mapAsync(GPUMapMode.READ).then(()=>{let t=new BigUint64Array(e.getMappedRange()),n=this.pendingQueries.get(e);for(let e=0;e<t.length/2;e++){let r=n[e],i=r.kernelId,a=this.kernels.get(i),o=a.kernelType,s=a.kernelName,c=r.programName,l=r.inputTensorViews,u=r.outputTensorViews,d=t[e*2],f=t[e*2+1];typeof this.queryTimeBase>`u`&&(this.queryTimeBase=d);let p=Number(d-this.queryTimeBase),m=Number(f-this.queryTimeBase);if(!Number.isSafeInteger(p)||!Number.isSafeInteger(m))throw RangeError(`incorrect timestamp range`);if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:l.map(e=>({dims:e.dims,dataType:PU(e.dataType)})),outputsMetadata:u.map(e=>({dims:e.dims,dataType:PU(e.dataType)})),kernelId:i,kernelType:o,kernelName:s,programName:c,startTime:p,endTime:m});else{let e=``;l.forEach((t,n)=>{e+=`input[${n}]: [${t.dims}] | ${PU(t.dataType)}, `});let t=``;u.forEach((e,n)=>{t+=`output[${n}]: [${e.dims}] | ${PU(e.dataType)}, `}),console.log(`[profiling] kernel "${i}|${o}|${s}|${c}" ${e}${t}start time: ${p} ns, execution time: ${m-p} ns`)}SH(`GPU`,`${c}::${d}::${f}`)}e.unmap(),this.pendingQueries.delete(e)}),TH()}run(e,t,n,r,i,a){wH(e.name);let o=[];for(let e=0;e<t.length;++e){let n=t[e].data;if(n===0)continue;let r=this.gpuDataManager.get(n);if(!r)throw Error(`no GPU data for input: ${n}`);o.push(r)}let{outputs:s,dispatchGroup:c,programUniforms:l}=e.getRunData(t),u=n.length===0?s.map((e,t)=>t):n;if(u.length!==s.length)throw Error(`Output size ${u.length} must be equal to ${s.length}.`);let d=[],f=[];for(let e=0;e<s.length;++e){if(!Number.isInteger(u[e])||u[e]<-3||u[e]>=a)throw Error(`Invalid output index: ${u[e]}`);if(u[e]===-3)continue;let t=u[e]===-1,n=u[e]===-2,o=t||n?i(s[e].dataType,s[e].dims):r(u[e],s[e].dataType,s[e].dims);if(d.push(o),o.data===0)continue;let c=this.gpuDataManager.get(o.data);if(!c)throw Error(`no GPU data for output: ${o.data}`);if(t&&this.temporaryData.push(c),n){let e=this.kernelPersistentData.get(this.currentKernelId);e||(e=[],this.kernelPersistentData.set(this.currentKernelId,e)),e.push(c)}f.push(c)}if(o.length!==t.length||f.length!==d.length){if(f.length===0)return TH(e.name),d;throw Error(`Program ${e.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}let p;if(l){let e=0,t=[];l.forEach(n=>{let r=typeof n.data==`number`?[n.data]:n.data;if(r.length===0)return;let i=n.type===10?2:4,a,o;n.type===10?(o=r.length>4?16:r.length>2?8:r.length*i,a=r.length>4?16:i*r.length):(o=r.length<=2?r.length*i:16,a=16),e=Math.ceil(e/o)*o,t.push(e);let s=n.type===10?8:4;e+=r.length>4?Math.ceil(r.length/s)*a:r.length*i}),e=Math.ceil(e/16)*16;let n=new ArrayBuffer(e);l.forEach((e,r)=>{let i=t[r],a=typeof e.data==`number`?[e.data]:e.data;if(e.type===6)new Int32Array(n,i,a.length).set(a);else if(e.type===12)new Uint32Array(n,i,a.length).set(a);else if(e.type===10)new Uint16Array(n,i,a.length).set(a);else if(e.type===1)new Float32Array(n,i,a.length).set(a);else throw Error(`Unsupported uniform type: ${PU(e.type)}`)});let r=this.gpuDataManager.create(e,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(r.buffer,0,n,0,e),this.gpuDataManager.release(r.id),p={offset:0,size:e,buffer:r.buffer}}let m=this.programManager.normalizeDispatchGroupSize(c),h=m[1]===1&&m[2]===1,g=qQ(e,t,h),_=this.programManager.getArtifact(g);if(_||(_=this.programManager.build(e,m),this.programManager.setArtifact(g,_),XU(`info`,()=>`[artifact] key: ${g}, programName: ${e.name}`)),l&&_.uniformVariablesInfo){if(l.length!==_.uniformVariablesInfo.length)throw Error(`Uniform variables count mismatch: expect ${_.uniformVariablesInfo.length}, got ${l.length} in program "${_.programInfo.name}".`);for(let e=0;e<l.length;e++){let t=l[e],n=t.type,r=typeof t.data==`number`?1:t.data.length,[i,a]=_.uniformVariablesInfo[e];if(n!==i||r!==a)throw Error(`Uniform variable ${e} mismatch: expect type ${i} with size ${a}, got type ${n} with size ${r} in program "${_.programInfo.name}".`)}}if(XU(`info`,()=>`[ProgramManager] run "${e.name}" (key=${g}) with ${m[0]}x${m[1]}x${m[2]}`),this.queryType!==`none`||this.sessionStatus===`capturing`){let e={kernelId:this.currentKernelId,programName:_.programInfo.name,inputTensorViews:t,outputTensorViews:d};this.pendingKernels.push(e),this.sessionStatus===`capturing`&&this.capturedPendingKernels.get(this.currentSessionId).push(e)}return this.programManager.run(_,o,f,m,p),TH(e.name),d}upload(e,t){this.gpuDataManager.upload(e,t)}memcpy(e,t){this.gpuDataManager.memcpy(e,t)}async download(e,t){await this.gpuDataManager.download(e,t)}alloc(e){return this.gpuDataManager.create(e).id}free(e){return this.gpuDataManager.release(e)}createKernel(e,t,n,r){let i=VQ.get(e);if(!i)throw Error(`kernel not implemented: ${e}`);let a={kernelType:e,kernelName:r,kernelEntry:i[0],attributes:[i[1],n]};this.kernels.set(t,a)}releaseKernel(e){let t=this.kernelPersistentData.get(e);if(t){for(let e of t)this.gpuDataManager.release(e.id);this.kernelPersistentData.delete(e)}this.kernelCustomData.delete(e),this.kernels.delete(e)}computeKernel(e,t,n){let r=this.kernels.get(e);if(!r)throw Error(`kernel not created: ${e}`);let i=r.kernelType,a=r.kernelName,o=r.kernelEntry,s=r.attributes;if(this.currentKernelId!==null)throw Error(`kernel "[${i}] ${a}" is not allowed to be called recursively`);this.currentKernelId=e,s[0]&&=(s[1]=s[0](s[1]),void 0),XU(`info`,()=>`[WebGPU] Start to run kernel "[${i}] ${a}"...`);let c=this.env.debug;this.temporaryData=[];try{return c&&this.device.pushErrorScope(`validation`),o(t,s[1]),0}catch(e){return n.push(Promise.resolve(`[WebGPU] Kernel "[${i}] ${a}" failed. ${e}`)),1}finally{c&&n.push(this.device.popErrorScope().then(e=>e?`GPU validation error for kernel "[${i}] ${a}": ${e.message}`:null));for(let e of this.temporaryData)this.gpuDataManager.release(e.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(e,t,n,r){let i=this.sessionExternalDataMapping.get(e);i||(i=new Map,this.sessionExternalDataMapping.set(e,i));let a=i.get(t),o=this.gpuDataManager.registerExternalBuffer(n,r,a);return i.set(t,[o,n]),o}unregisterBuffers(e){let t=this.sessionExternalDataMapping.get(e);t&&(t.forEach(e=>this.gpuDataManager.unregisterExternalBuffer(e[0])),this.sessionExternalDataMapping.delete(e))}getBuffer(e){let t=this.gpuDataManager.get(e);if(!t)throw Error(`no GPU data for buffer: ${e}`);return t.buffer}createDownloader(e,t,n){return async()=>{let r=await AW(this,e,t);return aW(r.buffer,n)}}writeTimestamp(e){this.queryType===`inside-passes`&&this.computePassEncoder.writeTimestamp(this.querySet,e)}setQueryType(){this.queryType=`none`,(this.env.webgpu.profiling?.mode==="default"||(typeof this.env.trace>`u`?this.env.wasm.trace:this.env.trace))&&(this.device.features.has(`chromium-experimental-timestamp-query-inside-passes`)?this.queryType=`inside-passes`:this.device.features.has(`timestamp-query`)&&(this.queryType=`at-passes`),this.queryType!==`none`&&typeof this.querySet>`u`&&(this.querySet=this.device.createQuerySet({type:`timestamp`,count:this.maxDispatchNumber*2}),this.queryResolveBuffer=this.device.createBuffer({size:this.maxDispatchNumber*2*8,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){XU(`info`,`captureBegin`),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus=`capturing`}captureEnd(){XU(`info`,`captureEnd`),this.flush(),this.sessionStatus=`default`}replay(){XU(`info`,`replay`),this.sessionStatus=`replaying`;let e=this.capturedCommandList.get(this.currentSessionId),t=this.capturedPendingKernels.get(this.currentSessionId),n=e.length;this.pendingKernels=[];for(let r=0;r<n;r++){let n=this.getComputePassEncoder(),i=e[r];this.writeTimestamp(this.pendingDispatchNumber*2),n.setPipeline(i.computePipeline),n.setBindGroup(0,i.bindGroup),n.dispatchWorkgroups(...i.dispatchGroup),this.writeTimestamp(this.pendingDispatchNumber*2+1),this.pendingDispatchNumber++,this.queryType!==`none`&&this.pendingKernels.push(t[r]),(this.pendingDispatchNumber>=this.maxDispatchNumber||this.queryType===`at-passes`)&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus=`default`}onCreateSession(){this.gpuDataManager.onCreateSession()}onReleaseSession(e){this.unregisterBuffers(e),this.capturedCommandList.has(e)&&this.capturedCommandList.delete(e),this.capturedPendingKernels.has(e)&&this.capturedPendingKernels.delete(e),this.gpuDataManager.onReleaseSession(e)}onRunStart(e){this.currentSessionId=e,this.setQueryType()}}}),ZQ={};LV(ZQ,{init:()=>e$});var QQ,$Q,e$,t$=Z(()=>{VU(),ZU(),iW(),SW(),QQ=class e{constructor(e,t,n,r){this.module=e,this.dataType=t,this.data=n,this.dims=r}getFloat32Array(){if(this.dataType!==1)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,e)}getBigInt64Array(){if(this.dataType!==7)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,e)}getInt32Array(){if(this.dataType!==6)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,e)}getUint16Array(){if(this.dataType!==10&&this.dataType!==4)throw Error(`Invalid data type`);let e=Q.size(this.dims);return e===0?new Uint16Array:new Uint16Array(this.module.HEAP8.buffer,this.data,e)}reshape(t){if(Q.size(t)!==Q.size(this.dims))throw Error(`Invalid new shape`);return new e(this.module,this.dataType,this.data,t)}},$Q=class{constructor(e,t,n){this.module=e,this.backend=t,this.customDataOffset=0,this.customDataSize=0,this.adapterInfo=t.adapterInfo;let r=e.PTR_SIZE,i=n/e.PTR_SIZE,a=r===4?`i32`:`i64`;this.opKernelContext=Number(e.getValue(r*i++,a));let o=Number(e.getValue(r*i++,a));this.outputCount=Number(e.getValue(r*i++,a)),this.customDataOffset=Number(e.getValue(r*i++,`*`)),this.customDataSize=Number(e.getValue(r*i++,a));let s=[];for(let t=0;t<o;t++){let t=Number(e.getValue(r*i++,a)),n=Number(e.getValue(r*i++,`*`)),o=Number(e.getValue(r*i++,a)),c=[];for(let t=0;t<o;t++)c.push(Number(e.getValue(r*i++,a)));s.push(new QQ(e,t,n,c))}this.inputs=s}get kernelCustomData(){return this.backend.currentKernelCustomData}get customDataBuffer(){return this.module.HEAPU8.subarray(this.customDataOffset,this.customDataOffset+this.customDataSize)}compute(e,t){let n=t?.inputs?.map(e=>typeof e==`number`?this.inputs[e]:e)??this.inputs,r=t?.outputs??[];return this.backend.run(e,n,r,(e,t,n)=>new QQ(this.module,t,this.output(e,n),n),(e,t)=>{let n=FU(e,t);if(!n)throw Error(`Unsupported data type: ${e}`);let r=n>0?this.backend.gpuDataManager.create(n).id:0;return new QQ(this.module,e,r,t)},this.outputCount)}output(e,t){let n=this.module.stackSave();try{let n=this.module.PTR_SIZE,r=n===4?`i32`:`i64`,i=this.module.stackAlloc((1+t.length)*n);this.module.setValue(i,t.length,r);for(let e=0;e<t.length;e++)this.module.setValue(i+n*(e+1),t[e],r);return this.module._JsepOutput(this.opKernelContext,e,i)}catch(n){throw Error(`Failed to generate kernel's output[${e}] with dims [${t}]. If you are running with pre-allocated output, please make sure the output type/dims are correct. Error: ${n}`)}finally{this.module.stackRestore(n)}}},e$=async(e,t,n,r)=>{let i=t.jsepInit;if(!i)throw Error(`Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.`);if(e===`webgpu`){let e=(XQ(),zV(GQ)).WebGpuBackend,a=new e;await a.initialize(n,r),i(`webgpu`,[a,e=>a.alloc(Number(e)),e=>a.free(e),(e,n,r,i=!1)=>{if(i)XU(`verbose`,()=>`[WebGPU] jsepCopyGpuToGpu: src=${Number(e)}, dst=${Number(n)}, size=${Number(r)}`),a.memcpy(Number(e),Number(n));else{XU(`verbose`,()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${Number(e)}, gpuDataId=${Number(n)}, size=${Number(r)}`);let i=t.HEAPU8.subarray(Number(e>>>0),Number(e>>>0)+Number(r));a.upload(Number(n),i)}},async(e,n,r)=>{XU(`verbose`,()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${e}, dataOffset=${n}, size=${r}`),await a.download(Number(e),()=>t.HEAPU8.subarray(Number(n)>>>0,Number(n+r)>>>0))},(e,n,r)=>a.createKernel(e,Number(n),r,t.UTF8ToString(t._JsepGetNodeName(Number(n)))),e=>a.releaseKernel(e),(e,n,r,i)=>{XU(`verbose`,()=>`[WebGPU] jsepRun: sessionHandle=${r}, kernel=${e}, contextDataOffset=${n}`);let o=new $Q(t,a,Number(n));return a.computeKernel(Number(e),o,i)},()=>a.captureBegin(),()=>a.captureEnd(),()=>a.replay()])}else{let e=new xW(n);i(`webnn`,[e,()=>e.reserveTensorId(),t=>e.releaseTensorId(t),async(t,n,r,i,a)=>e.ensureTensor(t,n,r,i,a),(t,n)=>{e.uploadTensor(t,n)},async(t,n)=>e.downloadTensor(t,n),(t,n)=>e.registerMLContext(t,n),!!n.trace])}}}),n$,r$,i$,a$,o$,s$,c$,l$,u$,d$,f$,p$,m$,h$=Z(()=>{LH(),TU(),MU(),VU(),yU(),CU(),UU(),n$=(e,t)=>{vU()._OrtInit(e,t)!==0&&SU(`Can't initialize onnxruntime.`)},r$=async e=>{n$(e.wasm.numThreads,LU(e.logLevel))},i$=async(e,t)=>{vU().asyncInit?.();let n=e.webgpu.adapter;if(t===`webgpu`){if(typeof navigator>`u`||!navigator.gpu)throw Error(`WebGPU is not supported in current environment`);if(n){if(typeof n.limits!=`object`||typeof n.features!=`object`||typeof n.requestDevice!=`function`)throw Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let t=e.webgpu.powerPreference;if(t!==void 0&&t!==`low-power`&&t!==`high-performance`)throw Error(`Invalid powerPreference setting: "${t}"`);let r=e.webgpu.forceFallbackAdapter;if(r!==void 0&&typeof r!=`boolean`)throw Error(`Invalid forceFallbackAdapter setting: "${r}"`);if(n=await navigator.gpu.requestAdapter({powerPreference:t,forceFallbackAdapter:r}),!n)throw Error(`Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.`)}}if(t===`webnn`&&(typeof navigator>`u`||!navigator.ml))throw Error(`WebNN is not supported in current environment`);{let r=(t$(),zV(ZQ)).init;t===`webgpu`&&await r(`webgpu`,vU(),e,n),t===`webnn`&&await r(`webnn`,vU(),e)}},a$=new Map,o$=e=>{let t=vU(),n=t.stackSave();try{let n=t.PTR_SIZE,r=t.stackAlloc(2*n);t._OrtGetInputOutputCount(e,r,r+n)!==0&&SU(`Can't get session input/output count.`);let i=n===4?`i32`:`i64`;return[Number(t.getValue(r,i)),Number(t.getValue(r+n,i))]}finally{t.stackRestore(n)}},s$=(e,t)=>{let n=vU(),r=n.stackSave(),i=0;try{let r=n.PTR_SIZE,a=n.stackAlloc(2*r);n._OrtGetInputOutputMetadata(e,t,a,a+r)!==0&&SU(`Can't get session input/output metadata.`);let o=Number(n.getValue(a,`*`));i=Number(n.getValue(a+r,`*`));let s=n.HEAP32[i/4];if(s===0)return[o,0];let c=n.HEAPU32[i/4+1],l=[];for(let e=0;e<c;e++){let t=Number(n.getValue(i+8+e*r,`*`));l.push(t===0?Number(n.getValue(i+8+(e+c)*r,`*`)):n.UTF8ToString(t))}return[o,s,l]}finally{n.stackRestore(r),i!==0&&n._OrtFree(i)}},c$=e=>{let t=vU(),n=t._malloc(e.byteLength);if(n===0)throw Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},l$=async(e,t)=>{let n,r,i=vU();Array.isArray(e)?[n,r]=e:e.buffer===i.HEAPU8.buffer?[n,r]=[e.byteOffset,e.byteLength]:[n,r]=c$(e);let a=0,o=0,s=0,c=[],l=[],u=[];try{if([o,c]=await jU(t),t?.externalData&&i.mountExternalData){let e=[];for(let n of t.externalData){let t=typeof n==`string`?n:n.path;e.push(HU(typeof n==`string`?n:n.data).then(e=>{i.mountExternalData(t,e)}))}await Promise.all(e)}for(let e of t?.executionProviders??[])if((typeof e==`string`?e:e.name)===`webnn`){if(i.shouldTransferToMLTensor=!1,typeof e!=`string`){let t=e,n=t?.context,r=t?.gpuDevice,a=t?.deviceType,o=t?.powerPreference;n?i.currentContext=n:r?i.currentContext=await i.webnnCreateMLContext(r):i.currentContext=await i.webnnCreateMLContext({deviceType:a,powerPreference:o})}else i.currentContext=await i.webnnCreateMLContext();break}a=await i._OrtCreateSession(n,r,o),i.webgpuOnCreateSession?.(a),a===0&&SU(`Can't create a session.`),i.jsepOnCreateSession?.(),i.currentContext&&(i.webnnRegisterMLContext(a,i.currentContext),i.currentContext=void 0,i.shouldTransferToMLTensor=!0);let[e,d]=o$(a),f=!!t?.enableGraphCapture,p=[],m=[],h=[],g=[],_=[];for(let t=0;t<e;t++){let[e,n,r]=s$(a,t);e===0&&SU(`Can't get an input name.`),l.push(e);let o=i.UTF8ToString(e);p.push(o),h.push(n===0?{name:o,isTensor:!1}:{name:o,isTensor:!0,type:PU(n),shape:r})}for(let n=0;n<d;n++){let[r,o,s]=s$(a,n+e);r===0&&SU(`Can't get an output name.`),u.push(r);let c=i.UTF8ToString(r);m.push(c),g.push(o===0?{name:c,isTensor:!1}:{name:c,isTensor:!0,type:PU(o),shape:s});{if(f&&t?.preferredOutputLocation===void 0){_.push(`gpu-buffer`);continue}let e=typeof t?.preferredOutputLocation==`string`?t.preferredOutputLocation:t?.preferredOutputLocation?.[c]??`cpu`,n=i.webnnIsGraphOutput;if(e===`cpu`&&n&&n(a,c)){_.push(`ml-tensor-cpu-output`);continue}if(e!==`cpu`&&e!==`cpu-pinned`&&e!==`gpu-buffer`&&e!==`ml-tensor`)throw Error(`Not supported preferred output location: ${e}.`);if(f&&e!==`gpu-buffer`)throw Error(`Not supported preferred output location: ${e}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);_.push(e)}}let v=null;return _.some(e=>e===`gpu-buffer`||e===`ml-tensor`||e===`ml-tensor-cpu-output`)&&(s=i._OrtCreateBinding(a),s===0&&SU(`Can't create IO binding.`),v={handle:s,outputPreferredLocations:_,outputPreferredLocationsEncoded:_.map(e=>e===`ml-tensor-cpu-output`?`ml-tensor`:e).map(e=>BU(e))}),a$.set(a,[a,l,u,v,f,!1]),[a,p,m,h,g]}catch(e){throw l.forEach(e=>i._OrtFree(e)),u.forEach(e=>i._OrtFree(e)),s!==0&&i._OrtReleaseBinding(s)!==0&&SU(`Can't release IO binding.`),a!==0&&i._OrtReleaseSession(a)!==0&&SU(`Can't release session.`),e}finally{i._free(n),o!==0&&i._OrtReleaseSessionOptions(o)!==0&&SU(`Can't release session options.`),c.forEach(e=>i._free(e)),i.unmountExternalData?.()}},u$=e=>{let t=vU(),n=a$.get(e);if(!n)throw Error(`cannot release session. invalid session id: ${e}`);let[r,i,a,o,s]=n;o&&(s&&t._OrtClearBoundOutputs(o.handle)!==0&&SU(`Can't clear bound outputs.`),t._OrtReleaseBinding(o.handle)!==0&&SU(`Can't release IO binding.`)),t.jsepOnReleaseSession?.(e),t.webnnOnReleaseSession?.(e),t.webgpuOnReleaseSession?.(e),i.forEach(e=>t._OrtFree(e)),a.forEach(e=>t._OrtFree(e)),t._OrtReleaseSession(r)!==0&&SU(`Can't release session.`),a$.delete(e)},d$=async(e,t,n,r,i,a,o=!1)=>{if(!e){t.push(0);return}let s=vU(),c=s.PTR_SIZE,l=e[0],u=e[1],d=e[3],f=d,p,m;if(l===`string`&&(d===`gpu-buffer`||d===`ml-tensor`))throw Error(`String tensor is not supported on GPU.`);if(o&&d!==`gpu-buffer`)throw Error(`External buffer must be provided for input/output index ${a} when enableGraphCapture is true.`);if(d===`gpu-buffer`){let t=e[2].gpuBuffer;m=FU(NU(l),u);{let e=s.jsepRegisterBuffer;if(!e)throw Error(`Tensor location "gpu-buffer" is not supported without using WebGPU.`);p=e(r,a,t,m)}}else if(d===`ml-tensor`){let t=e[2].mlTensor;m=FU(NU(l),u);let n=s.webnnRegisterMLTensor;if(!n)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);p=n(r,t,NU(l),u)}else{let t=e[2];if(Array.isArray(t)){m=c*t.length,p=s._malloc(m),n.push(p);for(let e=0;e<t.length;e++){if(typeof t[e]!=`string`)throw TypeError(`tensor data at index ${e} is not a string`);s.setValue(p+e*c,bU(t[e],n),`*`)}}else{let e=s.webnnIsGraphInput,a=s.webnnIsGraphOutput;if(l!==`string`&&e&&a){let o=s.UTF8ToString(i);if(e(r,o)||a(r,o)){let e=NU(l);m=FU(e,u),f=`ml-tensor`;let n=s.webnnCreateTemporaryTensor,i=s.webnnUploadTensor;if(!n||!i)throw Error(`Tensor location "ml-tensor" is not supported without using WebNN.`);let a=await n(r,e,u);i(a,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),p=a}else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p)}else m=t.byteLength,p=s._malloc(m),n.push(p),s.HEAPU8.set(new Uint8Array(t.buffer,t.byteOffset,m),p)}}let h=s.stackSave(),g=s.stackAlloc(4*u.length);try{u.forEach((e,t)=>s.setValue(g+t*c,e,c===4?`i32`:`i64`));let e=s._OrtCreateTensor(NU(l),p,m,g,u.length,BU(f));e===0&&SU(`Can't create tensor for input/output. session=${r}, index=${a}.`),t.push(e)}finally{s.stackRestore(h)}},f$=async(e,t,n,r,i,a)=>{let o=vU(),s=o.PTR_SIZE,c=a$.get(e);if(!c)throw Error(`cannot run inference. invalid session id: ${e}`);let l=c[0],u=c[1],d=c[2],f=c[3],p=c[4],m=c[5],h=t.length,g=r.length,_=0,v=[],y=[],b=[],x=[],S=[],C=o.stackSave(),w=o.stackAlloc(h*s),T=o.stackAlloc(h*s),E=o.stackAlloc(g*s),D=o.stackAlloc(g*s);try{[_,v]=wU(a),EH(`wasm prepareInputOutputTensor`);for(let r=0;r<h;r++)await d$(n[r],y,x,e,u[t[r]],t[r],p);for(let t=0;t<g;t++)await d$(i[t],b,x,e,d[r[t]],h+r[t],p);DH(`wasm prepareInputOutputTensor`);for(let e=0;e<h;e++)o.setValue(w+e*s,y[e],`*`),o.setValue(T+e*s,u[t[e]],`*`);for(let e=0;e<g;e++)o.setValue(E+e*s,b[e],`*`),o.setValue(D+e*s,d[r[e]],`*`);if(f&&!m){let{handle:n,outputPreferredLocations:a,outputPreferredLocationsEncoded:s}=f;if(u.length!==h)throw Error(`input count from feeds (${h}) is expected to be always equal to model's input count (${u.length}).`);EH(`wasm bindInputsOutputs`);for(let r=0;r<h;r++){let i=t[r];await o._OrtBindInput(n,u[i],y[r])!==0&&SU(`Can't bind input[${r}] for session=${e}.`)}for(let t=0;t<g;t++){let c=r[t];i[t]?.[3]?(S.push(b[t]),o._OrtBindOutput(n,d[c],b[t],0)!==0&&SU(`Can't bind pre-allocated output[${t}] for session=${e}.`)):o._OrtBindOutput(n,d[c],0,s[c])!==0&&SU(`Can't bind output[${t}] to ${a[t]} for session=${e}.`)}DH(`wasm bindInputsOutputs`),a$.set(e,[l,u,d,f,p,!0])}o.jsepOnRunStart?.(l),o.webnnOnRunStart?.(l);let c;c=f?await o._OrtRunWithBinding(l,f.handle,g,E,_):await o._OrtRun(l,T,w,h,D,g,E,_),c!==0&&SU(`failed to call OrtRun().`);let C=[],O=[];EH(`wasm ProcessOutputTensor`);for(let t=0;t<g;t++){let n=Number(o.getValue(E+t*s,`*`));if(n===b[t]||S.includes(b[t])){C.push(i[t]),n!==b[t]&&o._OrtReleaseTensor(n)!==0&&SU(`Can't release tensor.`);continue}let a=o.stackSave(),c=o.stackAlloc(4*s),l=!1,u,d=0;try{o._OrtGetTensorData(n,c,c+s,c+2*s,c+3*s)!==0&&SU(`Can't access output tensor data on index ${t}.`);let i=s===4?`i32`:`i64`,a=Number(o.getValue(c,i));d=o.getValue(c+s,`*`);let p=o.getValue(c+s*2,`*`),m=Number(o.getValue(c+s*3,i)),h=[];for(let e=0;e<m;e++)h.push(Number(o.getValue(p+e*s,i)));o._OrtFree(p)!==0&&SU(`Can't free memory for tensor dims.`);let g=h.reduce((e,t)=>e*t,1);u=PU(a);let _=f?.outputPreferredLocations[r[t]];if(u===`string`){if(_===`gpu-buffer`||_===`ml-tensor`)throw Error(`String tensor is not supported on GPU.`);let e=[];for(let t=0;t<g;t++){let n=o.getValue(d+t*s,`*`),r=o.getValue(d+(t+1)*s,`*`),i=t===g-1?void 0:r-n;e.push(o.UTF8ToString(n,i))}C.push([u,h,e,`cpu`])}else if(_===`gpu-buffer`&&g>0){let e=o.jsepGetBuffer;if(!e)throw Error(`preferredLocation "gpu-buffer" is not supported without using WebGPU.`);let t=e(d),r=FU(a,g);if(r===void 0||!RU(u))throw Error(`Unsupported data type: ${u}`);l=!0,C.push([u,h,{gpuBuffer:t,download:o.jsepCreateDownloader(t,r,u),dispose:()=>{o._OrtReleaseTensor(n)!==0&&SU(`Can't release tensor.`)}},`gpu-buffer`])}else if(_===`ml-tensor`&&g>0){let t=o.webnnEnsureTensor,r=o.webnnIsGraphInputOutputTypeSupported;if(!t||!r)throw Error(`preferredLocation "ml-tensor" is not supported without using WebNN.`);if(FU(a,g)===void 0||!zU(u))throw Error(`Unsupported data type: ${u}`);if(!r(e,u,!1))throw Error(`preferredLocation "ml-tensor" for ${u} output is not supported by current WebNN Context.`);let i=await t(e,d,a,h,!1);l=!0,C.push([u,h,{mlTensor:i,download:o.webnnCreateMLTensorDownloader(d,u),dispose:()=>{o.webnnReleaseTensorId(d),o._OrtReleaseTensor(n)}},`ml-tensor`])}else if(_===`ml-tensor-cpu-output`&&g>0){let e=o.webnnCreateMLTensorDownloader(d,u)(),t=C.length;l=!0,O.push((async()=>{let r=[t,await e];return o.webnnReleaseTensorId(d),o._OrtReleaseTensor(n),r})()),C.push([u,h,[],`cpu`])}else{let e=new(IU(u))(g);new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(o.HEAPU8.subarray(d,d+e.byteLength)),C.push([u,h,e,`cpu`])}}finally{o.stackRestore(a),u===`string`&&d&&o._free(d),l||o._OrtReleaseTensor(n)}}f&&!p&&(o._OrtClearBoundOutputs(f.handle)!==0&&SU(`Can't clear bound outputs.`),a$.set(e,[l,u,d,f,p,!1]));for(let[e,t]of await Promise.all(O))C[e][2]=t;return DH(`wasm ProcessOutputTensor`),C}finally{o.webnnOnRunEnd?.(l),o.stackRestore(C),y.forEach(e=>o._OrtReleaseTensor(e)),b.forEach(e=>o._OrtReleaseTensor(e)),x.forEach(e=>o._free(e)),_!==0&&o._OrtReleaseRunOptions(_),v.forEach(e=>o._free(e))}},p$=e=>{let t=vU(),n=a$.get(e);if(!n)throw Error(`invalid session id`);let r=n[0],i=t._OrtEndProfiling(r);i===0&&SU(`Can't get an profile file name.`),t._OrtFree(i)},m$=e=>{let t=[];for(let n of e){let e=n[2];!Array.isArray(e)&&`buffer`in e&&t.push(e.buffer)}return t}}),g$,_$,v$,y$,b$,x$,S$,C$,w$,T$,E$,D$,O$,k$,A$,j$,M$,N$,P$=Z(()=>{LH(),h$(),yU(),lU(),g$=()=>!!QV.wasm.proxy&&typeof document<`u`,v$=!1,y$=!1,b$=!1,C$=new Map,w$=(e,t)=>{let n=C$.get(e);n?n.push(t):C$.set(e,[t])},T$=()=>{if(v$||!y$||b$||!_$)throw Error(`worker not ready`)},E$=e=>{switch(e.data.type){case`init-wasm`:v$=!1,e.data.err?(b$=!0,S$[1](e.data.err)):(y$=!0,S$[0]()),x$&&=(URL.revokeObjectURL(x$),void 0);break;case`init-ep`:case`copy-from`:case`create`:case`release`:case`run`:case`end-profiling`:{let t=C$.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}default:}},D$=async()=>{if(!y$){if(v$)throw Error(`multiple calls to 'initWasm()' detected.`);if(b$)throw Error(`previous call to 'initWasm()' failed.`);if(v$=!0,g$())return new Promise((e,t)=>{_$?.terminate(),oU().then(([n,r])=>{try{_$=r,_$.onerror=e=>t(e),_$.onmessage=E$,S$=[e,t];let i={type:`init-wasm`,in:QV};!i.in.wasm.wasmPaths&&(n||XH)&&(i.in.wasm.wasmPaths={wasm:new URL(`/assets/ort-wasm-simd-threaded.jsep-C887KxcQ.wasm`,``+import.meta.url).href}),_$.postMessage(i),x$=n}catch(e){t(e)}},t)});try{await _U(QV.wasm),await r$(QV),y$=!0}catch(e){throw b$=!0,e}finally{v$=!1}}},O$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`init-ep`,[t,n]);let r={type:`init-ep`,in:{epName:e,env:QV}};_$.postMessage(r)});await i$(QV,e)},k$=async e=>g$()?(T$(),new Promise((t,n)=>{w$(`copy-from`,[t,n]);let r={type:`copy-from`,in:{buffer:e}};_$.postMessage(r,[e.buffer])})):c$(e),A$=async(e,t)=>{if(g$()){if(t?.preferredOutputLocation)throw Error(`session option "preferredOutputLocation" is not supported for proxy.`);return T$(),new Promise((n,r)=>{w$(`create`,[n,r]);let i={type:`create`,in:{model:e,options:{...t}}},a=[];e instanceof Uint8Array&&a.push(e.buffer),_$.postMessage(i,a)})}else return l$(e,t)},j$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`release`,[t,n]);let r={type:`release`,in:e};_$.postMessage(r)});u$(e)},M$=async(e,t,n,r,i,a)=>{if(g$()){if(n.some(e=>e[3]!==`cpu`))throw Error(`input tensor on GPU is not supported for proxy.`);if(i.some(e=>e))throw Error(`pre-allocated output tensor is not supported for proxy.`);return T$(),new Promise((i,o)=>{w$(`run`,[i,o]);let s=n,c={type:`run`,in:{sessionId:e,inputIndices:t,inputs:s,outputIndices:r,options:a}};_$.postMessage(c,m$(s))})}else return f$(e,t,n,r,i,a)},N$=async e=>{if(g$())return T$(),new Promise((t,n)=>{w$(`end-profiling`,[t,n]);let r={type:`end-profiling`,in:e};_$.postMessage(r)});p$(e)}}),F$,I$,L$,R$=Z(()=>{LH(),P$(),VU(),RH(),UU(),F$=(e,t)=>{switch(e.location){case`cpu`:return[e.type,e.dims,e.data,`cpu`];case`gpu-buffer`:return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},`gpu-buffer`];case`ml-tensor`:return[e.type,e.dims,{mlTensor:e.mlTensor},`ml-tensor`];default:throw Error(`invalid data location: ${e.location} for ${t()}`)}},I$=e=>{switch(e[3]){case`cpu`:return new bH(e[0],e[2],e[1]);case`gpu-buffer`:{let t=e[0];if(!RU(t))throw Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:r,dispose:i}=e[2];return bH.fromGpuBuffer(n,{dataType:t,dims:e[1],download:r,dispose:i})}case`ml-tensor`:{let t=e[0];if(!zU(t))throw Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:r,dispose:i}=e[2];return bH.fromMLTensor(n,{dataType:t,dims:e[1],download:r,dispose:i})}default:throw Error(`invalid data location: ${e[3]}`)}},L$=class{async fetchModelAndCopyToWasmMemory(e){return k$(await HU(e))}async loadModel(e,t){wH();let n;n=typeof e==`string`?await this.fetchModelAndCopyToWasmMemory(e):e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await A$(n,t),TH()}async dispose(){return j$(this.sessionId)}async run(e,t,n){wH();let r=[],i=[];Object.entries(e).forEach(e=>{let t=e[0],n=e[1],a=this.inputNames.indexOf(t);if(a===-1)throw Error(`invalid input '${t}'`);r.push(n),i.push(a)});let a=[],o=[];Object.entries(t).forEach(e=>{let t=e[0],n=e[1],r=this.outputNames.indexOf(t);if(r===-1)throw Error(`invalid output '${t}'`);a.push(n),o.push(r)});let s=r.map((e,t)=>F$(e,()=>`input "${this.inputNames[i[t]]}"`)),c=a.map((e,t)=>e?F$(e,()=>`output "${this.outputNames[o[t]]}"`):null),l=await M$(this.sessionId,i,s,o,c,n),u={};for(let e=0;e<l.length;e++)u[this.outputNames[o[e]]]=a[e]??I$(l[e]);return TH(),u}startProfiling(){}endProfiling(){N$(this.sessionId)}}}),z$={};LV(z$,{OnnxruntimeWebAssemblyBackend:()=>V$,initializeFlags:()=>B$,wasmBackend:()=>H$});var B$,V$,H$,U$=Z(()=>{LH(),P$(),R$(),B$=()=>{(typeof QV.wasm.initTimeout!=`number`||QV.wasm.initTimeout<0)&&(QV.wasm.initTimeout=0);let e=QV.wasm.simd;if(typeof e!=`boolean`&&e!==void 0&&e!==`fixed`&&e!==`relaxed`&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`),QV.wasm.simd=!1),typeof QV.wasm.proxy!=`boolean`&&(QV.wasm.proxy=!1),typeof QV.wasm.trace!=`boolean`&&(QV.wasm.trace=!1),typeof QV.wasm.numThreads!=`number`||!Number.isInteger(QV.wasm.numThreads)||QV.wasm.numThreads<=0)if(typeof self<`u`&&!self.crossOriginIsolated)QV.wasm.numThreads=1;else{let e=typeof navigator>`u`?IV(`node:os`).cpus().length:navigator.hardwareConcurrency;QV.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},V$=class{async init(e){B$(),await D$(),await O$(e)}async createInferenceSessionHandler(e,t){let n=new L$;return await n.loadModel(e,t),n}},H$=new V$});LH(),LH(),LH();var W$=`1.24.3`;{let e=(U$(),zV(z$)).wasmBackend;HV(`webgpu`,e,5),HV(`webnn`,e,5),HV(`cpu`,e,10),HV(`wasm`,e,10)}Object.defineProperty(QV.versions,"web",{value:W$,enumerable:!0});var G$=class{constructor(e,t){this.runner=e,this.config=t}},K$=class extends G${constructor(e,t){super(e,t),this.store=new EV,this.cachedSize=null,this.graph=t.graph,this.params=t.params??{}}get size(){return this.cachedSize??this.inferSize()}reset(e){this.store.reset()}compute(e){let t=this.evaluate(e);if(this.cachedSize===null)return this.cachedSize=t.length,t;if(t.length===this.cachedSize)return t;let n=new Float32Array(this.cachedSize);return n.set(t.subarray(0,Math.min(t.length,this.cachedSize))),n}evaluate(e){let t=DV(this.graph,{runner:this.runner,state:e,params:this.params},this.store);if(t instanceof Float32Array)return t;if(typeof t==`number`)return new Float32Array([t]);if(typeof t==`boolean`)return new Float32Array([+!!t]);if(t instanceof Uint8Array){let e=new Float32Array(t.length);for(let n=0;n<t.length;n++)e[n]=t[n];return e}return new Float32Array}inferSize(){this.runner.getContext();let e={jointPos:new Float32Array(this.runner.getNumActions())};return this.compute(e),this.cachedSize??0}},q$=class{constructor(e,t={}){this.motionCache=new Map,this.config=e,this.options=t,this.policyModule=null,this.obsGroups={},this.obsLayouts={},this.obsSizes={},this.historyConfig={},this.historyBuffers={},this.defaultObsKey=null,this.context=null,this.policyJointNames=(e.policy_joint_names??[]).slice(),this.numActions=e.policy_num_actions??this.policyJointNames.length,this.lastActions=new Float32Array(this.numActions),this.defaultJointPos=this.normalizeArray(e.default_joint_pos??[],this.numActions,0),this.encoderBias=this.normalizeArray(e.encoder_bias??[],this.numActions,0)}async init(e){this.context=e,this.policyModule=await this.buildPolicyModule(e),this.buildObservationGroups()}reset(e){this.lastActions.fill(0),this.policyModule?.reset();for(let t of Object.values(this.obsGroups))for(let n of t)n.reset&&n.reset(e);if(e){for(let[t,n]of Object.entries(this.historyConfig))if(n.steps>1){let r=this.buildFrame(this.obsGroups[t]??[],e),i=this.historyBuffers[t];for(let e=0;e<n.steps;e++)i.set(r,e*r.length)}}}update(e){this.policyModule?.update();for(let t of Object.values(this.obsGroups))for(let n of t)n.update&&n.update(e)}collectObservationsByKey(e){this.update(e);let t={};for(let[n,r]of Object.entries(this.obsGroups)){let i=this.historyConfig[n];if(i&&i.steps>1){let i=this.buildFrame(r,e),a=this.historyBuffers[n];for(let e=a.length-1;e>=i.length;e--)a[e]=a[e-i.length];a.set(i,0),t[n]=new Float32Array(a)}else t[n]=this.buildFrame(r,e)}return t}collectObservations(e){let t=this.collectObservationsByKey(e);if(this.defaultObsKey&&t[this.defaultObsKey])return t[this.defaultObsKey];let n=Object.keys(t)[0];return n?t[n]:new Float32Array}async preloadAll(){let e=[];for(let t of Object.values(this.obsGroups))for(let n of t)typeof n.preload==`function`&&e.push(n.preload());await Promise.all(e)}getObservationSize(){if(this.defaultObsKey&&this.obsSizes[this.defaultObsKey]!==void 0)return this.obsSizes[this.defaultObsKey];let e=Object.keys(this.obsSizes)[0];return e?this.obsSizes[e]:0}getObservationLayout(){if(this.defaultObsKey&&this.obsLayouts[this.defaultObsKey])return this.obsLayouts[this.defaultObsKey].map(e=>({...e}));let e=Object.keys(this.obsLayouts)[0];return e?this.obsLayouts[e].map(e=>({...e})):[]}getPolicyModuleContext(){return this.policyModule?.getContext()??{}}getPolicyModule(){return this.policyModule}getContext(){return this.context}getPolicyJointNames(){return this.policyJointNames.slice()}getNumActions(){return this.numActions}getDefaultJointPos(){return new Float32Array(this.defaultJointPos)}getEncoderBias(){return new Float32Array(this.encoderBias)}getLastActions(){return new Float32Array(this.lastActions)}getConfig(){return this.config}getMotionData(e){let t=this.motionCache.get(e);if(t)return t;let n=this.options.motions?.find(t=>t.name===e),r=n?UB(n.data):Promise.resolve(null);return this.motionCache.set(e,r),r}setLastActions(e){if(e.length!==this.lastActions.length){this.lastActions=new Float32Array(e);return}this.lastActions.set(e)}async buildPolicyModule(e){let t=this.options.policyModules??{},n=this.config.policy_module,r=n?t[n]:t.default;if(n&&!r)throw Error(`Unknown policy module: ${n}`);if(!r)return null;let i=new r(this.config);return await i.init(e),i}buildObservationGroups(){let e=this.options.observations??{},t=this.config.observations??{};this.obsGroups={},this.obsLayouts={},this.obsSizes={},this.historyConfig={},this.historyBuffers={},this.defaultObsKey=null;let n=t=>{let n=t;if(n.kind===`observation`&&Array.isArray(n.nodes))return new K$(this,{name:`DslObservation`,graph:{kind:`observation`,nodes:n.nodes,output:n.output??``},params:n.params});let r=e[t.name];if(!r)throw Error(`Unknown observation type: ${t.name}`);return new r(this,t)};for(let[r,i]of Object.entries(t)){if(Array.isArray(i)){let e=i.map(n);this.registerGroup(r,e,i);continue}if(i&&typeof i==`object`){let t=i;if(Array.isArray(t.components)){let n=t.components.map(t=>{let n=t;if(n.kind===`observation`&&Array.isArray(n.nodes))return new K$(this,{name:`DslObservation`,graph:{kind:`observation`,nodes:n.nodes,output:n.output??``},params:n.params});let r=e[t.name];if(!r)throw Error(`Unknown observation type: ${t.name}`);let i={...t,history_steps:1};return new r(this,i)}),i=Math.max(1,Math.floor(t.history_steps??1)),a=!!t.interleaved;this.registerGroup(r,n,t.components,{steps:i,interleaved:a})}}}this.obsGroups.policy?this.defaultObsKey=`policy`:this.obsGroups.observation?this.defaultObsKey=`observation`:this.obsGroups.obs_history?this.defaultObsKey=`obs_history`:this.defaultObsKey=Object.keys(this.obsGroups)[0]??null}registerGroup(e,t,n,r){this.obsGroups[e]=t,this.obsLayouts[e]=t.map((e,t)=>({name:n[t]?.name??`obs_${t}`,size:e.size}));let i=this.obsLayouts[e].reduce((e,t)=>e+t.size,0);r&&r.steps>1?(this.historyConfig[e]=r,this.historyBuffers[e]=new Float32Array(i*r.steps),this.obsSizes[e]=i*r.steps):this.obsSizes[e]=i}buildFrame(e,t){let n=e.map(e=>{let n=e.compute(t),r=n instanceof Float32Array?n:Float32Array.from(n);if(r.length!==e.size)throw Error(`Observation size mismatch: expected ${e.size}, got ${r.length}`);return r}),r=n.reduce((e,t)=>e+t.length,0),i=new Float32Array(r),a=0;for(let e of n)i.set(e,a),a+=e.length;return i}normalizeArray(e,t,n){let r=new Float32Array(t);for(let i=0;i<t;i++)r[i]=typeof e[i]==`number`?e[i]:n;return r}};QV.wasm.proxy=!1,QV.wasm.numThreads=1,typeof __ORT_CDN_BASE__<`u`&&(QV.wasm.wasmPaths=__ORT_CDN_BASE__);var J$=class{constructor(e,t){this.bytes=e,this.session=null;let n=t?.in_keys??[`policy`],r=t?.out_keys??[`action`];this.configuredInKeys=n.map(e=>Array.isArray(e)?e.join(`,`):e),this.inKeys=[...this.configuredInKeys],this.outKeys=r.map(e=>Array.isArray(e)?e.join(`,`):e),this.isRecurrent=this.inKeys.includes(`adapt_hx`)}async init(){this.session=await jH.create(this.bytes,{executionProviders:[`wasm`],graphOptimizationLevel:`all`}),this.inferInputKeys(),this.isRecurrent=this.inKeys.includes(`adapt_hx`)}initInput(){let e={};return this.isRecurrent&&(e.is_init=new bH(`bool`,[!0],[1]),e.adapt_hx=new bH(`float32`,new Float32Array(128),[1,128])),this.inKeys.includes(`time_step`)&&(e.time_step=new bH(`float32`,new Float32Array([0]),[1,1])),e}async runInference(e){if(!this.session)throw Error(`OnnxModule not initialized.`);let t={};for(let n=0;n<this.inKeys.length;n++){let r=this.inKeys[n],i=this.session.inputNames[n];if(!i||!e[r])throw Error(`Missing ONNX input for key: ${r}`);t[i]=e[r]}let n=await this.session.run(t),r={};for(let e=0;e<this.outKeys.length;e++){let t=this.outKeys[e],i=this.session.outputNames[e];i&&n[i]&&(r[t]=n[i])}let i={};return this.isRecurrent&&r[`next,adapt_hx`]&&(i.is_init=new bH(`bool`,[!1],[1]),i.adapt_hx=r[`next,adapt_hx`]),[r,i]}dispose(){this.session?.release?.(),this.session=null}inferInputKeys(){if(!this.session)return;let e=this.session.inputNames;if(e.length<=1){this.inKeys=[...this.configuredInKeys];return}if(this.configuredInKeys.length===e.length){this.inKeys=[...this.configuredInKeys];return}this.inKeys=e.map(e=>this.configuredInKeys.includes(e)?e:e===`obs`&&this.configuredInKeys.includes(`policy`)?`policy`:e)}},Y$=class{constructor(e,t,n,r){this.mujoco=e,this.mjModel=t,this.mjData=n;let i=this.getJointNames(t);this.qposAdr=[],this.qvelAdr=[],this.jointIndices=[],this.ctrlAdr=null;for(let e of r){let n=i.indexOf(e);if(n<0)throw Error(`Joint "${e}" not found in MuJoCo model`);this.qposAdr.push(t.jnt_qposadr[n]),this.qvelAdr.push(t.jnt_dofadr[n]),this.jointIndices.push(n)}this.numActions=r.length,this.ctrlAdr=this.buildCtrlAdr()}build(){let e=this.mjData.qpos,t=this.mjData.qvel,n=new Float32Array(this.numActions),r=new Float32Array(this.numActions);for(let i=0;i<this.numActions;i++)n[i]=e[this.qposAdr[i]],r[i]=t[this.qvelAdr[i]];return{jointPos:n,jointVel:r,rootPos:new Float32Array([e[0],e[1],e[2]]),rootQuat:new Float32Array([e[3],e[4],e[5],e[6]]),rootLinVel:new Float32Array([t[0],t[1],t[2]]),rootAngVel:new Float32Array([t[3],t[4],t[5]])}}getControlMapping(){return this.ctrlAdr?{ctrlAdr:this.ctrlAdr.slice(),qposAdr:this.qposAdr.slice(),qvelAdr:this.qvelAdr.slice()}:null}getControlMappingFor(e,t){if(!this.ctrlAdr)return null;let n=e.map(e=>RegExp(`^(?:${e})$`)),r=e=>n.some(t=>t.test(e)),i=[],a=[],o=[],s=[];for(let e=0;e<t.length;e++)r(t[e])&&(i.push(this.ctrlAdr[e]),a.push(this.qposAdr[e]),o.push(this.qvelAdr[e]),s.push(e));return i.length===0?null:{ctrlAdr:i,qposAdr:a,qvelAdr:o,actionIndices:s}}getCtrlMappingByActuatorNames(e){let t=this.getActuatorNames(this.mjModel),n=e.map(e=>RegExp(`^(?:${e})$`)),r=e=>n.some(t=>t.test(e)),i=[],a=[];for(let e=0;e<t.length;e++)r(t[e])&&(i.push(e),a.push(i.length-1));return i.length>0?{ctrlAdr:i,actionIndices:a}:null}getActuatorNames(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.nu;i++){let a=e.name_actuatoradr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;r.push(n.decode(t.subarray(a,o)))}return r}buildCtrlAdr(){if(this.mjModel.nu<=0)return null;let e=this.mujoco.mjtTrn?.mjTRN_JOINT?.value,t=[];for(let n=0;n<this.mjModel.nu;n++){let r=this.mjModel.actuator_trntype[n];e===void 0||r===e?t.push(this.mjModel.actuator_trnid[2*n]):t.push(-1)}let n=[];for(let e of this.jointIndices){let r=t.findIndex(t=>t===e);if(r<0)return null;n.push(r)}return n}getJointNames(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.njnt;i++){let a=e.name_jntadr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;let s=n.decode(t.subarray(a,o));!s&&i===0&&(s=`floating_base_joint`),r.push(s)}return r}},X$=class{constructor(e){this.config=e,this.context=null}init(e){this.context=e}reset(){}update(){}getContext(){return{}}},Z$=class{constructor(e){this.policyJointNames=(e.policy_joint_names??[]).slice(),this.datasetJointNames=(e.dataset_joint_names??[]).slice(),this.nJoints=this.datasetJointNames.length||this.policyJointNames.length||0,this.refJointPos=[],this.refRootPos=[],this.refRootQuat=[],this.refIdx=0,this.refLen=0,this.currentName=`default`,this.currentDone=!0}reset(e){let t=e?.jointPos??new Float32Array(this.nJoints),n=e?.rootPos??new Float32Array([0,0,0]),r=e?.rootQuat??new Float32Array([1,0,0,0]);this.refJointPos=[Float32Array.from(t)],this.refRootPos=[Float32Array.from(n)],this.refRootQuat=[Float32Array.from(r)],this.refIdx=0,this.refLen=1,this.currentDone=!0,this.currentName=`default`}advance(){this.refLen<=1||this.refIdx<this.refLen-1&&(this.refIdx+=1,this.refIdx===this.refLen-1&&(this.currentDone=!0))}isReady(){return this.refLen>0}},Q$=class extends X${constructor(e){super(e),this.tracking=null}async init(e){await super.init(e);let t=this.config.policy_joint_names??[],n={...this.config.tracking,policy_joint_names:t};this.tracking=new Z$(n)}reset(e){this.tracking?.reset(e)}update(){this.tracking?.advance()}getContext(){return{tracking:this.tracking}}},$$=class{constructor(e){this.policyJointNames=(e.policy_joint_names??[]).slice(),this.datasetJointNames=(e.dataset_joint_names??[]).slice(),this.nJoints=this.datasetJointNames.length||this.policyJointNames.length||0,this.refJointPos=[],this.refRootPos=[],this.refRootQuat=[],this.refIdx=0,this.refLen=0,this.currentName=`default`,this.currentDone=!0}reset(e){let t=e?.jointPos??new Float32Array(this.nJoints),n=e?.rootPos??new Float32Array([0,0,0]),r=e?.rootQuat??new Float32Array([1,0,0,0]);this.refJointPos=[Float32Array.from(t)],this.refRootPos=[Float32Array.from(n)],this.refRootQuat=[Float32Array.from(r)],this.refIdx=0,this.refLen=1,this.currentDone=!0,this.currentName=`default`}advance(){this.refLen<=1||this.refIdx<this.refLen-1&&(this.refIdx+=1,this.refIdx===this.refLen-1&&(this.currentDone=!0))}isReady(){return this.refLen>0}},e1=class extends X${constructor(e){super(e),this.locomotion=null}async init(e){await super.init(e);let t=this.config.policy_joint_names??[],n={...this.config.tracking,policy_joint_names:t};this.locomotion=new $$(n)}reset(e){this.locomotion?.reset(e)}update(){this.locomotion?.advance()}getContext(){return{tracking:this.locomotion}}},t1=class{constructor(e){this.config=e}};function n1(e,t){return e+Math.random()*(t-e)}function r1(e){let t=new Uint8Array(e.names),n=new TextDecoder,r=[];for(let i=0;i<e.njnt;i++){let a=e.name_jntadr[i],o=a;for(;o<t.length&&t[o]!==0;)o++;r.push(n.decode(t.subarray(a,o)))}return r}function i1(e){for(let t=0;t<e.njnt;t++)if(e.jnt_type[t]===0)return t;return-1}var a1=class extends t1{constructor(e){super(e),this.mutations=e.mutations??[]}onReset(e){let{mjModel:t,mjData:n}=e;if(!(!t||!n))for(let e of this.mutations)switch(e.target){case`joint_qpos`:this.applyJointOffset(t,n,e,`qpos`);break;case`joint_qvel`:this.applyJointOffset(t,n,e,`qvel`);break;case`freejoint_pos`:this.applyFreejointPos(t,n,e);break;case`freejoint_yaw`:this.applyFreejointYaw(t,n,e);break}}resolveJointIndices(e,t){let n=t.select??{};if(n.joint_ids&&n.joint_ids.length>0)return n.joint_ids.filter(t=>t>=0&&t<e.njnt);let r=r1(e);return n.joint_names&&n.joint_names.length>0?n.joint_names.map(e=>this.findJointIndex(r,e,n.entity_name)).filter(e=>e!==null):r.map((e,t)=>({name:e,idx:t})).filter(({name:t,idx:r})=>e.jnt_type[r]===0?!1:n.entity_name?t===n.entity_name||t.startsWith(`${n.entity_name}/`):!0).map(({idx:e})=>e)}findJointIndex(e,t,n){let r=e.indexOf(t);if(r>=0)return r;if(n){let r=e.indexOf(`${n}/${t}`);if(r>=0)return r}let i=e.map((e,t)=>({name:e,idx:t})).filter(({name:e})=>e===t||e.endsWith(`/${t}`));if(i.length===1)return i[0].idx;if(n){let e=i.find(({name:e})=>e===n||e.startsWith(`${n}/`));if(e)return e.idx}return null}applyJointOffset(e,t,n,r){if(n.sample.dist!==`uniform`)return;let{low:i,high:a}=n.sample;for(let o of this.resolveJointIndices(e,n)){let s=e.jnt_type[o];if(!(s!==2&&s!==3))if(r===`qpos`){let r=e.jnt_qposadr[o];if(t.qpos[r]+=n1(i,a),n.clip_to_limits&&e.jnt_limited[o]){let n=e.jnt_range[o*2],i=e.jnt_range[o*2+1];t.qpos[r]=Math.min(Math.max(t.qpos[r],n),i)}}else t.qvel[e.jnt_dofadr[o]]+=n1(i,a)}}applyFreejointPos(e,t,n){if(n.sample.dist!==`uniform_xyz`)return;let r=i1(e);if(r<0)return;let i=e.jnt_qposadr[r];t.qpos[i]+=n1(n.sample.x[0],n.sample.x[1]),t.qpos[i+1]+=n1(n.sample.y[0],n.sample.y[1]),t.qpos[i+2]+=n1(n.sample.z[0],n.sample.z[1])}applyFreejointYaw(e,t,n){if(n.sample.dist!==`uniform`)return;let r=i1(e);if(r<0)return;let i=e.jnt_qposadr[r]+3,a=n1(n.sample.low,n.sample.high),o=Math.cos(a/2),s=Math.sin(a/2),c=t.qpos[i],l=t.qpos[i+1],u=t.qpos[i+2],d=t.qpos[i+3];t.qpos[i]=o*c-s*d,t.qpos[i+1]=o*l+s*u,t.qpos[i+2]=o*u-s*l,t.qpos[i+3]=o*d+s*c}};function o1(e){return`kind`in e&&e.kind===`event`&&Array.isArray(e.mutations)}var s1=class{constructor(e,t){this.terms=[];for(let n of e){if(o1(n)){this.terms.push(new a1(n));continue}let e=t[n.name];if(!e){console.warn(`[EventManager] Unknown event type: ${n.name}`);continue}this.terms.push(new e(n))}}onReset(e){for(let t of this.terms)t.onReset(e)}get size(){return this.terms.length}},c1={};function l1(e){return typeof e==`object`&&!!e&&typeof e.setSelectedMotion==`function`}var u1=class extends Error{constructor(){super(`This scene cannot be loaded because it exceeds the browser's WebAssembly 2 GB memory limit. Try closing other browser tabs or reloading the page to free memory.`),this.name=`WasmMemoryLimitError`}};function d1(e){let t=e instanceof Error?e.message:String(e);return t.includes(`MjModel loading returned null`)||t.includes(`Could not allocate memory`)||t.includes(`memory allocation failed`)||t.includes(`bad_alloc`)}var f1=class{constructor(e,t){this.render=()=>{if(this.commandManager.updateDebugVisuals(),this.mjData&&AB(this.mjData,this.camera,this.controls,this.cameraState),this.controls.update(),this.mjModel&&this.mjData&&this.bodies){WN(this.camera,this.lights);for(let[e,t]of this.lastSimState.bodies){let n=this.bodies[e];n&&(n.position.copy(t.position),n.quaternion.copy(t.quaternion))}UN(this.mujoco,this.mjData,this.lights),this.mujocoRoot&&this.mujocoRoot.cylinders&&QN({cylinders:this.mujocoRoot.cylinders,spheres:this.mujocoRoot.spheres},this.lastSimState.tendons)}this.renderer.render(this.scene,this.camera)},this.onWindowResize=()=>{let{width:e,height:t}=this.getSize();this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)},this.mujoco=e,this.container=t,this.commandManager=new rV,this.scenePlugins={},this.policyPlugins={};let n=`/working`;try{this.mujoco.FS.mkdir(n)}catch(e){e&&typeof e==`object`&&`code`in e&&e.code!==`EEXIST`&&console.warn(`Failed to create /working directory:`,e)}try{this.mujoco.FS.mount(this.mujoco.MEMFS,{root:`.`},n)}catch(e){e&&typeof e==`object`&&`code`in e&&e.code!==`EEXIST`&&e.code!==`EBUSY`&&console.warn(`Failed to mount MEMFS at /working:`,e)}let{width:r,height:i}=this.getSize();this.scene=new nC,this.scene.name=`scene`,this.camera=new GS(45,r/i,.001,1e3),this.camera.name=`PerspectiveCamera`,this.camera.position.set(2,1.7,1.7),this.scene.add(this.camera),this.renderer=new hN({antialias:!0}),this.renderer.xr.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(r,i),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=2,this.renderer.outputColorSpace=Rv,this.renderer.toneMapping=4,this.renderer.toneMappingExposure=1,this.container.appendChild(this.renderer.domElement),this.vrButton=null,navigator.xr?.isSessionSupported(`immersive-vr`).then(e=>{e&&(this.vrButton=zN.createButton(this.renderer),document.body.appendChild(this.vrButton))}),this.controls=new EN(this.camera,this.renderer.domElement),this.controls.target.set(0,.2,0),this.controls.panSpeed=2,this.controls.zoomSpeed=1,this.controls.enableDamping=!0,this.controls.dampingFactor=.1,this.controls.screenSpacePanning=!0,this.controls.update(),this.renderer.setAnimationLoop(this.render),window.addEventListener(`resize`,this.onWindowResize),`ResizeObserver`in window?(this.resizeObserver=new ResizeObserver(()=>this.onWindowResize()),this.resizeObserver.observe(this.container)):this.resizeObserver=null,this.lastSimState={bodies:new Map,tendons:$N()},this.dynamicBodyIds=null,this.mjModel=null,this.mjData=null,this.bodies=null,this.lights=[],this.mujocoRoot=null,this.loopPromise=null,this.running=!1,this.timestep=.001,this.decimation=1,this.policyCtrlDt=null,this.loadingScene=null,this.dragStateManager=null,this.dragForceScale=100,this.policyRunner=null,this.policyStateBuilder=null,this.initialQpos=null,this.initialQvel=null,this.policyControl=null,this.onnxModule=null,this.onnxInputDict=null,this.onnxInferencing=!1,this.onnxTimeStep=0,this.terminationManager=null,this.eventManager=null,this.terrainData=null,this.splatMesh=null,this.colliderMesh=null,this.currentSplatTransform={},this.cameraState={trackBodyId:null,prevBodyPos:null}}async loadEnvironment(e){this.scenePlugins=e.plugins??{},this.terrainData=e.terrainData??null,e.events&&e.events.length>0?(this.eventManager=new s1(e.events,{...c1,...this.scenePlugins.events}),console.log(`[EventManager] ${this.eventManager.size} reset event(s) loaded`)):this.eventManager=null,await this.stop(),this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),this.initializeCommands(),this.mjModel=null,this.mjData=null,this.bodies=null,this.lights=[],this.mujocoRoot=null,this.dynamicBodyIds=null,await this.buildSceneFromMjz(e.model),e.splat&&await this.applySplat(e.splat),await this.loadPolicyConfig(e.policy??null),this.applyViewerConfig(e.viewer??null),this.running=!0,this.startLoop()}initializeCommands(){this.commandManager.clear()}initializeCommandsFromConfig(e,t){this.commandManager.initialize(e,t,this.policyPlugins.commands),console.log(`[mjswanRuntime] Commands loaded from policy config:`,Object.keys(e))}resetSimulation(){if(this.resetSimulationState(),this.policyRunner&&this.policyStateBuilder){let e=this.policyStateBuilder.build();this.policyRunner.reset(e)}console.log(`[mjswanRuntime] Simulation reset`)}async setSelectedMotion(e){let t=this.commandManager.getTerm(`motion`);if(!l1(t))return!1;let n=await t.setSelectedMotion(e);return n&&this.resetSimulation(),n}getSelectedMotionName(){let e=this.commandManager.getTerm(`motion`);return l1(e)?e.getSelectedMotionName?.()??null:null}setReferenceVisible(e){let t=this.commandManager.getTerm(`motion`);!l1(t)||typeof t.setReferenceVisible!=`function`||t.setReferenceVisible(e)}async buildScene(e){this.loadingScene&&await this.loadingScene,this.loadingScene=(async()=>{let t=this.scene.getObjectByName(`MuJoCo Root`);t&&this.scene.remove(t);let n={mjModel:this.mjModel,mjData:this.mjData,scene:this.scene};if([this.mjModel,this.mjData,this.bodies,this.lights]=await rP(this.mujoco,e,n),!this.mjModel||!this.mjData)throw Error(`Failed to load MuJoCo model.`);this.mujocoRoot=this.scene.getObjectByName(`MuJoCo Root`),this.mujoco.mj_forward(this.mjModel,this.mjData),UN(this.mujoco,this.mjData,this.lights),WN(this.camera,this.lights),this.dynamicBodyIds=this.computeDynamicBodyIds(this.mjModel),this.syncStaticBodiesFromData(),this.timestep=this.mjModel.opt.timestep||.001;let r=this.policyCtrlDt??.02;this.decimation=Math.max(1,Math.round(r/this.timestep)),this.lastSimState.bodies.clear(),this.updateCachedState(),this.dragStateManager?this.dragStateManager.setDraggableBodyIds(this.dynamicBodyIds):this.dragStateManager=new EB({scene:this.scene,renderer:this.renderer,camera:this.camera,container:this.container,controls:this.controls,draggableBodyIds:this.dynamicBodyIds}),this.loadingScene=null})(),await this.loadingScene}async buildSceneFromMjz(e){try{let t=await cP(this.mujoco,e);await this.buildScene(t)}catch(e){throw this.loadingScene=null,d1(e)?new u1:e}}async startLoop(){return this.loopPromise?this.loopPromise:(this.running=!0,this.loopPromise=this.mainLoop(),this.loopPromise)}async setSplat(e){this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),e&&await this.applySplat(e)}async applySplat(e){this.currentSplatTransform=e.transform??{},this.splatMesh=Sz(e.data,this.currentSplatTransform,this.scene),e.collider&&(this.colliderMesh=await wB(e.collider,this.scene))}calibrateSplat(e){this.currentSplatTransform=e,this.splatMesh&&xz(this.splatMesh,e)}setSplatVisible(e){this.splatMesh&&(this.splatMesh.visible=e)}get commands(){return this.commandManager}play(){this.running=!0,this.startLoop()}pause(){this.stop()}get isRunning(){return this.running}getCameraView(){let e=this.camera.position.clone().sub(this.controls.target),t=e.length(),n=VN(e),r=VN(this.controls.target.clone()),i=180/Math.PI,a=t>1e-9?Math.asin(-n.z/t)*i:0,o=Math.atan2(n.y,n.x)*i;return{lookat:[r.x,r.y,r.z],distance:t,azimuth:o,elevation:a,fovy:this.camera.fov}}setCameraView(e){let t=this.getCameraView(),n=e.lookat??t.lookat,r=e.distance??t.distance,i=e.elevation??t.elevation,a=e.azimuth??t.azimuth;this.camera.fov=e.fovy??t.fovy,this.camera.updateProjectionMatrix(),this.camera.position.copy(OB(n,r,i,a)),this.controls.target.copy(BN(n)),this.controls.update()}frameCamera(){if(!this.mujocoRoot)return;let e=new Cb().setFromObject(this.mujocoRoot);if(e.isEmpty())return;let t=e.getCenter(new Y),n=e.getSize(new Y).length(),r=this.camera.fov*Math.PI/180,i=n/(2*Math.tan(r/2)),a=this.getCameraView(),o=VN(t);this.setCameraView({lookat:[o.x,o.y,o.z],distance:i>0?i:a.distance})}async stop(){this.running=!1;let e=this.loopPromise;e&&await e,this.loopPromise=null}async mainLoop(){for(;this.running;){let e=performance.now(),t=this.timestep*this.decimation;if(this.mjModel&&this.mjData){if(this.mujoco.mj_forward(this.mjModel,this.mjData),this.policyRunner&&this.policyStateBuilder){let e=this.policyStateBuilder.build(),t=this.policyRunner.collectObservationsByKey(e);await this.runOnnxInference(t)}if(this.executeSimulationSteps(),this.updateCachedState(),this.terminationManager&&this.policyStateBuilder){let e=this.policyStateBuilder.build();if(this.terminationManager.evaluate(e).done&&(this.resetSimulationState(),this.terminationManager.reset(),this.policyRunner)){let e=this.policyStateBuilder.build();this.policyRunner.reset(e)}}this.commandManager.update(t),this.commandManager.updateDebugVisuals()}let n=(performance.now()-e)/1e3,r=Math.max(0,t-n);r>0&&await new Promise(e=>setTimeout(e,r*1e3))}this.loopPromise=null}async loadPolicyConfig(e){if(this.policyPlugins=e?.plugins??{},this.policyRunner=null,this.policyStateBuilder=null,this.policyControl=null,this.onnxModule=null,this.onnxInputDict=null,this.onnxInferencing=!1,this.onnxTimeStep=0,this.terminationManager=null,this.commandManager.clear(),e){if(!this.mjModel||!this.mjData){console.warn(`Policy config loaded before MuJoCo model is ready.`);return}this.resetSimulationState();try{let t=e.config;if(Array.isArray(t.motions)){let n=new Map(e.motions.map(e=>[e.name,e.data]));t.motions=t.motions.map(e=>({...e,data:n.get(e.name)}))}if(t.commands?.motion&&Array.isArray(t.motions)&&(t.commands.motion={...t.commands.motion,motions:t.motions}),this.initialQpos=Array.isArray(t.initial_qpos)?t.initial_qpos:null,this.initialQvel=Array.isArray(t.initial_qvel)?t.initial_qvel:null,this.resetSimulationState(),this.mujoco.mj_forward(this.mjModel,this.mjData),this.updateCachedState(),t.commands&&typeof t.commands==`object`){this.initializeCommandsFromConfig(t.commands,{mujoco:this.mujoco,mjModel:this.mjModel,mjData:this.mjData,scene:this.scene,bodies:this.bodies,mujocoRoot:this.mujocoRoot,requestReset:()=>this.resetSimulation()}),this.commandManager.resetTerms();let e=this.commandManager.getTerm(`motion`);l1(e)&&(await e.setSelectedMotion(t.motions?.find(e=>e.default)?.name??t.motions?.[0]?.name??null),e.setReferenceVisible?.(!0)),this.mujoco.mj_forward(this.mjModel,this.mjData),this.updateCachedState()}if(!t.policy_num_actions&&(!t.policy_joint_names||t.policy_joint_names.length===0))throw Error(`Policy config missing policy_joint_names.`);let n=new q$(t,{policyModules:{tracking:Q$,locomotion:e1},observations:{...jB,...this.policyPlugins.observations},motions:e.motions});await n.init({mujoco:this.mujoco,mjModel:this.mjModel,mjData:this.mjData,scene:this.scene,commandManager:this.commandManager}),await n.preloadAll(),this.policyRunner=n,this.policyStateBuilder=new Y$(this.mujoco,this.mjModel,this.mjData,n.getPolicyJointNames());let r=this.policyStateBuilder.build();this.policyRunner.reset(r),this.policyControl=this.buildPolicyControl(t,n,this.policyStateBuilder);{let e=t.observations,n=[];if(Array.isArray(e))n.push(...e);else if(e&&typeof e==`object`)for(let t of Object.values(e))Array.isArray(t)&&n.push(...t);for(let e of n)if(!(!e||this.timestep<=0)&&typeof e.fps==`number`&&e.fps>0){this.policyCtrlDt=1/e.fps;let t=Math.max(1,Math.round(this.policyCtrlDt/this.timestep));t!==this.decimation&&(console.log(`[PolicyRunner] Decimation updated: ${this.decimation} → ${t} (fps=${e.fps}, sim_dt=${this.timestep})`),this.decimation=t);break}}t.terminations&&Object.keys(t.terminations).length>0&&(this.terminationManager=new AV(t.terminations,{...jV,...this.policyPlugins.terminations},n),console.log(`[TerminationManager] ${this.terminationManager.size} termination term(s) loaded`));let i=new J$(e.onnx,t.onnx?.meta);await i.init(),this.onnxModule=i,this.onnxInputDict=i.initInput(),console.log(`[PolicyRunner] config loaded`,{obsSize:n.getObservationSize(),obsLayout:n.getObservationLayout(),pdEnabled:this.policyControl!==null})}catch(e){console.warn(`Failed to load policy config:`,e)}}}buildPolicyControl(e,t,n){let r=t.getPolicyJointNames(),i=this.mujoco.mjtBias?.mjBIAS_AFFINE?.value??1,a=(n,a,o,s,c,l,u,d)=>{let f=o.qposAdr.length,p=o.actionIndices.map(e=>r[e]),m=this.normalizeControlArray(s,f,1,p),h=this.normalizeControlArray(c,f,0,p),g=d?t.getDefaultJointPos():new Float32Array(r.length),_=new Float32Array(f);for(let e=0;e<f;e++)_[e]=g[o.actionIndices[e]];let v=Array.isArray(e.encoder_bias)?Float32Array.from(e.encoder_bias):new Float32Array(r.length),y=new Float32Array(f);for(let e=0;e<f;e++)y[e]=v[o.actionIndices[e]]??0;let b=this.normalizeControlArray(l,f,0,p),x=this.normalizeControlArray(u,f,0,p),S=o.ctrlAdr.map(e=>e<0||!this.mjModel?!1:this.mjModel.actuator_biastype[e]===i),C=S.some(Boolean),w=S.some(e=>!e);return C&&w&&console.warn(`[PolicyRunner] Action term "${n}": mixed actuator types detected.`),console.log(`[PolicyRunner] Action term "${n}" (${a}): ${f} joint(s), mode: ${C?`position (ctrl=target_pos)`:`motor (ctrl=torque, external PD)`}`),{controlType:a,ctrlAdr:o.ctrlAdr,qposAdr:o.qposAdr,qvelAdr:o.qvelAdr,actionIndices:o.actionIndices,actionScale:m,actionOffset:h,defaultJointPos:_,encoderBias:y,positionActuator:S,kp:b,kd:x,muscleNormalize:!1}},o=e.actions;if(!o||Object.keys(o).length===0){let t=e.control_type??`joint_position`;if(t!==`joint_position`&&t!==`torque`)return console.warn(`[PolicyRunner] Unsupported control_type: ${t}`),null;let r=n.getControlMapping();return r?[a(`legacy`,t,{...r,actionIndices:Array.from({length:r.qposAdr.length},(e,t)=>t)},e.action_scale,void 0,e.stiffness,e.damping,!0)]:(console.warn(`[PolicyRunner] Failed to build control mapping.`),null)}let s=[];for(let[e,t]of Object.entries(o)){let i=t.type??`joint_position`;if(i!==`joint_position`&&i!==`torque`&&i!==`muscle_activation`){console.warn(`[PolicyRunner] Action term "${e}": unsupported type "${i}", skipping.`);continue}let o=t.actuator_names??[`.*`];if(i===`muscle_activation`){let r=n.getCtrlMappingByActuatorNames(o);if(!r){console.warn(`[PolicyRunner] Action term "${e}": no actuators matched patterns [${o.join(`, `)}], skipping.`);continue}let a=r.ctrlAdr.length,c=this.normalizeControlArray(t.scale,a,1),l=this.normalizeControlArray(t.offset,a,0),u=t.normalize??!0;console.log(`[PolicyRunner] Action term "${e}" (muscle_activation): ${a} actuator(s), normalize=${u}`),s.push({controlType:i,ctrlAdr:r.ctrlAdr,qposAdr:[],qvelAdr:[],actionIndices:r.actionIndices,actionScale:c,actionOffset:l,defaultJointPos:new Float32Array(a),encoderBias:new Float32Array(a),positionActuator:Array(a).fill(!1),kp:new Float32Array(a),kd:new Float32Array(a),muscleNormalize:u});continue}let c=o.length===1&&o[0]===`.*`,l;if(c){let t=n.getControlMapping();if(!t){console.warn(`[PolicyRunner] Action term "${e}": failed to build control mapping, skipping.`);continue}l={...t,actionIndices:Array.from({length:t.qposAdr.length},(e,t)=>t)}}else if(l=n.getControlMappingFor(o,r),!l){console.warn(`[PolicyRunner] Action term "${e}": no joints matched patterns [${o.join(`, `)}], skipping.`);continue}let u=t.use_default_offset===void 0?i===`joint_position`:t.use_default_offset;s.push(a(e,i,l,t.scale,t.offset,t.stiffness,t.damping,u))}return s.length===0?(console.warn(`[PolicyRunner] No valid action terms found in config.actions.`),null):s}normalizeControlArray(e,t,n,r){let i=new Float32Array(t);if(i.fill(n),typeof e==`number`)return i.fill(e),i;if(Array.isArray(e)){for(let r=0;r<t;r++)i[r]=typeof e[r]==`number`?e[r]:n;return i}if(typeof e==`object`&&e&&r){for(let[n,a]of Object.entries(e)){let e=r.indexOf(n);e>=0&&e<t?i[e]=a:console.warn(`[PolicyRunner] Joint name "${n}" not found in policy_joint_names; skipping.`)}return i}return i}resetSimulationState(){if(!(!this.mjModel||!this.mjData)){if(this.mjModel.nkey>0?this.mujoco.mj_resetDataKeyframe(this.mjModel,this.mjData,0):this.mujoco.mj_resetData(this.mjModel,this.mjData),this.initialQpos){let e=this.mjData.qpos;for(let t=0;t<Math.min(this.initialQpos.length,this.mjModel.nq);t++)e[t]=this.initialQpos[t]}if(this.initialQvel){let e=this.mjData.qvel;for(let t=0;t<Math.min(this.initialQvel.length,this.mjModel.nv);t++)e[t]=this.initialQvel[t]}this.eventManager&&this.eventManager.onReset({mjModel:this.mjModel,mjData:this.mjData,terrainData:this.terrainData}),this.commandManager.resetTerms(),this.onnxModule&&(this.onnxInputDict=this.onnxModule.initInput()),this.onnxTimeStep=0,this.mujoco.mj_forward(this.mjModel,this.mjData),this.lastSimState.bodies.clear(),this.updateCachedState()}}executeSimulationSteps(){if(!(!this.mjModel||!this.mjData)){this.applyDragForces();for(let e=0;e<this.decimation;e++)this.applyPolicyControl(),this.mujoco.mj_step(this.mjModel,this.mjData)}}applyPolicyControl(){if(!this.policyControl||!this.mjData)return;let e=this.mjData.ctrl;e.fill(0);let t=this.policyRunner?.getLastActions()??new Float32Array;for(let n of this.policyControl){let{controlType:r,ctrlAdr:i,qposAdr:a,qvelAdr:o,actionIndices:s,actionScale:c,actionOffset:l,defaultJointPos:u,encoderBias:d,positionActuator:f,kp:p,kd:m,muscleNormalize:h}=n,g=i.length;if(r===`joint_position`)for(let n=0;n<g;n++){let r=i[n];if(r<0)continue;let h=t[s[n]]??0,g=u[n]+l[n]+c[n]*h-d[n];if(f[n])e[r]=g;else{let t=this.mjData.qpos[a[n]],i=this.mjData.qvel[o[n]];e[r]=p[n]*(g-t)+m[n]*(0-i)}}else if(r===`torque`)for(let n=0;n<g;n++){let r=i[n];r>=0&&(e[r]=c[n]*(t[s[n]]??0))}else if(r===`muscle_activation`)for(let n=0;n<g;n++){let r=i[n];if(r<0)continue;let a=(t[s[n]]??0)*c[n]+l[n];h?e[r]=1/(1+Math.exp(-5*(a-.5))):e[r]=a<0?0:a>1?1:a}}}async runOnnxInference(e){if(!(!this.onnxModule||!this.policyRunner||this.onnxInferencing)){this.onnxInferencing=!0;try{this.onnxInputDict||=this.onnxModule.initInput();let t={...this.onnxInputDict};this.onnxModule.inKeys.includes(`time_step`)&&(t.time_step=new bH(`float32`,new Float32Array([this.onnxTimeStep]),[1,1]));for(let[n,r]of Object.entries(e))t[n]=new bH(`float32`,r,[1,r.length]);for(let e of this.onnxModule.inKeys)if(!t[e]){console.warn(`[PolicyRunner] Missing ONNX input:`,{key:e,available:Object.keys(t)});return}let[n,r]=await this.onnxModule.runInference(t);Object.keys(r).length>0&&(this.onnxInputDict={...this.onnxInputDict,...r}),this.onnxModule.inKeys.includes(`time_step`)&&(this.onnxTimeStep+=1);let i=this.onnxModule.outKeys[0],a=n.action??(i?n[i]:null)??n.policy??null;if(!a)return;let o=a.data,s=ArrayBuffer.isView(o)?new Float32Array(o):Float32Array.from(o),c=this.policyRunner?.getNumActions()??0;if(this.policyControl&&s.length!==c){console.warn(`[PolicyRunner] Action size mismatch:`,{expected:c,got:s.length});return}this.policyRunner.setLastActions(s)}catch(e){console.warn(`[PolicyRunner] ONNX inference failed:`,e)}finally{this.onnxInferencing=!1}}}applyDragForces(){if(!this.dragStateManager||!this.mjModel||!this.mjData||!this.bodies)return;for(let e=0;e<this.mjData.xfrc_applied.length;e++)this.mjData.xfrc_applied[e]=0;let e=this.dragStateManager.physicsObject;if(!e||!(`bodyID`in e)||typeof e.bodyID!=`number`||e.bodyID<=0)return;let t=e.bodyID;if(this.dynamicBodyIds&&!this.dynamicBodyIds.has(t))return;for(let e=0;e<this.mjModel.nbody;e++)this.bodies[e]&&(aP(this.mjData.xpos,e,this.bodies[e].position),oP(this.mjData.xquat,e,this.bodies[e].quaternion),this.bodies[e].updateWorldMatrix(!0,!1));this.dragStateManager.update();let n=VN(this.dragStateManager.offset.clone().multiplyScalar(this.dragForceScale)),r=VN(this.dragStateManager.worldHit.clone()),i=new Y(this.mjData.xpos[t*3+0],this.mjData.xpos[t*3+1],this.mjData.xpos[t*3+2]),a=new Y(r.x-i.x,r.y-i.y,r.z-i.z),o=new Y(n.x,n.y,n.z),s=new Y().crossVectors(a,o),c=t*6;this.mjData.xfrc_applied[c+0]=n.x,this.mjData.xfrc_applied[c+1]=n.y,this.mjData.xfrc_applied[c+2]=n.z,this.mjData.xfrc_applied[c+3]=s.x,this.mjData.xfrc_applied[c+4]=s.y,this.mjData.xfrc_applied[c+5]=s.z}updateCachedState(){if(!this.mjModel||!this.mjData||!this.bodies)return;let e=this.dynamicBodyIds;for(let t=0;t<this.mjModel.nbody;t++)if(!(e&&!e.has(t))&&this.bodies[t]){this.lastSimState.bodies.has(t)||this.lastSimState.bodies.set(t,{position:new Y,quaternion:new Zy});let e=this.lastSimState.bodies.get(t);aP(this.mjData.xpos,t,e.position),oP(this.mjData.xquat,t,e.quaternion)}this.mujocoRoot&&this.mujocoRoot.cylinders&&ZN(this.mjModel,this.mjData,{cylinders:this.mujocoRoot.cylinders,spheres:this.mujocoRoot.spheres},this.lastSimState.tendons)}applyViewerConfig(e){this.cameraState=kB(e,this.camera,this.controls,this.mjModel,this.mjData)}computeDynamicBodyIds(e){let t=new Set;for(let n=1;n<e.nbody;n++){let r=n;for(;r>0;){if(e.body_jntnum[r]>0){t.add(n);break}r=e.body_parentid[r]}}return t}syncStaticBodiesFromData(){if(!this.mjModel||!this.mjData||!this.bodies)return;let e=this.dynamicBodyIds;for(let t=0;t<this.mjModel.nbody;t++){if(e?.has(t))continue;let n=this.bodies[t];n&&(aP(this.mjData.xpos,t,n.position),oP(this.mjData.xquat,t,n.quaternion))}}async captureThumbnail(e={}){let{maxDim:t=1280,quality:n=.85}=e,r=this.renderer.domElement;this.renderer.render(this.scene,this.camera);let i=r.width,a=r.height;if(!i||!a)throw Error(`mjswan: canvas has zero size; nothing to capture.`);let o=Math.min(1,t/Math.max(i,a)),s=Math.max(1,Math.round(i*o)),c=Math.max(1,Math.round(a*o)),l=document.createElement(`canvas`);l.width=s,l.height=c;let u=l.getContext(`2d`);if(!u)throw Error(`mjswan: failed to get a 2D context for thumbnail capture.`);return u.drawImage(r,0,0,s,c),await new Promise((e,t)=>{l.toBlob(n=>n?e(n):t(Error(`mjswan: toBlob returned null.`)),`image/jpeg`,n)})}async dispose(){await this.stop(),this.policyRunner=null,this.policyStateBuilder=null,this.onnxModule&&=(this.onnxModule.dispose(),null),this.onnxInputDict=null,this.onnxInferencing=!1,this.splatMesh&&=(Cz(this.splatMesh,this.scene),null),this.colliderMesh&&=(TB(this.colliderMesh,this.scene),null),this.dragStateManager&&=(this.dragStateManager.dispose(),null),this.mjData=null,this.mjModel=null,window.removeEventListener(`resize`,this.onWindowResize),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.controls.dispose(),this.renderer.setAnimationLoop(null),this.renderer.dispose(),this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this.vrButton?.parentElement&&(this.vrButton.parentElement.removeChild(this.vrButton),this.vrButton=null),this.bodies=null,this.lights=[],this.mujocoRoot=null,this.dynamicBodyIds=null,this.lastSimState.bodies.clear(),this.commandManager.dispose()}disposeThreeJSResources(){if(this.scene)for(this.scene.traverse(e=>{`geometry`in e&&e.geometry&&e.geometry.dispose(),`material`in e&&e.material&&(Array.isArray(e.material)?e.material.forEach(e=>this.disposeMaterial(e)):this.disposeMaterial(e.material))});this.scene.children.length>0;)this.scene.remove(this.scene.children[0])}disposeMaterial(e){let t=e;t.map&&t.map.dispose(),t.aoMap&&t.aoMap.dispose(),t.emissiveMap&&t.emissiveMap.dispose(),t.metalnessMap&&t.metalnessMap.dispose(),t.normalMap&&t.normalMap.dispose(),t.roughnessMap&&t.roughnessMap.dispose(),e.dispose()}getSize(){let e=this.container.clientWidth||window.innerWidth,t=this.container.clientHeight||window.innerHeight;return{width:Math.max(1,e),height:Math.max(1,t)}}};function p1(e){let t=e.config,n={id:e.id,group:e.groupName,type:t.type,label:t.label};return t.type===`slider`?{...n,min:t.min,max:t.max,step:t.step,enabledWhen:t.enabled_when}:n}async function m1(e){return{config:e.config,onnx:await UB(e.onnx),motions:(e.motions??[]).map(e=>({name:e.name,data:e.data,default:e.default})),plugins:e.plugins}}async function h1(e){return{data:await UB(e.data),collider:e.collider?await UB(e.collider):null,transform:e.transform}}var g1=class{constructor(e){this.phase=`paused`,this.loading=!1,this.loadingMessage=null,this.error=null,this.listeners=new Set,this.onCommandEvent=()=>this.refresh(),this.runtime=e,this.state=this.buildState(),this.runtime.commands.addEventListener(this.onCommandEvent),this.camera={set:e=>this.runtime.setCameraView(e),get:()=>this.runtime.getCameraView(),frame:()=>this.runtime.frameCamera()},this.commands={set:(e,t)=>this.runtime.commands.setValue(e,t),trigger:e=>this.runtime.commands.triggerButton(e)}}buildState(){let e=this.runtime.commands;return{phase:this.phase,loading:this.loading,loadingMessage:this.loadingMessage,error:this.error,commands:e.getCommands().map(p1),commandValues:e.getValues()}}refresh(){this.state=this.buildState();for(let e of this.listeners)try{e(this.state)}catch(e){console.warn(`[mjswan] subscribe listener error:`,e)}}async loadScene(e){this.loading=!0,this.loadingMessage=`Loading scene…`,this.error=null,this.refresh();try{let t={model:await UB(e.model),policy:e.policy?await m1(e.policy):null,splat:e.splat?await h1(e.splat):null,viewer:e.viewer??null,events:e.events??null,terrainData:e.terrainData??null,plugins:e.plugins};await this.runtime.loadEnvironment(t),this.phase=this.runtime.isRunning?`running`:`paused`}catch(e){throw this.error=e instanceof Error?e:Error(String(e)),e}finally{this.loading=!1,this.loadingMessage=null,this.refresh()}}async setPolicy(e){await this.runtime.loadPolicyConfig(e?await m1(e):null),this.refresh()}async setSplat(e){await this.runtime.setSplat(e?await h1(e):null)}setMotion(e){return this.runtime.setSelectedMotion(e)}setReferenceVisible(e){this.runtime.setReferenceVisible(e)}calibrateSplat(e){this.runtime.calibrateSplat(e)}play(){this.runtime.play(),this.phase=`running`,this.refresh()}pause(){this.runtime.pause(),this.phase=`paused`,this.refresh()}reset(){this.runtime.resetSimulation()}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}captureThumbnail(e){return this.runtime.captureThumbnail(e)}dispose(){this.runtime.commands.removeEventListener(this.onCommandEvent),this.listeners.clear(),this.runtime.dispose()}};async function _1(e,t={}){return new g1(new f1(await(t.multithreaded?await i(()=>import(`./mujoco-Bacjb_-g.js`),__vite__mapDeps([0,1,2])):await i(()=>import(`./mujoco-CKOf6FiF.js`),__vite__mapDeps([3,1,2]))).default(),e))}globalThis.__mjswanThree=lA;function v1(e){return e.toLowerCase().replace(/ /g,`_`).replace(/-/g,`_`)}function y1(e){return e.id?e.id:`main`}function b1(e,t){let n=t.path?t.path:`scene/${v1(t.name)}/scene.mjz`;return`${y1(e)}/assets/${n}`.replace(/\/+/g,`/`)}function x1(e,t){return`${y1(e)}/assets/${t}`.replace(/\/+/g,`/`)}function S1(e,t){let n=e.lastIndexOf(`/`);return`${n>=0?e.slice(0,n+1):``}${t}`.replace(/\/+/g,`/`)}function C1(e){return async()=>{let t=await fetch(e);if(!t.ok)throw Error(`mjswan/manifest: failed to fetch ${e}: ${t.status}`);return t.arrayBuffer()}}async function w1(e){let t=typeof e==`function`?await e():e;return JSON.parse(new TextDecoder().decode(t))}function T1(e){return{scale:e.scale,xOffset:e.xOffset,yOffset:e.yOffset,zOffset:e.zOffset,roll:e.roll,pitch:e.pitch,yaw:e.yaw}}function E1(e,t,n){return{data:t.path?n(x1(e,t.path)):C1(t.url),collider:t.colliderUrl?/^[a-z]+:\/\//i.test(t.colliderUrl)?C1(t.colliderUrl):n(x1(e,t.colliderUrl)):void 0,transform:T1(t)}}async function D1(e,t,n){if(!t.config)throw Error(`mjswan/manifest: policy "${t.name}" has no config path.`);let r=x1(e,t.config),i=await w1(n(r)),a=i.onnx?.path;if(!a)throw Error(`mjswan/manifest: policy "${t.name}" config missing onnx.path.`);return{config:i,onnx:n(S1(r,a)),motions:Array.isArray(i.motions)?i.motions.map(e=>({name:e.name,data:n(S1(r,e.path)),default:e.default})):[]}}function O1(e,t,n){let r=t.policies.map(t=>({name:t.name,default:t.default??!1,motions:(t.motions??[]).map(e=>({name:e.name,default:e.default??!1})),build:()=>D1(e,t,n)})),i=(t.splats??[]).map(t=>({name:t.name,control:t.control??!1,transform:T1(t),build:async()=>E1(e,t,n)}));return{name:t.name,camera:t.camera,splatSection:t.splatSection??!1,policies:r,splats:i,buildScene:async r=>{let i=r?.policy,a=i==null?t.policies.find(e=>e.default)??t.policies[0]:t.policies.find(e=>e.name===i),o=r?.splat,s=o==null?void 0:t.splats?.find(e=>e.name===o);return{model:n(b1(e,t)),policy:a?await D1(e,a,n):null,splat:s?E1(e,s,n):null,viewer:t.camera,events:t.events,terrainData:t.terrainData}}}}function k1(e,t){let n=typeof e==`string`?JSON.parse(e):e;if(!n.projects?.length)throw Error(`mjswan/manifest: config.json has no projects.`);return{projects:[...n.projects.filter(e=>e.id===null),...n.projects.filter(e=>e.id!==null)].map(e=>({name:e.name,id:e.id,scenes:e.scenes.map(n=>O1(e,n,t))})),pluginsPath:n.plugins}}var A1=`panel`,j1=`ref`;function M1(e){return new URLSearchParams(window.location.search).get(e)!==`0`}function N1(e){return t=>async()=>{let n=`${e}${t}`.replace(/([^:])\/{2,}/g,`$1/`),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch ${n}: ${r.status}`);return r.arrayBuffer()}}async function P1(e){let t=new URLSearchParams(window.location.search).get(`config`),n=t?new URL(t,window.location.href).toString():`${e}assets/config.json`.replace(/([^:])\/{2,}/g,`$1/`),r=await fetch(n,{cache:`no-store`});if(!r.ok)throw Error(`Failed to fetch ${n}: ${r.status}`);return k1(await r.text(),N1(e))}function F1(e,t,n){if(!t)return n;let r=t.trim().toLowerCase();return e.find(e=>e.name.toLowerCase()===r)??e.find(e=>v1(e.name)===r)??n}function I1(){let[e,t]=(0,b.useState)(null),[n,r]=(0,b.useState)(null),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(null),[d,f]=(0,b.useState)(null),[p,m]=(0,b.useState)(null),[h,g]=(0,b.useState)(()=>M1(j1)),[_,v]=(0,b.useState)(()=>M1(A1)),[y,x]=(0,b.useState)(null),S=(0,b.useRef)(null),C=(0,b.useRef)(null),w=(0,b.useRef)(null),{showLoading:T,hideLoading:E,setLoadingMessage:D}=Zg(),O=(0,b.useCallback)(e=>{let t=w.current;return t?(e.plugins=t,e.policy&&(e.policy.plugins=t),e):e},[]);(0,b.useEffect)(()=>{T(`Loading…`),P1(`/`).then(async e=>{if(e.pluginsPath){let t=`/${e.pluginsPath}`.replace(/([^:])\/{2,}/g,`$1/`);w.current=await i(()=>import(t),[])}let n=new URLSearchParams(window.location.search),r=F1(e.projects,n.get(`project`),e.projects[0]),a=F1(r?.scenes??[],n.get(`scene`),r?.scenes[0]),s=a?F1(a.policies,n.get(`policy`),a.policies.find(e=>e.default)??a.policies[0]):void 0,l=s?.motions.find(e=>e.default)??s?.motions[0];t(e),o(r?.name??null),c(a?.name??null),u(s?.name??null),f(l?.name??null),m(a?.splats[0]?.name??null)}).catch(e=>{r(e instanceof Error?e.message:String(e)),E(),n_()})},[]);let k=(0,b.useMemo)(()=>e?.projects.find(e=>e.name===a)??e?.projects[0]??null,[e,a]),A=(0,b.useMemo)(()=>k?.scenes.find(e=>e.name===s)??null,[k,s]);(0,b.useEffect)(()=>{let t=S.current;if(!e||!A||!t)return;let n=!1;return(async()=>{T(`Loading MuJoCo…`);let e=await _1(t,{multithreaded:!1});if(n){e.dispose();return}C.current=e,e.subscribe(x);try{D(`Loading scene…`);let t=await A.buildScene({policy:l,splat:p});await e.loadScene(O(t)),d&&await e.setMotion(d),e.setReferenceVisible(h),E(),t_()}catch(e){r(e instanceof Error?e.message:String(e)),E(),n_()}})(),()=>{n=!0,C.current?.dispose(),C.current=null}},[e]),(0,b.useEffect)(()=>{y&&(y.loading?T(y.loadingMessage??`Loading…`):y.error||E(),y.error&&(r(y.error.message),E(),n_()))},[y,T,E]);let j=(0,b.useCallback)(t=>{let n=new URLSearchParams(window.location.search),r=(e,t,r)=>t!=null&&r?n.set(e,t):n.delete(e);r(`project`,t.project??a,(e?.projects.length??0)>1),r(`scene`,t.scene??s,!0),r(`policy`,t.policy??l,!0),n.delete(A1),(t.panel??_)||n.set(A1,`0`),n.delete(j1),(t.ref??h)||n.set(j1,`0`);let i=n.toString();window.history.replaceState({},``,`${window.location.pathname}${i?`?${i}`:``}${window.location.hash}`)},[a,s,l,_,h,e]),M=(0,b.useCallback)(async e=>{let t=C.current;if(!t)return;let n=e.policies.find(e=>e.default)??e.policies[0],r=n?.motions.find(e=>e.default)??n?.motions[0],i=e.splats[0]?.name??null;c(e.name),u(n?.name??null),f(r?.name??null),m(i),j({scene:e.name,policy:n?.name??null}),T(`Loading scene "${e.name}"…`);try{await t.loadScene(O(await e.buildScene({policy:n?.name,splat:i}))),r&&await t.setMotion(r.name),t.setReferenceVisible(h)}catch(e){console.error(`Failed to load scene:`,e)}finally{E()}},[h,j,T,E,O]),N=(0,b.useCallback)(async e=>{let t=k?.scenes.find(t=>t.name===e);t&&await M(t)},[k,M]),P=(0,b.useCallback)(async t=>{let n=e?.projects.find(e=>e.name===t);n&&(o(n.name),j({project:n.name}),n.scenes[0]&&await M(n.scenes[0]))},[e,j,M]),F=(0,b.useCallback)(async e=>{let t=C.current,n=A?.policies.find(t=>t.name===e)??null;u(e);let r=n?.motions.find(e=>e.default)??n?.motions[0];if(f(r?.name??null),j({policy:e}),t){T(e?`Loading policy "${e}"…`:`Clearing policy…`);try{let e=n?await n.build():null;e&&w.current&&(e.plugins=w.current),await t.setPolicy(e),r&&await t.setMotion(r.name),t.setReferenceVisible(h)}catch(e){console.error(`Failed to load policy:`,e)}finally{E()}}},[A,h,j,T,E]),I=(0,b.useCallback)(async e=>{let t=C.current,n=d;if(f(e),t){T(e===null?`Clearing motion…`:`Loading motion "${e}"…`);try{!await t.setMotion(e)&&e!==null&&f(n)}catch(e){console.error(`Failed to load motion:`,e)}finally{E()}}},[d,T,E]),L=(0,b.useCallback)(async e=>{let t=C.current,n=e===null?null:A?.splats.find(t=>t.name===e)??null;if(m(e),!(!t||e!==null&&!n)){T(e===null?`Removing splat…`:`Loading splat "${e}"…`);try{await t.setSplat(n?await n.build():null)}catch(e){console.error(`Failed to load splat:`,e)}finally{E()}}},[A,T,E]),R=(0,b.useCallback)(e=>{g(e),C.current?.setReferenceVisible(e),j({ref:e})},[j]),z=(0,b.useCallback)(e=>{v(e),j({panel:e})},[j]),B=(0,b.useCallback)(e=>e.map(e=>({value:e.name,label:e.name})),[]);return n?(0,G.jsx)(fr,{theme:Yg,defaultColorScheme:`auto`,children:(0,G.jsx)(`div`,{className:`app`,children:(0,G.jsxs)(`div`,{className:`hud hud-error`,children:[(0,G.jsx)(`h1`,{className:`hud-title`,children:`mjswan`}),(0,G.jsx)(`p`,{className:`hud-message`,children:n})]})})}):(0,G.jsx)(fr,{theme:Yg,defaultColorScheme:`auto`,children:(0,G.jsxs)(`div`,{className:`app`,children:[(0,G.jsx)($g,{}),e&&A&&(0,G.jsx)(Gg,{visible:_,onVisibleChange:z,projects:B(e.projects),projectValue:k?.name??null,projectLabel:k?.name??``,onProjectChange:P,scenes:B(k?.scenes??[]),sceneValue:s,onSceneChange:N,splats:B(A.splats),splatSection:A.splatSection,splatValue:p,onSplatChange:L,splatConfig:(()=>{let e=A.splats.find(e=>e.name===p);return e?{name:e.name,control:e.control,...e.transform}:null})(),onCalibrateSplat:(e,t,n,r,i,a,o)=>C.current?.calibrateSplat({scale:e,xOffset:t,yOffset:n,zOffset:r,roll:i,pitch:a,yaw:o}),policies:B(A.policies),policyValue:l,onPolicyChange:F,motions:B(A.policies.find(e=>e.name===l)?.motions??[]),motionValue:d,onMotionChange:I,showReferenceMotion:h,onShowReferenceMotionChange:R,commandsEnabled:!!l,commands:y?.commands?[...y.commands]:[],commandValues:y?.commandValues??{},onCommandChange:(e,t)=>C.current?.commands.set(e,t),onReset:()=>C.current?.reset()}),(0,G.jsx)(`div`,{ref:S,className:`viewer`})]})})}function L1(){return(0,G.jsx)(Qg,{children:(0,G.jsx)(I1,{})})}var R1=document.getElementById(`root`);R1&&(0,wg.createRoot)(R1).render((0,G.jsx)(b.StrictMode,{children:(0,G.jsx)(L1,{})}));