var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;li[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var u=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u{t.exports=u()})),f=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0>>1,a=e[r];if(0>>1;ri(c,n))li(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(li(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-Tt&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),p=o(((e,t)=>{t.exports=f()})),m=o((e=>{var t=d();function n(e){var t=`https://react.dev/errors/`+e;if(1{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=m()})),g=o((e=>{var t=p(),n=d(),r=h();function i(e){var t=`https://react.dev/errors/`+e;if(1te||(e.current=R[te],R[te]=null,te--)}function V(e,t){te++,R[te]=e.current,e.current=t}var ne=z(null),re=z(null),ie=z(null),ae=z(null);function oe(e,t){switch(V(ie,t),V(re,e),V(ne,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Gd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Gd(t),e=Kd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}B(ne),V(ne,e)}function se(){B(ne),B(re),B(ie)}function ce(e){e.memoizedState!==null&&V(ae,e);var t=ne.current,n=Kd(t,e.type);t!==n&&(V(re,e),V(ne,n))}function H(e){re.current===e&&(B(ne),B(re)),ae.current===e&&(B(ae),tp._currentValue=ee)}var le,ue;function de(e){if(le===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);le=t&&t[1]||``,ue=-1)`:-1i||c[r]!==l[i]){var u=` `+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(``)&&(u=u.replace(``,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{fe=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?de(n):``}function me(e,t){switch(e.tag){case 26:case 27:case 5:return de(e.type);case 16:return de(`Lazy`);case 13:return e.child!==t&&t!==null?de(`Suspense Fallback`):de(`Suspense`);case 19:return de(`SuspenseList`);case 0:case 15:return pe(e.type,!1);case 11:return pe(e.type.render,!1);case 1:return pe(e.type,!0);case 31:return de(`Activity`);default:return``}}function he(e){try{var t=``,n=null;do t+=me(e,n),n=e,e=e.return;while(e);return t}catch(e){return` Error generating stack: `+e.message+` `+e.stack}}var ge=Object.prototype.hasOwnProperty,_e=t.unstable_scheduleCallback,ve=t.unstable_cancelCallback,ye=t.unstable_shouldYield,be=t.unstable_requestPaint,xe=t.unstable_now,Se=t.unstable_getCurrentPriorityLevel,U=t.unstable_ImmediatePriority,Ce=t.unstable_UserBlockingPriority,we=t.unstable_NormalPriority,Te=t.unstable_LowPriority,W=t.unstable_IdlePriority,Ee=t.log,De=t.unstable_setDisableYieldValue,Oe=null,ke=null;function Ae(e){if(typeof Ee==`function`&&De(e),ke&&typeof ke.setStrictMode==`function`)try{ke.setStrictMode(Oe,e)}catch{}}var je=Math.clz32?Math.clz32:Pe,Me=Math.log,Ne=Math.LN2;function Pe(e){return e>>>=0,e===0?32:31-(Me(e)/Ne|0)|0}var Fe=256,Ie=262144,Le=4194304;function Re(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function ze(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Re(n))):i=Re(o):i=Re(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Re(n))):i=Re(o)):i=Re(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Be(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Ve(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function He(){var e=Le;return Le<<=1,!(Le&62914560)&&(Le=4194304),e}function Ue(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function We(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Ge(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0`u`||window.document===void 0||window.document.createElement===void 0),nn=!1;if(tn)try{var rn={};Object.defineProperty(rn,"passive",{get:function(){nn=!0}}),window.addEventListener(`test`,rn,rn),window.removeEventListener(`test`,rn,rn)}catch{nn=!1}var an=null,on=null,sn=null;function cn(){if(sn)return sn;var e,t=on,n=t.length,r,i=`value`in an?an.value:an.textContent,a=i.length;for(e=0;e=Rn),Vn=` `,Hn=!1;function Un(e,t){switch(e){case`keyup`:return In.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Wn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var Gn=!1;function Kn(e,t){switch(e){case`compositionend`:return Wn(t);case`keypress`:return t.which===32?(Hn=!0,Vn):null;case`textInput`:return e=t.data,e===Vn&&Hn?null:e;default:return null}}function qn(e,t){if(Gn)return e===`compositionend`||!Ln&&Un(e,t)?(e=cn(),sn=on=an=null,Gn=!1,e):null;switch(e){case`paste`:return null;case`keypress`:if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}a:{for(;n;){if(n.nextSibling){n=n.nextSibling;break a}n=n.parentNode}n=void 0}n=mr(n)}}function gr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?gr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function _r(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=At(e.document);t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href==`string`}catch{n=!1}if(n)e=t.contentWindow;else break;t=At(e.document)}return t}function vr(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t===`input`&&(e.type===`text`||e.type===`search`||e.type===`tel`||e.type===`url`||e.type===`password`)||t===`textarea`||e.contentEditable===`true`)}var yr=tn&&`documentMode`in document&&11>=document.documentMode,br=null,xr=null,Sr=null,Cr=!1;function wr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Cr||br==null||br!==At(r)||(r=br,`selectionStart`in r&&vr(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Sr&&pr(Sr,r)||(Sr=r,r=kd(xr,`onSelect`),0>=o,i-=o,hi=1<<32-je(t)+i|n<h?(g=d,d=null):g=d.sibling;var _=p(i,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(i,d),a=o(_,a,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),wi&&_i(i,h),l;if(d===null){for(;hg?(_=h,h=null):_=h.sibling;var y=p(a,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(a,h),s=o(y,s,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(a,h),wi&&_i(a,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return wi&&_i(a,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,a,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(a,e)}),wi&&_i(a,g),u}function b(e,r,o,c){if(typeof o==`object`&&o&&o.type===y&&o.key===null&&(o=o.props.children),typeof o==`object`&&o){switch(o.$$typeof){case _:a:{for(var l=o.key;r!==null;){if(r.key===l){if(l=o.type,l===y){if(r.tag===7){n(e,r.sibling),c=a(r,o.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===O&&va(l)===r.type){n(e,r.sibling),c=a(r,o.props),Ta(c,o),c.return=e,e=c;break a}n(e,r);break}else t(e,r);r=r.sibling}o.type===y?(c=ni(o.props.children,e.mode,c,o.key),c.return=e,e=c):(c=ti(o.type,o.key,o.props,null,e.mode,c),Ta(c,o),c.return=e,e=c)}return s(e);case v:a:{for(l=o.key;r!==null;){if(r.key===l)if(r.tag===4&&r.stateNode.containerInfo===o.containerInfo&&r.stateNode.implementation===o.implementation){n(e,r.sibling),c=a(r,o.children||[]),c.return=e,e=c;break a}else{n(e,r);break}else t(e,r);r=r.sibling}c=ai(o,e.mode,c),c.return=e,e=c}return s(e);case O:return o=va(o),b(e,r,o,c)}if(F(o))return h(e,r,o,c);if(M(o)){if(l=M(o),typeof l!=`function`)throw Error(i(150));return o=l.call(o),g(e,r,o,c)}if(typeof o.then==`function`)return b(e,r,wa(o),c);if(o.$$typeof===C)return b(e,r,Ki(e,o),c);Ea(e,o)}return typeof o==`string`&&o!==``||typeof o==`number`||typeof o==`bigint`?(o=``+o,r!==null&&r.tag===6?(n(e,r.sibling),c=a(r,o),c.return=e,e=c):(n(e,r),c=ri(o,e.mode,c),c.return=e,e=c),s(e)):n(e,r)}return function(e,t,n,r){try{Ca=0;var i=b(e,t,n,r);return Sa=null,i}catch(t){if(t===fa||t===ma)throw t;var a=Zr(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var Oa=Da(!0),ka=Da(!1),Aa=!1;function ja(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Ma(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Na(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Pa(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Fl&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=Jr(e),qr(e,null,n),t}return Wr(e,r,t,n),Jr(e)}function Fa(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194048)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,qe(e,n)}}function Ia(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={lane:n.lane,tag:n.tag,payload:n.payload,callback:null,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,callbacks:r.callbacks},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}var La=!1;function Ra(){if(La){var e=ra;if(e!==null)throw e}}function za(e,t,n,r){La=!1;var i=e.updateQueue;Aa=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane&-536870913,p=f!==s.lane;if(p?(Rl&f)===f:(r&f)===f){f!==0&&f===na&&(La=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var h=e,g=s;f=t;var _=n;switch(g.tag){case 1:if(h=g.payload,typeof h==`function`){d=h.call(_,d,f);break a}d=h;break a;case 3:h.flags=h.flags&-65537|128;case 0:if(h=g.payload,f=typeof h==`function`?h.call(_,d,f):h,f==null)break a;d=m({},d,f);break a;case 2:Aa=!0}}f=s.callback,f!==null&&(e.flags|=64,p&&(e.flags|=8192),p=i.callbacks,p===null?i.callbacks=[f]:p.push(f))}else p={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;p=s,s=p.next,p.next=null,i.lastBaseUpdate=p,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),Kl|=o,e.lanes=o,e.memoizedState=d}}function Ba(e,t){if(typeof e!=`function`)throw Error(i(191,e));e.call(t)}function Va(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;ea?a:8;var o=I.T,s={};I.T=s,Os(e,!1,t,n);try{var c=i(),l=I.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?Ds(e,t,oa(c,r),mu(e)):Ds(e,t,r,mu(e))}catch(n){Ds(e,t,{then:function(){},status:`rejected`,reason:n},mu())}finally{L.p=a,o!==null&&s.types!==null&&(o.types=s.types),I.T=o}}function _s(){}function vs(e,t,n,r){if(e.tag!==5)throw Error(i(476));var a=ys(e).queue;gs(e,a,t,ee,n===null?_s:function(){return bs(e),n(r)})}function ys(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:ee,baseState:ee,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:ko,lastRenderedState:ee},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:ko,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function bs(e){var t=ys(e);t.next===null&&(t=e.alternate.memoizedState),Ds(e,t.next.queue,{},mu())}function xs(){return Gi(tp)}function Ss(){return wo().memoizedState}function Cs(){return wo().memoizedState}function ws(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=mu();e=Na(n);var r=Pa(t,e,n);r!==null&&(gu(r,t,n),Fa(r,t,n)),t={cache:Qi()},e.payload=t;return}t=t.return}}function Ts(e,t,n){var r=mu();n={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},ks(e)?As(t,n):(n=Gr(e,t,n,r),n!==null&&(gu(n,e,r),js(n,t,r)))}function Es(e,t,n){Ds(e,t,n,mu())}function Ds(e,t,n,r){var i={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null};if(ks(e))As(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,fr(s,o))return Wr(e,t,i,0),Il===null&&Ur(),!1}catch{}if(n=Gr(e,t,i,r),n!==null)return gu(n,e,r),js(n,t,r),!0}return!1}function Os(e,t,n,r){if(r={lane:2,revertLane:pd(),gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},ks(e)){if(t)throw Error(i(479))}else t=Gr(e,n,r,2),t!==null&&gu(t,e,2)}function ks(e){var t=e.alternate;return e===ro||t!==null&&t===ro}function As(e,t){so=oo=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function js(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,qe(e,n)}}var Ms={readContext:Gi,use:Do,useCallback:mo,useContext:mo,useEffect:mo,useImperativeHandle:mo,useLayoutEffect:mo,useInsertionEffect:mo,useMemo:mo,useReducer:mo,useRef:mo,useState:mo,useDebugValue:mo,useDeferredValue:mo,useTransition:mo,useSyncExternalStore:mo,useId:mo,useHostTransitionStatus:mo,useFormState:mo,useActionState:mo,useOptimistic:mo,useMemoCache:mo,useCacheRefresh:mo};Ms.useEffectEvent=mo;var Ns={readContext:Gi,use:Do,useCallback:function(e,t){return Co().memoizedState=[e,t===void 0?null:t],e},useContext:Gi,useEffect:rs,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),ts(4194308,4,ls.bind(null,t,e),n)},useLayoutEffect:function(e,t){return ts(4194308,4,e,t)},useInsertionEffect:function(e,t){ts(4,2,e,t)},useMemo:function(e,t){var n=Co();t=t===void 0?null:t;var r=e();if(co){Ae(!0);try{e()}finally{Ae(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=Co();if(n!==void 0){var i=n(t);if(co){Ae(!0);try{n(t)}finally{Ae(!1)}}}else i=t;return r.memoizedState=r.baseState=i,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:i},r.queue=e,e=e.dispatch=Ts.bind(null,ro,e),[r.memoizedState,e]},useRef:function(e){var t=Co();return e={current:e},t.memoizedState=e},useState:function(e){e=zo(e);var t=e.queue,n=Es.bind(null,ro,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:ds,useDeferredValue:function(e,t){return ms(Co(),e,t)},useTransition:function(){var e=zo(!1);return e=gs.bind(null,ro,e.queue,!0,!1),Co().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=ro,a=Co();if(wi){if(n===void 0)throw Error(i(407));n=n()}else{if(n=t(),Il===null)throw Error(i(349));Rl&127||Po(r,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,rs(Io.bind(null,r,o,e),[e]),r.flags|=2048,$o(9,{destroy:void 0},Fo.bind(null,r,o,n,t),null),n},useId:function(){var e=Co(),t=Il.identifierPrefix;if(wi){var n=gi,r=hi;n=(r&~(1<<32-je(r)-1)).toString(32)+n,t=`_`+t+`R_`+n,n=lo++,0<\/script>`,o=o.removeChild(o.firstChild);break;case`select`:o=typeof r.is==`string`?s.createElement(`select`,{is:r.is}):s.createElement(`select`),r.multiple?o.multiple=!0:r.size&&(o.size=r.size);break;default:o=typeof r.is==`string`?s.createElement(a,{is:r.is}):s.createElement(a)}}o[et]=t,o[tt]=r;a:for(s=t.child;s!==null;){if(s.tag===5||s.tag===6)o.appendChild(s.stateNode);else if(s.tag!==4&&s.tag!==27&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break a;for(;s.sibling===null;){if(s.return===null||s.return===t)break a;s=s.return}s.sibling.return=s.return,s=s.sibling}t.stateNode=o;a:switch(Rd(o,a,r),a){case`button`:case`input`:case`select`:case`textarea`:r=!!r.autoFocus;break a;case`img`:r=!0;break a;default:r=!1}r&&Dc(t)}}return Mc(t),Oc(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,n),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&Dc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(i(166));if(e=ie.current,ji(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,a=Si,a!==null)switch(a.tag){case 27:case 5:r=a.memoizedProps}e[et]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Fd(e.nodeValue,n)),e||Oi(t,!0)}else e=Wd(e).createTextNode(r),e[et]=t,t.stateNode=e}return Mc(t),null;case 31:if(n=t.memoizedState,e===null||e.memoizedState!==null){if(r=ji(t),n!==null){if(e===null){if(!r)throw Error(i(318));if(e=t.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(557));e[et]=t}else Mi(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Mc(t),e=!1}else n=Ni(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=n),e=!0;if(!e)return t.flags&256?($a(t),t):($a(t),null);if(t.flags&128)throw Error(i(558))}return Mc(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=ji(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(i(318));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(i(317));a[et]=t}else Mi(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Mc(t),a=!1}else a=Ni(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?($a(t),t):($a(t),null)}return $a(t),t.flags&128?(t.lanes=n,t):(n=r!==null,e=e!==null&&e.memoizedState!==null,n&&(r=t.child,a=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(a=r.alternate.memoizedState.cachePool.pool),o=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(o=r.memoizedState.cachePool.pool),o!==a&&(r.flags|=2048)),n!==e&&n&&(t.child.flags|=8192),Ac(t,t.updateQueue),Mc(t),null);case 4:return se(),e===null&&Td(t.stateNode.containerInfo),Mc(t),null;case 10:return zi(t.type),Mc(t),null;case 19:if(B(eo),r=t.memoizedState,r===null)return Mc(t),null;if(a=(t.flags&128)!=0,o=r.rendering,o===null)if(a)jc(r,!1);else{if(Gl!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=to(e),o!==null){for(t.flags|=128,jc(r,!1),e=o.updateQueue,t.updateQueue=e,Ac(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)ei(n,e),n=n.sibling;return V(eo,eo.current&1|2),wi&&_i(t,r.treeForkCount),t.child}e=e.sibling}r.tail!==null&&xe()>nu&&(t.flags|=128,a=!0,jc(r,!1),t.lanes=4194304)}else{if(!a)if(e=to(o),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,Ac(t,e),jc(r,!0),r.tail===null&&r.tailMode===`hidden`&&!o.alternate&&!wi)return Mc(t),null}else 2*xe()-r.renderingStartTime>nu&&n!==536870912&&(t.flags|=128,a=!0,jc(r,!1),t.lanes=4194304);r.isBackwards?(o.sibling=t.child,t.child=o):(e=r.last,e===null?t.child=o:e.sibling=o,r.last=o)}return r.tail===null?(Mc(t),null):(e=r.tail,r.rendering=e,r.tail=e.sibling,r.renderingStartTime=xe(),e.sibling=null,n=eo.current,V(eo,a?n&1|2:n&1),wi&&_i(t,r.treeForkCount),e);case 22:case 23:return $a(t),Ka(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Mc(t),t.subtreeFlags&6&&(t.flags|=8192)):Mc(t),n=t.updateQueue,n!==null&&Ac(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==n&&(t.flags|=2048),e!==null&&B(ca),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),zi(Zi),Mc(t),null;case 25:return null;case 30:return null}throw Error(i(156,t.tag))}function Pc(e,t){switch(bi(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return zi(Zi),se(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return H(t),null;case 31:if(t.memoizedState!==null){if($a(t),t.alternate===null)throw Error(i(340));Mi()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if($a(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(i(340));Mi()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return B(eo),null;case 4:return se(),null;case 10:return zi(t.type),null;case 22:case 23:return $a(t),Ka(),e!==null&&B(ca),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return zi(Zi),null;case 25:return null;default:return null}}function Fc(e,t){switch(bi(t),t.tag){case 3:zi(Zi),se();break;case 26:case 27:case 5:H(t);break;case 4:se();break;case 31:t.memoizedState!==null&&$a(t);break;case 13:$a(t);break;case 19:B(eo);break;case 10:zi(t.type);break;case 22:case 23:$a(t),Ka(),e!==null&&B(ca);break;case 24:zi(Zi)}}function Ic(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){Ku(t,t.return,e)}}function Lc(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){Ku(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Ku(t,t.return,e)}}function Rc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Va(t,n)}catch(t){Ku(e,e.return,t)}}}function zc(e,t,n){n.props=Bs(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Ku(e,t,n)}}function Bc(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=e.stateNode;break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){Ku(e,t,n)}}function Vc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null)if(typeof r==`function`)try{r()}catch(n){Ku(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){Ku(e,t,n)}else n.current=null}function Hc(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{a:switch(t){case`button`:case`input`:case`select`:case`textarea`:n.autoFocus&&r.focus();break a;case`img`:n.src?r.src=n.src:n.srcSet&&(r.srcset=n.srcSet)}}catch(t){Ku(e,e.return,t)}}function Uc(e,t,n){try{var r=e.stateNode;zd(r,e.type,n,t),r[tt]=t}catch(t){Ku(e,e.return,t)}}function Wc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&tf(e.type)||e.tag===4}function Gc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Wc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&tf(e.type)||e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Kc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?(n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n).insertBefore(e,t):(t=n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n,t.appendChild(e),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=qt));else if(r!==4&&(r===27&&tf(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(Kc(e,t,n),e=e.sibling;e!==null;)Kc(e,t,n),e=e.sibling}function qc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(r===27&&tf(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(qc(e,t,n),e=e.sibling;e!==null;)qc(e,t,n),e=e.sibling}function Jc(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Rd(t,r,n),t[et]=e,t[tt]=n}catch(t){Ku(e,e.return,t)}}var Yc=!1,Xc=!1,Zc=!1,Qc=typeof WeakSet==`function`?WeakSet:Set,$c=null;function el(e,t){if(e=e.containerInfo,Hd=up,e=_r(e),vr(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var a=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||r!==0&&f.nodeType!==3||(l=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===r&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(Ud={focusedElem:e,selectionRange:n},up=!1,$c=t;$c!==null;)if(t=$c,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,$c=e;else for(;$c!==null;){switch(t=$c,o=t.alternate,e=t.flags,t.tag){case 0:if(e&4&&(e=t.updateQueue,e=e===null?null:e.events,e!==null))for(n=0;n title`))),Rd(o,r,n),o[et]=e,pt(o),r=o;break a;case`link`:var s=Gf(`link`,`href`,a).get(r+(n.href||``));if(s){for(var c=0;cg&&(o=g,g=h,h=o);var _=hr(s,h),v=hr(s,g);if(_&&v&&(p.rangeCount!==1||p.anchorNode!==_.node||p.anchorOffset!==_.offset||p.focusNode!==v.node||p.focusOffset!==v.offset)){var y=d.createRange();y.setStart(_.node,_.offset),p.removeAllRanges(),h>g?(p.addRange(y),p.extend(v.node,v.offset)):(y.setEnd(v.node,v.offset),p.addRange(y))}}}}for(d=[],p=s;p=p.parentNode;)p.nodeType===1&&d.push({element:p,left:p.scrollLeft,top:p.scrollTop});for(typeof s.focus==`function`&&s.focus(),s=0;sn?32:n,I.T=null,n=uu,uu=null;var o=ou,s=cu;if(au=0,su=ou=null,cu=0,Fl&6)throw Error(i(331));var c=Fl;if(Fl|=4,Al(o.current),Sl(o,o.current,s,n),Fl=c,od(0,!1),ke&&typeof ke.onPostCommitFiberRoot==`function`)try{ke.onPostCommitFiberRoot(Oe,o)}catch{}return!0}finally{L.p=a,I.T=r,Hu(e,t)}}function Gu(e,t,n){t=si(n,t),t=Ks(e.stateNode,t,2),e=Pa(e,t,2),e!==null&&(We(e,2),ad(e))}function Ku(e,t,n){if(e.tag===3)Gu(e,e,n);else for(;t!==null;){if(t.tag===3){Gu(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(iu===null||!iu.has(r))){e=si(n,e),n=qs(2),r=Pa(t,n,2),r!==null&&(Js(n,r,t,e),We(r,2),ad(r));break}}t=t.return}}function qu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Pl;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Ul=!0,i.add(n),e=Ju.bind(null,e,t,n),t.then(e,e))}function Ju(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,Il===e&&(Rl&n)===n&&(Gl===4||Gl===3&&(Rl&62914560)===Rl&&300>xe()-eu?!(Fl&2)&&Cu(e,0):Jl|=n,Xl===Rl&&(Xl=0)),ad(e)}function Yu(e,t){t===0&&(t=He()),e=Kr(e,t),e!==null&&(We(e,t),ad(e))}function Xu(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Yu(e,n)}function Zu(e,t){var n=0;switch(e.tag){case 31:case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(i(314))}r!==null&&r.delete(t),Yu(e,n)}function Qu(e,t){return _e(e,t)}var $u=null,ed=null,td=!1,nd=!1,rd=!1,id=0;function ad(e){e!==ed&&e.next===null&&(ed===null?$u=ed=e:ed=ed.next=e),nd=!0,td||(td=!0,fd())}function od(e,t){if(!rd&&nd){rd=!0;do for(var n=!1,r=$u;r!==null;){if(!t)if(e!==0){var i=r.pendingLanes;if(i===0)var a=0;else{var o=r.suspendedLanes,s=r.pingedLanes;a=(1<<31-je(42|e)+1)-1,a&=i&~(o&~s),a=a&201326741?a&201326741|1:a?a|2:0}a!==0&&(n=!0,dd(r,a))}else a=Rl,a=ze(r,r===Il?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Be(r,a)||(n=!0,dd(r,a));r=r.next}while(n);rd=!1}}function sd(){cd()}function cd(){nd=td=!1;var e=0;id!==0&&Yd()&&(e=id);for(var t=xe(),n=null,r=$u;r!==null;){var i=r.next,a=ld(r,t);a===0?(r.next=null,n===null?$u=i:n.next=i,i===null&&(ed=n)):(n=r,(e!==0||a&3)&&(nd=!0)),r=i}au!==0&&au!==5||od(e,!1),id!==0&&(id=0)}function ld(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes&-62914561;0s)break;var u=c.transferSize,d=c.initiatorType;u&&Bd(d)&&(c=c.responseEnd,o+=u*(c`u`?null:document;function Tf(e,t,n){var r=wf;if(r&&typeof t==`string`&&t){var i=Mt(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),yf.has(i)||(yf.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Rd(t,`link`,e),pt(t),r.head.appendChild(t)))}}function Ef(e){xf.D(e),Tf(`dns-prefetch`,e,null)}function Df(e,t){xf.C(e,t),Tf(`preconnect`,e,t)}function Of(e,t,n){xf.L(e,t,n);var r=wf;if(r&&e&&t){var i=`link[rel="preload"][as="`+Mt(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Mt(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Mt(n.imageSizes)+`"]`)):i+=`[href="`+Mt(e)+`"]`;var a=i;switch(t){case`style`:a=Pf(e);break;case`script`:a=Rf(e)}vf.has(a)||(e=m({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),vf.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(Ff(a))||t===`script`&&r.querySelector(zf(a))||(t=r.createElement(`link`),Rd(t,`link`,e),pt(t),r.head.appendChild(t)))}}function kf(e,t){xf.m(e,t);var n=wf;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Mt(r)+`"][href="`+Mt(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=Rf(e)}if(!vf.has(a)&&(e=m({rel:`modulepreload`,href:e},t),vf.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(zf(a)))return}r=n.createElement(`link`),Rd(r,`link`,e),pt(r),n.head.appendChild(r)}}}function Af(e,t,n){xf.S(e,t,n);var r=wf;if(r&&e){var i=ft(r).hoistableStyles,a=Pf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(Ff(a)))s.loading=5;else{e=m({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=vf.get(a))&&Hf(e,n);var c=o=r.createElement(`link`);pt(c),Rd(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,Vf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function jf(e,t){xf.X(e,t);var n=wf;if(n&&e){var r=ft(n).hoistableScripts,i=Rf(e),a=r.get(i);a||(a=n.querySelector(zf(i)),a||(e=m({src:e,async:!0},t),(t=vf.get(i))&&Uf(e,t),a=n.createElement(`script`),pt(a),Rd(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Mf(e,t){xf.M(e,t);var n=wf;if(n&&e){var r=ft(n).hoistableScripts,i=Rf(e),a=r.get(i);a||(a=n.querySelector(zf(i)),a||(e=m({src:e,async:!0,type:`module`},t),(t=vf.get(i))&&Uf(e,t),a=n.createElement(`script`),pt(a),Rd(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Nf(e,t,n,r){var a=(a=ie.current)?bf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=Pf(n.href),n=ft(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=Pf(n.href);var o=ft(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(Ff(e)))&&!o._p&&(s.instance=o,s.state.loading=5),vf.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},vf.set(e,n),o||Lf(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=Rf(n),n=ft(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function Pf(e){return`href="`+Mt(e)+`"`}function Ff(e){return`link[rel="stylesheet"][`+e+`]`}function If(e){return m({},e,{"data-precedence":e.precedence,precedence:null})}function Lf(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),Rd(t,`link`,n),pt(t),e.head.appendChild(t))}function Rf(e){return`[src="`+Mt(e)+`"]`}function zf(e){return`script[async]`+e}function Bf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Mt(n.href)+`"]`);if(r)return t.instance=r,pt(r),r;var a=m({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),pt(r),Rd(r,`style`,a),Vf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=Pf(n.href);var o=e.querySelector(Ff(a));if(o)return t.state.loading|=4,t.instance=o,pt(o),o;r=If(n),(a=vf.get(a))&&Hf(r,a),o=(e.ownerDocument||e).createElement(`link`),pt(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Rd(o,`link`,r),t.state.loading|=4,Vf(o,n.precedence,e),t.instance=o;case`script`:return o=Rf(n.src),(a=e.querySelector(zf(o)))?(t.instance=a,pt(a),a):(r=n,(a=vf.get(o))&&(r=m({},n),Uf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),pt(a),Rd(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,Vf(r,n.precedence,e));return t.instance}function Vf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o title`):null)}function qf(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function Jf(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}function Yf(e,t,n,r){if(n.type===`stylesheet`&&(typeof r.media!=`string`||!1!==matchMedia(r.media).matches)&&!(n.state.loading&4)){if(n.instance===null){var i=Pf(r.href),a=t.querySelector(Ff(i));if(a){t=a._p,typeof t==`object`&&t&&typeof t.then==`function`&&(e.count++,e=Qf.bind(e),t.then(e,e)),n.state.loading|=4,n.instance=a,pt(a);return}a=t.ownerDocument||t,r=If(r),(i=vf.get(i))&&Hf(r,i),a=a.createElement(`link`),pt(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Rd(a,`link`,r),n.instance=a}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(n,t),(t=n.state.preload)&&!(n.state.loading&3)&&(e.count++,n=Qf.bind(e),t.addEventListener(`load`,n),t.addEventListener(`error`,n))}}var Xf=0;function Zf(e,t){return e.stylesheets&&e.count===0&&X(e,e.stylesheets),0Xf?50:800)+t);return e.unsuspend=n,function(){e.unsuspend=null,clearTimeout(r),clearTimeout(i)}}:null}function Qf(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)X(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var $f=null;function X(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,$f=new Map,t.forEach(ep,e),$f=null,Qf.call(e))}function ep(e,t){if(!(t.state.loading&4)){var n=$f.get(e);if(n)var r=n.get(null);else{n=new Map,$f.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=g()})),v=l(d(),1),y=l(_()),b={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},x={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},S=`attached`,C=`detached`,w=1e3,T=1001,E=1002,D=1003,O=1004,k=1004,A=1005,j=1005,M=1006,N=1007,P=1007,F=1008,I=1008,L=1009,ee=1010,R=1011,te=1012,z=1013,B=1014,V=1015,ne=1016,re=1017,ie=1018,ae=1020,oe=35902,se=35899,ce=1021,H=1022,le=1023,ue=1026,de=1027,fe=1028,pe=1029,me=1030,he=1031,ge=1032,_e=1033,ve=33776,ye=33777,be=33778,xe=33779,Se=35840,U=35841,Ce=35842,we=35843,Te=36196,W=37492,Ee=37496,De=37488,Oe=37489,ke=37490,Ae=37491,je=37808,Me=37809,Ne=37810,Pe=37811,Fe=37812,Ie=37813,Le=37814,Re=37815,ze=37816,Be=37817,Ve=37818,He=37819,Ue=37820,We=37821,Ge=36492,Ke=36494,qe=36495,Je=36283,Ye=36284,Xe=36285,Ze=36286,Qe=2200,$e=2201,et=2202,tt=2300,nt=2301,rt=2302,it=2303,at=2400,ot=2401,st=2402,ct=2500,lt=2501,ut=3200,dt=3201,ft=3202,pt=3203,mt=`srgb`,ht=`srgb-linear`,gt=`linear`,_t=`srgb`,vt=7680,yt=7681,bt=7682,xt=7683,St=34055,Ct=34056,wt=5386,Tt=35044,Et=35048,Dt=35040,Ot=35045,kt=35049,At=35041,jt=35046,Mt=35050,Nt=35042,Pt=`300 es`,Ft=2e3,It=2001,Lt={COMPUTE:`compute`,RENDER:`render`},Rt={PERSPECTIVE:`perspective`,LINEAR:`linear`,FLAT:`flat`},zt={NORMAL:`normal`,CENTROID:`centroid`,SAMPLE:`sample`,FIRST:`first`,EITHER:`either`},Bt={TEXTURE_COMPARE:`depthTextureCompare`};function Vt(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}var Ht={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function Ut(e,t){return new Ht[e](t)}function Wt(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Gt(e){return document.createElementNS(`http://www.w3.org/1999/xhtml`,e)}function Kt(){let e=Gt(`canvas`);return e.style.display=`block`,e}var qt={},Jt=null;function Yt(e){Jt=e}function Xt(){return Jt}function Zt(...e){let t=`THREE.`+e.shift();Jt?Jt(`log`,t,...e):console.log(t,...e)}function Qt(e){let t=e[0];if(typeof t==`string`&&t.startsWith(`TSL:`)){let t=e[1];t&&t.isStackTrace?e[0]+=` `+t.getLocation():e[1]=`Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.`}return e}function G(...e){e=Qt(e);let t=`THREE.`+e.shift();if(Jt)Jt(`warn`,t,...e);else{let n=e[0];n&&n.isStackTrace?console.warn(n.getError(t)):console.warn(t,...e)}}function $t(...e){e=Qt(e);let t=`THREE.`+e.shift();if(Jt)Jt(`error`,t,...e);else{let n=e[0];n&&n.isStackTrace?console.error(n.getError(t)):console.error(t,...e)}}function en(...e){let t=e.join(` `);t in qt||(qt[t]=!0,G(...e))}function tn(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 nn={0:1,2:6,4:7,3:5,1:0,6:2,7:4,5:3},rn=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>8&255]+an[e>>16&255]+an[e>>24&255]+`-`+an[t&255]+an[t>>8&255]+`-`+an[t>>16&15|64]+an[t>>24&255]+`-`+an[n&63|128]+an[n>>8&255]+`-`+an[n>>16&255]+an[n>>24&255]+an[r&255]+an[r>>8&255]+an[r>>16&255]+an[r>>24&255]).toLowerCase()}function un(e,t,n){return Math.max(t,Math.min(n,e))}function dn(e,t){return(e%t+t)%t}function fn(e,t,n,r,i){return r+(e-t)*(i-r)/(n-t)}function pn(e,t,n){return e===t?0:(n-e)/(t-e)}function mn(e,t,n){return(1-n)*e+n*t}function hn(e,t,n,r){return mn(e,t,1-Math.exp(-n*r))}function gn(e,t=1){return t-Math.abs(dn(e,t*2)-t)}function _n(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*(3-2*e))}function vn(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*e*(e*(e*6-15)+10))}function yn(e,t){return e+Math.floor(Math.random()*(t-e+1))}function bn(e,t){return e+Math.random()*(t-e)}function xn(e){return e*(.5-Math.random())}function Sn(e){e!==void 0&&(on=e);let t=on+=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 Cn(e){return e*sn}function wn(e){return e*cn}function Tn(e){return(e&e-1)==0&&e!==0}function En(e){return 2**Math.ceil(Math.log(e)/Math.LN2)}function Dn(e){return 2**Math.floor(Math.log(e)/Math.LN2)}function On(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:G(`MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: `+i)}}function kn(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 An(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 jn={DEG2RAD:sn,RAD2DEG:cn,generateUUID:ln,clamp:un,euclideanModulo:dn,mapLinear:fn,inverseLerp:pn,lerp:mn,damp:hn,pingpong:gn,smoothstep:_n,smootherstep:vn,randInt:yn,randFloat:bn,randFloatSpread:xn,seededRandom:Sn,degToRad:Cn,radToDeg:wn,isPowerOfTwo:Tn,ceilPowerOfTwo:En,floorPowerOfTwo:Dn,setQuaternionFromProperEuler:On,normalize:An,denormalize:kn},K=class e{static{e.prototype.isVector2=!0}constructor(e=0,t=0){this.x=e,this.y=t}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=un(this.x,e.x,t.x),this.y=un(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=un(this.x,e,t),this.y=un(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(un(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(un(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}},Mn=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(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:G(`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(un(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){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}},q=class e{static{e.prototype.isVector3=!0}constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}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(Pn.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Pn.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=un(this.x,e.x,t.x),this.y=un(this.y,e.y,t.y),this.z=un(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=un(this.x,e,t),this.y=un(this.y,e,t),this.z=un(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(un(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 Nn.copy(this).projectOnVector(e),this.sub(Nn)}reflect(e){return this.sub(Nn.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(un(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}},Nn=new q,Pn=new Mn,Fn=class e{static{e.prototype.isMatrix3=!0}constructor(e,t,n,r,i,a,o,s,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,r,i,a,o,s,c)}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(In.makeScale(e,t)),this}rotate(e){return this.premultiply(In.makeRotation(-e)),this}translate(e,t){return this.premultiply(In.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)}},In=new Fn,Ln=new Fn().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Rn=new Fn().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function zn(){let e={enabled:!0,workingColorSpace:ht,spaces:{},convert:function(e,t,n){return this.enabled===!1||t===n||!t||!n?e:(this.spaces[t].transfer===`srgb`&&(e.r=Vn(e.r),e.g=Vn(e.g),e.b=Vn(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=Hn(e.r),e.g=Hn(e.g),e.b=Hn(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===``?gt: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 en(`ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace().`),e.workingToColorSpace(t,n)},toWorkingColorSpace:function(t,n){return en(`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({[ht]:{primaries:t,whitePoint:r,transfer:gt,toXYZ:Ln,fromXYZ:Rn,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:mt},outputColorSpaceConfig:{drawingBufferColorSpace:mt}},[mt]:{primaries:t,whitePoint:r,transfer:_t,toXYZ:Ln,fromXYZ:Rn,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:mt}}}),e}var Bn=zn();function Vn(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}function Hn(e){return e<.0031308?e*12.92:1.055*e**.41666-.055}var Un,Wn=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{Un===void 0&&(Un=Gt(`canvas`)),Un.width=e.width,Un.height=e.height;let t=Un.getContext(`2d`);e instanceof ImageData?t.putImageData(e,0,0):t.drawImage(e,0,0,e.width,e.height),n=Un}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=Gt(`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;e1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Yn).x}get height(){return this.source.getSize(Yn).y}get depth(){return this.source.getSize(Yn).z}get image(){return this.source.data}set image(e){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.normalized=e.normalized,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){G(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){G(`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,normalized:this.normalized,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 w:e.x-=Math.floor(e.x);break;case T:e.x=e.x<0?0:1;break;case E: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 w:e.y-=Math.floor(e.y);break;case T:e.y=e.y<0?0:1;break;case E: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++}};Xn.DEFAULT_IMAGE=null,Xn.DEFAULT_MAPPING=300,Xn.DEFAULT_ANISOTROPY=1;var Zn=class e{static{e.prototype.isVector4=!0}constructor(e=0,t=0,n=0,r=1){this.x=e,this.y=t,this.z=n,this.w=r}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)s&&e>_?e_?s1);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>>0}enable(e){this.mask|=1<1){for(let e=0;e1){for(let e=0;e0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.pivot!==null&&(r.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(r.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(r.morphTargetInfluences=this.morphTargetInfluences.slice()),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;t0){r.children=[];for(let t=0;t0){r.animations=[];for(let t=0;t0&&(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.pivot=e.pivot===null?null:e.pivot.clone(),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.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let t=0;t.025?(c.inputState.pinching=!1,this.dispatchEvent({type:`pinchend`,handedness:e.handedness,target:this})):!c.inputState.pinching&&o<=.015&&(c.inputState.pinching=!0,this.dispatchEvent({type:`pinchstart`,handedness:e.handedness,target:this}))}else s!==null&&e.gripSpace&&(i=t.getPose(e.gripSpace,n),i!==null&&(s.matrix.fromArray(i.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.matrixWorldNeedsUpdate=!0,i.linearVelocity?(s.hasLinearVelocity=!0,s.linearVelocity.copy(i.linearVelocity)):s.hasLinearVelocity=!1,i.angularVelocity?(s.hasAngularVelocity=!0,s.angularVelocity.copy(i.angularVelocity)):s.hasAngularVelocity=!1,s.eventsEnabled&&s.dispatchEvent({type:`gripUpdated`,data:e,target:this})));o!==null&&(r=t.getPose(e.targetRaySpace,n),r===null&&i!==null&&(r=i),r!==null&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(Mr)))}return o!==null&&(o.visible=r!==null),s!==null&&(s.visible=i!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let n=new jr;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}},Pr={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},Fr={h:0,s:0,l:0},Ir={h:0,s:0,l:0};function Lr(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 Y=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=mt){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Bn.colorSpaceToWorking(this,t),this}setRGB(e,t,n,r=Bn.workingColorSpace){return this.r=e,this.g=t,this.b=n,Bn.colorSpaceToWorking(this,r),this}setHSL(e,t,n,r=Bn.workingColorSpace){if(e=dn(e,1),t=un(t,0,1),n=un(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=Lr(i,r,e+1/3),this.g=Lr(i,r,e),this.b=Lr(i,r,e-1/3)}return Bn.colorSpaceToWorking(this,r),this}setStyle(e,t=mt){function n(t){t!==void 0&&parseFloat(t)<1&&G(`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:G(`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);G(`Color: Invalid hex color `+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=mt){let n=Pr[e.toLowerCase()];return n===void 0?G(`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=Vn(e.r),this.g=Vn(e.g),this.b=Vn(e.b),this}copyLinearToSRGB(e){return this.r=Hn(e.r),this.g=Hn(e.g),this.b=Hn(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=mt){return Bn.workingToColorSpace(Rr.copy(this),e),Math.round(un(Rr.r*255,0,255))*65536+Math.round(un(Rr.g*255,0,255))*256+Math.round(un(Rr.b*255,0,255))}getHexString(e=mt){return(`000000`+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Bn.workingColorSpace){Bn.workingToColorSpace(Rr.copy(this),t);let n=Rr.r,r=Rr.g,i=Rr.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+(r0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}},Hr=new q,Ur=new q,Wr=new q,Gr=new q,Kr=new q,qr=new q,Jr=new q,Yr=new q,Xr=new q,Zr=new q,Qr=new Zn,$r=new Zn,ei=new Zn,ti=class e{constructor(e=new q,t=new q,n=new q){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,r){r.subVectors(n,t),Hr.subVectors(e,t),r.cross(Hr);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){Hr.subVectors(r,t),Ur.subVectors(n,t),Wr.subVectors(e,t);let a=Hr.dot(Hr),o=Hr.dot(Ur),s=Hr.dot(Wr),c=Ur.dot(Ur),l=Ur.dot(Wr),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,Gr)===null?!1:Gr.x>=0&&Gr.y>=0&&Gr.x+Gr.y<=1}static getInterpolation(e,t,n,r,i,a,o,s){return this.getBarycoord(e,t,n,r,Gr)===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,Gr.x),s.addScaledVector(a,Gr.y),s.addScaledVector(o,Gr.z),s)}static getInterpolatedAttribute(e,t,n,r,i,a){return Qr.setScalar(0),$r.setScalar(0),ei.setScalar(0),Qr.fromBufferAttribute(e,t),$r.fromBufferAttribute(e,n),ei.fromBufferAttribute(e,r),a.setScalar(0),a.addScaledVector(Qr,i.x),a.addScaledVector($r,i.y),a.addScaledVector(ei,i.z),a}static isFrontFacing(e,t,n,r){return Hr.subVectors(n,t),Ur.subVectors(e,t),Hr.cross(Ur).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 Hr.subVectors(this.c,this.b),Ur.subVectors(this.a,this.b),Hr.cross(Ur).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;Kr.subVectors(r,n),qr.subVectors(i,n),Yr.subVectors(e,n);let s=Kr.dot(Yr),c=qr.dot(Yr);if(s<=0&&c<=0)return t.copy(n);Xr.subVectors(e,r);let l=Kr.dot(Xr),u=qr.dot(Xr);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(Kr,a);Zr.subVectors(e,i);let f=Kr.dot(Zr),p=qr.dot(Zr);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(qr,o);let h=l*p-f*u;if(h<=0&&u-l>=0&&f-p>=0)return Jr.subVectors(i,r),o=(u-l)/(u-l+(f-p)),t.copy(r).addScaledVector(Jr,o);let g=1/(h+m+d);return a=m*g,o=d*g,t.copy(n).addScaledVector(Kr,a).addScaledVector(qr,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},ni=class{constructor(e=new q(1/0,1/0,1/0),t=new q(-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=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,ii),ii.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(fi),pi.subVectors(this.max,fi),oi.subVectors(e.a,fi),si.subVectors(e.b,fi),ci.subVectors(e.c,fi),li.subVectors(si,oi),ui.subVectors(ci,si),di.subVectors(oi,ci);let t=[0,-li.z,li.y,0,-ui.z,ui.y,0,-di.z,di.y,li.z,0,-li.x,ui.z,0,-ui.x,di.z,0,-di.x,-li.y,li.x,0,-ui.y,ui.x,0,-di.y,di.x,0];return!gi(t,oi,si,ci,pi)||(t=[1,0,0,0,1,0,0,0,1],!gi(t,oi,si,ci,pi))?!1:(mi.crossVectors(li,ui),t=[mi.x,mi.y,mi.z],gi(t,oi,si,ci,pi))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,ii).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(ii).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:(ri[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),ri[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),ri[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),ri[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),ri[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),ri[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),ri[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),ri[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(ri),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}},ri=[new q,new q,new q,new q,new q,new q,new q,new q],ii=new q,ai=new ni,oi=new q,si=new q,ci=new q,li=new q,ui=new q,di=new q,fi=new q,pi=new q,mi=new q,hi=new q;function gi(e,t,n,r,i){for(let a=0,o=e.length-3;a<=o;a+=3){hi.fromArray(e,a);let o=i.x*Math.abs(hi.x)+i.y*Math.abs(hi.y)+i.z*Math.abs(hi.z),s=t.dot(hi),c=n.dot(hi),l=r.dot(hi);if(Math.max(-Math.max(s,c,l),Math.min(s,c,l))>o)return!1}return!0}var _i=vi();function vi(){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 yi(e){Math.abs(e)>65504&&G(`DataUtils.toHalfFloat(): Value out of range.`),e=un(e,-65504,65504),_i.floatView[0]=e;let t=_i.uint32View[0],n=t>>23&511;return _i.baseTable[n]+((t&8388607)>>_i.shiftTable[n])}function bi(e){let t=e>>10;return _i.uint32View[0]=_i.mantissaTable[_i.offsetTable[t]+(e&1023)]+_i.exponentTable[t],_i.floatView[0]}var xi=class{static toHalfFloat(e){return yi(e)}static fromHalfFloat(e){return bi(e)}},Si=new q,Ci=new K,wi=0,Ti=class extends rn{constructor(e,t,n=!1){if(super(),Array.isArray(e))throw TypeError(`THREE.BufferAttribute: array should be a Typed Array.`);this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:wi++}),this.name=``,this.array=e,this.itemSize=t,this.count=e===void 0?0:e.length/t,this.normalized=n,this.usage=Tt,this.updateRanges=[],this.gpuType=V,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;rthis.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;Ii.subVectors(e,this.center);let t=Ii.lengthSq();if(t>this.radius*this.radius){let e=Math.sqrt(t),n=(e-this.radius)*.5;this.center.addScaledVector(Ii,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):(Li.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Ii.copy(e.center).add(Li)),this.expandByPoint(Ii.copy(e.center).sub(Li))),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}},zi=0,Bi=new J,Vi=new Ar,Hi=new q,Ui=new ni,Wi=new ni,Gi=new q,Ki=class e extends rn{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:zi++}),this.uuid=ln(),this.name=``,this.type=`BufferGeometry`,this.index=null,this.indirect=null,this.indirectOffset=0,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(Vt(e)?Mi:Ai)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,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 Fn().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 Bi.makeRotationFromQuaternion(e),this.applyMatrix4(Bi),this}rotateX(e){return Bi.makeRotationX(e),this.applyMatrix4(Bi),this}rotateY(e){return Bi.makeRotationY(e),this.applyMatrix4(Bi),this}rotateZ(e){return Bi.makeRotationZ(e),this.applyMatrix4(Bi),this}translate(e,t,n){return Bi.makeTranslation(e,t,n),this.applyMatrix4(Bi),this}scale(e,t,n){return Bi.makeScale(e,t,n),this.applyMatrix4(Bi),this}lookAt(e){return Vi.lookAt(e),Vi.updateMatrix(),this.applyMatrix4(Vi.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Hi).negate(),this.translate(Hi.x,Hi.y,Hi.z),this}setFromPoints(e){let t=this.getAttribute(`position`);if(t===void 0){let t=[];for(let n=0,r=e.length;nt.count&&G(`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 ni);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){$t(`BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.`,this),this.boundingBox.set(new q(-1/0,-1/0,-1/0),new q(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e0&&(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;t0&&(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;e0!=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){G(`Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){G(`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.allowOverride===!1&&(n.allowOverride=!1),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.allowOverride=e.allowOverride,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++}},Qi=class extends Zi{constructor(e){super(),this.isSpriteMaterial=!0,this.type=`SpriteMaterial`,this.color=new Y(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}},$i,ea=new q,ta=new q,na=new q,ra=new K,ia=new K,aa=new J,oa=new q,sa=new q,ca=new q,la=new K,ua=new K,da=new K,fa=class extends Ar{constructor(e=new Qi){if(super(),this.isSprite=!0,this.type=`Sprite`,$i===void 0){$i=new Ki;let e=new qi(new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),5);$i.setIndex([0,1,2,0,2,3]),$i.setAttribute(`position`,new Yi(e,3,0,!1)),$i.setAttribute(`uv`,new Yi(e,2,3,!1))}this.geometry=$i,this.material=e,this.center=new K(.5,.5),this.count=1}raycast(e,t){e.camera===null&&$t(`Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.`),ta.setFromMatrixScale(this.matrixWorld),aa.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),na.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&ta.multiplyScalar(-na.z);let n=this.material.rotation,r,i;n!==0&&(i=Math.cos(n),r=Math.sin(n));let a=this.center;pa(oa.set(-.5,-.5,0),na,a,ta,r,i),pa(sa.set(.5,-.5,0),na,a,ta,r,i),pa(ca.set(.5,.5,0),na,a,ta,r,i),la.set(0,0),ua.set(1,0),da.set(1,1);let o=e.ray.intersectTriangle(oa,sa,ca,!1,ea);if(o===null&&(pa(sa.set(-.5,.5,0),na,a,ta,r,i),ua.set(0,1),o=e.ray.intersectTriangle(oa,ca,sa,!1,ea),o===null))return;let s=e.ray.origin.distanceTo(ea);se.far||t.push({distance:s,point:ea.clone(),uv:ti.getInterpolation(ea,oa,sa,ca,la,ua,da,new K),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}};function pa(e,t,n,r,i,a){ra.subVectors(e,n).addScalar(.5).multiply(r),i===void 0?ia.copy(ra):(ia.x=a*ra.x-i*ra.y,ia.y=i*ra.x+a*ra.y),e.copy(t),e.x+=ia.x,e.y+=ia.y,e.applyMatrix4(aa)}var ma=new q,ha=new q,ga=class extends Ar{constructor(){super(),this.isLOD=!0,this._currentLevel=0,this.type=`LOD`,Object.defineProperties(this,{levels:{enumerable:!0,value:[]}}),this.autoUpdate=!0}copy(e){super.copy(e,!1);let t=e.levels;for(let e=0,n=t.length;e0){let n,r;for(n=1,r=t.length;n0){ma.setFromMatrixPosition(this.matrixWorld);let n=e.ray.origin.distanceTo(ma);this.getObjectForDistance(n).raycast(e,t)}}update(e){let t=this.levels;if(t.length>1){ma.setFromMatrixPosition(e.matrixWorld),ha.setFromMatrixPosition(this.matrixWorld);let n=ma.distanceTo(ha)/e.zoom;t[0].object.visible=!0;let r,i;for(r=1,i=t.length;r=e)t[r-1].object.visible=!1,t[r].object.visible=!0;else break}for(this._currentLevel=r-1;r0)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(va).addScaledVector(ya,d),f}intersectSphere(e,t){_a.subVectors(e.center,this.origin);let n=_a.dot(this.direction),r=_a.dot(_a)-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=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=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,_a)!==null}intersectTriangle(e,t,n,r,i){xa.subVectors(t,e),Sa.subVectors(n,e),Ca.crossVectors(xa,Sa);let a=this.direction.dot(Ca),o;if(a>0){if(r)return null;o=1}else if(a<0)o=-1,a=-a;else return null;ba.subVectors(this.origin,e);let s=o*this.direction.dot(Sa.crossVectors(ba,Sa));if(s<0)return null;let c=o*this.direction.dot(xa.cross(ba));if(c<0||s+c>a)return null;let l=-o*ba.dot(Ca);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)}},Ta=class extends Zi{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type=`MeshBasicMaterial`,this.color=new Y(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 pr,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}},Ea=new J,Da=new wa,Oa=new Ri,ka=new q,Aa=new q,ja=new q,Ma=new q,Na=new q,Pa=new q,Fa=new q,Ia=new q,La=class extends Ar{constructor(e=new Ki,t=new Ta){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(e.far-e.near)**2))&&(Ea.copy(i).invert(),Da.copy(e.ray).applyMatrix4(Ea),!(n.boundingBox!==null&&Da.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,Da)))}_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;in.far?null:{distance:l,point:Ia.clone(),object:e}}function za(e,t,n,r,i,a,o,s,c,l){e.getVertexPosition(s,Aa),e.getVertexPosition(c,ja),e.getVertexPosition(l,Ma);let u=Ra(e,t,n,r,Aa,ja,Ma,Fa);if(u){let e=new q;ti.getBarycoord(Fa,Aa,ja,Ma,e),i&&(u.uv=ti.getInterpolatedAttribute(i,s,c,l,e,new K)),a&&(u.uv1=ti.getInterpolatedAttribute(a,s,c,l,e,new K)),o&&(u.normal=ti.getInterpolatedAttribute(o,s,c,l,e,new q),u.normal.dot(r.direction)>0&&u.normal.multiplyScalar(-1));let t={a:s,b:c,c:l,normal:new q,materialIndex:0};ti.getNormal(Aa,ja,Ma,t.normal),u.face=t,u.barycoord=e}return u}var Ba=new Zn,Va=new Zn,Ha=new Zn,Ua=new Zn,Wa=new J,Ga=new q,Ka=new Ri,qa=new J,Ja=new wa,Ya=class extends La{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type=`SkinnedMesh`,this.bindMode=S,this.bindMatrix=new J,this.bindMatrixInverse=new J,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){let e=this.geometry;this.boundingBox===null&&(this.boundingBox=new ni),this.boundingBox.makeEmpty();let t=e.getAttribute(`position`);for(let e=0;e1)?null:t.copy(e.start).addScaledVector(r,a)}intersectsLine(e){let t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let n=t||po.getNormalMatrix(e),r=this.coplanarPoint(uo).applyMatrix4(e),i=this.normal.applyMatrix3(n).normalize();return this.constant=-r.dot(i),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}},ho=new Ri,go=new K(.5,.5),_o=new q,vo=class{constructor(e=new mo,t=new mo,n=new mo,r=new mo,i=new mo,a=new mo){this.planes=[e,t,n,r,i,a]}set(e,t,n,r,i,a){let o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(n),o[3].copy(r),o[4].copy(i),o[5].copy(a),this}copy(e){let t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=Ft,n=!1){let r=this.planes,i=e.elements,a=i[0],o=i[1],s=i[2],c=i[3],l=i[4],u=i[5],d=i[6],f=i[7],p=i[8],m=i[9],h=i[10],g=i[11],_=i[12],v=i[13],y=i[14],b=i[15];if(r[0].setComponents(c-a,f-l,g-p,b-_).normalize(),r[1].setComponents(c+a,f+l,g+p,b+_).normalize(),r[2].setComponents(c+o,f+u,g+m,b+v).normalize(),r[3].setComponents(c-o,f-u,g-m,b-v).normalize(),n)r[4].setComponents(s,d,h,y).normalize(),r[5].setComponents(c-s,f-d,g-h,b-y).normalize();else if(r[4].setComponents(c-s,f-d,g-h,b-y).normalize(),t===2e3)r[5].setComponents(c+s,f+d,g+h,b+y).normalize();else if(t===2001)r[5].setComponents(s,d,h,y).normalize();else throw Error(`THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: `+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),ho.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),ho.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(ho)}intersectsSprite(e){return ho.center.set(0,0,0),ho.radius=.7071067811865476+go.distanceTo(e.center),ho.applyMatrix4(e.matrixWorld),this.intersectsSphere(ho)}intersectsSphere(e){let t=this.planes,n=e.center,r=-e.radius;for(let e=0;e<6;e++)if(t[e].distanceToPoint(n)0?e.max.x:e.min.x,_o.y=r.normal.y>0?e.max.y:e.min.y,_o.z=r.normal.z>0?e.max.z:e.min.z,r.distanceToPoint(_o)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}},yo=new J,bo=new vo,xo=class e{constructor(){this.coordinateSystem=Ft}intersectsObject(e,t){if(!t.isArrayCamera||t.cameras.length===0)return!1;for(let n=0;n=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});let o=i[this.index];a.push(o),this.index++,o.start=e,o.count=t,o.z=n,o.index=r}reset(){this.list.length=0,this.index=0}},Eo=new J,Do=new Y(1,1,1),Oo=new vo,ko=new xo,Ao=new ni,jo=new Ri,Mo=new q,No=new q,Po=new q,Fo=new To,Io=new La,Lo=[];function Ro(e,t,n=0){let r=t.itemSize;if(e.isInterleavedBufferAttribute||e.array.constructor!==t.array.constructor){let i=e.count;for(let a=0;a65535?new Uint32Array(r):new Uint16Array(r);t.setIndex(new Ti(e,1))}this._geometryInitialized=!0}}_validateGeometry(e){let t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw Error(`THREE.BatchedMesh: All geometries must consistently have "index".`);for(let n in t.attributes){if(!e.hasAttribute(n))throw Error(`THREE.BatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);let r=e.getAttribute(n),i=t.getAttribute(n);if(r.itemSize!==i.itemSize||r.normalized!==i.normalized)throw Error(`THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.`)}}validateInstanceId(e){let t=this._instanceInfo;if(e<0||e>=t.length||t[e].active===!1)throw Error(`THREE.BatchedMesh: Invalid instanceId ${e}. Instance is either out of range or has been deleted.`)}validateGeometryId(e){let t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw Error(`THREE.BatchedMesh: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}setCustomSort(e){return this.customSort=e,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ni);let e=this.boundingBox,t=this._instanceInfo;e.makeEmpty();for(let n=0,r=t.length;n=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw Error(`THREE.BatchedMesh: Maximum item count reached.`);let t={visible:!0,active:!0,geometryIndex:e},n=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(So),n=this._availableInstanceIds.shift(),this._instanceInfo[n]=t):(n=this._instanceInfo.length,this._instanceInfo.push(t));let r=this._matricesTexture;Eo.identity().toArray(r.image.data,n*16),r.needsUpdate=!0;let i=this._colorsTexture;return i&&(Do.toArray(i.image.data,n*4),i.needsUpdate=!0),this._visibilityChanged=!0,n}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e);let r={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},i=this._geometryInfo;r.vertexStart=this._nextVertexStart,r.reservedVertexCount=t===-1?e.getAttribute(`position`).count:t;let a=e.getIndex();if(a!==null&&(r.indexStart=this._nextIndexStart,r.reservedIndexCount=n===-1?a.count:n),r.indexStart!==-1&&r.indexStart+r.reservedIndexCount>this._maxIndexCount||r.vertexStart+r.reservedVertexCount>this._maxVertexCount)throw Error(`THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.`);let o;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(So),o=this._availableGeometryIds.shift(),i[o]=r):(o=this._geometryCount,this._geometryCount++,i.push(r)),this.setGeometryAt(o,e),this._nextIndexStart=r.indexStart+r.reservedIndexCount,this._nextVertexStart=r.vertexStart+r.reservedVertexCount,o}setGeometryAt(e,t){if(e>=this._geometryCount)throw Error(`THREE.BatchedMesh: Maximum geometry count reached.`);this._validateGeometry(t);let n=this.geometry,r=n.getIndex()!==null,i=n.getIndex(),a=t.getIndex(),o=this._geometryInfo[e];if(r&&a.count>o.reservedIndexCount||t.attributes.position.count>o.reservedVertexCount)throw Error(`THREE.BatchedMesh: Reserved space not large enough for provided geometry.`);let s=o.vertexStart,c=o.reservedVertexCount;o.vertexCount=t.getAttribute(`position`).count;for(let e in n.attributes){let r=t.getAttribute(e),i=n.getAttribute(e);Ro(r,i,s);let a=r.itemSize;for(let e=r.count,t=c;e=t.length||t[e].active===!1)return this;let n=this._instanceInfo;for(let t=0,r=n.length;tt).sort((e,t)=>n[e].vertexStart-n[t].vertexStart),i=this.geometry;for(let a=0,o=n.length;a=this._geometryCount)return null;let n=this.geometry,r=this._geometryInfo[e];if(r.boundingBox===null){let e=new ni,t=n.index,i=n.attributes.position;for(let n=r.start,a=r.start+r.count;n=this._geometryCount)return null;let n=this.geometry,r=this._geometryInfo[e];if(r.boundingSphere===null){let t=new Ri;this.getBoundingBoxAt(e,Ao),Ao.getCenter(t.center);let i=n.index,a=n.attributes.position,o=0;for(let e=r.start,n=r.start+r.count;ee.active);if(Math.max(...n.map(e=>e.vertexStart+e.reservedVertexCount))>e)throw Error(`BatchedMesh: Geometry vertex values are being used outside the range ${t}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...n.map(e=>e.indexStart+e.reservedIndexCount))>t)throw Error(`BatchedMesh: Geometry index values are being used outside the range ${t}. Cannot shrink further.`);let r=this.geometry;r.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new Ki,this._initializeGeometry(r));let i=this.geometry;r.index&&zo(r.index.array,i.index.array);for(let e in r.attributes)zo(r.attributes[e].array,i.attributes[e].array)}raycast(e,t){let n=this._instanceInfo,r=this._geometryInfo,i=this.matrixWorld,a=this.geometry;Io.material=this.material,Io.geometry.index=a.index,Io.geometry.attributes=a.attributes,Io.geometry.boundingBox===null&&(Io.geometry.boundingBox=new ni),Io.geometry.boundingSphere===null&&(Io.geometry.boundingSphere=new Ri);for(let a=0,o=n.length;a({...e,boundingBox:e.boundingBox===null?null:e.boundingBox.clone(),boundingSphere:e.boundingSphere===null?null:e.boundingSphere.clone()})),this._instanceInfo=e._instanceInfo.map(e=>({...e})),this._availableInstanceIds=e._availableInstanceIds.slice(),this._availableGeometryIds=e._availableGeometryIds.slice(),this._nextIndexStart=e._nextIndexStart,this._nextVertexStart=e._nextVertexStart,this._geometryCount=e._geometryCount,this._maxInstanceCount=e._maxInstanceCount,this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._multiDrawCounts=e._multiDrawCounts.slice(),this._multiDrawStarts=e._multiDrawStarts.slice(),this._indirectTexture=e._indirectTexture.clone(),this._indirectTexture.image.data=this._indirectTexture.image.data.slice(),this._matricesTexture=e._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=e._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null)}onBeforeRender(e,t,n,r,i){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;let a=r.getIndex(),o=a===null?1:a.array.BYTES_PER_ELEMENT,s=1;i.wireframe&&(s=2,o=r.attributes.position.count>65535?4:2);let c=this._instanceInfo,l=this._multiDrawStarts,u=this._multiDrawCounts,d=this._geometryInfo,f=this.perObjectFrustumCulled,p=this._indirectTexture,m=p.image.data,h=n.isArrayCamera?ko:Oo;f&&!n.isArrayCamera&&(Eo.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(this.matrixWorld),Oo.setFromProjectionMatrix(Eo,n.coordinateSystem,n.reversedDepth));let g=0;if(this.sortObjects){Eo.copy(this.matrixWorld).invert(),Mo.setFromMatrixPosition(n.matrixWorld).applyMatrix4(Eo),No.set(0,0,-1).transformDirection(n.matrixWorld).transformDirection(Eo);for(let e=0,t=c.length;e0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;er)return;qo.applyMatrix4(e.matrixWorld);let c=t.ray.origin.distanceTo(qo);if(!(ct.far))return{distance:c,point:Jo.clone().applyMatrix4(e.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:e}}var Zo=new q,Qo=new q,$o=class extends Yo{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type=`LineSegments`}computeLineDistances(){let e=this.geometry;if(e.index===null){let t=e.attributes.position,n=[];for(let e=0,r=t.count;e0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;ei.far)return;a.push({distance:c,distanceToRay:Math.sqrt(s),point:n,index:t,face:null,faceIndex:null,barycoord:null,object:o})}}var cs=class extends Xn{constructor(e,t,n,r,i=M,a=M,o,s,c){super(e,t,n,r,i,a,o,s,c),this.isVideoTexture=!0,this.generateMipmaps=!1,this._requestVideoFrameCallbackId=0;let l=this;function u(){l.needsUpdate=!0,l._requestVideoFrameCallbackId=e.requestVideoFrameCallback(u)}`requestVideoFrameCallback`in e&&(this._requestVideoFrameCallbackId=e.requestVideoFrameCallback(u))}clone(){return new this.constructor(this.image).copy(this)}update(){let e=this.image;!(`requestVideoFrameCallback`in e)&&e.readyState>=e.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}dispose(){this._requestVideoFrameCallbackId!==0&&(this.source.data.cancelVideoFrameCallback(this._requestVideoFrameCallbackId),this._requestVideoFrameCallbackId=0),super.dispose()}},ls=class extends cs{constructor(e,t,n,r,i,a,o,s){super({},e,t,n,r,i,a,o,s),this.isVideoFrameTexture=!0}update(){}clone(){return new this.constructor().copy(this)}setFrame(e){this.image=e,this.needsUpdate=!0}},us=class extends Xn{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=D,this.minFilter=D,this.generateMipmaps=!1,this.needsUpdate=!0}},ds=class extends Xn{constructor(e,t,n,r,i,a,o,s,c,l,u,d){super(null,a,o,s,c,l,r,i,u,d),this.isCompressedTexture=!0,this.image={width:t,height:n},this.mipmaps=e,this.flipY=!1,this.generateMipmaps=!1}},fs=class extends ds{constructor(e,t,n,r,i,a){super(e,t,n,i,a),this.isCompressedArrayTexture=!0,this.image.depth=r,this.wrapR=T,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}},ps=class extends ds{constructor(e,t,n){super(void 0,e[0].width,e[0].height,t,n,301),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=e}},ms=class extends Xn{constructor(e=[],t=301,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}},hs=class extends Xn{constructor(e,t,n,r,i,a,o,s,c){super(e,t,n,r,i,a,o,s,c),this.isCanvasTexture=!0,this.needsUpdate=!0}},gs=class extends Xn{constructor(e,t,n,r,i,a,o,s,c){super(e,t,n,r,i,a,o,s,c),this.isHTMLTexture=!0,this.generateMipmaps=!1,this.needsUpdate=!0;let l=e?e.parentNode:null;l!==null&&`requestPaint`in l&&(l.onpaint=()=>{this.needsUpdate=!0},l.requestPaint())}dispose(){let e=this.image?this.image.parentNode:null;e!==null&&`onpaint`in e&&(e.onpaint=null),super.dispose()}},_s=class extends Xn{constructor(e,t,n=B,r,i,a,o=D,s=D,c,l=ue,u=1){if(l!==1026&&l!==1027)throw Error(`DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat`);super({width:e,height:t,depth:u},r,i,a,o,s,l,n,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new Kn(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}},vs=class extends _s{constructor(e,t=B,n=301,r,i,a=D,o=D,s,c=ue){let l={width:e,height:e,depth:1},u=[l,l,l,l,l,l];super(e,e,t,n,r,i,a,o,s,c),this.image=u,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}},ys=class extends Xn{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}},bs=class e extends Ki{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 Pi(c,3)),this.setAttribute(`normal`,new Pi(l,3)),this.setAttribute(`uv`,new Pi(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 q;for(let a=0;a0?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;e0){let e=(_-1)*m;for(let t=0;t0&&v(!0),t>0&&v(!1)),this.setIndex(l),this.setAttribute(`position`,new Pi(u,3)),this.setAttribute(`normal`,new Pi(d,3)),this.setAttribute(`uv`,new Pi(f,2));function _(){let a=new q,_=new q,v=0,y=(t-e)/n;for(let c=0;c<=i;c++){let l=[],g=c/i,v=g*(t-e)+e;for(let e=0;e<=r;e++){let t=e/r,i=t*s+o,c=Math.sin(i),m=Math.cos(i);_.x=v*c,_.y=-g*n+h,_.z=v*m,u.push(_.x,_.y,_.z),a.set(c,y,m).normalize(),d.push(a.x,a.y,a.z),f.push(t,1-g),l.push(p++)}m.push(l)}for(let n=0;n0||r!==0)&&(l.push(a,o,c),v+=3),(t>0||r!==i-1)&&(l.push(o,s,c),v+=3)}c.addGroup(g,v,0),g+=v}function v(n){let i=p,a=new K,m=new q,_=0,v=n===!0?e:t,y=n===!0?1:-1;for(let e=1;e<=r;e++)u.push(0,h*y,0),d.push(0,y,0),f.push(.5,.5),p++;let b=p;for(let e=0;e<=r;e++){let t=e/r*s+o,n=Math.cos(t),i=Math.sin(t);m.x=v*i,m.y=h*y,m.z=v*n,u.push(m.x,m.y,m.z),d.push(0,y,0),a.x=n*.5+.5,a.y=i*.5*y+.5,f.push(a.x,a.y),p++}for(let e=0;e.9&&Math.min(t,n,r)<.1&&(t<.2&&(a[e+0]+=1),n<.2&&(a[e+2]+=1),r<.2&&(a[e+4]+=1))}}function d(e){i.push(e.x,e.y,e.z)}function f(t,n){let r=t*3;n.x=e[r+0],n.y=e[r+1],n.z=e[r+2]}function p(){let e=new q,t=new q,n=new q,r=new q,o=new K,s=new K,c=new K;for(let l=0,u=0;l0)s=r-1;else{s=r;break}if(r=s,n[r]===a)return r/(i-1);let l=n[r],u=n[r+1]-l,d=(a-l)/u;return(r+d)/(i-1)}getTangent(e,t){let n=1e-4,r=e-n,i=e+n;r<0&&(r=0),i>1&&(i=1);let a=this.getPoint(r),o=this.getPoint(i),s=t||(a.isVector2?new K:new q);return s.copy(o).sub(a).normalize(),s}getTangentAt(e,t){let n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t=!1){let n=new q,r=[],i=[],a=[],o=new q,s=new J;for(let t=0;t<=e;t++){let n=t/e;r[t]=this.getTangentAt(n,new q)}i[0]=new q,a[0]=new q;let c=Number.MAX_VALUE,l=Math.abs(r[0].x),u=Math.abs(r[0].y),d=Math.abs(r[0].z);l<=c&&(c=l,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),d<=c&&n.set(0,0,1),o.crossVectors(r[0],n).normalize(),i[0].crossVectors(r[0],o),a[0].crossVectors(r[0],i[0]);for(let t=1;t<=e;t++){if(i[t]=i[t-1].clone(),a[t]=a[t-1].clone(),o.crossVectors(r[t-1],r[t]),o.length()>2**-52){o.normalize();let e=Math.acos(un(r[t-1].dot(r[t]),-1,1));i[t].applyMatrix4(s.makeRotationAxis(o,e))}a[t].crossVectors(r[t],i[t])}if(t===!0){let t=Math.acos(un(i[0].dot(i[e]),-1,1));t/=e,r[0].dot(o.crossVectors(i[0],i[e]))>0&&(t=-t);for(let n=1;n<=e;n++)i[n].applyMatrix4(s.makeRotationAxis(r[n],t*n)),a[n].crossVectors(r[n],i[n])}return{tangents:r,normals:i,binormals:a}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){let e={metadata:{version:4.7,type:`Curve`,generator:`Curve.toJSON`}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}},Ns=class extends Ms{constructor(e=0,t=0,n=1,r=1,i=0,a=Math.PI*2,o=!1,s=0){super(),this.isEllipseCurve=!0,this.type=`EllipseCurve`,this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=r,this.aStartAngle=i,this.aEndAngle=a,this.aClockwise=o,this.aRotation=s}getPoint(e,t=new K){let n=t,r=Math.PI*2,i=this.aEndAngle-this.aStartAngle,a=Math.abs(i)<2**-52;for(;i<0;)i+=r;for(;i>r;)i-=r;i<2**-52&&(i=a?0:r),this.aClockwise===!0&&!a&&(i===r?i=-r:i-=r);let o=this.aStartAngle+e*i,s=this.aX+this.xRadius*Math.cos(o),c=this.aY+this.yRadius*Math.sin(o);if(this.aRotation!==0){let e=Math.cos(this.aRotation),t=Math.sin(this.aRotation),n=s-this.aX,r=c-this.aY;s=n*e-r*t+this.aX,c=n*t+r*e+this.aY}return n.set(s,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){let e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}},Ps=class extends Ns{constructor(e,t,n,r,i,a){super(e,t,n,n,r,i,a),this.isArcCurve=!0,this.type=`ArcCurve`}};function Fs(){let e=0,t=0,n=0,r=0;function i(i,a,o,s){e=i,t=o,n=-3*i+3*a-2*o-s,r=2*i-2*a+o+s}return{initCatmullRom:function(e,t,n,r,a){i(t,n,a*(n-e),a*(r-t))},initNonuniformCatmullRom:function(e,t,n,r,a,o,s){let c=(t-e)/a-(n-e)/(a+o)+(n-t)/o,l=(n-t)/o-(r-t)/(o+s)+(r-n)/s;c*=o,l*=o,i(t,n,c,l)},calc:function(i){let a=i*i,o=a*i;return e+t*i+n*a+r*o}}}var Is=new q,Ls=new q,Rs=new Fs,zs=new Fs,Bs=new Fs,Vs=class extends Ms{constructor(e=[],t=!1,n=`centripetal`,r=.5){super(),this.isCatmullRomCurve3=!0,this.type=`CatmullRomCurve3`,this.points=e,this.closed=t,this.curveType=n,this.tension=r}getPoint(e,t=new q){let n=t,r=this.points,i=r.length,a=(i-+!this.closed)*e,o=Math.floor(a),s=a-o;this.closed?o+=o>0?0:(Math.floor(Math.abs(o)/i)+1)*i:s===0&&o===i-1&&(o=i-2,s=1);let c,l;this.closed||o>0?c=r[(o-1)%i]:(Ls.subVectors(r[0],r[1]).add(r[0]),c=Ls);let u=r[o%i],d=r[(o+1)%i];if(this.closed||o+2r.length-2?r.length-1:a+1],u=r[a>r.length-3?r.length-1:a+2];return n.set(Hs(o,s.x,c.x,l.x,u.x),Hs(o,s.y,c.y,l.y,u.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t=n){let e=r[i]-n,a=this.curves[i],o=a.getLength(),s=o===0?0:1-e/o;return a.getPointAt(s,t)}i++}return null}getLength(){let e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let e=[],t=0;for(let n=0,r=this.curves.length;n1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,n=e.curves.length;t0){let e=c.getPoint(0);e.equals(this.currentPoint)||this.lineTo(e.x,e.y)}this.curves.push(c);let l=c.getPoint(1);return this.currentPoint.copy(l),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){let e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}},cc=class extends sc{constructor(e){super(e),this.uuid=ln(),this.type=`Shape`,this.holes=[]}getPointsHoles(e){let t=[];for(let n=0,r=this.holes.length;n80*n){s=e[0],c=e[1];let t=s,r=c;for(let a=n;at&&(t=n),i>r&&(r=i)}l=Math.max(t-s,r-c),l=l===0?0:32767/l}return fc(a,o,n,s,c,l,0),o}function uc(e,t,n,r,i){let a;if(i===Vc(e,t,n,r)>0)for(let i=t;i=t;i-=r)a=Rc(i/r|0,e[i],e[i+1],a);return a&&Ac(a,a.next)&&(zc(a),a=a.next),a}function dc(e,t){if(!e)return e;t||=e;let n=e,r;do if(r=!1,!n.steiner&&(Ac(n,n.next)||kc(n.prev,n,n.next)===0)){if(zc(n),n=t=n.prev,n===n.next)break;r=!0}else n=n.next;while(r||n!==t);return t}function fc(e,t,n,r,i,a,o){if(!e)return;!o&&a&&Sc(e,r,i,a);let s=e;for(;e.prev!==e.next;){let c=e.prev,l=e.next;if(a?mc(e,r,i,a):pc(e)){t.push(c.i,e.i,l.i),zc(e),e=l.next,s=l.next;continue}if(e=l,e===s){o?o===1?(e=hc(dc(e),t),fc(e,t,n,r,i,a,2)):o===2&&gc(e,t,n,r,i,a):fc(dc(e),t,n,r,i,a,1);break}}}function pc(e){let t=e.prev,n=e,r=e.next;if(kc(t,n,r)>=0)return!1;let i=t.x,a=n.x,o=r.x,s=t.y,c=n.y,l=r.y,u=Math.min(i,a,o),d=Math.min(s,c,l),f=Math.max(i,a,o),p=Math.max(s,c,l),m=r.next;for(;m!==t;){if(m.x>=u&&m.x<=f&&m.y>=d&&m.y<=p&&Dc(i,s,a,c,o,l,m.x,m.y)&&kc(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function mc(e,t,n,r){let i=e.prev,a=e,o=e.next;if(kc(i,a,o)>=0)return!1;let s=i.x,c=a.x,l=o.x,u=i.y,d=a.y,f=o.y,p=Math.min(s,c,l),m=Math.min(u,d,f),h=Math.max(s,c,l),g=Math.max(u,d,f),_=wc(p,m,t,n,r),v=wc(h,g,t,n,r),y=e.prevZ,b=e.nextZ;for(;y&&y.z>=_&&b&&b.z<=v;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Dc(s,u,c,d,l,f,y.x,y.y)&&kc(y.prev,y,y.next)>=0||(y=y.prevZ,b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Dc(s,u,c,d,l,f,b.x,b.y)&&kc(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;y&&y.z>=_;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Dc(s,u,c,d,l,f,y.x,y.y)&&kc(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=v;){if(b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Dc(s,u,c,d,l,f,b.x,b.y)&&kc(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function hc(e,t){let n=e;do{let r=n.prev,i=n.next.next;!Ac(r,i)&&jc(r,n,n.next,i)&&Fc(r,i)&&Fc(i,r)&&(t.push(r.i,n.i,i.i),zc(n),zc(n.next),n=e=i),n=n.next}while(n!==e);return dc(n)}function gc(e,t,n,r,i,a){let o=e;do{let e=o.next.next;for(;e!==o.prev;){if(o.i!==e.i&&Oc(o,e)){let s=Lc(o,e);o=dc(o,o.next),s=dc(s,s.next),fc(o,t,n,r,i,a,0),fc(s,t,n,r,i,a,0);return}e=e.next}o=o.next}while(o!==e)}function _c(e,t,n,r){let i=[];for(let n=0,a=t.length;n=n.next.y&&n.next.y!==n.y){let e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>a&&(a=e,o=n.x=n.x&&n.x>=c&&r!==n.x&&Ec(io.x||n.x===o.x&&xc(o,n)))&&(o=n,u=t)}n=n.next}while(n!==s);return o}function xc(e,t){return kc(e.prev,e,t.prev)<0&&kc(t.next,e,e.next)<0}function Sc(e,t,n,r){let i=e;do i.z===0&&(i.z=wc(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,Cc(i)}function Cc(e){let t,n=1;do{let r=e,i;e=null;let a=null;for(t=0;r;){t++;let o=r,s=0;for(let e=0;e0||c>0&&o;)s!==0&&(c===0||!o||r.z<=o.z)?(i=r,r=r.nextZ,s--):(i=o,o=o.nextZ,c--),a?a.nextZ=i:e=i,i.prevZ=a,a=i;r=o}a.nextZ=null,n*=2}while(t>1);return e}function wc(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function Tc(e){let t=e,n=e;do(t.x=(e-o)*(a-s)&&(e-o)*(r-s)>=(n-o)*(t-s)&&(n-o)*(a-s)>=(i-o)*(r-s)}function Dc(e,t,n,r,i,a,o,s){return!(e===o&&t===s)&&Ec(e,t,n,r,i,a,o,s)}function Oc(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!Pc(e,t)&&(Fc(e,t)&&Fc(t,e)&&Ic(e,t)&&(kc(e.prev,e,t.prev)||kc(e,t.prev,t))||Ac(e,t)&&kc(e.prev,e,e.next)>0&&kc(t.prev,t,t.next)>0)}function kc(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function Ac(e,t){return e.x===t.x&&e.y===t.y}function jc(e,t,n,r){let i=Nc(kc(e,t,n)),a=Nc(kc(e,t,r)),o=Nc(kc(n,r,e)),s=Nc(kc(n,r,t));return!!(i!==a&&o!==s||i===0&&Mc(e,n,t)||a===0&&Mc(e,r,t)||o===0&&Mc(n,e,r)||s===0&&Mc(n,t,r))}function Mc(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function Nc(e){return e>0?1:e<0?-1:0}function Pc(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&jc(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}function Fc(e,t){return kc(e.prev,e,e.next)<0?kc(e,t,e.next)>=0&&kc(e,e.prev,t)>=0:kc(e,t,e.prev)<0||kc(e,e.next,t)<0}function Ic(e,t){let n=e,r=!1,i=(e.x+t.x)/2,a=(e.y+t.y)/2;do n.y>a!=n.next.y>a&&n.next.y!==n.y&&i<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next;while(n!==e);return r}function Lc(e,t){let n=Bc(e.i,e.x,e.y),r=Bc(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function Rc(e,t,n,r){let i=Bc(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function zc(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Bc(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Vc(e,t,n,r){let i=0;for(let a=t,o=n-r;a2&&e[t-1].equals(e[0])&&e.pop()}function Gc(e,t){for(let n=0;n2**-52){let d=Math.sqrt(u),f=Math.sqrt(c*c+l*l),p=t.x-s/d,m=t.y+o/d,h=n.x-l/f,g=n.y+c/f,_=((h-p)*l-(g-m)*c)/(o*l-s*c);r=p+o*_-e.x,i=m+s*_-e.y;let v=r*r+i*i;if(v<=2)return new K(r,i);a=Math.sqrt(v/2)}else{let e=!1;o>2**-52?c>2**-52&&(e=!0):o<-(2**-52)?c<-(2**-52)&&(e=!0):Math.sign(s)===Math.sign(l)&&(e=!0),e?(r=-s,i=o,a=Math.sqrt(u)):(r=o,i=s,a=Math.sqrt(u/2))}return new K(r/a,i/a)}let j=[];for(let e=0,t=D.length,n=t-1,r=e+1;e=0;e--){let t=e/p,n=u*Math.cos(t*Math.PI/2),r=d*Math.sin(t*Math.PI/2)+f;for(let e=0,t=D.length;e=0;){let r=n,i=n-1;i<0&&(i=e.length-1);for(let e=0,n=s+p*2;e0)&&f.push(t,i,c),(e!==n-1||s0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let e in this.extensions)this.extensions[e]===!0&&(n[e]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}},bl=class extends yl{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type=`RawShaderMaterial`}},xl=class extends Zi{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type=`MeshStandardMaterial`,this.defines={STANDARD:``},this.color=new Y(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Y(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new pr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:``},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},Sl=class extends xl{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:``,PHYSICAL:``},this.type=`MeshPhysicalMaterial`,this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new K(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return un(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(e){this.ior=(1+.4*e)/(1-.4*e)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new Y(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new Y(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new Y(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:``,PHYSICAL:``},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}},Cl=class extends Zi{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type=`MeshPhongMaterial`,this.color=new Y(16777215),this.specular=new Y(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Y(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new pr,this.combine=0,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,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.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},wl=class extends Zi{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:``},this.type=`MeshToonMaterial`,this.color=new Y(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Y(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,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.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Tl=class extends Zi{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type=`MeshNormalMaterial`,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}},El=class extends Zi{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type=`MeshLambertMaterial`,this.color=new Y(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Y(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new pr,this.combine=0,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.flatShading=!1,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.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,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.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},Dl=class extends Zi{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type=`MeshDepthMaterial`,this.depthPacking=ut,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}},Ol=class extends Zi{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type=`MeshDistanceMaterial`,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}},kl=class extends Zi{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:``},this.type=`MeshMatcapMaterial`,this.color=new Y(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new K(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:``},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}},Al=class extends Vo{constructor(e){super(),this.isLineDashedMaterial=!0,this.type=`LineDashedMaterial`,this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}};function jl(e,t){return!e||e.constructor===t?e:typeof t.BYTES_PER_ELEMENT==`number`?new t(e):Array.prototype.slice.call(e)}function Ml(e){function t(t,n){return e[t]-e[n]}let n=e.length,r=Array(n);for(let e=0;e!==n;++e)r[e]=e;return r.sort(t),r}function Nl(e,t,n){let r=e.length,i=new e.constructor(r);for(let a=0,o=0;o!==r;++a){let r=n[a]*t;for(let n=0;n!==t;++n)i[o++]=e[r+n]}return i}function Pl(e,t,n,r){let i=1,a=e[0];for(;a!==void 0&&a[r]===void 0;)a=e[i++];if(a===void 0)return;let o=a[r];if(o!==void 0)if(Array.isArray(o))do o=a[r],o!==void 0&&(t.push(a.time),n.push(...o)),a=e[i++];while(a!==void 0);else if(o.toArray!==void 0)do o=a[r],o!==void 0&&(t.push(a.time),o.toArray(n,n.length)),a=e[i++];while(a!==void 0);else do o=a[r],o!==void 0&&(t.push(a.time),n.push(o)),a=e[i++];while(a!==void 0)}function Fl(e,t,n,r,i=30){let a=e.clone();a.name=t;let o=[];for(let e=0;e=r)){c.push(t.times[e]);for(let n=0;na.tracks[e].times[0]&&(s=a.tracks[e].times[0]);for(let e=0;e=r.times[d]){let e=d*c+s,t=e+c-s;f=r.values.slice(e,t)}else{let e=r.createInterpolant(),t=s,n=c-s;e.evaluate(a),f=e.resultBuffer.slice(t,n)}i===`quaternion`&&new Mn().fromArray(f).normalize().conjugate().toArray(f);let p=o.times.length;for(let e=0;e=i)){let o=t[1];e=i)break seek}a=n,n=0;break linear_scan}break validate_interval}for(;n>>1;et;)--a;if(++a,i!==0||a!==r){i>=a&&(a=Math.max(a,1),i=a-1);let e=this.getValueSize();this.times=n.slice(i,a),this.values=this.values.slice(i*e,a*e)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&($t(`KeyframeTrack: Invalid value size in track.`,this),e=!1);let n=this.times,r=this.values,i=n.length;i===0&&($t(`KeyframeTrack: Track is empty.`,this),e=!1);let a=null;for(let t=0;t!==i;t++){let r=n[t];if(typeof r==`number`&&isNaN(r)){$t(`KeyframeTrack: Time is not a valid number.`,this,t,r),e=!1;break}if(a!==null&&a>r){$t(`KeyframeTrack: Out of order keys.`,this,t,r,a),e=!1;break}a=r}if(r!==void 0&&Wt(r))for(let t=0,n=r.length;t!==n;++t){let n=r[t];if(isNaN(n)){$t(`KeyframeTrack: Value is not a valid number.`,this,t,n),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),n=this.getValueSize(),r=this.getInterpolation()===rt,i=e.length-1,a=1;for(let o=1;o0){e[a]=e[i];for(let e=i*n,r=a*n,o=0;o!==n;++o)t[r+o]=t[e+o];++a}return a===e.length?(this.times=e,this.values=t):(this.times=e.slice(0,a),this.values=t.slice(0,a*n)),this}clone(){let e=this.times.slice(),t=this.values.slice(),n=this.constructor,r=new n(this.name,e,t);return r.createInterpolant=this.createInterpolant,r}};Ul.prototype.ValueTypeName=``,Ul.prototype.TimeBufferType=Float32Array,Ul.prototype.ValueBufferType=Float32Array,Ul.prototype.DefaultInterpolation=nt;var Wl=class extends Ul{constructor(e,t,n){super(e,t,n)}};Wl.prototype.ValueTypeName=`bool`,Wl.prototype.ValueBufferType=Array,Wl.prototype.DefaultInterpolation=tt,Wl.prototype.InterpolantFactoryMethodLinear=void 0,Wl.prototype.InterpolantFactoryMethodSmooth=void 0;var Gl=class extends Ul{constructor(e,t,n,r){super(e,t,n,r)}};Gl.prototype.ValueTypeName=`color`;var Kl=class extends Ul{constructor(e,t,n,r){super(e,t,n,r)}};Kl.prototype.ValueTypeName=`number`;var ql=class extends Rl{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=(n-t)/(r-t),c=e*o;for(let e=c+o;c!==e;c+=4)Mn.slerpFlat(i,0,a,c-o,a,c,s);return i}},Jl=class extends Ul{constructor(e,t,n,r){super(e,t,n,r)}InterpolantFactoryMethodLinear(e){return new ql(this.times,this.values,this.getValueSize(),e)}};Jl.prototype.ValueTypeName=`quaternion`,Jl.prototype.InterpolantFactoryMethodSmooth=void 0;var Yl=class extends Ul{constructor(e,t,n){super(e,t,n)}};Yl.prototype.ValueTypeName=`string`,Yl.prototype.ValueBufferType=Array,Yl.prototype.DefaultInterpolation=tt,Yl.prototype.InterpolantFactoryMethodLinear=void 0,Yl.prototype.InterpolantFactoryMethodSmooth=void 0;var Xl=class extends Ul{constructor(e,t,n,r){super(e,t,n,r)}};Xl.prototype.ValueTypeName=`vector`;var Zl=class{constructor(e=``,t=-1,n=[],r=ct){this.name=e,this.tracks=n,this.duration=t,this.blendMode=r,this.uuid=ln(),this.userData={},this.duration<0&&this.resetDuration()}static parse(e){let t=[],n=e.tracks,r=1/(e.fps||1);for(let e=0,i=n.length;e!==i;++e)t.push($l(n[e]).scale(r));let i=new this(e.name,e.duration,t,e.blendMode);return i.uuid=e.uuid,i.userData=JSON.parse(e.userData||`{}`),i}static toJSON(e){let t=[],n=e.tracks,r={name:e.name,duration:e.duration,tracks:t,uuid:e.uuid,blendMode:e.blendMode,userData:JSON.stringify(e.userData)};for(let e=0,r=n.length;e!==r;++e)t.push(Ul.toJSON(n[e]));return r}static CreateFromMorphTargetSequence(e,t,n,r){let i=t.length,a=[];for(let e=0;e1){let e=a[1],t=r[e];t||(r[e]=t=[]),t.push(n)}}let a=[];for(let e in r)a.push(this.CreateFromMorphTargetSequence(e,r[e],t,n));return a}static parseAnimation(e,t){if(G(`AnimationClip: parseAnimation() is deprecated and will be removed with r185`),!e)return $t(`AnimationClip: No animation in JSONLoader data.`),null;let n=function(e,t,n,r,i){if(n.length!==0){let a=[],o=[];Pl(n,a,o,r),a.length!==0&&i.push(new e(t,a,o))}},r=[],i=e.name||`default`,a=e.fps||30,o=e.blendMode,s=e.length||-1,c=e.hierarchy||[];for(let e=0;e{t&&t(i),this.manager.itemEnd(e)},0);return}if(au[e]!==void 0){au[e].push({onLoad:t,onProgress:n,onError:r});return}au[e]=[],au[e].push({onLoad:t,onProgress:n,onError:r});let a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?`include`:`same-origin`,signal:typeof AbortSignal.any==`function`?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),o=this.mimeType,s=this.responseType;fetch(a).then(t=>{if(t.status===200||t.status===0){if(t.status===0&&G(`FileLoader: HTTP Status 0 received.`),typeof ReadableStream>`u`||t.body===void 0||t.body.getReader===void 0)return t;let n=au[e],r=t.body.getReader(),i=t.headers.get(`X-File-Size`)||t.headers.get(`Content-Length`),a=i?parseInt(i):0,o=a!==0,s=0,c=new ReadableStream({start(e){t();function t(){r.read().then(({done:r,value:i})=>{if(r)e.close();else{s+=i.byteLength;let r=new ProgressEvent(`progress`,{lengthComputable:o,loaded:s,total:a});for(let e=0,t=n.length;e{e.error(t)})}}});return new Response(c)}else throw new ou(`fetch for "${t.url}" responded with ${t.status}: ${t.statusText}`,t)}).then(e=>{switch(s){case`arraybuffer`:return e.arrayBuffer();case`blob`:return e.blob();case`document`:return e.text().then(e=>new DOMParser().parseFromString(e,o));case`json`:return e.json();default:if(o===``)return e.text();{let t=/charset="?([^;"\s]*)"?/i.exec(o),n=t&&t[1]?t[1].toLowerCase():void 0,r=new TextDecoder(n);return e.arrayBuffer().then(e=>r.decode(e))}}}).then(t=>{eu.add(`file:${e}`,t);let n=au[e];delete au[e];for(let e=0,r=n.length;e{let n=au[e];if(n===void 0)throw this.manager.itemError(e),t;delete au[e];for(let e=0,r=n.length;e{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},cu=class extends iu{constructor(e){super(e)}load(e,t,n,r){let i=this,a=new su(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{t(i.parse(JSON.parse(n)))}catch(t){r?r(t):$t(t),i.manager.itemError(e)}},n,r)}parse(e){let t=[];for(let n=0;n0:r.vertexColors=e.vertexColors),e.uniforms!==void 0)for(let t in e.uniforms){let i=e.uniforms[t];switch(r.uniforms[t]={},i.type){case`t`:r.uniforms[t].value=n(i.value);break;case`c`:r.uniforms[t].value=new Y().setHex(i.value);break;case`v2`:r.uniforms[t].value=new K().fromArray(i.value);break;case`v3`:r.uniforms[t].value=new q().fromArray(i.value);break;case`v4`:r.uniforms[t].value=new Zn().fromArray(i.value);break;case`m3`:r.uniforms[t].value=new Fn().fromArray(i.value);break;case`m4`:r.uniforms[t].value=new J().fromArray(i.value);break;default:r.uniforms[t].value=i.value}}if(e.defines!==void 0&&(r.defines=e.defines),e.vertexShader!==void 0&&(r.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(r.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(r.glslVersion=e.glslVersion),e.extensions!==void 0)for(let t in e.extensions)r.extensions[t]=e.extensions[t];if(e.lights!==void 0&&(r.lights=e.lights),e.clipping!==void 0&&(r.clipping=e.clipping),e.size!==void 0&&(r.size=e.size),e.sizeAttenuation!==void 0&&(r.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(r.map=n(e.map)),e.matcap!==void 0&&(r.matcap=n(e.matcap)),e.alphaMap!==void 0&&(r.alphaMap=n(e.alphaMap)),e.bumpMap!==void 0&&(r.bumpMap=n(e.bumpMap)),e.bumpScale!==void 0&&(r.bumpScale=e.bumpScale),e.normalMap!==void 0&&(r.normalMap=n(e.normalMap)),e.normalMapType!==void 0&&(r.normalMapType=e.normalMapType),e.normalScale!==void 0){let t=e.normalScale;Array.isArray(t)===!1&&(t=[t,t]),r.normalScale=new K().fromArray(t)}return e.displacementMap!==void 0&&(r.displacementMap=n(e.displacementMap)),e.displacementScale!==void 0&&(r.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(r.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(r.roughnessMap=n(e.roughnessMap)),e.metalnessMap!==void 0&&(r.metalnessMap=n(e.metalnessMap)),e.emissiveMap!==void 0&&(r.emissiveMap=n(e.emissiveMap)),e.emissiveIntensity!==void 0&&(r.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(r.specularMap=n(e.specularMap)),e.specularIntensityMap!==void 0&&(r.specularIntensityMap=n(e.specularIntensityMap)),e.specularColorMap!==void 0&&(r.specularColorMap=n(e.specularColorMap)),e.envMap!==void 0&&(r.envMap=n(e.envMap)),e.envMapRotation!==void 0&&r.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(r.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(r.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(r.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(r.lightMap=n(e.lightMap)),e.lightMapIntensity!==void 0&&(r.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(r.aoMap=n(e.aoMap)),e.aoMapIntensity!==void 0&&(r.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(r.gradientMap=n(e.gradientMap)),e.clearcoatMap!==void 0&&(r.clearcoatMap=n(e.clearcoatMap)),e.clearcoatRoughnessMap!==void 0&&(r.clearcoatRoughnessMap=n(e.clearcoatRoughnessMap)),e.clearcoatNormalMap!==void 0&&(r.clearcoatNormalMap=n(e.clearcoatNormalMap)),e.clearcoatNormalScale!==void 0&&(r.clearcoatNormalScale=new K().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(r.iridescenceMap=n(e.iridescenceMap)),e.iridescenceThicknessMap!==void 0&&(r.iridescenceThicknessMap=n(e.iridescenceThicknessMap)),e.transmissionMap!==void 0&&(r.transmissionMap=n(e.transmissionMap)),e.thicknessMap!==void 0&&(r.thicknessMap=n(e.thicknessMap)),e.anisotropyMap!==void 0&&(r.anisotropyMap=n(e.anisotropyMap)),e.sheenColorMap!==void 0&&(r.sheenColorMap=n(e.sheenColorMap)),e.sheenRoughnessMap!==void 0&&(r.sheenRoughnessMap=n(e.sheenRoughnessMap)),r}setTextures(e){return this.textures=e,this}createMaterialFromType(t){return e.createMaterialFromType(t)}static createMaterialFromType(e){return new{ShadowMaterial:ul,SpriteMaterial:Qi,RawShaderMaterial:bl,ShaderMaterial:yl,PointsMaterial:ts,MeshPhysicalMaterial:Sl,MeshStandardMaterial:xl,MeshPhongMaterial:Cl,MeshToonMaterial:wl,MeshNormalMaterial:Tl,MeshLambertMaterial:El,MeshDepthMaterial:Dl,MeshDistanceMaterial:Ol,MeshBasicMaterial:Ta,MeshMatcapMaterial:kl,LineDashedMaterial:Al,LineBasicMaterial:Vo,Material:Zi}[e]}},Vu=class{static extractUrlBase(e){let t=e.lastIndexOf(`/`);return t===-1?`./`:e.slice(0,t+1)}static resolveURL(e,t){return typeof e!=`string`||e===``?``:(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,`$1`)),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}},Hu=class extends Ki{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type=`InstancedBufferGeometry`,this.instanceCount=1/0}copy(e){return super.copy(e),this.instanceCount=e.instanceCount,this}toJSON(){let e=super.toJSON();return e.instanceCount=this.instanceCount,e.isInstancedBufferGeometry=!0,e}},Uu=class extends iu{constructor(e){super(e)}load(e,t,n,r){let i=this,a=new su(i.manager);a.setPath(i.path),a.setRequestHeader(i.requestHeader),a.setWithCredentials(i.withCredentials),a.load(e,function(n){try{t(i.parse(JSON.parse(n)))}catch(t){r?r(t):$t(t),i.manager.itemError(e)}},n,r)}parse(e){let t={},n={};function r(e,n){if(t[n]!==void 0)return t[n];let r=e.interleavedBuffers[n],a=i(e,r.buffer),o=new qi(Ut(r.type,a),r.stride);return o.uuid=r.uuid,t[n]=o,o}function i(e,t){if(n[t]!==void 0)return n[t];let r=e.arrayBuffers[t],i=new Uint32Array(r).buffer;return n[t]=i,i}let a=e.isInstancedBufferGeometry?new Hu:new Ki,o=e.data.index;if(o!==void 0){let e=Ut(o.type,o.array);a.setIndex(new Ti(e,1))}let s=e.data.attributes;for(let t in s){let n=s[t],i;if(n.isInterleavedBufferAttribute)i=new Yi(r(e.data,n.data),n.itemSize,n.offset,n.normalized);else{let e=Ut(n.type,n.array);i=new(n.isInstancedBufferAttribute?to:Ti)(e,n.itemSize,n.normalized)}n.name!==void 0&&(i.name=n.name),n.usage!==void 0&&i.setUsage(n.usage),a.setAttribute(t,i)}let c=e.data.morphAttributes;if(c)for(let t in c){let n=c[t],i=[];for(let t=0,a=n.length;t0){i=new du(new nu(t)),i.setCrossOrigin(this.crossOrigin);for(let t=0,n=e.length;t0){r=new du(this.manager),r.setCrossOrigin(this.crossOrigin);for(let t=0,r=e.length;t{let t=null,n=null;return e.boundingBox!==void 0&&(t=new ni().fromJSON(e.boundingBox)),e.boundingSphere!==void 0&&(n=new Ri().fromJSON(e.boundingSphere)),{...e,boundingBox:t,boundingSphere:n}}),a._instanceInfo=e.instanceInfo,a._availableInstanceIds=e._availableInstanceIds,a._availableGeometryIds=e._availableGeometryIds,a._nextIndexStart=e.nextIndexStart,a._nextVertexStart=e.nextVertexStart,a._geometryCount=e.geometryCount,a._maxInstanceCount=e.maxInstanceCount,a._maxVertexCount=e.maxVertexCount,a._maxIndexCount=e.maxIndexCount,a._geometryInitialized=e.geometryInitialized,a._matricesTexture=c(e.matricesTexture.uuid),a._indirectTexture=c(e.indirectTexture.uuid),e.colorsTexture!==void 0&&(a._colorsTexture=c(e.colorsTexture.uuid)),e.boundingSphere!==void 0&&(a.boundingSphere=new Ri().fromJSON(e.boundingSphere)),e.boundingBox!==void 0&&(a.boundingBox=new ni().fromJSON(e.boundingBox));break;case`LOD`:a=new ga;break;case`Line`:a=new Yo(o(e.geometry),s(e.material));break;case`LineLoop`:a=new es(o(e.geometry),s(e.material));break;case`LineSegments`:a=new $o(o(e.geometry),s(e.material));break;case`PointCloud`:case`Points`:a=new os(o(e.geometry),s(e.material));break;case`Sprite`:a=new fa(s(e.material));break;case`Group`:a=new jr;break;case`Bone`:a=new Xa;break;default:a=new Ar}if(a.uuid=e.uuid,e.name!==void 0&&(a.name=e.name),e.matrix===void 0?(e.position!==void 0&&a.position.fromArray(e.position),e.rotation!==void 0&&a.rotation.fromArray(e.rotation),e.quaternion!==void 0&&a.quaternion.fromArray(e.quaternion),e.scale!==void 0&&a.scale.fromArray(e.scale)):(a.matrix.fromArray(e.matrix),e.matrixAutoUpdate!==void 0&&(a.matrixAutoUpdate=e.matrixAutoUpdate),a.matrixAutoUpdate&&a.matrix.decompose(a.position,a.quaternion,a.scale)),e.up!==void 0&&a.up.fromArray(e.up),e.pivot!==void 0&&(a.pivot=new q().fromArray(e.pivot)),e.morphTargetDictionary!==void 0&&(a.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),e.morphTargetInfluences!==void 0&&(a.morphTargetInfluences=e.morphTargetInfluences.slice()),e.castShadow!==void 0&&(a.castShadow=e.castShadow),e.receiveShadow!==void 0&&(a.receiveShadow=e.receiveShadow),e.shadow&&(e.shadow.intensity!==void 0&&(a.shadow.intensity=e.shadow.intensity),e.shadow.bias!==void 0&&(a.shadow.bias=e.shadow.bias),e.shadow.normalBias!==void 0&&(a.shadow.normalBias=e.shadow.normalBias),e.shadow.radius!==void 0&&(a.shadow.radius=e.shadow.radius),e.shadow.mapSize!==void 0&&a.shadow.mapSize.fromArray(e.shadow.mapSize),e.shadow.camera!==void 0&&(a.shadow.camera=this.parseObject(e.shadow.camera))),e.visible!==void 0&&(a.visible=e.visible),e.frustumCulled!==void 0&&(a.frustumCulled=e.frustumCulled),e.renderOrder!==void 0&&(a.renderOrder=e.renderOrder),e.static!==void 0&&(a.static=e.static),e.userData!==void 0&&(a.userData=e.userData),e.layers!==void 0&&(a.layers.mask=e.layers),e.children!==void 0){let o=e.children;for(let e=0;e`u`&&G(`ImageBitmapLoader: createImageBitmap() not supported.`),typeof fetch>`u`&&G(`ImageBitmapLoader: fetch() not supported.`),this.options={premultiplyAlpha:`none`},this._abortController=new AbortController}setOptions(e){return this.options=e,this}load(e,t,n,r){e===void 0&&(e=``),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let i=this,a=eu.get(`image-bitmap:${e}`);if(a!==void 0){if(i.manager.itemStart(e),a.then){a.then(n=>{Yu.has(a)===!0?(r&&r(Yu.get(a)),i.manager.itemError(e),i.manager.itemEnd(e)):(t&&t(n),i.manager.itemEnd(e))});return}setTimeout(function(){t&&t(a),i.manager.itemEnd(e)},0);return}let o={};o.credentials=this.crossOrigin===`anonymous`?`same-origin`:`include`,o.headers=this.requestHeader,o.signal=typeof AbortSignal.any==`function`?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;let s=fetch(e,o).then(function(e){return e.blob()}).then(function(e){return createImageBitmap(e,Object.assign(i.options,{colorSpaceConversion:`none`}))}).then(function(n){eu.add(`image-bitmap:${e}`,n),t&&t(n),i.manager.itemEnd(e)}).catch(function(t){r&&r(t),Yu.set(s,t),eu.remove(`image-bitmap:${e}`),i.manager.itemError(e),i.manager.itemEnd(e)});eu.add(`image-bitmap:${e}`,s),i.manager.itemStart(e)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},Zu,Qu=class{static getContext(){return Zu===void 0&&(Zu=new(window.AudioContext||window.webkitAudioContext)),Zu}static setContext(e){Zu=e}},$u=class extends iu{constructor(e){super(e)}load(e,t,n,r){let i=this,a=new su(this.manager);a.setResponseType(`arraybuffer`),a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(n){try{let r=n.slice(0),a=Qu.getContext(),s=e+`#decode`;i.manager.itemStart(s),a.decodeAudioData(r,function(e){t(e),i.manager.itemEnd(s)}).catch(function(e){o(e),i.manager.itemEnd(s)})}catch(e){o(e)}},n,r);function o(t){r?r(t):$t(t),i.manager.itemError(e)}}},ed=new J,td=new J,nd=new J,rd=class{constructor(){this.type=`StereoCamera`,this.aspect=1,this.eyeSep=.064,this.cameraL=new Ou,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Ou,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(e){let t=this._cache;if(t.focus!==e.focus||t.fov!==e.fov||t.aspect!==e.aspect*this.aspect||t.near!==e.near||t.far!==e.far||t.zoom!==e.zoom||t.eyeSep!==this.eyeSep){t.focus=e.focus,t.fov=e.fov,t.aspect=e.aspect*this.aspect,t.near=e.near,t.far=e.far,t.zoom=e.zoom,t.eyeSep=this.eyeSep,nd.copy(e.projectionMatrix);let n=t.eyeSep/2,r=n*t.near/t.focus,i=t.near*Math.tan(sn*t.fov*.5)/t.zoom,a,o;td.elements[12]=-n,ed.elements[12]=n,a=-i*t.aspect+r,o=i*t.aspect+r,nd.elements[0]=2*t.near/(o-a),nd.elements[8]=(o+a)/(o-a),this.cameraL.projectionMatrix.copy(nd),a=-i*t.aspect-r,o=i*t.aspect-r,nd.elements[0]=2*t.near/(o-a),nd.elements[8]=(o+a)/(o-a),this.cameraR.projectionMatrix.copy(nd)}this.cameraL.matrixWorld.copy(e.matrixWorld).multiply(td),this.cameraR.matrixWorld.copy(e.matrixWorld).multiply(ed)}},id=-90,ad=1,od=class extends Ar{constructor(e,t,n){super(),this.type=`CubeCamera`,this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let r=new Ou(id,ad,e,t);r.layers=this.layers,this.add(r);let i=new Ou(id,ad,e,t);i.layers=this.layers,this.add(i);let a=new Ou(id,ad,e,t);a.layers=this.layers,this.add(a);let o=new Ou(id,ad,e,t);o.layers=this.layers,this.add(o);let s=new Ou(id,ad,e,t);s.layers=this.layers,this.add(s);let c=new Ou(id,ad,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,r,i,a,o,s]=t;for(let e of t)this.remove(e);if(e===2e3)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.lookAt(-1,0,0),i.up.set(0,0,-1),i.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),s.up.set(0,1,0),s.lookAt(0,0,-1);else if(e===2001)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.lookAt(1,0,0),i.up.set(0,0,1),i.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),s.up.set(0,-1,0),s.lookAt(0,0,-1);else throw Error(`THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: `+e);for(let e of t)this.add(e),e.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[i,a,o,s,c,l]=this.children,u=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;let m=n.texture.generateMipmaps;n.texture.generateMipmaps=!1;let h=!1;h=e.isWebGLRenderer===!0?e.state.buffers.depth.getReversed():e.reversedDepthBuffer,e.setRenderTarget(n,0,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,i),e.setRenderTarget(n,1,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,2,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,3,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,4,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.generateMipmaps=m,e.setRenderTarget(n,5,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(u,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},sd=class extends Ou{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}},cd=class{constructor(){this._previousTime=0,this._currentTime=0,this._startTime=performance.now(),this._delta=0,this._elapsed=0,this._timescale=1,this._document=null,this._pageVisibilityHandler=null}connect(e){this._document=e,e.hidden!==void 0&&(this._pageVisibilityHandler=ld.bind(this),e.addEventListener(`visibilitychange`,this._pageVisibilityHandler,!1))}disconnect(){this._pageVisibilityHandler!==null&&(this._document.removeEventListener(`visibilitychange`,this._pageVisibilityHandler),this._pageVisibilityHandler=null),this._document=null}getDelta(){return this._delta/1e3}getElapsed(){return this._elapsed/1e3}getTimescale(){return this._timescale}setTimescale(e){return this._timescale=e,this}reset(){return this._currentTime=performance.now()-this._startTime,this}dispose(){this.disconnect()}update(e){return this._pageVisibilityHandler!==null&&this._document.hidden===!0?this._delta=0:(this._previousTime=this._currentTime,this._currentTime=(e===void 0?performance.now():e)-this._startTime,this._delta=(this._currentTime-this._previousTime)*this._timescale,this._elapsed+=this._delta),this}};function ld(){this._document.hidden===!1&&this.reset()}var ud=new q,dd=new Mn,fd=new q,pd=new q,md=new q,hd=class extends Ar{constructor(){super(),this.type=`AudioListener`,this.context=Qu.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._timer=new cd}getInput(){return this.gain}removeFilter(){return this.filter!==null&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(e){return this.filter===null?this.gain.disconnect(this.context.destination):(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)),this.filter=e,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(e){return this.gain.gain.setTargetAtTime(e,this.context.currentTime,.01),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this._timer.update();let t=this.context.listener;if(this.timeDelta=this._timer.getDelta(),this.matrixWorld.decompose(ud,dd,fd),pd.set(0,0,-1).applyQuaternion(dd),md.set(0,1,0).applyQuaternion(dd),t.positionX){let e=this.context.currentTime+this.timeDelta;t.positionX.linearRampToValueAtTime(ud.x,e),t.positionY.linearRampToValueAtTime(ud.y,e),t.positionZ.linearRampToValueAtTime(ud.z,e),t.forwardX.linearRampToValueAtTime(pd.x,e),t.forwardY.linearRampToValueAtTime(pd.y,e),t.forwardZ.linearRampToValueAtTime(pd.z,e),t.upX.linearRampToValueAtTime(md.x,e),t.upY.linearRampToValueAtTime(md.y,e),t.upZ.linearRampToValueAtTime(md.z,e)}else t.setPosition(ud.x,ud.y,ud.z),t.setOrientation(pd.x,pd.y,pd.z,md.x,md.y,md.z)}},gd=class extends Ar{constructor(e){super(),this.type=`Audio`,this.listener=e,this.context=e.context,this.gain=this.context.createGain(),this.gain.connect(e.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType=`empty`,this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(e){return this.hasPlaybackControl=!1,this.sourceType=`audioNode`,this.source=e,this.connect(),this}setMediaElementSource(e){return this.hasPlaybackControl=!1,this.sourceType=`mediaNode`,this.source=this.context.createMediaElementSource(e),this.connect(),this}setMediaStreamSource(e){return this.hasPlaybackControl=!1,this.sourceType=`mediaStreamNode`,this.source=this.context.createMediaStreamSource(e),this.connect(),this}setBuffer(e){return this.buffer=e,this.sourceType=`buffer`,this.autoplay&&this.play(),this}play(e=0){if(this.isPlaying===!0){G(`Audio: Audio is already playing.`);return}if(this.hasPlaybackControl===!1){G(`Audio: this Audio has no playback control.`);return}this._startedAt=this.context.currentTime+e;let t=this.context.createBufferSource();return t.buffer=this.buffer,t.loop=this.loop,t.loopStart=this.loopStart,t.loopEnd=this.loopEnd,t.onended=this.onEnded.bind(this),t.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=t,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(this.hasPlaybackControl===!1){G(`Audio: this Audio has no playback control.`);return}return this.isPlaying===!0&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,this.loop===!0&&(this._progress%=this.duration||this.buffer.duration),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(e=0){if(this.hasPlaybackControl===!1){G(`Audio: this Audio has no playback control.`);return}return this._progress=0,this.source!==null&&(this.source.stop(this.context.currentTime+e),this.source.onended=null),this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let e=1,t=this.filters.length;e0){this.source.disconnect(this.filters[0]);for(let e=1,t=this.filters.length;e0&&this._mixBufferRegionAdditive(n,r,this._addIndex*t,1,t);for(let e=t,i=t+t;e!==i;++e)if(n[e]!==n[e+t]){o.setValue(n,r);break}}saveOriginalState(){let e=this.binding,t=this.buffer,n=this.valueSize,r=n*this._origIndex;e.getValue(t,r);for(let e=n,i=r;e!==i;++e)t[e]=t[r+e%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){let e=this.valueSize*3;this.binding.setValue(this.buffer,e)}_setAdditiveIdentityNumeric(){let e=this._addIndex*this.valueSize,t=e+this.valueSize;for(let n=e;n=.5)for(let r=0;r!==i;++r)e[t+r]=e[n+r]}_slerp(e,t,n,r){Mn.slerpFlat(e,t,e,t,e,n,r)}_slerpAdditive(e,t,n,r,i){let a=this._workIndex*i;Mn.multiplyQuaternionsFlat(e,a,e,t,e,n),Mn.slerpFlat(e,t,e,t,e,a,r)}_lerp(e,t,n,r,i){let a=1-r;for(let o=0;o!==i;++o){let i=t+o;e[i]=e[i]*a+e[n+o]*r}}_lerpAdditive(e,t,n,r,i){for(let a=0;a!==i;++a){let i=t+a;e[i]=e[i]+e[n+a]*r}}},wd=`\\[\\]\\.:\\/`,Td=RegExp(`[\\[\\]\\.:\\/]`,`g`),Ed=`[^\\[\\]\\.:\\/]`,Dd=`[^`+wd.replace(`\\.`,``)+`]`,Od=`((?:WC+[\\/:])*)`.replace(`WC`,Ed),kd=`(WCOD+)?`.replace(`WCOD`,Dd),Ad=`(?:\\.(WC+)(?:\\[(.+)\\])?)?`.replace(`WC`,Ed),jd=`\\.(WC+)(?:\\[(.+)\\])?`.replace(`WC`,Ed),Md=RegExp(`^`+Od+kd+Ad+jd+`$`),Nd=[`material`,`materials`,`bones`,`map`],Pd=class{constructor(e,t,n){let r=n||Fd.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,r)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,r=this._bindings[n];r!==void 0&&r.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let r=this._targetGroup.nCachedObjects_,i=n.length;r!==i;++r)n[r].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].unbind()}},Fd=class e{constructor(t,n,r){this.path=n,this.parsedPath=r||e.parseTrackName(n),this.node=e.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,n,r){return t&&t.isAnimationObjectGroup?new e.Composite(t,n,r):new e(t,n,r)}static sanitizeNodeName(e){return e.replace(/\s/g,`_`).replace(Td,``)}static parseTrackName(e){let t=Md.exec(e);if(t===null)throw Error(`PropertyBinding: Cannot parse trackName: `+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},r=n.nodeName&&n.nodeName.lastIndexOf(`.`);if(r!==void 0&&r!==-1){let e=n.nodeName.substring(r+1);Nd.indexOf(e)!==-1&&(n.nodeName=n.nodeName.substring(0,r),n.objectName=e)}if(n.propertyName===null||n.propertyName.length===0)throw Error(`PropertyBinding: can not parse propertyName from trackName: `+e);return n}static findNode(e,t){if(t===void 0||t===``||t===`.`||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let n=e.skeleton.getBoneByName(t);if(n!==void 0)return n}if(e.children){let n=function(e){for(let r=0;r=i){let a=i++,l=e[a];t[l.uuid]=c,e[c]=l,t[s]=a,e[a]=o;for(let e=0,t=r;e!==t;++e){let t=n[e],r=t[a],i=t[c];t[c]=r,t[a]=i}}}this.nCachedObjects_=i}uncache(){let e=this._objects,t=this._indicesByUUID,n=this._bindings,r=n.length,i=this.nCachedObjects_,a=e.length;for(let o=0,s=arguments.length;o!==s;++o){let s=arguments[o].uuid,c=t[s];if(c!==void 0)if(delete t[s],c0&&(t[o.uuid]=c),e[c]=o,e.pop();for(let e=0,t=r;e!==t;++e){let t=n[e];t[c]=t[i],t.pop()}}}this.nCachedObjects_=i}subscribe_(e,t){let n=this._bindingsIndicesByPath,r=n[e],i=this._bindings;if(r!==void 0)return i[r];let a=this._paths,o=this._parsedPaths,s=this._objects,c=s.length,l=this.nCachedObjects_,u=Array(c);r=i.length,n[e]=r,a.push(e),o.push(t),i.push(u);for(let n=l,r=s.length;n!==r;++n){let r=s[n];u[n]=new Fd(r,e,t)}return u}unsubscribe_(e){let t=this._bindingsIndicesByPath,n=t[e];if(n!==void 0){let r=this._paths,i=this._parsedPaths,a=this._bindings,o=a.length-1,s=a[o],c=e[o];t[c]=n,a[n]=s,a.pop(),i[n]=i[o],i.pop(),r[n]=r[o],r.pop()}}},Ld=class{constructor(e,t,n=null,r=t.blendMode){this._mixer=e,this._clip=t,this._localRoot=n,this.blendMode=r;let i=t.tracks,a=i.length,o=Array(a),s={endingStart:at,endingEnd:at};for(let e=0;e!==a;++e){let t=i[e].createInterpolant(null);o[e]=t,t.settings&&Object.assign(s,t.settings),t.settings=s}this._interpolantSettings=s,this._interpolants=o,this._propertyBindings=Array(a),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=$e,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(e){return this._startTime=e,this}setLoop(e,t){return this.loop=e,this.repetitions=t,this}setEffectiveWeight(e){return this.weight=e,this._effectiveWeight=this.enabled?e:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(e){return this._scheduleFading(e,0,1)}fadeOut(e){return this._scheduleFading(e,1,0)}crossFadeFrom(e,t,n=!1){if(e.fadeOut(t),this.fadeIn(t),n===!0){let n=this._clip.duration,r=e._clip.duration,i=r/n,a=n/r;e.warp(1,i,t),this.warp(a,1,t)}return this}crossFadeTo(e,t,n=!1){return e.crossFadeFrom(this,t,n)}stopFading(){let e=this._weightInterpolant;return e!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}setEffectiveTimeScale(e){return this.timeScale=e,this._effectiveTimeScale=this.paused?0:e,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(e){return this.timeScale=this._clip.duration/e,this.stopWarping()}syncWith(e){return this.time=e.time,this.timeScale=e.timeScale,this.stopWarping()}halt(e){return this.warp(this._effectiveTimeScale,0,e)}warp(e,t,n){let r=this._mixer,i=r.time,a=this.timeScale,o=this._timeScaleInterpolant;o===null&&(o=r._lendControlInterpolant(),this._timeScaleInterpolant=o);let s=o.parameterPositions,c=o.sampleValues;return s[0]=i,s[1]=i+n,c[0]=e/a,c[1]=t/a,this}stopWarping(){let e=this._timeScaleInterpolant;return e!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(e,t,n,r){if(!this.enabled){this._updateWeight(e);return}let i=this._startTime;if(i!==null){let r=(e-i)*n;r<0||n===0?t=0:(this._startTime=null,t=n*r)}t*=this._updateTimeScale(e);let a=this._updateTime(t),o=this._updateWeight(e);if(o>0){let e=this._interpolants,t=this._propertyBindings;switch(this.blendMode){case lt:for(let n=0,r=e.length;n!==r;++n)e[n].evaluate(a),t[n].accumulateAdditive(o);break;case ct:default:for(let n=0,i=e.length;n!==i;++n)e[n].evaluate(a),t[n].accumulate(r,o)}}}_updateWeight(e){let t=0;if(this.enabled){t=this.weight;let n=this._weightInterpolant;if(n!==null){let r=n.evaluate(e)[0];t*=r,e>n.parameterPositions[1]&&(this.stopFading(),r===0&&(this.enabled=!1))}}return this._effectiveWeight=t,t}_updateTimeScale(e){let t=0;if(!this.paused){t=this.timeScale;let n=this._timeScaleInterpolant;if(n!==null){let r=n.evaluate(e)[0];t*=r,e>n.parameterPositions[1]&&(this.stopWarping(),t===0?this.paused=!0:this.timeScale=t)}}return this._effectiveTimeScale=t,t}_updateTime(e){let t=this._clip.duration,n=this.loop,r=this.time+e,i=this._loopCount,a=n===et;if(e===0)return i===-1?r:a&&(i&1)==1?t-r:r;if(n===2200){i===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));handle_stop:{if(r>=t)r=t;else if(r<0)r=0;else{this.time=r;break handle_stop}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=r,this._mixer.dispatchEvent({type:`finished`,action:this,direction:e<0?-1:1})}}else{if(i===-1&&(e>=0?(i=0,this._setEndings(!0,this.repetitions===0,a)):this._setEndings(this.repetitions===0,!0,a)),r>=t||r<0){let n=Math.floor(r/t);r-=t*n,i+=Math.abs(n);let o=this.repetitions-i;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,r=e>0?t:0,this.time=r,this._mixer.dispatchEvent({type:`finished`,action:this,direction:e>0?1:-1});else{if(o===1){let t=e<0;this._setEndings(t,!t,a)}else this._setEndings(!1,!1,a);this._loopCount=i,this.time=r,this._mixer.dispatchEvent({type:`loop`,action:this,loopDelta:n})}}else this._loopCount=i,this.time=r;if(a&&(i&1)==1)return t-r}return r}_setEndings(e,t,n){let r=this._interpolantSettings;n?(r.endingStart=ot,r.endingEnd=ot):(e?r.endingStart=this.zeroSlopeAtStart?ot:at:r.endingStart=st,t?r.endingEnd=this.zeroSlopeAtEnd?ot:at:r.endingEnd=st)}_scheduleFading(e,t,n){let r=this._mixer,i=r.time,a=this._weightInterpolant;a===null&&(a=r._lendControlInterpolant(),this._weightInterpolant=a);let o=a.parameterPositions,s=a.sampleValues;return o[0]=i,s[0]=t,o[1]=i+e,s[1]=n,this}},Rd=new Float32Array(1),zd=class extends rn{constructor(e){super(),this._root=e,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}_bindAction(e,t){let n=e._localRoot||this._root,r=e._clip.tracks,i=r.length,a=e._propertyBindings,o=e._interpolants,s=n.uuid,c=this._bindingsByRootAndName,l=c[s];l===void 0&&(l={},c[s]=l);for(let e=0;e!==i;++e){let i=r[e],c=i.name,u=l[c];if(u!==void 0)++u.referenceCount,a[e]=u;else{if(u=a[e],u!==void 0){u._cacheIndex===null&&(++u.referenceCount,this._addInactiveBinding(u,s,c));continue}let r=t&&t._propertyBindings[e].binding.parsedPath;u=new Cd(Fd.create(n,c,r),i.ValueTypeName,i.getValueSize()),++u.referenceCount,this._addInactiveBinding(u,s,c),a[e]=u}o[e].resultBuffer=u.buffer}}_activateAction(e){if(!this._isActiveAction(e)){if(e._cacheIndex===null){let t=(e._localRoot||this._root).uuid,n=e._clip.uuid,r=this._actionsByClip[n];this._bindAction(e,r&&r.knownActions[0]),this._addInactiveAction(e,n,t)}let t=e._propertyBindings;for(let e=0,n=t.length;e!==n;++e){let n=t[e];n.useCount++===0&&(this._lendBinding(n),n.saveOriginalState())}this._lendAction(e)}}_deactivateAction(e){if(this._isActiveAction(e)){let t=e._propertyBindings;for(let e=0,n=t.length;e!==n;++e){let n=t[e];--n.useCount===0&&(n.restoreOriginalState(),this._takeBackBinding(n))}this._takeBackAction(e)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;let e=this;this.stats={actions:{get total(){return e._actions.length},get inUse(){return e._nActiveActions}},bindings:{get total(){return e._bindings.length},get inUse(){return e._nActiveBindings}},controlInterpolants:{get total(){return e._controlInterpolants.length},get inUse(){return e._nActiveControlInterpolants}}}}_isActiveAction(e){let t=e._cacheIndex;return t!==null&&t=0;--n)e[n].stop();return this}update(e){e*=this.timeScale;let t=this._actions,n=this._nActiveActions,r=this.time+=e,i=Math.sign(e),a=this._accuIndex^=1;for(let o=0;o!==n;++o)t[o]._update(r,e,i,a);let o=this._bindings,s=this._nActiveBindings;for(let e=0;e!==s;++e)o[e].apply(a);return this}setTime(e){this.time=0;for(let e=0;e=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y}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}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))}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}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,ef).distanceTo(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}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)}},nf=new q,rf=new q,af=new q,of=new q,sf=new q,cf=new q,lf=new q,uf=class{constructor(e=new q,t=new q){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){nf.subVectors(e,this.start),rf.subVectors(this.end,this.start);let n=rf.dot(rf);if(n===0)return 0;let r=rf.dot(nf)/n;return t&&(r=un(r,0,1)),r}closestPointToPoint(e,t,n){let r=this.closestPointToPointParameter(e,t);return this.delta(n).multiplyScalar(r).add(this.start)}distanceSqToLine3(e,t=cf,n=lf){let r=1e-8*1e-8,i,a,o=this.start,s=e.start,c=this.end,l=e.end;af.subVectors(c,o),of.subVectors(l,s),sf.subVectors(o,s);let u=af.dot(af),d=of.dot(of),f=of.dot(sf);if(u<=r&&d<=r)return t.copy(o),n.copy(s),t.sub(n),t.dot(t);if(u<=r)i=0,a=f/d,a=un(a,0,1);else{let e=af.dot(sf);if(d<=r)a=0,i=un(-e/u,0,1);else{let t=af.dot(of),n=u*d-t*t;i=n===0?0:un((t*f-e*d)/n,0,1),a=(t*i+f)/d,a<0?(a=0,i=un(-e/u,0,1)):a>1&&(a=1,i=un((t-e)/u,0,1))}}return t.copy(o).addScaledVector(af,i),n.copy(s).addScaledVector(of,a),t.distanceToSquared(n)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},df=new q,ff=class extends Ar{constructor(e,t){super(),this.light=e,this.matrixAutoUpdate=!1,this.color=t,this.type=`SpotLightHelper`;let n=new Ki,r=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let e=0,t=1;e<32;e++,t++){let n=e/32*Math.PI*2,i=t/32*Math.PI*2;r.push(Math.cos(n),Math.sin(n),1,Math.cos(i),Math.sin(i),1)}n.setAttribute(`position`,new Pi(r,3));let i=new Vo({fog:!1,toneMapped:!1});this.cone=new $o(n,i),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);let e=this.light.distance?this.light.distance:1e3,t=e*Math.tan(this.light.angle);this.cone.scale.set(t,t,e),df.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(df),this.color===void 0?this.cone.material.color.copy(this.light.color):this.cone.material.color.set(this.color)}},pf=new q,mf=new J,hf=new J,gf=class extends $o{constructor(e){let t=_f(e),n=new Ki,r=[],i=[];for(let e=0;e1)for(let n=0;n.99999)this.quaternion.set(0,0,0,1);else if(e.y<-.99999)this.quaternion.set(1,0,0,0);else{Lf.set(e.z,0,-e.x).normalize();let t=Math.acos(e.y);this.quaternion.setFromAxisAngle(Lf,t)}}setLength(e,t=e*.2,n=t*.2){this.line.scale.set(1,Math.max(1e-4,e-t),1),this.line.updateMatrix(),this.cone.scale.set(n,t,n),this.cone.position.y=e,this.cone.updateMatrix()}setColor(e){this.line.material.color.set(e),this.cone.material.color.set(e)}copy(e){return super.copy(e,!1),this.line.copy(e.line),this.cone.copy(e.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}},Vf=class extends $o{constructor(e=1){let t=[0,0,0,e,0,0,0,0,0,0,e,0,0,0,0,0,0,e],n=[1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],r=new Ki;r.setAttribute(`position`,new Pi(t,3)),r.setAttribute(`color`,new Pi(n,3));let i=new Vo({vertexColors:!0,toneMapped:!1});super(r,i),this.type=`AxesHelper`}setColors(e,t,n){let r=new Y,i=this.geometry.attributes.color.array;return r.set(e),r.toArray(i,0),r.toArray(i,3),r.set(t),r.toArray(i,6),r.toArray(i,9),r.set(n),r.toArray(i,12),r.toArray(i,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},Hf=class{constructor(){this.type=`ShapePath`,this.color=new Y,this.subPaths=[],this.currentPath=null}moveTo(e,t){return this.currentPath=new sc,this.subPaths.push(this.currentPath),this.currentPath.moveTo(e,t),this}lineTo(e,t){return this.currentPath.lineTo(e,t),this}quadraticCurveTo(e,t,n,r){return this.currentPath.quadraticCurveTo(e,t,n,r),this}bezierCurveTo(e,t,n,r,i,a){return this.currentPath.bezierCurveTo(e,t,n,r,i,a),this}splineThru(e){return this.currentPath.splineThru(e),this}toShapes(e){function t(e){let t=[];for(let n=0,r=e.length;n2**-52){if(c<0&&(n=t[a],s=-s,o=t[i],c=-c),e.yo.y)continue;if(e.y===n.y){if(e.x===n.x)return!0}else{let t=c*(e.x-n.x)-s*(e.y-n.y);if(t===0)return!0;if(t<0)continue;r=!r}}else{if(e.y!==n.y)continue;if(o.x<=e.x&&e.x<=n.x||n.x<=e.x&&e.x<=o.x)return!0}}return r}let r=Uc.isClockWise,i=this.subPaths;if(i.length===0)return[];let a,o,s,c=[];if(i.length===1)return o=i[0],s=new cc,s.curves=o.curves,c.push(s),c;let l=!r(i[0].getPoints());l=e?!l:l;let u=[],d=[],f=[],p=0,m;d[p]=void 0,f[p]=[];for(let t=0,n=i.length;t1){let e=!1,t=0;for(let e=0,t=d.length;e0&&e===!1&&(f=u)}let h;for(let e=0,t=d.length;et?(e.repeat.x=1,e.repeat.y=n/t,e.offset.x=0,e.offset.y=(1-e.repeat.y)/2):(e.repeat.x=t/n,e.repeat.y=1,e.offset.x=(1-e.repeat.x)/2,e.offset.y=0),e}function Gf(e,t){let n=e.image&&e.image.width?e.image.width/e.image.height:1;return n>t?(e.repeat.x=t/n,e.repeat.y=1,e.offset.x=(1-e.repeat.x)/2,e.offset.y=0):(e.repeat.x=1,e.repeat.y=n/t,e.offset.x=0,e.offset.y=(1-e.repeat.y)/2),e}function Kf(e){return e.repeat.x=1,e.repeat.y=1,e.offset.x=0,e.offset.y=0,e}function qf(e,t,n,r){let i=Jf(r);switch(n){case ce:return e*t;case fe:return e*t/i.components*i.byteLength;case pe:return e*t/i.components*i.byteLength;case me:return e*t*2/i.components*i.byteLength;case he:return e*t*2/i.components*i.byteLength;case H:return e*t*3/i.components*i.byteLength;case le:return e*t*4/i.components*i.byteLength;case _e:return e*t*4/i.components*i.byteLength;case ve:case ye:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case be:case xe:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case U:case we:return Math.max(e,16)*Math.max(t,8)/4;case Se:case Ce:return Math.max(e,8)*Math.max(t,8)/2;case Te:case W:case De:case Oe:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case Ee:case ke:case Ae:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case je:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case Me:return Math.floor((e+4)/5)*Math.floor((t+3)/4)*16;case Ne:return Math.floor((e+4)/5)*Math.floor((t+4)/5)*16;case Pe:return Math.floor((e+5)/6)*Math.floor((t+4)/5)*16;case Fe:return Math.floor((e+5)/6)*Math.floor((t+5)/6)*16;case Ie:return Math.floor((e+7)/8)*Math.floor((t+4)/5)*16;case Le:return Math.floor((e+7)/8)*Math.floor((t+5)/6)*16;case Re:return Math.floor((e+7)/8)*Math.floor((t+7)/8)*16;case ze:return Math.floor((e+9)/10)*Math.floor((t+4)/5)*16;case Be:return Math.floor((e+9)/10)*Math.floor((t+5)/6)*16;case Ve:return Math.floor((e+9)/10)*Math.floor((t+7)/8)*16;case He:return Math.floor((e+9)/10)*Math.floor((t+9)/10)*16;case Ue:return Math.floor((e+11)/12)*Math.floor((t+9)/10)*16;case We:return Math.floor((e+11)/12)*Math.floor((t+11)/12)*16;case Ge:case Ke:case qe:return Math.ceil(e/4)*Math.ceil(t/4)*16;case Je:case Ye:return Math.ceil(e/4)*Math.ceil(t/4)*8;case Xe:case Ze:return Math.ceil(e/4)*Math.ceil(t/4)*16}throw Error(`Unable to determine texture byte length for ${n} format.`)}function Jf(e){switch(e){case L:case ee:return{byteLength:1,components:1};case te:case R:case ne:return{byteLength:2,components:1};case re:case ie:return{byteLength:2,components:4};case B:case z:case V:return{byteLength:4,components:1};case oe:case se:return{byteLength:4,components:3}}throw Error(`Unknown texture type ${e}.`)}var Yf=class{static contain(e,t){return Wf(e,t)}static cover(e,t){return Gf(e,t)}static fill(e){return Kf(e)}static getByteLength(e,t,n,r){return qf(e,t,n,r)}};typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`register`,{detail:{revision:`184`}})),typeof window<`u`&&(window.__THREE__?G(`WARNING: Multiple instances of Three.js being imported.`):window.__THREE__=`184`);var Xf=s({ACESFilmicToneMapping:()=>4,AddEquation:()=>100,AddOperation:()=>2,AdditiveAnimationBlendMode:()=>lt,AdditiveBlending:()=>2,AgXToneMapping:()=>6,AlphaFormat:()=>ce,AlwaysCompare:()=>519,AlwaysDepth:()=>1,AlwaysStencilFunc:()=>519,AmbientLight:()=>Iu,AnimationAction:()=>Ld,AnimationClip:()=>Zl,AnimationLoader:()=>cu,AnimationMixer:()=>zd,AnimationObjectGroup:()=>Id,AnimationUtils:()=>Ll,ArcCurve:()=>Ps,ArrayCamera:()=>sd,ArrowHelper:()=>Bf,AttachedBindMode:()=>S,Audio:()=>gd,AudioAnalyser:()=>Sd,AudioContext:()=>Qu,AudioListener:()=>hd,AudioLoader:()=>$u,AxesHelper:()=>Vf,BackSide:()=>1,BasicDepthPacking:()=>ut,BasicShadowMap:()=>0,BatchedMesh:()=>Bo,BezierInterpolant:()=>Hl,Bone:()=>Xa,BooleanKeyframeTrack:()=>Wl,Box2:()=>tf,Box3:()=>ni,Box3Helper:()=>Ff,BoxGeometry:()=>bs,BoxHelper:()=>Pf,BufferAttribute:()=>Ti,BufferGeometry:()=>Ki,BufferGeometryLoader:()=>Uu,ByteType:()=>ee,Cache:()=>eu,Camera:()=>wu,CameraHelper:()=>jf,CanvasTexture:()=>hs,CapsuleGeometry:()=>xs,CatmullRomCurve3:()=>Vs,CineonToneMapping:()=>3,CircleGeometry:()=>Ss,ClampToEdgeWrapping:()=>T,Clock:()=>Xd,Color:()=>Y,ColorKeyframeTrack:()=>Gl,ColorManagement:()=>Bn,Compatibility:()=>Bt,CompressedArrayTexture:()=>fs,CompressedCubeTexture:()=>ps,CompressedTexture:()=>ds,CompressedTextureLoader:()=>lu,ConeGeometry:()=>ws,ConstantAlphaFactor:()=>213,ConstantColorFactor:()=>211,Controls:()=>Uf,CubeCamera:()=>od,CubeDepthTexture:()=>vs,CubeReflectionMapping:()=>301,CubeRefractionMapping:()=>302,CubeTexture:()=>ms,CubeTextureLoader:()=>fu,CubeUVReflectionMapping:()=>306,CubicBezierCurve:()=>Qs,CubicBezierCurve3:()=>$s,CubicInterpolant:()=>zl,CullFaceBack:()=>1,CullFaceFront:()=>2,CullFaceFrontBack:()=>3,CullFaceNone:()=>0,Curve:()=>Ms,CurvePath:()=>oc,CustomBlending:()=>5,CustomToneMapping:()=>5,CylinderGeometry:()=>Cs,Cylindrical:()=>Qd,Data3DTexture:()=>nr,DataArrayTexture:()=>er,DataTexture:()=>Za,DataTextureLoader:()=>pu,DataUtils:()=>xi,DecrementStencilOp:()=>xt,DecrementWrapStencilOp:()=>Ct,DefaultLoadingManager:()=>ru,DepthFormat:()=>ue,DepthStencilFormat:()=>de,DepthTexture:()=>_s,DetachedBindMode:()=>C,DirectionalLight:()=>Fu,DirectionalLightHelper:()=>Of,DiscreteInterpolant:()=>Vl,DodecahedronGeometry:()=>Es,DoubleSide:()=>2,DstAlphaFactor:()=>206,DstColorFactor:()=>208,DynamicCopyUsage:()=>Mt,DynamicDrawUsage:()=>Et,DynamicReadUsage:()=>kt,EdgesGeometry:()=>js,EllipseCurve:()=>Ns,EqualCompare:()=>514,EqualDepth:()=>4,EqualStencilFunc:()=>514,EquirectangularReflectionMapping:()=>303,EquirectangularRefractionMapping:()=>304,Euler:()=>pr,EventDispatcher:()=>rn,ExternalTexture:()=>ys,ExtrudeGeometry:()=>Kc,FileLoader:()=>su,Float16BufferAttribute:()=>Ni,Float32BufferAttribute:()=>Pi,FloatType:()=>V,Fog:()=>Br,FogExp2:()=>zr,FramebufferTexture:()=>us,FrontSide:()=>0,Frustum:()=>vo,FrustumArray:()=>xo,GLBufferAttribute:()=>Gd,GLSL1:()=>`100`,GLSL3:()=>Pt,GreaterCompare:()=>516,GreaterDepth:()=>6,GreaterEqualCompare:()=>518,GreaterEqualDepth:()=>5,GreaterEqualStencilFunc:()=>518,GreaterStencilFunc:()=>516,GridHelper:()=>Cf,Group:()=>jr,HTMLTexture:()=>gs,HalfFloatType:()=>ne,HemisphereLight:()=>gu,HemisphereLightHelper:()=>Sf,IcosahedronGeometry:()=>Yc,ImageBitmapLoader:()=>Xu,ImageLoader:()=>du,ImageUtils:()=>Wn,IncrementStencilOp:()=>bt,IncrementWrapStencilOp:()=>St,InstancedBufferAttribute:()=>to,InstancedBufferGeometry:()=>Hu,InstancedInterleavedBuffer:()=>Wd,InstancedMesh:()=>lo,Int16BufferAttribute:()=>ki,Int32BufferAttribute:()=>ji,Int8BufferAttribute:()=>Ei,IntType:()=>z,InterleavedBuffer:()=>qi,InterleavedBufferAttribute:()=>Yi,Interpolant:()=>Rl,InterpolateBezier:()=>it,InterpolateDiscrete:()=>tt,InterpolateLinear:()=>nt,InterpolateSmooth:()=>rt,InterpolationSamplingMode:()=>zt,InterpolationSamplingType:()=>Rt,InvertStencilOp:()=>wt,KeepStencilOp:()=>vt,KeyframeTrack:()=>Ul,LOD:()=>ga,LatheGeometry:()=>Xc,Layers:()=>mr,LessCompare:()=>513,LessDepth:()=>2,LessEqualCompare:()=>515,LessEqualDepth:()=>3,LessEqualStencilFunc:()=>515,LessStencilFunc:()=>513,Light:()=>hu,LightProbe:()=>zu,Line:()=>Yo,Line3:()=>uf,LineBasicMaterial:()=>Vo,LineCurve:()=>ec,LineCurve3:()=>tc,LineDashedMaterial:()=>Al,LineLoop:()=>es,LineSegments:()=>$o,LinearFilter:()=>M,LinearInterpolant:()=>Bl,LinearMipMapLinearFilter:()=>I,LinearMipMapNearestFilter:()=>P,LinearMipmapLinearFilter:()=>F,LinearMipmapNearestFilter:()=>N,LinearSRGBColorSpace:()=>ht,LinearToneMapping:()=>1,LinearTransfer:()=>gt,Loader:()=>iu,LoaderUtils:()=>Vu,LoadingManager:()=>nu,LoopOnce:()=>Qe,LoopPingPong:()=>et,LoopRepeat:()=>$e,MOUSE:()=>b,Material:()=>Zi,MaterialBlending:()=>6,MaterialLoader:()=>Bu,MathUtils:()=>jn,Matrix2:()=>$d,Matrix3:()=>Fn,Matrix4:()=>J,MaxEquation:()=>104,Mesh:()=>La,MeshBasicMaterial:()=>Ta,MeshDepthMaterial:()=>Dl,MeshDistanceMaterial:()=>Ol,MeshLambertMaterial:()=>El,MeshMatcapMaterial:()=>kl,MeshNormalMaterial:()=>Tl,MeshPhongMaterial:()=>Cl,MeshPhysicalMaterial:()=>Sl,MeshStandardMaterial:()=>xl,MeshToonMaterial:()=>wl,MinEquation:()=>103,MirroredRepeatWrapping:()=>E,MixOperation:()=>1,MultiplyBlending:()=>4,MultiplyOperation:()=>0,NearestFilter:()=>D,NearestMipMapLinearFilter:()=>j,NearestMipMapNearestFilter:()=>k,NearestMipmapLinearFilter:()=>A,NearestMipmapNearestFilter:()=>O,NeutralToneMapping:()=>7,NeverCompare:()=>512,NeverDepth:()=>0,NeverStencilFunc:()=>512,NoBlending:()=>0,NoColorSpace:()=>``,NoNormalPacking:()=>``,NoToneMapping:()=>0,NormalAnimationBlendMode:()=>ct,NormalBlending:()=>1,NormalGAPacking:()=>`ga`,NormalRGPacking:()=>`rg`,NotEqualCompare:()=>517,NotEqualDepth:()=>7,NotEqualStencilFunc:()=>517,NumberKeyframeTrack:()=>Kl,Object3D:()=>Ar,ObjectLoader:()=>Gu,ObjectSpaceNormalMap:()=>1,OctahedronGeometry:()=>Zc,OneFactor:()=>201,OneMinusConstantAlphaFactor:()=>214,OneMinusConstantColorFactor:()=>212,OneMinusDstAlphaFactor:()=>207,OneMinusDstColorFactor:()=>209,OneMinusSrcAlphaFactor:()=>205,OneMinusSrcColorFactor:()=>203,OrthographicCamera:()=>Nu,PCFShadowMap:()=>1,PCFSoftShadowMap:()=>2,PMREMGenerator:()=>bp,Path:()=>sc,PerspectiveCamera:()=>Ou,Plane:()=>mo,PlaneGeometry:()=>Qc,PlaneHelper:()=>If,PointLight:()=>Mu,PointLightHelper:()=>vf,Points:()=>os,PointsMaterial:()=>ts,PolarGridHelper:()=>wf,PolyhedronGeometry:()=>Ts,PositionalAudio:()=>xd,PropertyBinding:()=>Fd,PropertyMixer:()=>Cd,QuadraticBezierCurve:()=>nc,QuadraticBezierCurve3:()=>rc,Quaternion:()=>Mn,QuaternionKeyframeTrack:()=>Jl,QuaternionLinearInterpolant:()=>ql,R11_EAC_Format:()=>De,RED_GREEN_RGTC2_Format:()=>Xe,RED_RGTC1_Format:()=>Je,REVISION:()=>`184`,RG11_EAC_Format:()=>ke,RGBADepthPacking:()=>dt,RGBAFormat:()=>le,RGBAIntegerFormat:()=>_e,RGBA_ASTC_10x10_Format:()=>He,RGBA_ASTC_10x5_Format:()=>ze,RGBA_ASTC_10x6_Format:()=>Be,RGBA_ASTC_10x8_Format:()=>Ve,RGBA_ASTC_12x10_Format:()=>Ue,RGBA_ASTC_12x12_Format:()=>We,RGBA_ASTC_4x4_Format:()=>je,RGBA_ASTC_5x4_Format:()=>Me,RGBA_ASTC_5x5_Format:()=>Ne,RGBA_ASTC_6x5_Format:()=>Pe,RGBA_ASTC_6x6_Format:()=>Fe,RGBA_ASTC_8x5_Format:()=>Ie,RGBA_ASTC_8x6_Format:()=>Le,RGBA_ASTC_8x8_Format:()=>Re,RGBA_BPTC_Format:()=>Ge,RGBA_ETC2_EAC_Format:()=>Ee,RGBA_PVRTC_2BPPV1_Format:()=>we,RGBA_PVRTC_4BPPV1_Format:()=>Ce,RGBA_S3TC_DXT1_Format:()=>ye,RGBA_S3TC_DXT3_Format:()=>be,RGBA_S3TC_DXT5_Format:()=>xe,RGBDepthPacking:()=>ft,RGBFormat:()=>H,RGBIntegerFormat:()=>ge,RGB_BPTC_SIGNED_Format:()=>Ke,RGB_BPTC_UNSIGNED_Format:()=>qe,RGB_ETC1_Format:()=>Te,RGB_ETC2_Format:()=>W,RGB_PVRTC_2BPPV1_Format:()=>U,RGB_PVRTC_4BPPV1_Format:()=>Se,RGB_S3TC_DXT1_Format:()=>ve,RGDepthPacking:()=>pt,RGFormat:()=>me,RGIntegerFormat:()=>he,RawShaderMaterial:()=>bl,Ray:()=>wa,Raycaster:()=>qd,RectAreaLight:()=>Lu,RedFormat:()=>fe,RedIntegerFormat:()=>pe,ReinhardToneMapping:()=>2,RenderTarget:()=>Qn,RenderTarget3D:()=>Bd,RepeatWrapping:()=>w,ReplaceStencilOp:()=>yt,ReverseSubtractEquation:()=>102,RingGeometry:()=>$c,SIGNED_R11_EAC_Format:()=>Oe,SIGNED_RED_GREEN_RGTC2_Format:()=>Ze,SIGNED_RED_RGTC1_Format:()=>Ye,SIGNED_RG11_EAC_Format:()=>Ae,SRGBColorSpace:()=>mt,SRGBTransfer:()=>_t,Scene:()=>Vr,ShaderChunk:()=>$f,ShaderLib:()=>ep,ShaderMaterial:()=>yl,ShadowMaterial:()=>ul,Shape:()=>cc,ShapeGeometry:()=>el,ShapePath:()=>Hf,ShapeUtils:()=>Uc,ShortType:()=>R,Skeleton:()=>eo,SkeletonHelper:()=>gf,SkinnedMesh:()=>Ya,Source:()=>Kn,Sphere:()=>Ri,SphereGeometry:()=>nl,Spherical:()=>Zd,SphericalHarmonics3:()=>Ru,SplineCurve:()=>ic,SpotLight:()=>Au,SpotLightHelper:()=>ff,Sprite:()=>fa,SpriteMaterial:()=>Qi,SrcAlphaFactor:()=>204,SrcAlphaSaturateFactor:()=>210,SrcColorFactor:()=>202,StaticCopyUsage:()=>jt,StaticDrawUsage:()=>Tt,StaticReadUsage:()=>Ot,StereoCamera:()=>rd,StreamCopyUsage:()=>Nt,StreamDrawUsage:()=>Dt,StreamReadUsage:()=>At,StringKeyframeTrack:()=>Yl,SubtractEquation:()=>101,SubtractiveBlending:()=>3,TOUCH:()=>x,TangentSpaceNormalMap:()=>0,TetrahedronGeometry:()=>rl,Texture:()=>Xn,TextureLoader:()=>mu,TextureUtils:()=>Yf,Timer:()=>cd,TimestampQuery:()=>Lt,TorusGeometry:()=>il,TorusKnotGeometry:()=>al,Triangle:()=>ti,TriangleFanDrawMode:()=>2,TriangleStripDrawMode:()=>1,TrianglesDrawMode:()=>0,TubeGeometry:()=>ol,UVMapping:()=>300,Uint16BufferAttribute:()=>Ai,Uint32BufferAttribute:()=>Mi,Uint8BufferAttribute:()=>Di,Uint8ClampedBufferAttribute:()=>Oi,Uniform:()=>Vd,UniformsGroup:()=>Ud,UniformsLib:()=>X,UniformsUtils:()=>gl,UnsignedByteType:()=>L,UnsignedInt101111Type:()=>se,UnsignedInt248Type:()=>ae,UnsignedInt5999Type:()=>oe,UnsignedIntType:()=>B,UnsignedShort4444Type:()=>re,UnsignedShort5551Type:()=>ie,UnsignedShortType:()=>te,VSMShadowMap:()=>3,Vector2:()=>K,Vector3:()=>q,Vector4:()=>Zn,VectorKeyframeTrack:()=>Xl,VideoFrameTexture:()=>ls,VideoTexture:()=>cs,WebGL3DRenderTarget:()=>rr,WebGLArrayRenderTarget:()=>tr,WebGLCoordinateSystem:()=>Ft,WebGLCubeRenderTarget:()=>kp,WebGLRenderTarget:()=>$n,WebGLRenderer:()=>pg,WebGLUtils:()=>tg,WebGPUCoordinateSystem:()=>It,WebXRController:()=>Nr,WireframeGeometry:()=>sl,WrapAroundEnding:()=>st,ZeroCurvatureEnding:()=>at,ZeroFactor:()=>200,ZeroSlopeEnding:()=>ot,ZeroStencilOp:()=>0,createCanvasElement:()=>Kt,error:()=>$t,getConsoleFunction:()=>Xt,log:()=>Zt,setConsoleFunction:()=>Yt,warn:()=>G,warnOnce:()=>en});function Zf(){let e=null,t=!1,n=null,r=null;function i(t,a){n(t,a),r=e.requestAnimationFrame(i)}return{start:function(){t!==!0&&n!==null&&e!==null&&(r=e.requestAnimationFrame(i),t=!0)},stop:function(){e!==null&&e.cancelAnimationFrame(r),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function Qf(e){let t=new WeakMap;function n(t,n){let r=t.array,i=t.usage,a=r.byteLength,o=e.createBuffer();e.bindBuffer(n,o),e.bufferData(n,r,i),t.onUploadCallback();let s;if(r instanceof Float32Array)s=e.FLOAT;else if(typeof Float16Array<`u`&&r instanceof Float16Array)s=e.HALF_FLOAT;else if(r instanceof Uint16Array)s=t.isFloat16BufferAttribute?e.HALF_FLOAT:e.UNSIGNED_SHORT;else if(r instanceof Int16Array)s=e.SHORT;else if(r instanceof Uint32Array)s=e.UNSIGNED_INT;else if(r instanceof Int32Array)s=e.INT;else if(r instanceof Int8Array)s=e.BYTE;else if(r instanceof Uint8Array)s=e.UNSIGNED_BYTE;else if(r instanceof Uint8ClampedArray)s=e.UNSIGNED_BYTE;else throw Error(`THREE.WebGLAttributes: Unsupported buffer data format: `+r);return{buffer:o,type:s,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,size:a}}function r(t,n,r){let i=n.array,a=n.updateRanges;if(e.bindBuffer(r,t),a.length===0)e.bufferSubData(r,0,i);else{a.sort((e,t)=>e.start-t.start);let t=0;for(let e=1;e 0 vec4 plane; #ifdef ALPHA_TO_COVERAGE float distanceToPlane, distanceGradient; float clipOpacity = 1.0; #pragma unroll_loop_start for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; distanceGradient = fwidth( distanceToPlane ) / 2.0; clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); if ( clipOpacity == 0.0 ) discard; } #pragma unroll_loop_end #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES float unionClipOpacity = 1.0; #pragma unroll_loop_start for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; distanceGradient = fwidth( distanceToPlane ) / 2.0; unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); } #pragma unroll_loop_end clipOpacity *= 1.0 - unionClipOpacity; #endif diffuseColor.a *= clipOpacity; if ( diffuseColor.a == 0.0 ) discard; #else #pragma unroll_loop_start for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; } #pragma unroll_loop_end #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES bool clipped = true; #pragma unroll_loop_start for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; } #pragma unroll_loop_end if ( clipped ) discard; #endif #endif #endif`,clipping_planes_pars_fragment:`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; #endif`,clipping_planes_pars_vertex:`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; #endif`,clipping_planes_vertex:`#if NUM_CLIPPING_PLANES > 0 vClipPosition = - mvPosition.xyz; #endif`,color_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) diffuseColor *= vColor; #endif`,color_pars_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) varying vec4 vColor; #endif`,color_pars_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) varying vec4 vColor; #endif`,color_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) vColor = vec4( 1.0 ); #endif #ifdef USE_COLOR_ALPHA vColor *= color; #elif defined( USE_COLOR ) vColor.rgb *= color; #endif #ifdef USE_INSTANCING_COLOR vColor.rgb *= instanceColor.rgb; #endif #ifdef USE_BATCHING_COLOR vColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) ); #endif`,common:`#define PI 3.141592653589793 #define PI2 6.283185307179586 #define PI_HALF 1.5707963267948966 #define RECIPROCAL_PI 0.3183098861837907 #define RECIPROCAL_PI2 0.15915494309189535 #define EPSILON 1e-6 #ifndef saturate #define saturate( a ) clamp( a, 0.0, 1.0 ) #endif #define whiteComplement( a ) ( 1.0 - saturate( a ) ) float pow2( const in float x ) { return x*x; } vec3 pow2( const in vec3 x ) { return x*x; } float pow3( const in float x ) { return x*x*x; } float pow4( const in float x ) { float x2 = x*x; return x2*x2; } float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } highp float rand( const in vec2 uv ) { const highp float a = 12.9898, b = 78.233, c = 43758.5453; highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); return fract( sin( sn ) * c ); } #ifdef HIGH_PRECISION float precisionSafeLength( vec3 v ) { return length( v ); } #else float precisionSafeLength( vec3 v ) { float maxComponent = max3( abs( v ) ); return length( v / maxComponent ) * maxComponent; } #endif struct IncidentLight { vec3 color; vec3 direction; bool visible; }; struct ReflectedLight { vec3 directDiffuse; vec3 directSpecular; vec3 indirectDiffuse; vec3 indirectSpecular; }; #ifdef USE_ALPHAHASH varying vec3 vPosition; #endif vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); } bool isPerspectiveMatrix( mat4 m ) { return m[ 2 ][ 3 ] == - 1.0; } vec2 equirectUv( in vec3 dir ) { float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; return vec2( u, v ); } vec3 BRDF_Lambert( const in vec3 diffuseColor ) { return RECIPROCAL_PI * diffuseColor; } vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); } float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); } // validated`,cube_uv_reflection_fragment:`#ifdef ENVMAP_TYPE_CUBE_UV #define cubeUV_minMipLevel 4.0 #define cubeUV_minTileSize 16.0 float getFace( vec3 direction ) { vec3 absDirection = abs( direction ); float face = - 1.0; if ( absDirection.x > absDirection.z ) { if ( absDirection.x > absDirection.y ) face = direction.x > 0.0 ? 0.0 : 3.0; else face = direction.y > 0.0 ? 1.0 : 4.0; } else { if ( absDirection.z > absDirection.y ) face = direction.z > 0.0 ? 2.0 : 5.0; else face = direction.y > 0.0 ? 1.0 : 4.0; } return face; } vec2 getUV( vec3 direction, float face ) { vec2 uv; if ( face == 0.0 ) { uv = vec2( direction.z, direction.y ) / abs( direction.x ); } else if ( face == 1.0 ) { uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); } else if ( face == 2.0 ) { uv = vec2( - direction.x, direction.y ) / abs( direction.z ); } else if ( face == 3.0 ) { uv = vec2( - direction.z, direction.y ) / abs( direction.x ); } else if ( face == 4.0 ) { uv = vec2( - direction.x, direction.z ) / abs( direction.y ); } else { uv = vec2( direction.x, direction.y ) / abs( direction.z ); } return 0.5 * ( uv + 1.0 ); } vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { float face = getFace( direction ); float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); mipInt = max( mipInt, cubeUV_minMipLevel ); float faceSize = exp2( mipInt ); highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; if ( face > 2.0 ) { uv.y += faceSize; face -= 3.0; } uv.x += face * faceSize; uv.x += filterInt * 3.0 * cubeUV_minTileSize; uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); uv.x *= CUBEUV_TEXEL_WIDTH; uv.y *= CUBEUV_TEXEL_HEIGHT; #ifdef texture2DGradEXT return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; #else return texture2D( envMap, uv ).rgb; #endif } #define cubeUV_r0 1.0 #define cubeUV_m0 - 2.0 #define cubeUV_r1 0.8 #define cubeUV_m1 - 1.0 #define cubeUV_r4 0.4 #define cubeUV_m4 2.0 #define cubeUV_r5 0.305 #define cubeUV_m5 3.0 #define cubeUV_r6 0.21 #define cubeUV_m6 4.0 float roughnessToMip( float roughness ) { float mip = 0.0; if ( roughness >= cubeUV_r1 ) { mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; } else if ( roughness >= cubeUV_r4 ) { mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; } else if ( roughness >= cubeUV_r5 ) { mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; } else if ( roughness >= cubeUV_r6 ) { mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; } else { mip = - 2.0 * log2( 1.16 * roughness ); } return mip; } vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); float mipF = fract( mip ); float mipInt = floor( mip ); vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); if ( mipF == 0.0 ) { return vec4( color0, 1.0 ); } else { vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); return vec4( mix( color0, color1, mipF ), 1.0 ); } } #endif`,defaultnormal_vertex:`vec3 transformedNormal = objectNormal; #ifdef USE_TANGENT vec3 transformedTangent = objectTangent; #endif #ifdef USE_BATCHING mat3 bm = mat3( batchingMatrix ); transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); transformedNormal = bm * transformedNormal; #ifdef USE_TANGENT transformedTangent = bm * transformedTangent; #endif #endif #ifdef USE_INSTANCING mat3 im = mat3( instanceMatrix ); transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); transformedNormal = im * transformedNormal; #ifdef USE_TANGENT transformedTangent = im * transformedTangent; #endif #endif transformedNormal = normalMatrix * transformedNormal; #ifdef FLIP_SIDED transformedNormal = - transformedNormal; #endif #ifdef USE_TANGENT transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; #ifdef FLIP_SIDED transformedTangent = - transformedTangent; #endif #endif`,displacementmap_pars_vertex:`#ifdef USE_DISPLACEMENTMAP uniform sampler2D displacementMap; uniform float displacementScale; uniform float displacementBias; #endif`,displacementmap_vertex:`#ifdef USE_DISPLACEMENTMAP transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); #endif`,emissivemap_fragment:`#ifdef USE_EMISSIVEMAP vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE emissiveColor = sRGBTransferEOTF( emissiveColor ); #endif totalEmissiveRadiance *= emissiveColor.rgb; #endif`,emissivemap_pars_fragment:`#ifdef USE_EMISSIVEMAP uniform sampler2D emissiveMap; #endif`,colorspace_fragment:`gl_FragColor = linearToOutputTexel( gl_FragColor );`,colorspace_pars_fragment:`vec4 LinearTransferOETF( in vec4 value ) { return value; } vec4 sRGBTransferEOTF( in vec4 value ) { return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a ); } vec4 sRGBTransferOETF( in vec4 value ) { return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); }`,envmap_fragment:`#ifdef USE_ENVMAP #ifdef ENV_WORLDPOS vec3 cameraToFrag; if ( isOrthographic ) { cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); } else { cameraToFrag = normalize( vWorldPosition - cameraPosition ); } vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); #ifdef ENVMAP_MODE_REFLECTION vec3 reflectVec = reflect( cameraToFrag, worldNormal ); #else vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); #endif #else vec3 reflectVec = vReflect; #endif #ifdef ENVMAP_TYPE_CUBE vec4 envColor = textureCube( envMap, envMapRotation * reflectVec ); #ifdef ENVMAP_BLENDING_MULTIPLY outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); #elif defined( ENVMAP_BLENDING_MIX ) outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); #elif defined( ENVMAP_BLENDING_ADD ) outgoingLight += envColor.xyz * specularStrength * reflectivity; #endif #endif #endif`,envmap_common_pars_fragment:`#ifdef USE_ENVMAP uniform float envMapIntensity; uniform mat3 envMapRotation; #ifdef ENVMAP_TYPE_CUBE uniform samplerCube envMap; #else uniform sampler2D envMap; #endif #endif`,envmap_pars_fragment:`#ifdef USE_ENVMAP uniform float reflectivity; #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) #define ENV_WORLDPOS #endif #ifdef ENV_WORLDPOS varying vec3 vWorldPosition; uniform float refractionRatio; #else varying vec3 vReflect; #endif #endif`,envmap_pars_vertex:`#ifdef USE_ENVMAP #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) #define ENV_WORLDPOS #endif #ifdef ENV_WORLDPOS varying vec3 vWorldPosition; #else varying vec3 vReflect; uniform float refractionRatio; #endif #endif`,envmap_physical_pars_fragment:`#ifdef USE_ENVMAP vec3 getIBLIrradiance( const in vec3 normal ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 ); return PI * envMapColor.rgb * envMapIntensity; #else return vec3( 0.0 ); #endif } vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 reflectVec = reflect( - viewDir, normal ); reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) ); reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness ); return envMapColor.rgb * envMapIntensity; #else return vec3( 0.0 ); #endif } #ifdef USE_ANISOTROPY vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 bentNormal = cross( bitangent, viewDir ); bentNormal = normalize( cross( bentNormal, bitangent ) ); bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); return getIBLRadiance( viewDir, bentNormal, roughness ); #else return vec3( 0.0 ); #endif } #endif #endif`,envmap_vertex:`#ifdef USE_ENVMAP #ifdef ENV_WORLDPOS vWorldPosition = worldPosition.xyz; #else vec3 cameraToVertex; if ( isOrthographic ) { cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); } else { cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); } vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); #ifdef ENVMAP_MODE_REFLECTION vReflect = reflect( cameraToVertex, worldNormal ); #else vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); #endif #endif #endif`,fog_vertex:`#ifdef USE_FOG vFogDepth = - mvPosition.z; #endif`,fog_pars_vertex:`#ifdef USE_FOG varying float vFogDepth; #endif`,fog_fragment:`#ifdef USE_FOG #ifdef FOG_EXP2 float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); #else float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); #endif gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); #endif`,fog_pars_fragment:`#ifdef USE_FOG uniform vec3 fogColor; varying float vFogDepth; #ifdef FOG_EXP2 uniform float fogDensity; #else uniform float fogNear; uniform float fogFar; #endif #endif`,gradientmap_pars_fragment:`#ifdef USE_GRADIENTMAP uniform sampler2D gradientMap; #endif vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { float dotNL = dot( normal, lightDirection ); vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); #ifdef USE_GRADIENTMAP return vec3( texture2D( gradientMap, coord ).r ); #else vec2 fw = fwidth( coord ) * 0.5; return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); #endif }`,lightmap_pars_fragment:`#ifdef USE_LIGHTMAP uniform sampler2D lightMap; uniform float lightMapIntensity; #endif`,lights_lambert_fragment:`LambertMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularStrength = specularStrength;`,lights_lambert_pars_fragment:`varying vec3 vViewPosition; struct LambertMaterial { vec3 diffuseColor; float specularStrength; }; void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_Lambert #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lights_pars_begin:`uniform bool receiveShadow; uniform vec3 ambientLightColor; #if defined( USE_LIGHT_PROBES ) uniform vec3 lightProbe[ 9 ]; #endif vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { float x = normal.x, y = normal.y, z = normal.z; vec3 result = shCoefficients[ 0 ] * 0.886227; result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); return result; } vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); return irradiance; } vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { vec3 irradiance = ambientLightColor; return irradiance; } float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); if ( cutoffDistance > 0.0 ) { distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); } return distanceFalloff; } float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { return smoothstep( coneCosine, penumbraCosine, angleCosine ); } #if NUM_DIR_LIGHTS > 0 struct DirectionalLight { vec3 direction; vec3 color; }; uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { light.color = directionalLight.color; light.direction = directionalLight.direction; light.visible = true; } #endif #if NUM_POINT_LIGHTS > 0 struct PointLight { vec3 position; vec3 color; float distance; float decay; }; uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { vec3 lVector = pointLight.position - geometryPosition; light.direction = normalize( lVector ); float lightDistance = length( lVector ); light.color = pointLight.color; light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); light.visible = ( light.color != vec3( 0.0 ) ); } #endif #if NUM_SPOT_LIGHTS > 0 struct SpotLight { vec3 position; vec3 direction; vec3 color; float distance; float decay; float coneCos; float penumbraCos; }; uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { vec3 lVector = spotLight.position - geometryPosition; light.direction = normalize( lVector ); float angleCos = dot( light.direction, spotLight.direction ); float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); if ( spotAttenuation > 0.0 ) { float lightDistance = length( lVector ); light.color = spotLight.color * spotAttenuation; light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); light.visible = ( light.color != vec3( 0.0 ) ); } else { light.color = vec3( 0.0 ); light.visible = false; } } #endif #if NUM_RECT_AREA_LIGHTS > 0 struct RectAreaLight { vec3 color; vec3 position; vec3 halfWidth; vec3 halfHeight; }; uniform sampler2D ltc_1; uniform sampler2D ltc_2; uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; #endif #if NUM_HEMI_LIGHTS > 0 struct HemisphereLight { vec3 direction; vec3 skyColor; vec3 groundColor; }; uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { float dotNL = dot( normal, hemiLight.direction ); float hemiDiffuseWeight = 0.5 * dotNL + 0.5; vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); return irradiance; } #endif #include `,lights_toon_fragment:`ToonMaterial material; material.diffuseColor = diffuseColor.rgb;`,lights_toon_pars_fragment:`varying vec3 vViewPosition; struct ToonMaterial { vec3 diffuseColor; }; void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_Toon #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lights_phong_fragment:`BlinnPhongMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularColor = specular; material.specularShininess = shininess; material.specularStrength = specularStrength;`,lights_phong_pars_fragment:`varying vec3 vViewPosition; struct BlinnPhongMaterial { vec3 diffuseColor; vec3 specularColor; float specularShininess; float specularStrength; }; void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; } void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_BlinnPhong #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,lights_physical_fragment:`PhysicalMaterial material; material.diffuseColor = diffuseColor.rgb; material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor ); material.metalness = metalnessFactor; vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; material.roughness = min( material.roughness, 1.0 ); #ifdef IOR material.ior = ior; #ifdef USE_SPECULAR float specularIntensityFactor = specularIntensity; vec3 specularColorFactor = specularColor; #ifdef USE_SPECULAR_COLORMAP specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; #endif #ifdef USE_SPECULAR_INTENSITYMAP specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; #endif material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); #else float specularIntensityFactor = 1.0; vec3 specularColorFactor = vec3( 1.0 ); material.specularF90 = 1.0; #endif material.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor; material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor ); #else material.specularColor = vec3( 0.04 ); material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor ); material.specularF90 = 1.0; #endif #ifdef USE_CLEARCOAT material.clearcoat = clearcoat; material.clearcoatRoughness = clearcoatRoughness; material.clearcoatF0 = vec3( 0.04 ); material.clearcoatF90 = 1.0; #ifdef USE_CLEARCOATMAP material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; #endif material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); material.clearcoatRoughness += geometryRoughness; material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); #endif #ifdef USE_DISPERSION material.dispersion = dispersion; #endif #ifdef USE_IRIDESCENCE material.iridescence = iridescence; material.iridescenceIOR = iridescenceIOR; #ifdef USE_IRIDESCENCEMAP material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; #else material.iridescenceThickness = iridescenceThicknessMaximum; #endif #endif #ifdef USE_SHEEN material.sheenColor = sheenColor; #ifdef USE_SHEEN_COLORMAP material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; #endif material.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 ); #ifdef USE_SHEEN_ROUGHNESSMAP material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; #endif #endif #ifdef USE_ANISOTROPY #ifdef USE_ANISOTROPYMAP mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; #else vec2 anisotropyV = anisotropyVector; #endif material.anisotropy = length( anisotropyV ); if( material.anisotropy == 0.0 ) { anisotropyV = vec2( 1.0, 0.0 ); } else { anisotropyV /= material.anisotropy; material.anisotropy = saturate( material.anisotropy ); } material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; #endif`,lights_physical_pars_fragment:`uniform sampler2D dfgLUT; struct PhysicalMaterial { vec3 diffuseColor; vec3 diffuseContribution; vec3 specularColor; vec3 specularColorBlended; float roughness; float metalness; float specularF90; float dispersion; #ifdef USE_CLEARCOAT float clearcoat; float clearcoatRoughness; vec3 clearcoatF0; float clearcoatF90; #endif #ifdef USE_IRIDESCENCE float iridescence; float iridescenceIOR; float iridescenceThickness; vec3 iridescenceFresnel; vec3 iridescenceF0; vec3 iridescenceFresnelDielectric; vec3 iridescenceFresnelMetallic; #endif #ifdef USE_SHEEN vec3 sheenColor; float sheenRoughness; #endif #ifdef IOR float ior; #endif #ifdef USE_TRANSMISSION float transmission; float transmissionAlpha; float thickness; float attenuationDistance; vec3 attenuationColor; #endif #ifdef USE_ANISOTROPY float anisotropy; float alphaT; vec3 anisotropyT; vec3 anisotropyB; #endif }; vec3 clearcoatSpecularDirect = vec3( 0.0 ); vec3 clearcoatSpecularIndirect = vec3( 0.0 ); vec3 sheenSpecularDirect = vec3( 0.0 ); vec3 sheenSpecularIndirect = vec3(0.0 ); vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); float x2 = x * x; float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); } float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { float a2 = pow2( alpha ); float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); return 0.5 / max( gv + gl, EPSILON ); } float D_GGX( const in float alpha, const in float dotNH ) { float a2 = pow2( alpha ); float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; return RECIPROCAL_PI * a2 / pow2( denom ); } #ifdef USE_ANISOTROPY float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); return 0.5 / max( gv + gl, EPSILON ); } float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { float a2 = alphaT * alphaB; highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); highp float v2 = dot( v, v ); float w2 = a2 / v2; return RECIPROCAL_PI * a2 * pow2 ( w2 ); } #endif #ifdef USE_CLEARCOAT vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { vec3 f0 = material.clearcoatF0; float f90 = material.clearcoatF90; float roughness = material.clearcoatRoughness; float alpha = pow2( roughness ); vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float dotVH = saturate( dot( viewDir, halfDir ) ); vec3 F = F_Schlick( f0, f90, dotVH ); float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); float D = D_GGX( alpha, dotNH ); return F * ( V * D ); } #endif vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { vec3 f0 = material.specularColorBlended; float f90 = material.specularF90; float roughness = material.roughness; float alpha = pow2( roughness ); vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float dotVH = saturate( dot( viewDir, halfDir ) ); vec3 F = F_Schlick( f0, f90, dotVH ); #ifdef USE_IRIDESCENCE F = mix( F, material.iridescenceFresnel, material.iridescence ); #endif #ifdef USE_ANISOTROPY float dotTL = dot( material.anisotropyT, lightDir ); float dotTV = dot( material.anisotropyT, viewDir ); float dotTH = dot( material.anisotropyT, halfDir ); float dotBL = dot( material.anisotropyB, lightDir ); float dotBV = dot( material.anisotropyB, viewDir ); float dotBH = dot( material.anisotropyB, halfDir ); float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); #else float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); float D = D_GGX( alpha, dotNH ); #endif return F * ( V * D ); } vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { const float LUT_SIZE = 64.0; const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; const float LUT_BIAS = 0.5 / LUT_SIZE; float dotNV = saturate( dot( N, V ) ); vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); uv = uv * LUT_SCALE + LUT_BIAS; return uv; } float LTC_ClippedSphereFormFactor( const in vec3 f ) { float l = length( f ); return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); } vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { float x = dot( v1, v2 ); float y = abs( x ); float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; float b = 3.4175940 + ( 4.1616724 + y ) * y; float v = a / b; float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; return cross( v1, v2 ) * theta_sintheta; } vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; vec3 lightNormal = cross( v1, v2 ); if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); vec3 T1, T2; T1 = normalize( V - N * dot( V, N ) ); T2 = - cross( N, T1 ); mat3 mat = mInv * transpose( mat3( T1, T2, N ) ); vec3 coords[ 4 ]; coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); coords[ 0 ] = normalize( coords[ 0 ] ); coords[ 1 ] = normalize( coords[ 1 ] ); coords[ 2 ] = normalize( coords[ 2 ] ); coords[ 3 ] = normalize( coords[ 3 ] ); vec3 vectorFormFactor = vec3( 0.0 ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); return vec3( result ); } #if defined( USE_SHEEN ) float D_Charlie( float roughness, float dotNH ) { float alpha = pow2( roughness ); float invAlpha = 1.0 / alpha; float cos2h = dotNH * dotNH; float sin2h = max( 1.0 - cos2h, 0.0078125 ); return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); } float V_Neubelt( float dotNV, float dotNL ) { return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); } vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float D = D_Charlie( sheenRoughness, dotNH ); float V = V_Neubelt( dotNV, dotNL ); return sheenColor * ( D * V ); } #endif float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { float dotNV = saturate( dot( normal, viewDir ) ); float r2 = roughness * roughness; float rInv = 1.0 / ( roughness + 0.1 ); float a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv; float b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv; float DG = exp( a * dotNV + b ); return saturate( DG ); } vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { float dotNV = saturate( dot( normal, viewDir ) ); vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg; return specularColor * fab.x + specularF90 * fab.y; } #ifdef USE_IRIDESCENCE void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { #else void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { #endif float dotNV = saturate( dot( normal, viewDir ) ); vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg; #ifdef USE_IRIDESCENCE vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); #else vec3 Fr = specularColor; #endif vec3 FssEss = Fr * fab.x + specularF90 * fab.y; float Ess = fab.x + fab.y; float Ems = 1.0 - Ess; vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); singleScatter += FssEss; multiScatter += Fms * Ems; } vec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { vec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); vec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg; vec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg; vec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y; vec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y; float Ess_V = dfgV.x + dfgV.y; float Ess_L = dfgL.x + dfgL.y; float Ems_V = 1.0 - Ess_V; float Ems_L = 1.0 - Ess_L; vec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619; vec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON ); float compensationFactor = Ems_V * Ems_L; vec3 multiScatter = Fms * compensationFactor; return singleScatter + multiScatter; } #if NUM_RECT_AREA_LIGHTS > 0 void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { vec3 normal = geometryNormal; vec3 viewDir = geometryViewDir; vec3 position = geometryPosition; vec3 lightPos = rectAreaLight.position; vec3 halfWidth = rectAreaLight.halfWidth; vec3 halfHeight = rectAreaLight.halfHeight; vec3 lightColor = rectAreaLight.color; float roughness = material.roughness; vec3 rectCoords[ 4 ]; rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; vec2 uv = LTC_Uv( normal, viewDir, roughness ); vec4 t1 = texture2D( ltc_1, uv ); vec4 t2 = texture2D( ltc_2, uv ); mat3 mInv = mat3( vec3( t1.x, 0, t1.y ), vec3( 0, 1, 0 ), vec3( t1.z, 0, t1.w ) ); vec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y ); reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); reflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); #ifdef USE_CLEARCOAT vec3 Ncc = geometryClearcoatNormal; vec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness ); vec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat ); vec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat ); mat3 mInvClearcoat = mat3( vec3( t1Clearcoat.x, 0, t1Clearcoat.y ), vec3( 0, 1, 0 ), vec3( t1Clearcoat.z, 0, t1Clearcoat.w ) ); vec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y; clearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords ); #endif } #endif void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; #ifdef USE_CLEARCOAT float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); vec3 ccIrradiance = dotNLcc * directLight.color; clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); #endif #ifdef USE_SHEEN sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); float sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); float sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness ); float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL ); irradiance *= sheenEnergyComp; #endif reflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material ); reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution ); } void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { vec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution ); #ifdef USE_SHEEN float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo; diffuse *= sheenEnergyComp; #endif reflectedLight.indirectDiffuse += diffuse; } void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { #ifdef USE_CLEARCOAT clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); #endif #ifdef USE_SHEEN sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI; #endif vec3 singleScatteringDielectric = vec3( 0.0 ); vec3 multiScatteringDielectric = vec3( 0.0 ); vec3 singleScatteringMetallic = vec3( 0.0 ); vec3 multiScatteringMetallic = vec3( 0.0 ); #ifdef USE_IRIDESCENCE computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric ); computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic ); #else computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric ); computeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic ); #endif vec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness ); vec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness ); vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric; vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric ); vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; vec3 indirectSpecular = radiance * singleScattering; indirectSpecular += multiScattering * cosineWeightedIrradiance; vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance; #ifdef USE_SHEEN float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo; indirectSpecular *= sheenEnergyComp; indirectDiffuse *= sheenEnergyComp; #endif reflectedLight.indirectSpecular += indirectSpecular; reflectedLight.indirectDiffuse += indirectDiffuse; } #define RE_Direct RE_Direct_Physical #define RE_Direct_RectArea RE_Direct_RectArea_Physical #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical #define RE_IndirectSpecular RE_IndirectSpecular_Physical float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); }`,lights_fragment_begin:` vec3 geometryPosition = - vViewPosition; vec3 geometryNormal = normal; vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); vec3 geometryClearcoatNormal = vec3( 0.0 ); #ifdef USE_CLEARCOAT geometryClearcoatNormal = clearcoatNormal; #endif #ifdef USE_IRIDESCENCE float dotNVi = saturate( dot( normal, geometryViewDir ) ); if ( material.iridescenceThickness == 0.0 ) { material.iridescence = 0.0; } else { material.iridescence = saturate( material.iridescence ); } if ( material.iridescence > 0.0 ) { material.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); material.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor ); material.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness ); material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); } #endif IncidentLight directLight; #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) PointLight pointLight; #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 PointLightShadow pointLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { pointLight = pointLights[ i ]; getPointLightInfo( pointLight, geometryPosition, directLight ); #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) ) pointLightShadow = pointLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) SpotLight spotLight; vec4 spotColor; vec3 spotLightCoord; bool inSpotLightMap; #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 SpotLightShadow spotLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { spotLight = spotLights[ i ]; getSpotLightInfo( spotLight, geometryPosition, directLight ); #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS #else #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) #endif #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; #endif #undef SPOT_LIGHT_MAP_INDEX #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) spotLightShadow = spotLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) DirectionalLight directionalLight; #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 DirectionalLightShadow directionalLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { directionalLight = directionalLights[ i ]; getDirectionalLightInfo( directionalLight, directLight ); #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) directionalLightShadow = directionalLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) RectAreaLight rectAreaLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { rectAreaLight = rectAreaLights[ i ]; RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if defined( RE_IndirectDiffuse ) vec3 iblIrradiance = vec3( 0.0 ); vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); #if defined( USE_LIGHT_PROBES ) irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); #endif #if ( NUM_HEMI_LIGHTS > 0 ) #pragma unroll_loop_start for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); } #pragma unroll_loop_end #endif #ifdef USE_LIGHT_PROBES_GRID vec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz; vec3 probeWorldNormal = inverseTransformDirection( geometryNormal, viewMatrix ); irradiance += getLightProbeGridIrradiance( probeWorldPos, probeWorldNormal ); #endif #endif #if defined( RE_IndirectSpecular ) vec3 radiance = vec3( 0.0 ); vec3 clearcoatRadiance = vec3( 0.0 ); #endif`,lights_fragment_maps:`#if defined( RE_IndirectDiffuse ) #ifdef USE_LIGHTMAP vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; irradiance += lightMapIrradiance; #endif #if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV ) #if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG ) iblIrradiance += getIBLIrradiance( geometryNormal ); #endif #endif #endif #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) #ifdef USE_ANISOTROPY radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); #else radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); #endif #ifdef USE_CLEARCOAT clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); #endif #endif`,lights_fragment_end:`#if defined( RE_IndirectDiffuse ) #if defined( LAMBERT ) || defined( PHONG ) irradiance += iblIrradiance; #endif RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); #endif #if defined( RE_IndirectSpecular ) RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); #endif`,lightprobes_pars_fragment:`#ifdef USE_LIGHT_PROBES_GRID uniform highp sampler3D probesSH; uniform vec3 probesMin; uniform vec3 probesMax; uniform vec3 probesResolution; vec3 getLightProbeGridIrradiance( vec3 worldPos, vec3 worldNormal ) { vec3 res = probesResolution; vec3 gridRange = probesMax - probesMin; vec3 resMinusOne = res - 1.0; vec3 probeSpacing = gridRange / resMinusOne; vec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5; vec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.0, 1.0 ); uvw = uvw * resMinusOne / res + 0.5 / res; float nz = res.z; float paddedSlices = nz + 2.0; float atlasDepth = 7.0 * paddedSlices; float uvZBase = uvw.z * nz + 1.0; vec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) ); vec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) ); vec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) ); vec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) ); vec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) ); vec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) ); vec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) ); vec3 c0 = s0.xyz; vec3 c1 = vec3( s0.w, s1.xy ); vec3 c2 = vec3( s1.zw, s2.x ); vec3 c3 = s2.yzw; vec3 c4 = s3.xyz; vec3 c5 = vec3( s3.w, s4.xy ); vec3 c6 = vec3( s4.zw, s5.x ); vec3 c7 = s5.yzw; vec3 c8 = s6.xyz; float x = worldNormal.x, y = worldNormal.y, z = worldNormal.z; vec3 result = c0 * 0.886227; result += c1 * 2.0 * 0.511664 * y; result += c2 * 2.0 * 0.511664 * z; result += c3 * 2.0 * 0.511664 * x; result += c4 * 2.0 * 0.429043 * x * y; result += c5 * 2.0 * 0.429043 * y * z; result += c6 * ( 0.743125 * z * z - 0.247708 ); result += c7 * 2.0 * 0.429043 * x * z; result += c8 * 0.429043 * ( x * x - y * y ); return max( result, vec3( 0.0 ) ); } #endif`,logdepthbuf_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; #endif`,logdepthbuf_pars_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) uniform float logDepthBufFC; varying float vFragDepth; varying float vIsPerspective; #endif`,logdepthbuf_pars_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER varying float vFragDepth; varying float vIsPerspective; #endif`,logdepthbuf_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER vFragDepth = 1.0 + gl_Position.w; vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); #endif`,map_fragment:`#ifdef USE_MAP vec4 sampledDiffuseColor = texture2D( map, vMapUv ); #ifdef DECODE_VIDEO_TEXTURE sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor ); #endif diffuseColor *= sampledDiffuseColor; #endif`,map_pars_fragment:`#ifdef USE_MAP uniform sampler2D map; #endif`,map_particle_fragment:`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) #if defined( USE_POINTS_UV ) vec2 uv = vUv; #else vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; #endif #endif #ifdef USE_MAP diffuseColor *= texture2D( map, uv ); #endif #ifdef USE_ALPHAMAP diffuseColor.a *= texture2D( alphaMap, uv ).g; #endif`,map_particle_pars_fragment:`#if defined( USE_POINTS_UV ) varying vec2 vUv; #else #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) uniform mat3 uvTransform; #endif #endif #ifdef USE_MAP uniform sampler2D map; #endif #ifdef USE_ALPHAMAP uniform sampler2D alphaMap; #endif`,metalnessmap_fragment:`float metalnessFactor = metalness; #ifdef USE_METALNESSMAP vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); metalnessFactor *= texelMetalness.b; #endif`,metalnessmap_pars_fragment:`#ifdef USE_METALNESSMAP uniform sampler2D metalnessMap; #endif`,morphinstance_vertex:`#ifdef USE_INSTANCING_MORPH float morphTargetInfluences[ MORPHTARGETS_COUNT ]; float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r; for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r; } #endif`,morphcolor_vertex:`#if defined( USE_MORPHCOLORS ) vColor *= morphTargetBaseInfluence; for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { #if defined( USE_COLOR_ALPHA ) if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; #elif defined( USE_COLOR ) if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; #endif } #endif`,morphnormal_vertex:`#ifdef USE_MORPHNORMALS objectNormal *= morphTargetBaseInfluence; for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; } #endif`,morphtarget_pars_vertex:`#ifdef USE_MORPHTARGETS #ifndef USE_INSTANCING_MORPH uniform float morphTargetBaseInfluence; uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; #endif uniform sampler2DArray morphTargetsTexture; uniform ivec2 morphTargetsTextureSize; vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; int y = texelIndex / morphTargetsTextureSize.x; int x = texelIndex - y * morphTargetsTextureSize.x; ivec3 morphUV = ivec3( x, y, morphTargetIndex ); return texelFetch( morphTargetsTexture, morphUV, 0 ); } #endif`,morphtarget_vertex:`#ifdef USE_MORPHTARGETS transformed *= morphTargetBaseInfluence; for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; } #endif`,normal_fragment_begin:`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; #ifdef FLAT_SHADED vec3 fdx = dFdx( vViewPosition ); vec3 fdy = dFdy( vViewPosition ); vec3 normal = normalize( cross( fdx, fdy ) ); #else vec3 normal = normalize( vNormal ); #ifdef DOUBLE_SIDED normal *= faceDirection; #endif #endif #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) #ifdef USE_TANGENT mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn = getTangentFrame( - vViewPosition, normal, #if defined( USE_NORMALMAP ) vNormalMapUv #elif defined( USE_CLEARCOAT_NORMALMAP ) vClearcoatNormalMapUv #else vUv #endif ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn[0] *= faceDirection; tbn[1] *= faceDirection; #endif #endif #ifdef USE_CLEARCOAT_NORMALMAP #ifdef USE_TANGENT mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn2[0] *= faceDirection; tbn2[1] *= faceDirection; #endif #endif vec3 nonPerturbedNormal = normal;`,normal_fragment_maps:`#ifdef USE_NORMALMAP_OBJECTSPACE normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; #ifdef FLIP_SIDED normal = - normal; #endif #ifdef DOUBLE_SIDED normal = normal * faceDirection; #endif normal = normalize( normalMatrix * normal ); #elif defined( USE_NORMALMAP_TANGENTSPACE ) vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; #if defined( USE_PACKED_NORMALMAP ) mapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) ); #endif mapN.xy *= normalScale; normal = normalize( tbn * mapN ); #elif defined( USE_BUMPMAP ) normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); #endif`,normal_pars_fragment:`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,normal_pars_vertex:`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,normal_vertex:`#ifndef FLAT_SHADED vNormal = normalize( transformedNormal ); #ifdef USE_TANGENT vTangent = normalize( transformedTangent ); vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); #endif #endif`,normalmap_pars_fragment:`#ifdef USE_NORMALMAP uniform sampler2D normalMap; uniform vec2 normalScale; #endif #ifdef USE_NORMALMAP_OBJECTSPACE uniform mat3 normalMatrix; #endif #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { vec3 q0 = dFdx( eye_pos.xyz ); vec3 q1 = dFdy( eye_pos.xyz ); vec2 st0 = dFdx( uv.st ); vec2 st1 = dFdy( uv.st ); vec3 N = surf_norm; vec3 q1perp = cross( q1, N ); vec3 q0perp = cross( N, q0 ); vec3 T = q1perp * st0.x + q0perp * st1.x; vec3 B = q1perp * st0.y + q0perp * st1.y; float det = max( dot( T, T ), dot( B, B ) ); float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); return mat3( T * scale, B * scale, N ); } #endif`,clearcoat_normal_fragment_begin:`#ifdef USE_CLEARCOAT vec3 clearcoatNormal = nonPerturbedNormal; #endif`,clearcoat_normal_fragment_maps:`#ifdef USE_CLEARCOAT_NORMALMAP vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; clearcoatMapN.xy *= clearcoatNormalScale; clearcoatNormal = normalize( tbn2 * clearcoatMapN ); #endif`,clearcoat_pars_fragment:`#ifdef USE_CLEARCOATMAP uniform sampler2D clearcoatMap; #endif #ifdef USE_CLEARCOAT_NORMALMAP uniform sampler2D clearcoatNormalMap; uniform vec2 clearcoatNormalScale; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP uniform sampler2D clearcoatRoughnessMap; #endif`,iridescence_pars_fragment:`#ifdef USE_IRIDESCENCEMAP uniform sampler2D iridescenceMap; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP uniform sampler2D iridescenceThicknessMap; #endif`,opaque_fragment:`#ifdef OPAQUE diffuseColor.a = 1.0; #endif #ifdef USE_TRANSMISSION diffuseColor.a *= material.transmissionAlpha; #endif gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,packing:`vec3 packNormalToRGB( const in vec3 normal ) { return normalize( normal ) * 0.5 + 0.5; } vec3 unpackRGBToNormal( const in vec3 rgb ) { return 2.0 * rgb.xyz - 1.0; } const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.; const float Inv255 = 1. / 255.; const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 ); const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g ); const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b ); const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a ); vec4 packDepthToRGBA( const in float v ) { if( v <= 0.0 ) return vec4( 0., 0., 0., 0. ); if( v >= 1.0 ) return vec4( 1., 1., 1., 1. ); float vuf; float af = modf( v * PackFactors.a, vuf ); float bf = modf( vuf * ShiftRight8, vuf ); float gf = modf( vuf * ShiftRight8, vuf ); return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af ); } vec3 packDepthToRGB( const in float v ) { if( v <= 0.0 ) return vec3( 0., 0., 0. ); if( v >= 1.0 ) return vec3( 1., 1., 1. ); float vuf; float bf = modf( v * PackFactors.b, vuf ); float gf = modf( vuf * ShiftRight8, vuf ); return vec3( vuf * Inv255, gf * PackUpscale, bf ); } vec2 packDepthToRG( const in float v ) { if( v <= 0.0 ) return vec2( 0., 0. ); if( v >= 1.0 ) return vec2( 1., 1. ); float vuf; float gf = modf( v * 256., vuf ); return vec2( vuf * Inv255, gf ); } float unpackRGBAToDepth( const in vec4 v ) { return dot( v, UnpackFactors4 ); } float unpackRGBToDepth( const in vec3 v ) { return dot( v, UnpackFactors3 ); } float unpackRGToDepth( const in vec2 v ) { return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g; } vec4 pack2HalfToRGBA( const in vec2 v ) { vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); } vec2 unpackRGBATo2Half( const in vec4 v ) { return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); } float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { return ( viewZ + near ) / ( near - far ); } float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { #ifdef USE_REVERSED_DEPTH_BUFFER return depth * ( far - near ) - far; #else return depth * ( near - far ) - near; #endif } float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); } float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { #ifdef USE_REVERSED_DEPTH_BUFFER return ( near * far ) / ( ( near - far ) * depth - near ); #else return ( near * far ) / ( ( far - near ) * depth - far ); #endif }`,premultiplied_alpha_fragment:`#ifdef PREMULTIPLIED_ALPHA gl_FragColor.rgb *= gl_FragColor.a; #endif`,project_vertex:`vec4 mvPosition = vec4( transformed, 1.0 ); #ifdef USE_BATCHING mvPosition = batchingMatrix * mvPosition; #endif #ifdef USE_INSTANCING mvPosition = instanceMatrix * mvPosition; #endif mvPosition = modelViewMatrix * mvPosition; gl_Position = projectionMatrix * mvPosition;`,dithering_fragment:`#ifdef DITHERING gl_FragColor.rgb = dithering( gl_FragColor.rgb ); #endif`,dithering_pars_fragment:`#ifdef DITHERING vec3 dithering( vec3 color ) { float grid_position = rand( gl_FragCoord.xy ); vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); return color + dither_shift_RGB; } #endif`,roughnessmap_fragment:`float roughnessFactor = roughness; #ifdef USE_ROUGHNESSMAP vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); roughnessFactor *= texelRoughness.g; #endif`,roughnessmap_pars_fragment:`#ifdef USE_ROUGHNESSMAP uniform sampler2D roughnessMap; #endif`,shadowmap_pars_fragment:`#if NUM_SPOT_LIGHT_COORDS > 0 varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; #endif #if NUM_SPOT_LIGHT_MAPS > 0 uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; #endif #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 #if defined( SHADOWMAP_TYPE_PCF ) uniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; #else uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; #endif varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; struct DirectionalLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 #if defined( SHADOWMAP_TYPE_PCF ) uniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; #else uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; #endif struct SpotLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; #endif #if NUM_POINT_LIGHT_SHADOWS > 0 #if defined( SHADOWMAP_TYPE_PCF ) uniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; #elif defined( SHADOWMAP_TYPE_BASIC ) uniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; #endif varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; struct PointLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; float shadowCameraNear; float shadowCameraFar; }; uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; #endif #if defined( SHADOWMAP_TYPE_PCF ) float interleavedGradientNoise( vec2 position ) { return fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) ); } vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) { const float goldenAngle = 2.399963229728653; float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) ); float theta = float( sampleIndex ) * goldenAngle + phi; return vec2( cos( theta ), sin( theta ) ) * r; } #endif #if defined( SHADOWMAP_TYPE_PCF ) float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) { float shadow = 1.0; shadowCoord.xyz /= shadowCoord.w; shadowCoord.z += shadowBias; bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; bool frustumTest = inFrustum && shadowCoord.z <= 1.0; if ( frustumTest ) { vec2 texelSize = vec2( 1.0 ) / shadowMapSize; float radius = shadowRadius * texelSize.x; float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2; shadow = ( texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) + texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) + texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) + texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) + texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) ) ) * 0.2; } return mix( 1.0, shadow, shadowIntensity ); } #elif defined( SHADOWMAP_TYPE_VSM ) float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) { float shadow = 1.0; shadowCoord.xyz /= shadowCoord.w; #ifdef USE_REVERSED_DEPTH_BUFFER shadowCoord.z -= shadowBias; #else shadowCoord.z += shadowBias; #endif bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; bool frustumTest = inFrustum && shadowCoord.z <= 1.0; if ( frustumTest ) { vec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg; float mean = distribution.x; float variance = distribution.y * distribution.y; #ifdef USE_REVERSED_DEPTH_BUFFER float hard_shadow = step( mean, shadowCoord.z ); #else float hard_shadow = step( shadowCoord.z, mean ); #endif if ( hard_shadow == 1.0 ) { shadow = 1.0; } else { variance = max( variance, 0.0000001 ); float d = shadowCoord.z - mean; float p_max = variance / ( variance + d * d ); p_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 ); shadow = max( hard_shadow, p_max ); } } return mix( 1.0, shadow, shadowIntensity ); } #else float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) { float shadow = 1.0; shadowCoord.xyz /= shadowCoord.w; #ifdef USE_REVERSED_DEPTH_BUFFER shadowCoord.z -= shadowBias; #else shadowCoord.z += shadowBias; #endif bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; bool frustumTest = inFrustum && shadowCoord.z <= 1.0; if ( frustumTest ) { float depth = texture2D( shadowMap, shadowCoord.xy ).r; #ifdef USE_REVERSED_DEPTH_BUFFER shadow = step( depth, shadowCoord.z ); #else shadow = step( shadowCoord.z, depth ); #endif } return mix( 1.0, shadow, shadowIntensity ); } #endif #if NUM_POINT_LIGHT_SHADOWS > 0 #if defined( SHADOWMAP_TYPE_PCF ) float getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { float shadow = 1.0; vec3 lightToPosition = shadowCoord.xyz; vec3 bd3D = normalize( lightToPosition ); vec3 absVec = abs( lightToPosition ); float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z ); if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) { #ifdef USE_REVERSED_DEPTH_BUFFER float dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ); dp -= shadowBias; #else float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ); dp += shadowBias; #endif float texelSize = shadowRadius / shadowMapSize.x; vec3 absDir = abs( bd3D ); vec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 ); tangent = normalize( cross( bd3D, tangent ) ); vec3 bitangent = cross( bd3D, tangent ); float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2; vec2 sample0 = vogelDiskSample( 0, 5, phi ); vec2 sample1 = vogelDiskSample( 1, 5, phi ); vec2 sample2 = vogelDiskSample( 2, 5, phi ); vec2 sample3 = vogelDiskSample( 3, 5, phi ); vec2 sample4 = vogelDiskSample( 4, 5, phi ); shadow = ( texture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) + texture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) + texture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) + texture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) + texture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) ) ) * 0.2; } return mix( 1.0, shadow, shadowIntensity ); } #elif defined( SHADOWMAP_TYPE_BASIC ) float getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { float shadow = 1.0; vec3 lightToPosition = shadowCoord.xyz; vec3 absVec = abs( lightToPosition ); float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z ); if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) { float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ); dp += shadowBias; vec3 bd3D = normalize( lightToPosition ); float depth = textureCube( shadowMap, bd3D ).r; #ifdef USE_REVERSED_DEPTH_BUFFER depth = 1.0 - depth; #endif shadow = step( dp, depth ); } return mix( 1.0, shadow, shadowIntensity ); } #endif #endif #endif`,shadowmap_pars_vertex:`#if NUM_SPOT_LIGHT_COORDS > 0 uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; #endif #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; struct DirectionalLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 struct SpotLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; #endif #if NUM_POINT_LIGHT_SHADOWS > 0 uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; struct PointLightShadow { float shadowIntensity; float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; float shadowCameraNear; float shadowCameraFar; }; uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; #endif #endif`,shadowmap_vertex:`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) #ifdef HAS_NORMAL vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); #else vec3 shadowWorldNormal = vec3( 0.0 ); #endif vec4 shadowWorldPosition; #endif #if defined( USE_SHADOWMAP ) #if NUM_DIR_LIGHT_SHADOWS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif #if NUM_POINT_LIGHT_SHADOWS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif #endif #if NUM_SPOT_LIGHT_COORDS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { shadowWorldPosition = worldPosition; #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; #endif vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif`,shadowmask_pars_fragment:`float getShadowMask() { float shadow = 1.0; #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 DirectionalLightShadow directionalLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { directionalLight = directionalLightShadows[ i ]; shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; } #pragma unroll_loop_end #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 SpotLightShadow spotLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { spotLight = spotLightShadows[ i ]; shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; } #pragma unroll_loop_end #endif #if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) ) PointLightShadow pointLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { pointLight = pointLightShadows[ i ]; shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; } #pragma unroll_loop_end #endif #endif return shadow; }`,skinbase_vertex:`#ifdef USE_SKINNING mat4 boneMatX = getBoneMatrix( skinIndex.x ); mat4 boneMatY = getBoneMatrix( skinIndex.y ); mat4 boneMatZ = getBoneMatrix( skinIndex.z ); mat4 boneMatW = getBoneMatrix( skinIndex.w ); #endif`,skinning_pars_vertex:`#ifdef USE_SKINNING uniform mat4 bindMatrix; uniform mat4 bindMatrixInverse; uniform highp sampler2D boneTexture; mat4 getBoneMatrix( const in float i ) { int size = textureSize( boneTexture, 0 ).x; int j = int( i ) * 4; int x = j % size; int y = j / size; vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); return mat4( v1, v2, v3, v4 ); } #endif`,skinning_vertex:`#ifdef USE_SKINNING vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); vec4 skinned = vec4( 0.0 ); skinned += boneMatX * skinVertex * skinWeight.x; skinned += boneMatY * skinVertex * skinWeight.y; skinned += boneMatZ * skinVertex * skinWeight.z; skinned += boneMatW * skinVertex * skinWeight.w; transformed = ( bindMatrixInverse * skinned ).xyz; #endif`,skinnormal_vertex:`#ifdef USE_SKINNING mat4 skinMatrix = mat4( 0.0 ); skinMatrix += skinWeight.x * boneMatX; skinMatrix += skinWeight.y * boneMatY; skinMatrix += skinWeight.z * boneMatZ; skinMatrix += skinWeight.w * boneMatW; skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; #ifdef USE_TANGENT objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; #endif #endif`,specularmap_fragment:`float specularStrength; #ifdef USE_SPECULARMAP vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); specularStrength = texelSpecular.r; #else specularStrength = 1.0; #endif`,specularmap_pars_fragment:`#ifdef USE_SPECULARMAP uniform sampler2D specularMap; #endif`,tonemapping_fragment:`#if defined( TONE_MAPPING ) gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); #endif`,tonemapping_pars_fragment:`#ifndef saturate #define saturate( a ) clamp( a, 0.0, 1.0 ) #endif uniform float toneMappingExposure; vec3 LinearToneMapping( vec3 color ) { return saturate( toneMappingExposure * color ); } vec3 ReinhardToneMapping( vec3 color ) { color *= toneMappingExposure; return saturate( color / ( vec3( 1.0 ) + color ) ); } vec3 CineonToneMapping( vec3 color ) { color *= toneMappingExposure; color = max( vec3( 0.0 ), color - 0.004 ); return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); } vec3 RRTAndODTFit( vec3 v ) { vec3 a = v * ( v + 0.0245786 ) - 0.000090537; vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; return a / b; } vec3 ACESFilmicToneMapping( vec3 color ) { const mat3 ACESInputMat = mat3( vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), vec3( 0.04823, 0.01566, 0.83777 ) ); const mat3 ACESOutputMat = mat3( vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), vec3( -0.07367, -0.00605, 1.07602 ) ); color *= toneMappingExposure / 0.6; color = ACESInputMat * color; color = RRTAndODTFit( color ); color = ACESOutputMat * color; return saturate( color ); } const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( vec3( 1.6605, - 0.1246, - 0.0182 ), vec3( - 0.5876, 1.1329, - 0.1006 ), vec3( - 0.0728, - 0.0083, 1.1187 ) ); const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( vec3( 0.6274, 0.0691, 0.0164 ), vec3( 0.3293, 0.9195, 0.0880 ), vec3( 0.0433, 0.0113, 0.8956 ) ); vec3 agxDefaultContrastApprox( vec3 x ) { vec3 x2 = x * x; vec3 x4 = x2 * x2; return + 15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232; } vec3 AgXToneMapping( vec3 color ) { const mat3 AgXInsetMatrix = mat3( vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) ); const mat3 AgXOutsetMatrix = mat3( vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) ); const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; color *= toneMappingExposure; color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; color = AgXInsetMatrix * color; color = max( color, 1e-10 ); color = log2( color ); color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); color = clamp( color, 0.0, 1.0 ); color = agxDefaultContrastApprox( color ); color = AgXOutsetMatrix * color; color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); color = LINEAR_REC2020_TO_LINEAR_SRGB * color; color = clamp( color, 0.0, 1.0 ); return color; } vec3 NeutralToneMapping( vec3 color ) { const float StartCompression = 0.8 - 0.04; const float Desaturation = 0.15; color *= toneMappingExposure; float x = min( color.r, min( color.g, color.b ) ); float offset = x < 0.08 ? x - 6.25 * x * x : 0.04; color -= offset; float peak = max( color.r, max( color.g, color.b ) ); if ( peak < StartCompression ) return color; float d = 1. - StartCompression; float newPeak = 1. - d * d / ( peak + d - StartCompression ); color *= newPeak / peak; float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. ); return mix( color, vec3( newPeak ), g ); } vec3 CustomToneMapping( vec3 color ) { return color; }`,transmission_fragment:`#ifdef USE_TRANSMISSION material.transmission = transmission; material.transmissionAlpha = 1.0; material.thickness = thickness; material.attenuationDistance = attenuationDistance; material.attenuationColor = attenuationColor; #ifdef USE_TRANSMISSIONMAP material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; #endif #ifdef USE_THICKNESSMAP material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; #endif vec3 pos = vWorldPosition; vec3 v = normalize( cameraPosition - pos ); vec3 n = inverseTransformDirection( normal, viewMatrix ); vec4 transmitted = getIBLVolumeRefraction( n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90, pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness, material.attenuationColor, material.attenuationDistance ); material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); #endif`,transmission_pars_fragment:`#ifdef USE_TRANSMISSION uniform float transmission; uniform float thickness; uniform float attenuationDistance; uniform vec3 attenuationColor; #ifdef USE_TRANSMISSIONMAP uniform sampler2D transmissionMap; #endif #ifdef USE_THICKNESSMAP uniform sampler2D thicknessMap; #endif uniform vec2 transmissionSamplerSize; uniform sampler2D transmissionSamplerMap; uniform mat4 modelMatrix; uniform mat4 projectionMatrix; varying vec3 vWorldPosition; float w0( float a ) { return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); } float w1( float a ) { return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); } float w2( float a ){ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); } float w3( float a ) { return ( 1.0 / 6.0 ) * ( a * a * a ); } float g0( float a ) { return w0( a ) + w1( a ); } float g1( float a ) { return w2( a ) + w3( a ); } float h0( float a ) { return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); } float h1( float a ) { return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); } vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { uv = uv * texelSize.zw + 0.5; vec2 iuv = floor( uv ); vec2 fuv = fract( uv ); float g0x = g0( fuv.x ); float g1x = g1( fuv.x ); float h0x = h0( fuv.x ); float h1x = h1( fuv.x ); float h0y = h0( fuv.y ); float h1y = h1( fuv.y ); vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); } vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); vec2 fLodSizeInv = 1.0 / fLodSize; vec2 cLodSizeInv = 1.0 / cLodSize; vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); return mix( fSample, cSample, fract( lod ) ); } vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); vec3 modelScale; modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); return normalize( refractionVector ) * thickness * modelScale; } float applyIorToRoughness( const in float roughness, const in float ior ) { return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); } vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); } vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { if ( isinf( attenuationDistance ) ) { return vec3( 1.0 ); } else { vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; } } vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness, const in vec3 attenuationColor, const in float attenuationDistance ) { vec4 transmittedLight; vec3 transmittance; #ifdef USE_DISPERSION float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion; vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread ); for ( int i = 0; i < 3; i ++ ) { vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix ); vec3 refractedRayExit = position + transmissionRay; vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); vec2 refractionCoords = ndcPos.xy / ndcPos.w; refractionCoords += 1.0; refractionCoords /= 2.0; vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] ); transmittedLight[ i ] = transmissionSample[ i ]; transmittedLight.a += transmissionSample.a; transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ]; } transmittedLight.a /= 3.0; #else vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); vec3 refractedRayExit = position + transmissionRay; vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); vec2 refractionCoords = ndcPos.xy / ndcPos.w; refractionCoords += 1.0; refractionCoords /= 2.0; transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); #endif vec3 attenuatedColor = transmittance * transmittedLight.rgb; vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); } #endif`,uv_pars_fragment:`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) varying vec2 vUv; #endif #ifdef USE_MAP varying vec2 vMapUv; #endif #ifdef USE_ALPHAMAP varying vec2 vAlphaMapUv; #endif #ifdef USE_LIGHTMAP varying vec2 vLightMapUv; #endif #ifdef USE_AOMAP varying vec2 vAoMapUv; #endif #ifdef USE_BUMPMAP varying vec2 vBumpMapUv; #endif #ifdef USE_NORMALMAP varying vec2 vNormalMapUv; #endif #ifdef USE_EMISSIVEMAP varying vec2 vEmissiveMapUv; #endif #ifdef USE_METALNESSMAP varying vec2 vMetalnessMapUv; #endif #ifdef USE_ROUGHNESSMAP varying vec2 vRoughnessMapUv; #endif #ifdef USE_ANISOTROPYMAP varying vec2 vAnisotropyMapUv; #endif #ifdef USE_CLEARCOATMAP varying vec2 vClearcoatMapUv; #endif #ifdef USE_CLEARCOAT_NORMALMAP varying vec2 vClearcoatNormalMapUv; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP varying vec2 vClearcoatRoughnessMapUv; #endif #ifdef USE_IRIDESCENCEMAP varying vec2 vIridescenceMapUv; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP varying vec2 vIridescenceThicknessMapUv; #endif #ifdef USE_SHEEN_COLORMAP varying vec2 vSheenColorMapUv; #endif #ifdef USE_SHEEN_ROUGHNESSMAP varying vec2 vSheenRoughnessMapUv; #endif #ifdef USE_SPECULARMAP varying vec2 vSpecularMapUv; #endif #ifdef USE_SPECULAR_COLORMAP varying vec2 vSpecularColorMapUv; #endif #ifdef USE_SPECULAR_INTENSITYMAP varying vec2 vSpecularIntensityMapUv; #endif #ifdef USE_TRANSMISSIONMAP uniform mat3 transmissionMapTransform; varying vec2 vTransmissionMapUv; #endif #ifdef USE_THICKNESSMAP uniform mat3 thicknessMapTransform; varying vec2 vThicknessMapUv; #endif`,uv_pars_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) varying vec2 vUv; #endif #ifdef USE_MAP uniform mat3 mapTransform; varying vec2 vMapUv; #endif #ifdef USE_ALPHAMAP uniform mat3 alphaMapTransform; varying vec2 vAlphaMapUv; #endif #ifdef USE_LIGHTMAP uniform mat3 lightMapTransform; varying vec2 vLightMapUv; #endif #ifdef USE_AOMAP uniform mat3 aoMapTransform; varying vec2 vAoMapUv; #endif #ifdef USE_BUMPMAP uniform mat3 bumpMapTransform; varying vec2 vBumpMapUv; #endif #ifdef USE_NORMALMAP uniform mat3 normalMapTransform; varying vec2 vNormalMapUv; #endif #ifdef USE_DISPLACEMENTMAP uniform mat3 displacementMapTransform; varying vec2 vDisplacementMapUv; #endif #ifdef USE_EMISSIVEMAP uniform mat3 emissiveMapTransform; varying vec2 vEmissiveMapUv; #endif #ifdef USE_METALNESSMAP uniform mat3 metalnessMapTransform; varying vec2 vMetalnessMapUv; #endif #ifdef USE_ROUGHNESSMAP uniform mat3 roughnessMapTransform; varying vec2 vRoughnessMapUv; #endif #ifdef USE_ANISOTROPYMAP uniform mat3 anisotropyMapTransform; varying vec2 vAnisotropyMapUv; #endif #ifdef USE_CLEARCOATMAP uniform mat3 clearcoatMapTransform; varying vec2 vClearcoatMapUv; #endif #ifdef USE_CLEARCOAT_NORMALMAP uniform mat3 clearcoatNormalMapTransform; varying vec2 vClearcoatNormalMapUv; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP uniform mat3 clearcoatRoughnessMapTransform; varying vec2 vClearcoatRoughnessMapUv; #endif #ifdef USE_SHEEN_COLORMAP uniform mat3 sheenColorMapTransform; varying vec2 vSheenColorMapUv; #endif #ifdef USE_SHEEN_ROUGHNESSMAP uniform mat3 sheenRoughnessMapTransform; varying vec2 vSheenRoughnessMapUv; #endif #ifdef USE_IRIDESCENCEMAP uniform mat3 iridescenceMapTransform; varying vec2 vIridescenceMapUv; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP uniform mat3 iridescenceThicknessMapTransform; varying vec2 vIridescenceThicknessMapUv; #endif #ifdef USE_SPECULARMAP uniform mat3 specularMapTransform; varying vec2 vSpecularMapUv; #endif #ifdef USE_SPECULAR_COLORMAP uniform mat3 specularColorMapTransform; varying vec2 vSpecularColorMapUv; #endif #ifdef USE_SPECULAR_INTENSITYMAP uniform mat3 specularIntensityMapTransform; varying vec2 vSpecularIntensityMapUv; #endif #ifdef USE_TRANSMISSIONMAP uniform mat3 transmissionMapTransform; varying vec2 vTransmissionMapUv; #endif #ifdef USE_THICKNESSMAP uniform mat3 thicknessMapTransform; varying vec2 vThicknessMapUv; #endif`,uv_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) vUv = vec3( uv, 1 ).xy; #endif #ifdef USE_MAP vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; #endif #ifdef USE_ALPHAMAP vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; #endif #ifdef USE_LIGHTMAP vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; #endif #ifdef USE_AOMAP vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; #endif #ifdef USE_BUMPMAP vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; #endif #ifdef USE_NORMALMAP vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; #endif #ifdef USE_DISPLACEMENTMAP vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; #endif #ifdef USE_EMISSIVEMAP vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; #endif #ifdef USE_METALNESSMAP vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_ROUGHNESSMAP vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_ANISOTROPYMAP vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOATMAP vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOAT_NORMALMAP vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_IRIDESCENCEMAP vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_SHEEN_COLORMAP vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; #endif #ifdef USE_SHEEN_ROUGHNESSMAP vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULARMAP vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULAR_COLORMAP vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULAR_INTENSITYMAP vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; #endif #ifdef USE_TRANSMISSIONMAP vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; #endif #ifdef USE_THICKNESSMAP vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; #endif`,worldpos_vertex:`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 vec4 worldPosition = vec4( transformed, 1.0 ); #ifdef USE_BATCHING worldPosition = batchingMatrix * worldPosition; #endif #ifdef USE_INSTANCING worldPosition = instanceMatrix * worldPosition; #endif worldPosition = modelMatrix * worldPosition; #endif`,background_vert:`varying vec2 vUv; uniform mat3 uvTransform; void main() { vUv = ( uvTransform * vec3( uv, 1 ) ).xy; gl_Position = vec4( position.xy, 1.0, 1.0 ); }`,background_frag:`uniform sampler2D t2D; uniform float backgroundIntensity; varying vec2 vUv; void main() { vec4 texColor = texture2D( t2D, vUv ); #ifdef DECODE_VIDEO_TEXTURE texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); #endif texColor.rgb *= backgroundIntensity; gl_FragColor = texColor; #include #include }`,backgroundCube_vert:`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,backgroundCube_frag:`#ifdef ENVMAP_TYPE_CUBE uniform samplerCube envMap; #elif defined( ENVMAP_TYPE_CUBE_UV ) uniform sampler2D envMap; #endif uniform float backgroundBlurriness; uniform float backgroundIntensity; uniform mat3 backgroundRotation; varying vec3 vWorldDirection; #include void main() { #ifdef ENVMAP_TYPE_CUBE vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection ); #elif defined( ENVMAP_TYPE_CUBE_UV ) vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness ); #else vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); #endif texColor.rgb *= backgroundIntensity; gl_FragColor = texColor; #include #include }`,cube_vert:`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,cube_frag:`uniform samplerCube tCube; uniform float tFlip; uniform float opacity; varying vec3 vWorldDirection; void main() { vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); gl_FragColor = texColor; gl_FragColor.a *= opacity; #include #include }`,depth_vert:`#include #include #include #include #include #include #include #include varying vec2 vHighPrecisionZW; void main() { #include #include #include #include #ifdef USE_DISPLACEMENTMAP #include #include #include #endif #include #include #include #include #include #include #include vHighPrecisionZW = gl_Position.zw; }`,depth_frag:`#if DEPTH_PACKING == 3200 uniform float opacity; #endif #include #include #include #include #include #include #include #include #include varying vec2 vHighPrecisionZW; void main() { vec4 diffuseColor = vec4( 1.0 ); #include #if DEPTH_PACKING == 3200 diffuseColor.a = opacity; #endif #include #include #include #include #include #ifdef USE_REVERSED_DEPTH_BUFFER float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ]; #else float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5; #endif #if DEPTH_PACKING == 3200 gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); #elif DEPTH_PACKING == 3201 gl_FragColor = packDepthToRGBA( fragCoordZ ); #elif DEPTH_PACKING == 3202 gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 ); #elif DEPTH_PACKING == 3203 gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 ); #endif }`,distance_vert:`#define DISTANCE varying vec3 vWorldPosition; #include #include #include #include #include #include #include void main() { #include #include #include #include #ifdef USE_DISPLACEMENTMAP #include #include #include #endif #include #include #include #include #include #include #include vWorldPosition = worldPosition.xyz; }`,distance_frag:`#define DISTANCE uniform vec3 referencePosition; uniform float nearDistance; uniform float farDistance; varying vec3 vWorldPosition; #include #include #include #include #include #include #include void main () { vec4 diffuseColor = vec4( 1.0 ); #include #include #include #include #include float dist = length( vWorldPosition - referencePosition ); dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); dist = saturate( dist ); gl_FragColor = vec4( dist, 0.0, 0.0, 1.0 ); }`,equirect_vert:`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include }`,equirect_frag:`uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); #include #include }`,linedashed_vert:`uniform float scale; attribute float lineDistance; varying float vLineDistance; #include #include #include #include #include #include #include void main() { vLineDistance = scale * lineDistance; #include #include #include #include #include #include #include #include #include #include }`,linedashed_frag:`uniform vec3 diffuse; uniform float opacity; uniform float dashSize; uniform float totalSize; varying float vLineDistance; #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include if ( mod( vLineDistance, totalSize ) > dashSize ) { discard; } vec3 outgoingLight = vec3( 0.0 ); #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include #include }`,meshbasic_vert:`#include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) #include #include #include #include #include #endif #include #include #include #include #include #include #include #include #include }`,meshbasic_frag:`uniform vec3 diffuse; uniform float opacity; #ifndef FLAT_SHADED varying vec3 vNormal; #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include #include #include #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); #ifdef USE_LIGHTMAP vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; #else reflectedLight.indirectDiffuse += vec3( 1.0 ); #endif #include reflectedLight.indirectDiffuse *= diffuseColor.rgb; vec3 outgoingLight = reflectedLight.indirectDiffuse; #include #include #include #include #include #include #include }`,meshlambert_vert:`#define LAMBERT varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #include }`,meshlambert_frag:`#define LAMBERT uniform vec3 diffuse; uniform vec3 emissive; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; #include #include #include #include #include #include #include }`,meshmatcap_vert:`#define MATCAP varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; }`,meshmatcap_frag:`#define MATCAP uniform vec3 diffuse; uniform float opacity; uniform sampler2D matcap; varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include #include #include #include #include vec3 viewDir = normalize( vViewPosition ); vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); vec3 y = cross( viewDir, x ); vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; #ifdef USE_MATCAP vec4 matcapColor = texture2D( matcap, uv ); #else vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); #endif vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; #include #include #include #include #include #include }`,meshnormal_vert:`#define NORMAL #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) varying vec3 vViewPosition; #endif #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) vViewPosition = - mvPosition.xyz; #endif }`,meshnormal_frag:`#define NORMAL uniform float opacity; #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) varying vec3 vViewPosition; #endif #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity ); #include #include #include #include gl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a ); #ifdef OPAQUE gl_FragColor.a = 1.0; #endif }`,meshphong_vert:`#define PHONG varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #include }`,meshphong_frag:`#define PHONG uniform vec3 diffuse; uniform vec3 emissive; uniform vec3 specular; uniform float shininess; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; #include #include #include #include #include #include #include }`,meshphysical_vert:`#define STANDARD varying vec3 vViewPosition; #ifdef USE_TRANSMISSION varying vec3 vWorldPosition; #endif #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #ifdef USE_TRANSMISSION vWorldPosition = worldPosition.xyz; #endif }`,meshphysical_frag:`#define STANDARD #ifdef PHYSICAL #define IOR #define USE_SPECULAR #endif uniform vec3 diffuse; uniform vec3 emissive; uniform float roughness; uniform float metalness; uniform float opacity; #ifdef IOR uniform float ior; #endif #ifdef USE_SPECULAR uniform float specularIntensity; uniform vec3 specularColor; #ifdef USE_SPECULAR_COLORMAP uniform sampler2D specularColorMap; #endif #ifdef USE_SPECULAR_INTENSITYMAP uniform sampler2D specularIntensityMap; #endif #endif #ifdef USE_CLEARCOAT uniform float clearcoat; uniform float clearcoatRoughness; #endif #ifdef USE_DISPERSION uniform float dispersion; #endif #ifdef USE_IRIDESCENCE uniform float iridescence; uniform float iridescenceIOR; uniform float iridescenceThicknessMinimum; uniform float iridescenceThicknessMaximum; #endif #ifdef USE_SHEEN uniform vec3 sheenColor; uniform float sheenRoughness; #ifdef USE_SHEEN_COLORMAP uniform sampler2D sheenColorMap; #endif #ifdef USE_SHEEN_ROUGHNESSMAP uniform sampler2D sheenRoughnessMap; #endif #endif #ifdef USE_ANISOTROPY uniform vec2 anisotropyVector; #ifdef USE_ANISOTROPYMAP uniform sampler2D anisotropyMap; #endif #endif varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; #include vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; #ifdef USE_SHEEN outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect; #endif #ifdef USE_CLEARCOAT float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; #endif #include #include #include #include #include #include }`,meshtoon_vert:`#define TOON varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include }`,meshtoon_frag:`#define TOON uniform vec3 diffuse; uniform vec3 emissive; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; #include #include #include #include #include #include }`,points_vert:`uniform float size; uniform float scale; #include #include #include #include #include #include #ifdef USE_POINTS_UV varying vec2 vUv; uniform mat3 uvTransform; #endif void main() { #ifdef USE_POINTS_UV vUv = ( uvTransform * vec3( uv, 1 ) ).xy; #endif #include #include #include #include #include #include gl_PointSize = size; #ifdef USE_SIZEATTENUATION bool isPerspective = isPerspectiveMatrix( projectionMatrix ); if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); #endif #include #include #include #include }`,points_frag:`uniform vec3 diffuse; uniform float opacity; #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include vec3 outgoingLight = vec3( 0.0 ); #include #include #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include #include }`,shadow_vert:`#include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include }`,shadow_frag:`uniform vec3 color; uniform float opacity; #include #include #include #include #include #include #include void main() { #include gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); #include #include #include #include }`,sprite_vert:`uniform float rotation; uniform vec2 center; #include #include #include #include #include void main() { #include vec4 mvPosition = modelViewMatrix[ 3 ]; vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) ); #ifndef USE_SIZEATTENUATION bool isPerspective = isPerspectiveMatrix( projectionMatrix ); if ( isPerspective ) scale *= - mvPosition.z; #endif vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; vec2 rotatedPosition; rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; mvPosition.xy += rotatedPosition; gl_Position = projectionMatrix * mvPosition; #include #include #include }`,sprite_frag:`uniform vec3 diffuse; uniform float opacity; #include #include #include #include #include #include #include #include #include void main() { vec4 diffuseColor = vec4( diffuse, opacity ); #include vec3 outgoingLight = vec3( 0.0 ); #include #include #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include }`},X={common:{diffuse:{value:new Y(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Fn},alphaMap:{value:null},alphaMapTransform:{value:new Fn},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Fn}},envmap:{envMap:{value:null},envMapRotation:{value:new Fn},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Fn}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Fn}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Fn},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Fn},normalScale:{value:new K(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Fn},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Fn}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Fn}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Fn}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Y(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:null},probesMin:{value:new q},probesMax:{value:new q},probesResolution:{value:new q}},points:{diffuse:{value:new Y(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Fn},alphaTest:{value:0},uvTransform:{value:new Fn}},sprite:{diffuse:{value:new Y(16777215)},opacity:{value:1},center:{value:new K(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Fn},alphaMap:{value:null},alphaMapTransform:{value:new Fn},alphaTest:{value:0}}},ep={basic:{uniforms:fl([X.common,X.specularmap,X.envmap,X.aomap,X.lightmap,X.fog]),vertexShader:$f.meshbasic_vert,fragmentShader:$f.meshbasic_frag},lambert:{uniforms:fl([X.common,X.specularmap,X.envmap,X.aomap,X.lightmap,X.emissivemap,X.bumpmap,X.normalmap,X.displacementmap,X.fog,X.lights,{emissive:{value:new Y(0)},envMapIntensity:{value:1}}]),vertexShader:$f.meshlambert_vert,fragmentShader:$f.meshlambert_frag},phong:{uniforms:fl([X.common,X.specularmap,X.envmap,X.aomap,X.lightmap,X.emissivemap,X.bumpmap,X.normalmap,X.displacementmap,X.fog,X.lights,{emissive:{value:new Y(0)},specular:{value:new Y(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:$f.meshphong_vert,fragmentShader:$f.meshphong_frag},standard:{uniforms:fl([X.common,X.envmap,X.aomap,X.lightmap,X.emissivemap,X.bumpmap,X.normalmap,X.displacementmap,X.roughnessmap,X.metalnessmap,X.fog,X.lights,{emissive:{value:new Y(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:$f.meshphysical_vert,fragmentShader:$f.meshphysical_frag},toon:{uniforms:fl([X.common,X.aomap,X.lightmap,X.emissivemap,X.bumpmap,X.normalmap,X.displacementmap,X.gradientmap,X.fog,X.lights,{emissive:{value:new Y(0)}}]),vertexShader:$f.meshtoon_vert,fragmentShader:$f.meshtoon_frag},matcap:{uniforms:fl([X.common,X.bumpmap,X.normalmap,X.displacementmap,X.fog,{matcap:{value:null}}]),vertexShader:$f.meshmatcap_vert,fragmentShader:$f.meshmatcap_frag},points:{uniforms:fl([X.points,X.fog]),vertexShader:$f.points_vert,fragmentShader:$f.points_frag},dashed:{uniforms:fl([X.common,X.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:$f.linedashed_vert,fragmentShader:$f.linedashed_frag},depth:{uniforms:fl([X.common,X.displacementmap]),vertexShader:$f.depth_vert,fragmentShader:$f.depth_frag},normal:{uniforms:fl([X.common,X.bumpmap,X.normalmap,X.displacementmap,{opacity:{value:1}}]),vertexShader:$f.meshnormal_vert,fragmentShader:$f.meshnormal_frag},sprite:{uniforms:fl([X.sprite,X.fog]),vertexShader:$f.sprite_vert,fragmentShader:$f.sprite_frag},background:{uniforms:{uvTransform:{value:new Fn},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:$f.background_vert,fragmentShader:$f.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Fn}},vertexShader:$f.backgroundCube_vert,fragmentShader:$f.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:$f.cube_vert,fragmentShader:$f.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:$f.equirect_vert,fragmentShader:$f.equirect_frag},distance:{uniforms:fl([X.common,X.displacementmap,{referencePosition:{value:new q},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:$f.distance_vert,fragmentShader:$f.distance_frag},shadow:{uniforms:fl([X.lights,X.fog,{color:{value:new Y(0)},opacity:{value:1}}]),vertexShader:$f.shadow_vert,fragmentShader:$f.shadow_frag}};ep.physical={uniforms:fl([ep.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Fn},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Fn},clearcoatNormalScale:{value:new K(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Fn},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Fn},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Fn},sheen:{value:0},sheenColor:{value:new Y(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Fn},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Fn},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Fn},transmissionSamplerSize:{value:new K},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Fn},attenuationDistance:{value:0},attenuationColor:{value:new Y(0)},specularColor:{value:new Y(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Fn},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Fn},anisotropyVector:{value:new K},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Fn}}]),vertexShader:$f.meshphysical_vert,fragmentShader:$f.meshphysical_frag};var tp={r:0,b:0,g:0},np=new J,rp=new Fn;rp.set(-1,0,0,0,1,0,0,0,1);function ip(e,t,n,r,i,a){let o=new Y(0),s=i===!0?0:1,c,l,u=null,d=0,f=null;function p(e){let n=e.isScene===!0?e.background:null;if(n&&n.isTexture){let r=e.backgroundBlurriness>0;n=t.get(n,r)}return n}function m(t){let r=!1,i=p(t);i===null?g(o,s):i&&i.isColor&&(g(i,1),r=!0);let c=e.xr.getEnvironmentBlendMode();c===`additive`?n.buffers.color.setClear(0,0,0,1,a):c===`alpha-blend`&&n.buffers.color.setClear(0,0,0,0,a),(e.autoClear||r)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil))}function h(t,n){let i=p(n);i&&(i.isCubeTexture||i.mapping===306)?(l===void 0&&(l=new La(new bs(1,1,1),new yl({name:`BackgroundCubeMaterial`,uniforms:dl(ep.backgroundCube.uniforms),vertexShader:ep.backgroundCube.vertexShader,fragmentShader:ep.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute(`normal`),l.geometry.deleteAttribute(`uv`),l.onBeforeRender=function(e,t,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),r.update(l)),l.material.uniforms.envMap.value=i,l.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(np.makeRotationFromEuler(n.backgroundRotation)).transpose(),i.isCubeTexture&&i.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(rp),l.material.toneMapped=Bn.getTransfer(i.colorSpace)!==_t,(u!==i||d!==i.version||f!==e.toneMapping)&&(l.material.needsUpdate=!0,u=i,d=i.version,f=e.toneMapping),l.layers.enableAll(),t.unshift(l,l.geometry,l.material,0,0,null)):i&&i.isTexture&&(c===void 0&&(c=new La(new Qc(2,2),new yl({name:`BackgroundMaterial`,uniforms:dl(ep.background.uniforms),vertexShader:ep.background.vertexShader,fragmentShader:ep.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute(`normal`),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),r.update(c)),c.material.uniforms.t2D.value=i,c.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,c.material.toneMapped=Bn.getTransfer(i.colorSpace)!==_t,i.matrixAutoUpdate===!0&&i.updateMatrix(),c.material.uniforms.uvTransform.value.copy(i.matrix),(u!==i||d!==i.version||f!==e.toneMapping)&&(c.material.needsUpdate=!0,u=i,d=i.version,f=e.toneMapping),c.layers.enableAll(),t.unshift(c,c.geometry,c.material,0,0,null))}function g(t,r){t.getRGB(tp,hl(e)),n.buffers.color.setClear(tp.r,tp.g,tp.b,r,a)}function _(){l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0),c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0)}return{getClearColor:function(){return o},setClearColor:function(e,t=1){o.set(e),s=t,g(o,s)},getClearAlpha:function(){return s},setClearAlpha:function(e){s=e,g(o,s)},render:m,addToRenderList:h,dispose:_}}function ap(e,t){let n=e.getParameter(e.MAX_VERTEX_ATTRIBS),r={},i=f(null),a=i,o=!1;function s(n,r,i,s,c){let u=!1,f=d(n,s,i,r);a!==f&&(a=f,l(a.object)),u=p(n,s,i,c),u&&m(n,s,i,c),c!==null&&t.update(c,e.ELEMENT_ARRAY_BUFFER),(u||o)&&(o=!1,b(n,r,i,s),c!==null&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.get(c).buffer))}function c(){return e.createVertexArray()}function l(t){return e.bindVertexArray(t)}function u(t){return e.deleteVertexArray(t)}function d(e,t,n,i){let a=i.wireframe===!0,o=r[t.id];o===void 0&&(o={},r[t.id]=o);let s=e.isInstancedMesh===!0?e.id:0,l=o[s];l===void 0&&(l={},o[s]=l);let u=l[n.id];u===void 0&&(u={},l[n.id]=u);let d=u[a];return d===void 0&&(d=f(c()),u[a]=d),d}function f(e){let t=[],r=[],i=[];for(let e=0;e=0){let n=i[t],r=o[t];if(r===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(r=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(r=e.instanceColor)),n===void 0||n.attribute!==r||r&&n.data!==r.data)return!0;s++}return a.attributesNum!==s||a.index!==r}function m(e,t,n,r){let i={},o=t.attributes,s=0,c=n.getAttributes();for(let t in c)if(c[t].location>=0){let n=o[t];n===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(n=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(n=e.instanceColor));let r={};r.attribute=n,n&&n.data&&(r.data=n.data),i[t]=r,s++}a.attributes=i,a.attributesNum=s,a.index=r}function h(){let e=a.newAttributes;for(let t=0,n=e.length;t=0){let s=o[r];if(s===void 0&&(r===`instanceMatrix`&&n.instanceMatrix&&(s=n.instanceMatrix),r===`instanceColor`&&n.instanceColor&&(s=n.instanceColor)),s!==void 0){let r=s.normalized,o=s.itemSize,c=t.get(s);if(c===void 0)continue;let l=c.buffer,u=c.type,d=c.bytesPerElement,f=u===e.INT||u===e.UNSIGNED_INT||s.gpuType===1013;if(s.isInterleavedBufferAttribute){let t=s.data,c=t.stride,p=s.offset;if(t.isInstancedInterleavedBuffer){for(let e=0;e0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0)return`highp`;t=`mediump`}return t===`mediump`&&e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?`mediump`:`lowp`}let l=n.precision===void 0?`highp`:n.precision,u=c(l);u!==l&&(G(`WebGLRenderer:`,l,`not supported, using`,u,`instead.`),l=u);let d=n.logarithmicDepthBuffer===!0,f=n.reversedDepthBuffer===!0&&t.has(`EXT_clip_control`);n.reversedDepthBuffer===!0&&f===!1&&G(`WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.`);let p=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),m=e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS),h=e.getParameter(e.MAX_TEXTURE_SIZE),g=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),_=e.getParameter(e.MAX_VERTEX_ATTRIBS),v=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),y=e.getParameter(e.MAX_VARYING_VECTORS),b=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),x=e.getParameter(e.MAX_SAMPLES),S=e.getParameter(e.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:a,getMaxPrecision:c,textureFormatReadable:o,textureTypeReadable:s,precision:l,logarithmicDepthBuffer:d,reversedDepthBuffer:f,maxTextures:p,maxVertexTextures:m,maxTextureSize:h,maxCubemapSize:g,maxAttributes:_,maxVertexUniforms:v,maxVaryings:y,maxFragmentUniforms:b,maxSamples:x,samples:S}}function cp(e){let t=this,n=null,r=0,i=!1,a=!1,o=new mo,s=new Fn,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(e,t){let n=e.length!==0||t||r!==0||i;return i=t,r=e.length,n},this.beginShadows=function(){a=!0,u(null)},this.endShadows=function(){a=!1},this.setGlobalState=function(e,t){n=u(e,t,0)},this.setState=function(t,o,s){let d=t.clippingPlanes,f=t.clipIntersection,p=t.clipShadows,m=e.get(t);if(!i||d===null||d.length===0||a&&!p)a?u(null):l();else{let e=a?0:r,t=e*4,i=m.clippingState||null;c.value=i,i=u(d,o,t,s);for(let e=0;e!==t;++e)i[e]=n[e];m.clippingState=i,this.numIntersection=f?this.numPlanes:0,this.numPlanes+=e}};function l(){c.value!==n&&(c.value=n,c.needsUpdate=r>0),t.numPlanes=r,t.numIntersection=0}function u(e,n,r,i){let a=e===null?0:e.length,l=null;if(a!==0){if(l=c.value,i!==!0||l===null){let t=r+a*4,i=n.matrixWorldInverse;s.getNormalMatrix(i),(l===null||l.length0&&this._blur(s,0,0,t),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Dp(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Ep(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=2**this._lodMax}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e2?l:0,l,l),c.setRenderTarget(r),p&&c.render(d,a),c.render(e,a)}c.toneMapping=u,c.autoClear=l,e.background=m}_textureToCubeUV(e,t){let n=this._renderer,r=e.mapping===301||e.mapping===302;r?(this._cubemapMaterial===null&&(this._cubemapMaterial=Dp()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Ep());let i=r?this._cubemapMaterial:this._equirectMaterial,a=this._lodMeshes[0];a.material=i;let o=i.uniforms;o.envMap.value=e;let s=this._cubeSize;Cp(t,0,0,3*s,2*s),n.setRenderTarget(t),n.render(a,pp)}_applyPMREM(e){let t=this._renderer,n=t.autoClear;t.autoClear=!1;let r=this._lodMeshes.length;for(let t=1;td-lp?n-d+lp:0),m=4*(this._cubeSize-f);s.envMap.value=e.texture,s.roughness.value=u,s.mipInt.value=d-t,Cp(i,p,m,3*f,2*f),r.setRenderTarget(i),r.render(o,pp),s.envMap.value=i.texture,s.roughness.value=0,s.mipInt.value=d-n,Cp(e,p,m,3*f,2*f),r.setRenderTarget(e),r.render(o,pp)}_blur(e,t,n,r,i){let a=this._pingPongRenderTarget;this._halfBlur(e,a,t,n,r,`latitudinal`,i),this._halfBlur(a,e,n,n,r,`longitudinal`,i)}_halfBlur(e,t,n,r,i,a,o){let s=this._renderer,c=this._blurMaterial;a!==`latitudinal`&&a!==`longitudinal`&&$t(`blur direction must be either latitudinal or longitudinal!`);let l=this._lodMeshes[r];l.material=c;let u=c.uniforms,d=this._sizeLods[n]-1,f=isFinite(i)?Math.PI/(2*d):2*Math.PI/(2*dp-1),p=i/f,m=isFinite(i)?1+Math.floor(3*p):dp;m>dp&&G(`sigmaRadians, ${i}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${dp}`);let h=[],g=0;for(let e=0;e_-lp?r-_+lp:0),4*(this._cubeSize-v),3*v,2*v),s.setRenderTarget(t),s.render(l,pp)}};function xp(e){let t=[],n=[],r=[],i=e,a=e-lp+1+up.length;for(let o=0;oe-lp?s=up[o-e+lp-1]:o===0&&(s=0),n.push(s);let c=1/(a-2),l=-c,u=1+c,d=[l,l,u,l,u,u,l,l,u,u,l,u],f=new Float32Array(108),p=new Float32Array(72),m=new Float32Array(36);for(let e=0;e<6;e++){let t=e%3*2/3-1,n=e>2?0:-1,r=[t,n,0,t+2/3,n,0,t+2/3,n+1,0,t,n,0,t+2/3,n+1,0,t,n+1,0];f.set(r,18*e),p.set(d,12*e);let i=[e,e,e,e,e,e];m.set(i,6*e)}let h=new Ki;h.setAttribute(`position`,new Ti(f,3)),h.setAttribute(`uv`,new Ti(p,2)),h.setAttribute(`faceIndex`,new Ti(m,1)),r.push(new La(h,null)),i>lp&&i--}return{lodMeshes:r,sizeLods:t,sigmas:n}}function Sp(e,t,n){let r=new $n(e,t,n);return r.texture.mapping=306,r.texture.name=`PMREM.cubeUv`,r.scissorTest=!0,r}function Cp(e,t,n,r,i){e.viewport.set(t,n,r,i),e.scissor.set(t,n,r,i)}function wp(e,t,n){return new yl({name:`PMREMGGXConvolution`,defines:{GGX_SAMPLES:fp,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${e}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:Op(),fragmentShader:` precision highp float; precision highp int; varying vec3 vOutputDirection; uniform sampler2D envMap; uniform float roughness; uniform float mipInt; #define ENVMAP_TYPE_CUBE_UV #include #define PI 3.14159265359 // Van der Corput radical inverse float radicalInverse_VdC(uint bits) { bits = (bits << 16u) | (bits >> 16u); bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); return float(bits) * 2.3283064365386963e-10; // / 0x100000000 } // Hammersley sequence vec2 hammersley(uint i, uint N) { return vec2(float(i) / float(N), radicalInverse_VdC(i)); } // GGX VNDF importance sampling (Eric Heitz 2018) // "Sampling the GGX Distribution of Visible Normals" // https://jcgt.org/published/0007/04/01/ vec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) { float alpha = roughness * roughness; // Section 4.1: Orthonormal basis vec3 T1 = vec3(1.0, 0.0, 0.0); vec3 T2 = cross(V, T1); // Section 4.2: Parameterization of projected area float r = sqrt(Xi.x); float phi = 2.0 * PI * Xi.y; float t1 = r * cos(phi); float t2 = r * sin(phi); float s = 0.5 * (1.0 + V.z); t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2; // Section 4.3: Reprojection onto hemisphere vec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V; // Section 3.4: Transform back to ellipsoid configuration return normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z))); } void main() { vec3 N = normalize(vOutputDirection); vec3 V = N; // Assume view direction equals normal for pre-filtering vec3 prefilteredColor = vec3(0.0); float totalWeight = 0.0; // For very low roughness, just sample the environment directly if (roughness < 0.001) { gl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0); return; } // Tangent space basis for VNDF sampling vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); vec3 tangent = normalize(cross(up, N)); vec3 bitangent = cross(N, tangent); for(uint i = 0u; i < uint(GGX_SAMPLES); i++) { vec2 Xi = hammersley(i, uint(GGX_SAMPLES)); // For PMREM, V = N, so in tangent space V is always (0, 0, 1) vec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness); // Transform H back to world space vec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z); vec3 L = normalize(2.0 * dot(V, H) * H - V); float NdotL = max(dot(N, L), 0.0); if(NdotL > 0.0) { // Sample environment at fixed mip level // VNDF importance sampling handles the distribution filtering vec3 sampleColor = bilinearCubeUV(envMap, L, mipInt); // Weight by NdotL for the split-sum approximation // VNDF PDF naturally accounts for the visible microfacet distribution prefilteredColor += sampleColor * NdotL; totalWeight += NdotL; } } if (totalWeight > 0.0) { prefilteredColor = prefilteredColor / totalWeight; } gl_FragColor = vec4(prefilteredColor, 1.0); } `,blending:0,depthTest:!1,depthWrite:!1})}function Tp(e,t,n){let r=new Float32Array(dp),i=new q(0,1,0);return new yl({name:`SphericalGaussianBlur`,defines:{n:dp,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${e}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:r},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:Op(),fragmentShader:` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; uniform int samples; uniform float weights[ n ]; uniform bool latitudinal; uniform float dTheta; uniform float mipInt; uniform vec3 poleAxis; #define ENVMAP_TYPE_CUBE_UV #include vec3 getSample( float theta, vec3 axis ) { float cosTheta = cos( theta ); // Rodrigues' axis-angle rotation vec3 sampleDirection = vOutputDirection * cosTheta + cross( axis, vOutputDirection ) * sin( theta ) + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); return bilinearCubeUV( envMap, sampleDirection, mipInt ); } void main() { vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); if ( all( equal( axis, vec3( 0.0 ) ) ) ) { axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); } axis = normalize( axis ); gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); for ( int i = 1; i < n; i++ ) { if ( i >= samples ) { break; } float theta = dTheta * float( i ); gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); } } `,blending:0,depthTest:!1,depthWrite:!1})}function Ep(){return new yl({name:`EquirectangularToCubeUV`,uniforms:{envMap:{value:null}},vertexShader:Op(),fragmentShader:` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; #include void main() { vec3 outputDirection = normalize( vOutputDirection ); vec2 uv = equirectUv( outputDirection ); gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); } `,blending:0,depthTest:!1,depthWrite:!1})}function Dp(){return new yl({name:`CubemapToCubeUV`,uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Op(),fragmentShader:` precision mediump float; precision mediump int; uniform float flipEnvMap; varying vec3 vOutputDirection; uniform samplerCube envMap; void main() { gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); } `,blending:0,depthTest:!1,depthWrite:!1})}function Op(){return` precision mediump float; precision mediump int; attribute float faceIndex; varying vec3 vOutputDirection; // RH coordinate system; PMREM face-indexing convention vec3 getDirection( vec2 uv, float face ) { uv = 2.0 * uv - 1.0; vec3 direction = vec3( uv, 1.0 ); if ( face == 0.0 ) { direction = direction.zyx; // ( 1, v, u ) pos x } else if ( face == 1.0 ) { direction = direction.xzy; direction.xz *= -1.0; // ( -u, 1, -v ) pos y } else if ( face == 2.0 ) { direction.x *= -1.0; // ( -u, v, 1 ) pos z } else if ( face == 3.0 ) { direction = direction.zyx; direction.xz *= -1.0; // ( -1, v, -u ) neg x } else if ( face == 4.0 ) { direction = direction.xzy; direction.xy *= -1.0; // ( -u, -1, v ) neg y } else if ( face == 5.0 ) { direction.z *= -1.0; // ( u, v, -1 ) neg z } return direction; } void main() { vOutputDirection = getDirection( uv, faceIndex ); gl_Position = vec4( position, 1.0 ); } `}var kp=class extends $n{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;let n={width:e,height:e,depth:1},r=[n,n,n,n,n,n];this.texture=new ms(r),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let n={uniforms:{tEquirect:{value:null}},vertexShader:` varying vec3 vWorldDirection; vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include } `,fragmentShader:` uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); } `},r=new bs(5,5,5),i=new yl({name:`CubemapFromEquirect`,uniforms:dl(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});i.uniforms.tEquirect.value=t;let a=new La(r,i),o=t.minFilter;return t.minFilter===1008&&(t.minFilter=M),new od(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t=!0,n=!0,r=!0){let i=e.getRenderTarget();for(let i=0;i<6;i++)e.setRenderTarget(this,i),e.clear(t,n,r);e.setRenderTarget(i)}};function Ap(e){let t=new WeakMap,n=new WeakMap,r=null;function i(e,t=!1){return e==null?null:t?o(e):a(e)}function a(n){if(n&&n.isTexture){let r=n.mapping;if(r===303||r===304)if(t.has(n)){let e=t.get(n).texture;return s(e,n.mapping)}else{let r=n.image;if(r&&r.height>0){let i=new kp(r.height);return i.fromEquirectangularTexture(e,n),t.set(n,i),n.addEventListener(`dispose`,l),s(i.texture,n.mapping)}else return null}}return n}function o(t){if(t&&t.isTexture){let i=t.mapping,a=i===303||i===304,o=i===301||i===302;if(a||o){let i=n.get(t),s=i===void 0?0:i.texture.pmremVersion;if(t.isRenderTargetTexture&&t.pmremVersion!==s)return r===null&&(r=new bp(e)),i=a?r.fromEquirectangular(t,i):r.fromCubemap(t,i),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),i.texture;if(i!==void 0)return i.texture;{let s=t.image;return a&&s&&s.height>0||o&&s&&c(s)?(r===null&&(r=new bp(e)),i=a?r.fromEquirectangular(t):r.fromCubemap(t),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),t.addEventListener(`dispose`,u),i.texture):null}}}return t}function s(e,t){return t===303?e.mapping=301:t===304&&(e.mapping=302),e}function c(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function l(e){let n=e.target;n.removeEventListener(`dispose`,l);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function u(e){let t=e.target;t.removeEventListener(`dispose`,u);let r=n.get(t);r!==void 0&&(n.delete(t),r.dispose())}function d(){t=new WeakMap,n=new WeakMap,r!==null&&(r.dispose(),r=null)}return{get:i,dispose:d}}function jp(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r=e.getExtension(n);return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(){n(`EXT_color_buffer_float`),n(`WEBGL_clip_cull_distance`),n(`OES_texture_float_linear`),n(`EXT_color_buffer_half_float`),n(`WEBGL_multisampled_render_to_texture`),n(`WEBGL_render_shared_exponent`)},get:function(e){let t=n(e);return t===null&&en(`WebGLRenderer: `+e+` extension not supported.`),t}}}function Mp(e,t,n,r){let i={},a=new WeakMap;function o(e){let s=e.target;s.index!==null&&t.remove(s.index);for(let e in s.attributes)t.remove(s.attributes[e]);s.removeEventListener(`dispose`,o),delete i[s.id];let c=a.get(s);c&&(t.remove(c),a.delete(s)),r.releaseStatesOfGeometry(s),s.isInstancedBufferGeometry===!0&&delete s._maxInstanceCount,n.memory.geometries--}function s(e,t){return i[t.id]===!0?t:(t.addEventListener(`dispose`,o),i[t.id]=!0,n.memory.geometries++,t)}function c(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER)}function l(e){let n=[],r=e.index,i=e.attributes.position,o=0;if(i===void 0)return;if(r!==null){let e=r.array;o=r.version;for(let t=0,r=e.length;t=65535?Mi:Ai)(n,1);s.version=o;let c=a.get(e);c&&t.remove(c),a.set(e,s)}function u(e){let t=a.get(e);if(t){let n=e.index;n!==null&&t.versiont.maxTextureSize&&(m=Math.ceil(p/t.maxTextureSize),p=t.maxTextureSize);let h=new Float32Array(p*m*4*u),g=new er(h,p,m,u);g.type=V,g.needsUpdate=!0;let _=f*4;for(let t=0;t #include void main() { gl_FragColor = texture2D( tDiffuse, vUv ); #ifdef LINEAR_TONE_MAPPING gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb ); #elif defined( REINHARD_TONE_MAPPING ) gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb ); #elif defined( CINEON_TONE_MAPPING ) gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb ); #elif defined( ACES_FILMIC_TONE_MAPPING ) gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb ); #elif defined( AGX_TONE_MAPPING ) gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb ); #elif defined( NEUTRAL_TONE_MAPPING ) gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb ); #elif defined( CUSTOM_TONE_MAPPING ) gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb ); #endif #ifdef SRGB_TRANSFER gl_FragColor = sRGBTransferOETF( gl_FragColor ); #endif }`,depthTest:!1,depthWrite:!1}),l=new La(s,c),u=new Nu(-1,1,1,-1,0,1),d=null,f=null,p=!1,m,h=null,g=[],_=!1;this.setSize=function(e,t){a.setSize(e,t),o.setSize(e,t);for(let n=0;n0&&g[0].isRenderPass===!0;let t=a.width,n=a.height;for(let e=0;e0)return e;let i=t*n,a=Wp[i];if(a===void 0&&(a=new Float32Array(i),Wp[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function Xp(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n0&&(this.seq=r.concat(i))}setValue(e,t,n,r){let i=this.map[t];i!==void 0&&i.setValue(e,n,r)}setOptional(e,t,n){let r=t[n];r!==void 0&&this.setValue(e,n,r)}static upload(e,t,n,r){for(let i=0,a=t.length;i!==a;++i){let a=t[i],o=n[a.id];o.needsUpdate!==!1&&a.setValue(e,o.value,r)}}static seqWithValue(e,t){let n=[];for(let r=0,i=e.length;r!==i;++r){let i=e[r];i.id in t&&n.push(i)}return n}};function Km(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}var qm=37297,Jm=0;function Ym(e,t){let n=e.split(` `),r=[],i=Math.max(t-6,0),a=Math.min(t+6,n.length);for(let e=i;e`:` `} ${i}: ${n[e]}`)}return r.join(` `)}var Xm=new Fn;function Zm(e){Bn._getMatrix(Xm,Bn.workingColorSpace,e);let t=`mat3( ${Xm.elements.map(e=>e.toFixed(4))} )`;switch(Bn.getTransfer(e)){case gt:return[t,`LinearTransferOETF`];case _t:return[t,`sRGBTransferOETF`];default:return G(`WebGLProgram: Unsupported color space: `,e),[t,`LinearTransferOETF`]}}function Qm(e,t,n){let r=e.getShaderParameter(t,e.COMPILE_STATUS),i=(e.getShaderInfoLog(t)||``).trim();if(r&&i===``)return``;let a=/ERROR: 0:(\d+)/.exec(i);if(a){let r=parseInt(a[1]);return n.toUpperCase()+` `+i+` `+Ym(e.getShaderSource(t),r)}else return i}function $m(e,t){let n=Zm(t);return[`vec4 ${e}( vec4 value ) {`,` return ${n[1]}( vec4( value.rgb * ${n[0]}, value.a ) );`,`}`].join(` `)}var eh={1:`Linear`,2:`Reinhard`,3:`Cineon`,4:`ACESFilmic`,6:`AgX`,7:`Neutral`,5:`Custom`};function th(e,t){let n=eh[t];return n===void 0?(G(`WebGLProgram: Unsupported toneMapping:`,t),`vec3 `+e+`( vec3 color ) { return LinearToneMapping( color ); }`):`vec3 `+e+`( vec3 color ) { return `+n+`ToneMapping( color ); }`}var nh=new q;function rh(){return Bn.getLuminanceCoefficients(nh),[`float luminance( const in vec3 rgb ) {`,` const vec3 weights = vec3( ${nh.x.toFixed(4)}, ${nh.y.toFixed(4)}, ${nh.z.toFixed(4)} );`,` return dot( weights, rgb );`,`}`].join(` `)}function ih(e){return[e.extensionClipCullDistance?`#extension GL_ANGLE_clip_cull_distance : require`:``,e.extensionMultiDraw?`#extension GL_ANGLE_multi_draw : require`:``].filter(sh).join(` `)}function ah(e){let t=[];for(let n in e){let r=e[n];r!==!1&&t.push(`#define `+n+` `+r)}return t.join(` `)}function oh(e,t){let n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let i=0;i/gm;function dh(e){return e.replace(uh,ph)}var fh=new Map;function ph(e,t){let n=$f[t];if(n===void 0){let e=fh.get(t);if(e!==void 0)n=$f[e],G(`WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.`,t,e);else throw Error(`Can not resolve #include <`+t+`>`)}return dh(n)}var mh=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function hh(e){return e.replace(mh,gh)}function gh(e,t,n,r){let i=``;for(let e=parseInt(t);e0&&(g+=` `),_=[`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m].filter(sh).join(` `),_.length>0&&(_+=` `)):(g=[_h(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m,n.extensionClipCullDistance?`#define USE_CLIP_DISTANCE`:``,n.batching?`#define USE_BATCHING`:``,n.batchingColor?`#define USE_BATCHING_COLOR`:``,n.instancing?`#define USE_INSTANCING`:``,n.instancingColor?`#define USE_INSTANCING_COLOR`:``,n.instancingMorph?`#define USE_INSTANCING_MORPH`:``,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.map?`#define USE_MAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+u:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.displacementMap?`#define USE_DISPLACEMENTMAP`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.mapUv?`#define MAP_UV `+n.mapUv:``,n.alphaMapUv?`#define ALPHAMAP_UV `+n.alphaMapUv:``,n.lightMapUv?`#define LIGHTMAP_UV `+n.lightMapUv:``,n.aoMapUv?`#define AOMAP_UV `+n.aoMapUv:``,n.emissiveMapUv?`#define EMISSIVEMAP_UV `+n.emissiveMapUv:``,n.bumpMapUv?`#define BUMPMAP_UV `+n.bumpMapUv:``,n.normalMapUv?`#define NORMALMAP_UV `+n.normalMapUv:``,n.displacementMapUv?`#define DISPLACEMENTMAP_UV `+n.displacementMapUv:``,n.metalnessMapUv?`#define METALNESSMAP_UV `+n.metalnessMapUv:``,n.roughnessMapUv?`#define ROUGHNESSMAP_UV `+n.roughnessMapUv:``,n.anisotropyMapUv?`#define ANISOTROPYMAP_UV `+n.anisotropyMapUv:``,n.clearcoatMapUv?`#define CLEARCOATMAP_UV `+n.clearcoatMapUv:``,n.clearcoatNormalMapUv?`#define CLEARCOAT_NORMALMAP_UV `+n.clearcoatNormalMapUv:``,n.clearcoatRoughnessMapUv?`#define CLEARCOAT_ROUGHNESSMAP_UV `+n.clearcoatRoughnessMapUv:``,n.iridescenceMapUv?`#define IRIDESCENCEMAP_UV `+n.iridescenceMapUv:``,n.iridescenceThicknessMapUv?`#define IRIDESCENCE_THICKNESSMAP_UV `+n.iridescenceThicknessMapUv:``,n.sheenColorMapUv?`#define SHEEN_COLORMAP_UV `+n.sheenColorMapUv:``,n.sheenRoughnessMapUv?`#define SHEEN_ROUGHNESSMAP_UV `+n.sheenRoughnessMapUv:``,n.specularMapUv?`#define SPECULARMAP_UV `+n.specularMapUv:``,n.specularColorMapUv?`#define SPECULAR_COLORMAP_UV `+n.specularColorMapUv:``,n.specularIntensityMapUv?`#define SPECULAR_INTENSITYMAP_UV `+n.specularIntensityMapUv:``,n.transmissionMapUv?`#define TRANSMISSIONMAP_UV `+n.transmissionMapUv:``,n.thicknessMapUv?`#define THICKNESSMAP_UV `+n.thicknessMapUv:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexNormals?`#define HAS_NORMAL`:``,n.vertexColors?`#define USE_COLOR`:``,n.vertexAlphas?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.flatShading?`#define FLAT_SHADED`:``,n.skinning?`#define USE_SKINNING`:``,n.morphTargets?`#define USE_MORPHTARGETS`:``,n.morphNormals&&n.flatShading===!1?`#define USE_MORPHNORMALS`:``,n.morphColors?`#define USE_MORPHCOLORS`:``,n.morphTargetsCount>0?`#define MORPHTARGETS_TEXTURE_STRIDE `+n.morphTextureStride:``,n.morphTargetsCount>0?`#define MORPHTARGETS_COUNT `+n.morphTargetsCount:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.sizeAttenuation?`#define USE_SIZEATTENUATION`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,n.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 modelMatrix;`,`uniform mat4 modelViewMatrix;`,`uniform mat4 projectionMatrix;`,`uniform mat4 viewMatrix;`,`uniform mat3 normalMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,`#ifdef USE_INSTANCING`,` attribute mat4 instanceMatrix;`,`#endif`,`#ifdef USE_INSTANCING_COLOR`,` attribute vec3 instanceColor;`,`#endif`,`#ifdef USE_INSTANCING_MORPH`,` uniform sampler2D morphTexture;`,`#endif`,`attribute vec3 position;`,`attribute vec3 normal;`,`attribute vec2 uv;`,`#ifdef USE_UV1`,` attribute vec2 uv1;`,`#endif`,`#ifdef USE_UV2`,` attribute vec2 uv2;`,`#endif`,`#ifdef USE_UV3`,` attribute vec2 uv3;`,`#endif`,`#ifdef USE_TANGENT`,` attribute vec4 tangent;`,`#endif`,`#if defined( USE_COLOR_ALPHA )`,` attribute vec4 color;`,`#elif defined( USE_COLOR )`,` attribute vec3 color;`,`#endif`,`#ifdef USE_SKINNING`,` attribute vec4 skinIndex;`,` attribute vec4 skinWeight;`,`#endif`,` `].filter(sh).join(` `),_=[_h(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.alphaToCoverage?`#define ALPHA_TO_COVERAGE`:``,n.map?`#define USE_MAP`:``,n.matcap?`#define USE_MATCAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+l:``,n.envMap?`#define `+u:``,n.envMap?`#define `+d:``,f?`#define CUBEUV_TEXEL_WIDTH `+f.texelWidth:``,f?`#define CUBEUV_TEXEL_HEIGHT `+f.texelHeight:``,f?`#define CUBEUV_MAX_MIP `+f.maxMip+`.0`:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.packedNormalMap?`#define USE_PACKED_NORMALMAP`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoat?`#define USE_CLEARCOAT`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.dispersion?`#define USE_DISPERSION`:``,n.iridescence?`#define USE_IRIDESCENCE`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaTest?`#define USE_ALPHATEST`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.sheen?`#define USE_SHEEN`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexColors||n.instancingColor?`#define USE_COLOR`:``,n.vertexAlphas||n.batchingColor?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.gradientMap?`#define USE_GRADIENTMAP`:``,n.flatShading?`#define FLAT_SHADED`:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.premultipliedAlpha?`#define PREMULTIPLIED_ALPHA`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.numLightProbeGrids>0?`#define USE_LIGHT_PROBES_GRID`:``,n.decodeVideoTexture?`#define DECODE_VIDEO_TEXTURE`:``,n.decodeVideoTextureEmissive?`#define DECODE_VIDEO_TEXTURE_EMISSIVE`:``,n.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,n.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 viewMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,n.toneMapping===0?``:`#define TONE_MAPPING`,n.toneMapping===0?``:$f.tonemapping_pars_fragment,n.toneMapping===0?``:th(`toneMapping`,n.toneMapping),n.dithering?`#define DITHERING`:``,n.opaque?`#define OPAQUE`:``,$f.colorspace_pars_fragment,$m(`linearToOutputTexel`,n.outputColorSpace),rh(),n.useDepthPacking?`#define DEPTH_PACKING `+n.depthPacking:``,` `].filter(sh).join(` `)),o=dh(o),o=ch(o,n),o=lh(o,n),s=dh(s),s=ch(s,n),s=lh(s,n),o=hh(o),s=hh(s),n.isRawShaderMaterial!==!0&&(v=`#version 300 es `,g=[p,`#define attribute in`,`#define varying out`,`#define texture2D texture`].join(` `)+` `+g,_=[`#define varying in`,n.glslVersion===`300 es`?``:`layout(location = 0) out highp vec4 pc_fragColor;`,n.glslVersion===`300 es`?``:`#define gl_FragColor pc_fragColor`,`#define gl_FragDepthEXT gl_FragDepth`,`#define texture2D texture`,`#define textureCube texture`,`#define texture2DProj textureProj`,`#define texture2DLodEXT textureLod`,`#define texture2DProjLodEXT textureProjLod`,`#define textureCubeLodEXT textureLod`,`#define texture2DGradEXT textureGrad`,`#define texture2DProjGradEXT textureProjGrad`,`#define textureCubeGradEXT textureGrad`].join(` `)+` `+_);let y=v+g+o,b=v+_+s,x=Km(i,i.VERTEX_SHADER,y),S=Km(i,i.FRAGMENT_SHADER,b);i.attachShader(h,x),i.attachShader(h,S),n.index0AttributeName===void 0?n.morphTargets===!0&&i.bindAttribLocation(h,0,`position`):i.bindAttribLocation(h,0,n.index0AttributeName),i.linkProgram(h);function C(t){if(e.debug.checkShaderErrors){let n=i.getProgramInfoLog(h)||``,r=i.getShaderInfoLog(x)||``,a=i.getShaderInfoLog(S)||``,o=n.trim(),s=r.trim(),c=a.trim(),l=!0,u=!0;if(i.getProgramParameter(h,i.LINK_STATUS)===!1)if(l=!1,typeof e.debug.onShaderError==`function`)e.debug.onShaderError(i,h,x,S);else{let e=Qm(i,x,`vertex`),n=Qm(i,S,`fragment`);$t(`THREE.WebGLProgram: Shader Error `+i.getError()+` - VALIDATE_STATUS `+i.getProgramParameter(h,i.VALIDATE_STATUS)+` Material Name: `+t.name+` Material Type: `+t.type+` Program Info Log: `+o+` `+e+` `+n)}else o===``?(s===``||c===``)&&(u=!1):G(`WebGLProgram: Program Info Log:`,o);u&&(t.diagnostics={runnable:l,programLog:o,vertexShader:{log:s,prefix:g},fragmentShader:{log:c,prefix:_}})}i.deleteShader(x),i.deleteShader(S),w=new Gm(i,h),T=oh(i,h)}let w;this.getUniforms=function(){return w===void 0&&C(this),w};let T;this.getAttributes=function(){return T===void 0&&C(this),T};let E=n.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return E===!1&&(E=i.getProgramParameter(h,qm)),E},this.destroy=function(){r.releaseStatesOfProgram(this),i.deleteProgram(h),this.program=void 0},this.type=n.shaderType,this.name=n.shaderName,this.id=Jm++,this.cacheKey=t,this.usedTimes=1,this.program=h,this.vertexShader=x,this.fragmentShader=S,this}var Oh=0,kh=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){let t=e.vertexShader,n=e.fragmentShader,r=this._getShaderStage(t),i=this._getShaderStage(n),a=this._getShaderCacheForMaterial(e);return a.has(r)===!1&&(a.add(r),r.usedTimes++),a.has(i)===!1&&(a.add(i),i.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let e of t)e.usedTimes--,e.usedTimes===0&&this.shaderCache.delete(e.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache,n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){let t=this.shaderCache,n=t.get(e);return n===void 0&&(n=new Ah(e),t.set(e,n)),n}},Ah=class{constructor(e){this.id=Oh++,this.code=e,this.usedTimes=0}};function jh(e){return e===1030||e===37490||e===36285}function Mh(e,t,n,r,i,a){let o=new mr,s=new kh,c=new Set,l=[],u=new Map,d=r.logarithmicDepthBuffer,f=r.precision,p={MeshDepthMaterial:`depth`,MeshDistanceMaterial:`distance`,MeshNormalMaterial:`normal`,MeshBasicMaterial:`basic`,MeshLambertMaterial:`lambert`,MeshPhongMaterial:`phong`,MeshToonMaterial:`toon`,MeshStandardMaterial:`physical`,MeshPhysicalMaterial:`physical`,MeshMatcapMaterial:`matcap`,LineBasicMaterial:`basic`,LineDashedMaterial:`dashed`,PointsMaterial:`points`,ShadowMaterial:`shadow`,SpriteMaterial:`sprite`};function m(e){return c.add(e),e===0?`uv`:`uv${e}`}function h(i,o,l,u,h,g){let _=u.fog,v=h.geometry,y=i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial?u.environment:null,b=i.isMeshStandardMaterial||i.isMeshLambertMaterial&&!i.envMap||i.isMeshPhongMaterial&&!i.envMap,x=t.get(i.envMap||y,b),S=x&&x.mapping===306?x.image.height:null,C=p[i.type];i.precision!==null&&(f=r.getMaxPrecision(i.precision),f!==i.precision&&G(`WebGLProgram.getParameters:`,i.precision,`not supported, using`,f,`instead.`));let w=v.morphAttributes.position||v.morphAttributes.normal||v.morphAttributes.color,T=w===void 0?0:w.length,E=0;v.morphAttributes.position!==void 0&&(E=1),v.morphAttributes.normal!==void 0&&(E=2),v.morphAttributes.color!==void 0&&(E=3);let D,O,k,A;if(C){let e=ep[C];D=e.vertexShader,O=e.fragmentShader}else D=i.vertexShader,O=i.fragmentShader,s.update(i),k=s.getVertexShaderID(i),A=s.getFragmentShaderID(i);let j=e.getRenderTarget(),M=e.state.buffers.depth.getReversed(),N=h.isInstancedMesh===!0,P=h.isBatchedMesh===!0,F=!!i.map,I=!!i.matcap,L=!!x,ee=!!i.aoMap,R=!!i.lightMap,te=!!i.bumpMap,z=!!i.normalMap,B=!!i.displacementMap,V=!!i.emissiveMap,ne=!!i.metalnessMap,re=!!i.roughnessMap,ie=i.anisotropy>0,ae=i.clearcoat>0,oe=i.dispersion>0,se=i.iridescence>0,ce=i.sheen>0,H=i.transmission>0,le=ie&&!!i.anisotropyMap,ue=ae&&!!i.clearcoatMap,de=ae&&!!i.clearcoatNormalMap,fe=ae&&!!i.clearcoatRoughnessMap,pe=se&&!!i.iridescenceMap,me=se&&!!i.iridescenceThicknessMap,he=ce&&!!i.sheenColorMap,ge=ce&&!!i.sheenRoughnessMap,_e=!!i.specularMap,ve=!!i.specularColorMap,ye=!!i.specularIntensityMap,be=H&&!!i.transmissionMap,xe=H&&!!i.thicknessMap,Se=!!i.gradientMap,U=!!i.alphaMap,Ce=i.alphaTest>0,we=!!i.alphaHash,Te=!!i.extensions,W=0;i.toneMapped&&(j===null||j.isXRRenderTarget===!0)&&(W=e.toneMapping);let Ee={shaderID:C,shaderType:i.type,shaderName:i.name,vertexShader:D,fragmentShader:O,defines:i.defines,customVertexShaderID:k,customFragmentShaderID:A,isRawShaderMaterial:i.isRawShaderMaterial===!0,glslVersion:i.glslVersion,precision:f,batching:P,batchingColor:P&&h._colorsTexture!==null,instancing:N,instancingColor:N&&h.instanceColor!==null,instancingMorph:N&&h.morphTexture!==null,outputColorSpace:j===null?e.outputColorSpace:j.isXRRenderTarget===!0?j.texture.colorSpace:Bn.workingColorSpace,alphaToCoverage:!!i.alphaToCoverage,map:F,matcap:I,envMap:L,envMapMode:L&&x.mapping,envMapCubeUVHeight:S,aoMap:ee,lightMap:R,bumpMap:te,normalMap:z,displacementMap:B,emissiveMap:V,normalMapObjectSpace:z&&i.normalMapType===1,normalMapTangentSpace:z&&i.normalMapType===0,packedNormalMap:z&&i.normalMapType===0&&jh(i.normalMap.format),metalnessMap:ne,roughnessMap:re,anisotropy:ie,anisotropyMap:le,clearcoat:ae,clearcoatMap:ue,clearcoatNormalMap:de,clearcoatRoughnessMap:fe,dispersion:oe,iridescence:se,iridescenceMap:pe,iridescenceThicknessMap:me,sheen:ce,sheenColorMap:he,sheenRoughnessMap:ge,specularMap:_e,specularColorMap:ve,specularIntensityMap:ye,transmission:H,transmissionMap:be,thicknessMap:xe,gradientMap:Se,opaque:i.transparent===!1&&i.blending===1&&i.alphaToCoverage===!1,alphaMap:U,alphaTest:Ce,alphaHash:we,combine:i.combine,mapUv:F&&m(i.map.channel),aoMapUv:ee&&m(i.aoMap.channel),lightMapUv:R&&m(i.lightMap.channel),bumpMapUv:te&&m(i.bumpMap.channel),normalMapUv:z&&m(i.normalMap.channel),displacementMapUv:B&&m(i.displacementMap.channel),emissiveMapUv:V&&m(i.emissiveMap.channel),metalnessMapUv:ne&&m(i.metalnessMap.channel),roughnessMapUv:re&&m(i.roughnessMap.channel),anisotropyMapUv:le&&m(i.anisotropyMap.channel),clearcoatMapUv:ue&&m(i.clearcoatMap.channel),clearcoatNormalMapUv:de&&m(i.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:fe&&m(i.clearcoatRoughnessMap.channel),iridescenceMapUv:pe&&m(i.iridescenceMap.channel),iridescenceThicknessMapUv:me&&m(i.iridescenceThicknessMap.channel),sheenColorMapUv:he&&m(i.sheenColorMap.channel),sheenRoughnessMapUv:ge&&m(i.sheenRoughnessMap.channel),specularMapUv:_e&&m(i.specularMap.channel),specularColorMapUv:ve&&m(i.specularColorMap.channel),specularIntensityMapUv:ye&&m(i.specularIntensityMap.channel),transmissionMapUv:be&&m(i.transmissionMap.channel),thicknessMapUv:xe&&m(i.thicknessMap.channel),alphaMapUv:U&&m(i.alphaMap.channel),vertexTangents:!!v.attributes.tangent&&(z||ie),vertexNormals:!!v.attributes.normal,vertexColors:i.vertexColors,vertexAlphas:i.vertexColors===!0&&!!v.attributes.color&&v.attributes.color.itemSize===4,pointsUvs:h.isPoints===!0&&!!v.attributes.uv&&(F||U),fog:!!_,useFog:i.fog===!0,fogExp2:!!_&&_.isFogExp2,flatShading:i.wireframe===!1&&(i.flatShading===!0||v.attributes.normal===void 0&&z===!1&&(i.isMeshLambertMaterial||i.isMeshPhongMaterial||i.isMeshStandardMaterial||i.isMeshPhysicalMaterial)),sizeAttenuation:i.sizeAttenuation===!0,logarithmicDepthBuffer:d,reversedDepthBuffer:M,skinning:h.isSkinnedMesh===!0,morphTargets:v.morphAttributes.position!==void 0,morphNormals:v.morphAttributes.normal!==void 0,morphColors:v.morphAttributes.color!==void 0,morphTargetsCount:T,morphTextureStride:E,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numSpotLightMaps:o.spotLightMap.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numSpotLightShadowsWithMaps:o.numSpotLightShadowsWithMaps,numLightProbes:o.numLightProbes,numLightProbeGrids:g.length,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:i.dithering,shadowMapEnabled:e.shadowMap.enabled&&l.length>0,shadowMapType:e.shadowMap.type,toneMapping:W,decodeVideoTexture:F&&i.map.isVideoTexture===!0&&Bn.getTransfer(i.map.colorSpace)===`srgb`,decodeVideoTextureEmissive:V&&i.emissiveMap.isVideoTexture===!0&&Bn.getTransfer(i.emissiveMap.colorSpace)===`srgb`,premultipliedAlpha:i.premultipliedAlpha,doubleSided:i.side===2,flipSided:i.side===1,useDepthPacking:i.depthPacking>=0,depthPacking:i.depthPacking||0,index0AttributeName:i.index0AttributeName,extensionClipCullDistance:Te&&i.extensions.clipCullDistance===!0&&n.has(`WEBGL_clip_cull_distance`),extensionMultiDraw:(Te&&i.extensions.multiDraw===!0||P)&&n.has(`WEBGL_multi_draw`),rendererExtensionParallelShaderCompile:n.has(`KHR_parallel_shader_compile`),customProgramCacheKey:i.customProgramCacheKey()};return Ee.vertexUv1s=c.has(1),Ee.vertexUv2s=c.has(2),Ee.vertexUv3s=c.has(3),c.clear(),Ee}function g(t){let n=[];if(t.shaderID?n.push(t.shaderID):(n.push(t.customVertexShaderID),n.push(t.customFragmentShaderID)),t.defines!==void 0)for(let e in t.defines)n.push(e),n.push(t.defines[e]);return t.isRawShaderMaterial===!1&&(_(n,t),v(n,t),n.push(e.outputColorSpace)),n.push(t.customProgramCacheKey),n.join()}function _(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapCubeUVHeight),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.morphAttributeCount),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}function v(e,t){o.disableAll(),t.instancing&&o.enable(0),t.instancingColor&&o.enable(1),t.instancingMorph&&o.enable(2),t.matcap&&o.enable(3),t.envMap&&o.enable(4),t.normalMapObjectSpace&&o.enable(5),t.normalMapTangentSpace&&o.enable(6),t.clearcoat&&o.enable(7),t.iridescence&&o.enable(8),t.alphaTest&&o.enable(9),t.vertexColors&&o.enable(10),t.vertexAlphas&&o.enable(11),t.vertexUv1s&&o.enable(12),t.vertexUv2s&&o.enable(13),t.vertexUv3s&&o.enable(14),t.vertexTangents&&o.enable(15),t.anisotropy&&o.enable(16),t.alphaHash&&o.enable(17),t.batching&&o.enable(18),t.dispersion&&o.enable(19),t.batchingColor&&o.enable(20),t.gradientMap&&o.enable(21),t.packedNormalMap&&o.enable(22),t.vertexNormals&&o.enable(23),e.push(o.mask),o.disableAll(),t.fog&&o.enable(0),t.useFog&&o.enable(1),t.flatShading&&o.enable(2),t.logarithmicDepthBuffer&&o.enable(3),t.reversedDepthBuffer&&o.enable(4),t.skinning&&o.enable(5),t.morphTargets&&o.enable(6),t.morphNormals&&o.enable(7),t.morphColors&&o.enable(8),t.premultipliedAlpha&&o.enable(9),t.shadowMapEnabled&&o.enable(10),t.doubleSided&&o.enable(11),t.flipSided&&o.enable(12),t.useDepthPacking&&o.enable(13),t.dithering&&o.enable(14),t.transmission&&o.enable(15),t.sheen&&o.enable(16),t.opaque&&o.enable(17),t.pointsUvs&&o.enable(18),t.decodeVideoTexture&&o.enable(19),t.decodeVideoTextureEmissive&&o.enable(20),t.alphaToCoverage&&o.enable(21),t.numLightProbeGrids>0&&o.enable(22),e.push(o.mask)}function y(e){let t=p[e.type],n;if(t){let e=ep[t];n=gl.clone(e.uniforms)}else n=e.uniforms;return n}function b(t,n){let r=u.get(n);return r===void 0?(r=new Dh(e,n,t,i),l.push(r),u.set(n,r)):++r.usedTimes,r}function x(e){if(--e.usedTimes===0){let t=l.indexOf(e);l[t]=l[l.length-1],l.pop(),u.delete(e.cacheKey),e.destroy()}}function S(e){s.remove(e)}function C(){s.dispose()}return{getParameters:h,getProgramCacheKey:g,getUniforms:y,acquireProgram:b,releaseProgram:x,releaseShaderCache:S,programs:l,dispose:C}}function Nh(){let e=new WeakMap;function t(t){return e.has(t)}function n(t){let n=e.get(t);return n===void 0&&(n={},e.set(t,n)),n}function r(t){e.delete(t)}function i(t,n,r){e.get(t)[n]=r}function a(){e=new WeakMap}return{has:t,get:n,remove:r,update:i,dispose:a}}function Ph(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.material.id===t.material.id?e.materialVariant===t.materialVariant?e.z===t.z?e.id-t.id:e.z-t.z:e.materialVariant-t.materialVariant:e.material.id-t.material.id:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function Fh(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.z===t.z?e.id-t.id:t.z-e.z:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function Ih(){let e=[],t=0,n=[],r=[],i=[];function a(){t=0,n.length=0,r.length=0,i.length=0}function o(e){let t=0;return e.isInstancedMesh&&(t+=2),e.isSkinnedMesh&&(t+=1),t}function s(n,r,i,a,s,c){let l=e[t];return l===void 0?(l={id:n.id,object:n,geometry:r,material:i,materialVariant:o(n),groupOrder:a,renderOrder:n.renderOrder,z:s,group:c},e[t]=l):(l.id=n.id,l.object=n,l.geometry=r,l.material=i,l.materialVariant=o(n),l.groupOrder=a,l.renderOrder=n.renderOrder,l.z=s,l.group=c),t++,l}function c(e,t,a,o,c,l){let u=s(e,t,a,o,c,l);a.transmission>0?r.push(u):a.transparent===!0?i.push(u):n.push(u)}function l(e,t,a,o,c,l){let u=s(e,t,a,o,c,l);a.transmission>0?r.unshift(u):a.transparent===!0?i.unshift(u):n.unshift(u)}function u(e,t){n.length>1&&n.sort(e||Ph),r.length>1&&r.sort(t||Fh),i.length>1&&i.sort(t||Fh)}function d(){for(let n=t,r=e.length;n=r.length?(i=new Ih,r.push(i)):i=r[n],i}function n(){e=new WeakMap}return{get:t,dispose:n}}function Rh(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`DirectionalLight`:n={direction:new q,color:new Y};break;case`SpotLight`:n={position:new q,direction:new q,color:new Y,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case`PointLight`:n={position:new q,color:new Y,distance:0,decay:0};break;case`HemisphereLight`:n={direction:new q,skyColor:new Y,groundColor:new Y};break;case`RectAreaLight`:n={color:new Y,position:new q,halfWidth:new q,halfHeight:new q};break}return e[t.id]=n,n}}}function zh(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`DirectionalLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K};break;case`SpotLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K};break;case`PointLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K,shadowCameraNear:1,shadowCameraFar:1e3};break}return e[t.id]=n,n}}}var Bh=0;function Vh(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+ +!!t.map-!!e.map}function Hh(e){let t=new Rh,n=zh(),r={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let e=0;e<9;e++)r.probe.push(new q);let i=new q,a=new J,o=new J;function s(i){let a=0,o=0,s=0;for(let e=0;e<9;e++)r.probe[e].set(0,0,0);let c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0;i.sort(Vh);for(let e=0,y=i.length;e0&&(e.has(`OES_texture_float_linear`)===!0?(r.rectAreaLTC1=X.LTC_FLOAT_1,r.rectAreaLTC2=X.LTC_FLOAT_2):(r.rectAreaLTC1=X.LTC_HALF_1,r.rectAreaLTC2=X.LTC_HALF_2)),r.ambient[0]=a,r.ambient[1]=o,r.ambient[2]=s;let y=r.hash;(y.directionalLength!==c||y.pointLength!==l||y.spotLength!==u||y.rectAreaLength!==d||y.hemiLength!==f||y.numDirectionalShadows!==p||y.numPointShadows!==m||y.numSpotShadows!==h||y.numSpotMaps!==g||y.numLightProbes!==v)&&(r.directional.length=c,r.spot.length=u,r.rectArea.length=d,r.point.length=l,r.hemi.length=f,r.directionalShadow.length=p,r.directionalShadowMap.length=p,r.pointShadow.length=m,r.pointShadowMap.length=m,r.spotShadow.length=h,r.spotShadowMap.length=h,r.directionalShadowMatrix.length=p,r.pointShadowMatrix.length=m,r.spotLightMatrix.length=h+g-_,r.spotLightMap.length=g,r.numSpotLightShadowsWithMaps=_,r.numLightProbes=v,y.directionalLength=c,y.pointLength=l,y.spotLength=u,y.rectAreaLength=d,y.hemiLength=f,y.numDirectionalShadows=p,y.numPointShadows=m,y.numSpotShadows=h,y.numSpotMaps=g,y.numLightProbes=v,r.version=Bh++)}function c(e,t){let n=0,s=0,c=0,l=0,u=0,d=t.matrixWorldInverse;for(let t=0,f=e.length;t=i.length?(a=new Uh(e),i.push(a)):a=i[r],a}function r(){t=new WeakMap}return{get:n,dispose:r}}var Gh=`void main() { gl_Position = vec4( position, 1.0 ); }`,Kh=`uniform sampler2D shadow_pass; uniform vec2 resolution; uniform float radius; void main() { const float samples = float( VSM_SAMPLES ); float mean = 0.0; float squared_mean = 0.0; float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); float uvStart = samples <= 1.0 ? 0.0 : - 1.0; for ( float i = 0.0; i < samples; i ++ ) { float uvOffset = uvStart + i * uvStride; #ifdef HORIZONTAL_PASS vec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg; mean += distribution.x; squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; #else float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r; mean += depth; squared_mean += depth * depth; #endif } mean = mean / samples; squared_mean = squared_mean / samples; float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) ); gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 ); }`,qh=[new q(1,0,0),new q(-1,0,0),new q(0,1,0),new q(0,-1,0),new q(0,0,1),new q(0,0,-1)],Jh=[new q(0,-1,0),new q(0,-1,0),new q(0,0,1),new q(0,0,-1),new q(0,-1,0),new q(0,-1,0)],Yh=new J,Xh=new q,Zh=new q;function Qh(e,t,n){let r=new vo,i=new K,a=new K,o=new Zn,s=new Dl,c=new Ol,l={},u=n.maxTextureSize,d={0:1,1:0,2:2},f=new yl({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new K},radius:{value:4}},vertexShader:Gh,fragmentShader:Kh}),p=f.clone();p.defines.HORIZONTAL_PASS=1;let m=new Ki;m.setAttribute(`position`,new Ti(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let h=new La(m,f),g=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let _=this.type;this.render=function(t,n,s){if(g.enabled===!1||g.autoUpdate===!1&&g.needsUpdate===!1||t.length===0)return;this.type===2&&(G(`WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.`),this.type=1);let c=e.getRenderTarget(),l=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),f=e.state;f.setBlending(0),f.buffers.depth.getReversed()===!0?f.buffers.color.setClear(0,0,0,0):f.buffers.color.setClear(1,1,1,1),f.buffers.depth.setTest(!0),f.setScissorTest(!1);let p=_!==this.type;p&&n.traverse(function(e){e.material&&(Array.isArray(e.material)?e.material.forEach(e=>e.needsUpdate=!0):e.material.needsUpdate=!0)});for(let c=0,l=t.length;cu||i.y>u)&&(i.x>u&&(a.x=Math.floor(u/m.x),i.x=a.x*m.x,d.mapSize.x=a.x),i.y>u&&(a.y=Math.floor(u/m.y),i.y=a.y*m.y,d.mapSize.y=a.y));let h=e.state.buffers.depth.getReversed();if(d.camera._reversedDepth=h,d.map===null||p===!0){if(d.map!==null&&(d.map.depthTexture!==null&&(d.map.depthTexture.dispose(),d.map.depthTexture=null),d.map.dispose()),this.type===3){if(l.isPointLight){G(`WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.`);continue}d.map=new $n(i.x,i.y,{format:me,type:ne,minFilter:M,magFilter:M,generateMipmaps:!1}),d.map.texture.name=l.name+`.shadowMap`,d.map.depthTexture=new _s(i.x,i.y,V),d.map.depthTexture.name=l.name+`.shadowMapDepth`,d.map.depthTexture.format=ue,d.map.depthTexture.compareFunction=null,d.map.depthTexture.minFilter=D,d.map.depthTexture.magFilter=D}else l.isPointLight?(d.map=new kp(i.x),d.map.depthTexture=new vs(i.x,B)):(d.map=new $n(i.x,i.y),d.map.depthTexture=new _s(i.x,i.y,B)),d.map.depthTexture.name=l.name+`.shadowMap`,d.map.depthTexture.format=ue,this.type===1?(d.map.depthTexture.compareFunction=h?518:515,d.map.depthTexture.minFilter=M,d.map.depthTexture.magFilter=M):(d.map.depthTexture.compareFunction=null,d.map.depthTexture.minFilter=D,d.map.depthTexture.magFilter=D);d.camera.updateProjectionMatrix()}let g=d.map.isWebGLCubeRenderTarget?6:1;for(let t=0;t0||n.map&&n.alphaTest>0||n.alphaToCoverage===!0){let e=a.uuid,t=n.uuid,r=l[e];r===void 0&&(r={},l[e]=r);let i=r[t];i===void 0&&(i=a.clone(),r[t]=i,n.addEventListener(`dispose`,x)),a=i}if(a.visible=n.visible,a.wireframe=n.wireframe,i===3?a.side=n.shadowSide===null?n.side:n.shadowSide:a.side=n.shadowSide===null?d[n.side]:n.shadowSide,a.alphaMap=n.alphaMap,a.alphaTest=n.alphaToCoverage===!0?.5:n.alphaTest,a.map=n.map,a.clipShadows=n.clipShadows,a.clippingPlanes=n.clippingPlanes,a.clipIntersection=n.clipIntersection,a.displacementMap=n.displacementMap,a.displacementScale=n.displacementScale,a.displacementBias=n.displacementBias,a.wireframeLinewidth=n.wireframeLinewidth,a.linewidth=n.linewidth,r.isPointLight===!0&&a.isMeshDistanceMaterial===!0){let t=e.properties.get(a);t.light=r}return a}function b(n,i,a,o,s){if(n.visible===!1)return;if(n.layers.test(i.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&s===3)&&(!n.frustumCulled||r.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,n.matrixWorld);let r=t.update(n),c=n.material;if(Array.isArray(c)){let t=r.groups;for(let l=0,u=t.length;l=2):(P=parseFloat(/^WebGL (\d)/.exec(F)[1]),N=P>=1);let I=null,L={},ee=e.getParameter(e.SCISSOR_BOX),R=e.getParameter(e.VIEWPORT),te=new Zn().fromArray(ee),z=new Zn().fromArray(R);function B(t,n,r,i){let a=new Uint8Array(4),o=e.createTexture();e.bindTexture(t,o),e.texParameteri(t,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(t,e.TEXTURE_MAG_FILTER,e.NEAREST);for(let o=0;o`u`?!1:/OculusBrowser/g.test(navigator.userAgent),l=new K,u=new WeakMap,d=new Set,f,p=new WeakMap,m=!1;try{m=typeof OffscreenCanvas<`u`&&new OffscreenCanvas(1,1).getContext(`2d`)!==null}catch{}function h(e,t){return m?new OffscreenCanvas(e,t):Gt(`canvas`)}function g(e,t,n){let r=1,i=Ee(e);if((i.width>n||i.height>n)&&(r=n/Math.max(i.width,i.height)),r<1)if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap||typeof VideoFrame<`u`&&e instanceof VideoFrame){let n=Math.floor(r*i.width),a=Math.floor(r*i.height);f===void 0&&(f=h(n,a));let o=t?h(n,a):f;return o.width=n,o.height=a,o.getContext(`2d`).drawImage(e,0,0,n,a),G(`WebGLRenderer: Texture has been resized from (`+i.width+`x`+i.height+`) to (`+n+`x`+a+`).`),o}else return`data`in e&&G(`WebGLRenderer: Image in DataTexture is too big (`+i.width+`x`+i.height+`).`),e;return e}function _(e){return e.generateMipmaps}function v(t){e.generateMipmap(t)}function y(t){return t.isWebGLCubeRenderTarget?e.TEXTURE_CUBE_MAP:t.isWebGL3DRenderTarget?e.TEXTURE_3D:t.isWebGLArrayRenderTarget||t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:e.TEXTURE_2D}function b(n,r,i,a,o,s=!1){if(n!==null){if(e[n]!==void 0)return e[n];G(`WebGLRenderer: Attempt to use non-existing WebGL internal format '`+n+`'`)}let c;a&&(c=t.get(`EXT_texture_norm16`),c||G(`WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension`));let l=r;if(r===e.RED&&(i===e.FLOAT&&(l=e.R32F),i===e.HALF_FLOAT&&(l=e.R16F),i===e.UNSIGNED_BYTE&&(l=e.R8),i===e.UNSIGNED_SHORT&&c&&(l=c.R16_EXT),i===e.SHORT&&c&&(l=c.R16_SNORM_EXT)),r===e.RED_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.R8UI),i===e.UNSIGNED_SHORT&&(l=e.R16UI),i===e.UNSIGNED_INT&&(l=e.R32UI),i===e.BYTE&&(l=e.R8I),i===e.SHORT&&(l=e.R16I),i===e.INT&&(l=e.R32I)),r===e.RG&&(i===e.FLOAT&&(l=e.RG32F),i===e.HALF_FLOAT&&(l=e.RG16F),i===e.UNSIGNED_BYTE&&(l=e.RG8),i===e.UNSIGNED_SHORT&&c&&(l=c.RG16_EXT),i===e.SHORT&&c&&(l=c.RG16_SNORM_EXT)),r===e.RG_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RG8UI),i===e.UNSIGNED_SHORT&&(l=e.RG16UI),i===e.UNSIGNED_INT&&(l=e.RG32UI),i===e.BYTE&&(l=e.RG8I),i===e.SHORT&&(l=e.RG16I),i===e.INT&&(l=e.RG32I)),r===e.RGB_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RGB8UI),i===e.UNSIGNED_SHORT&&(l=e.RGB16UI),i===e.UNSIGNED_INT&&(l=e.RGB32UI),i===e.BYTE&&(l=e.RGB8I),i===e.SHORT&&(l=e.RGB16I),i===e.INT&&(l=e.RGB32I)),r===e.RGBA_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RGBA8UI),i===e.UNSIGNED_SHORT&&(l=e.RGBA16UI),i===e.UNSIGNED_INT&&(l=e.RGBA32UI),i===e.BYTE&&(l=e.RGBA8I),i===e.SHORT&&(l=e.RGBA16I),i===e.INT&&(l=e.RGBA32I)),r===e.RGB&&(i===e.UNSIGNED_SHORT&&c&&(l=c.RGB16_EXT),i===e.SHORT&&c&&(l=c.RGB16_SNORM_EXT),i===e.UNSIGNED_INT_5_9_9_9_REV&&(l=e.RGB9_E5),i===e.UNSIGNED_INT_10F_11F_11F_REV&&(l=e.R11F_G11F_B10F)),r===e.RGBA){let t=s?gt:Bn.getTransfer(o);i===e.FLOAT&&(l=e.RGBA32F),i===e.HALF_FLOAT&&(l=e.RGBA16F),i===e.UNSIGNED_BYTE&&(l=t===`srgb`?e.SRGB8_ALPHA8:e.RGBA8),i===e.UNSIGNED_SHORT&&c&&(l=c.RGBA16_EXT),i===e.SHORT&&c&&(l=c.RGBA16_SNORM_EXT),i===e.UNSIGNED_SHORT_4_4_4_4&&(l=e.RGBA4),i===e.UNSIGNED_SHORT_5_5_5_1&&(l=e.RGB5_A1)}return(l===e.R16F||l===e.R32F||l===e.RG16F||l===e.RG32F||l===e.RGBA16F||l===e.RGBA32F)&&t.get(`EXT_color_buffer_float`),l}function x(t,n){let r;return t?n===null||n===1014||n===1020?r=e.DEPTH24_STENCIL8:n===1015?r=e.DEPTH32F_STENCIL8:n===1012&&(r=e.DEPTH24_STENCIL8,G(`DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.`)):n===null||n===1014||n===1020?r=e.DEPTH_COMPONENT24:n===1015?r=e.DEPTH_COMPONENT32F:n===1012&&(r=e.DEPTH_COMPONENT16),r}function S(e,t){return _(e)===!0||e.isFramebufferTexture&&e.minFilter!==1003&&e.minFilter!==1006?Math.log2(Math.max(t.width,t.height))+1:e.mipmaps!==void 0&&e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function C(e){let t=e.target;t.removeEventListener(`dispose`,C),j(t),t.isVideoTexture&&u.delete(t),t.isHTMLTexture&&d.delete(t)}function k(e){let t=e.target;t.removeEventListener(`dispose`,k),I(t)}function j(e){let t=r.get(e);if(t.__webglInit===void 0)return;let n=e.source,i=p.get(n);if(i){let r=i[t.__cacheKey];r.usedTimes--,r.usedTimes===0&&P(e),Object.keys(i).length===0&&p.delete(n)}r.remove(e)}function P(t){let n=r.get(t);e.deleteTexture(n.__webglTexture);let i=t.source,a=p.get(i);delete a[n.__cacheKey],o.memory.textures--}function I(t){let n=r.get(t);if(t.depthTexture&&(t.depthTexture.dispose(),r.remove(t.depthTexture)),t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++){if(Array.isArray(n.__webglFramebuffer[t]))for(let r=0;r=i.maxTextures&&G(`WebGLTextures: Trying to use `+e+` texture units while this GPU supports only `+i.maxTextures),L+=1,e}function B(e){let t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}function V(t,i){let a=r.get(t);if(t.isVideoTexture&&Te(t),t.isRenderTargetTexture===!1&&t.isExternalTexture!==!0&&t.version>0&&a.__version!==t.version){let e=t.image;if(e===null)G(`WebGLRenderer: Texture marked for update but no image data found.`);else if(e.complete===!1)G(`WebGLRenderer: Texture marked for update but image is incomplete`);else{fe(a,t,i);return}}else t.isExternalTexture&&(a.__webglTexture=t.sourceTexture?t.sourceTexture:null);n.bindTexture(e.TEXTURE_2D,a.__webglTexture,e.TEXTURE0+i)}function ne(t,i){let a=r.get(t);if(t.isRenderTargetTexture===!1&&t.version>0&&a.__version!==t.version){fe(a,t,i);return}else t.isExternalTexture&&(a.__webglTexture=t.sourceTexture?t.sourceTexture:null);n.bindTexture(e.TEXTURE_2D_ARRAY,a.__webglTexture,e.TEXTURE0+i)}function re(t,i){let a=r.get(t);if(t.isRenderTargetTexture===!1&&t.version>0&&a.__version!==t.version){fe(a,t,i);return}n.bindTexture(e.TEXTURE_3D,a.__webglTexture,e.TEXTURE0+i)}function ie(t,i){let a=r.get(t);if(t.isCubeDepthTexture!==!0&&t.version>0&&a.__version!==t.version){pe(a,t,i);return}n.bindTexture(e.TEXTURE_CUBE_MAP,a.__webglTexture,e.TEXTURE0+i)}let ae={[w]:e.REPEAT,[T]:e.CLAMP_TO_EDGE,[E]:e.MIRRORED_REPEAT},oe={[D]:e.NEAREST,[O]:e.NEAREST_MIPMAP_NEAREST,[A]:e.NEAREST_MIPMAP_LINEAR,[M]:e.LINEAR,[N]:e.LINEAR_MIPMAP_NEAREST,[F]:e.LINEAR_MIPMAP_LINEAR},se={512:e.NEVER,519:e.ALWAYS,513:e.LESS,515:e.LEQUAL,514:e.EQUAL,518:e.GEQUAL,516:e.GREATER,517:e.NOTEQUAL};function ce(n,a){if(a.type===1015&&t.has(`OES_texture_float_linear`)===!1&&(a.magFilter===1006||a.magFilter===1007||a.magFilter===1005||a.magFilter===1008||a.minFilter===1006||a.minFilter===1007||a.minFilter===1005||a.minFilter===1008)&&G(`WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.`),e.texParameteri(n,e.TEXTURE_WRAP_S,ae[a.wrapS]),e.texParameteri(n,e.TEXTURE_WRAP_T,ae[a.wrapT]),(n===e.TEXTURE_3D||n===e.TEXTURE_2D_ARRAY)&&e.texParameteri(n,e.TEXTURE_WRAP_R,ae[a.wrapR]),e.texParameteri(n,e.TEXTURE_MAG_FILTER,oe[a.magFilter]),e.texParameteri(n,e.TEXTURE_MIN_FILTER,oe[a.minFilter]),a.compareFunction&&(e.texParameteri(n,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE),e.texParameteri(n,e.TEXTURE_COMPARE_FUNC,se[a.compareFunction])),t.has(`EXT_texture_filter_anisotropic`)===!0){if(a.magFilter===1003||a.minFilter!==1005&&a.minFilter!==1008||a.type===1015&&t.has(`OES_texture_float_linear`)===!1)return;if(a.anisotropy>1||r.get(a).__currentAnisotropy){let o=t.get(`EXT_texture_filter_anisotropic`);e.texParameterf(n,o.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(a.anisotropy,i.getMaxAnisotropy())),r.get(a).__currentAnisotropy=a.anisotropy}}}function H(t,n){let r=!1;t.__webglInit===void 0&&(t.__webglInit=!0,n.addEventListener(`dispose`,C));let i=n.source,a=p.get(i);a===void 0&&(a={},p.set(i,a));let s=B(n);if(s!==t.__cacheKey){a[s]===void 0&&(a[s]={texture:e.createTexture(),usedTimes:0},o.memory.textures++,r=!0),a[s].usedTimes++;let i=a[t.__cacheKey];i!==void 0&&(a[t.__cacheKey].usedTimes--,i.usedTimes===0&&P(n)),t.__cacheKey=s,t.__webglTexture=a[s].texture}return r}function le(e,t,n){return Math.floor(Math.floor(e/n)/t)}function ue(t,r,i,a){let o=t.updateRanges;if(o.length===0)n.texSubImage2D(e.TEXTURE_2D,0,0,0,r.width,r.height,i,a,r.data);else{o.sort((e,t)=>e.start-t.start);let s=0;for(let e=1;e0){C&&w&&n.texStorage2D(e.TEXTURE_2D,E,m,y[0].width,y[0].height);for(let t=0,i=y.length;t0){let t=qf(h.width,h.height,o.format,o.type);for(let a of o.layerUpdates){let o=h.data.subarray(a*t/h.data.BYTES_PER_ELEMENT,(a+1)*t/h.data.BYTES_PER_ELEMENT);n.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,a,h.width,h.height,1,r,o)}o.clearLayerUpdates()}else n.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,0,h.width,h.height,t.depth,r,h.data)}else n.compressedTexImage3D(e.TEXTURE_2D_ARRAY,i,m,h.width,h.height,t.depth,0,h.data,0,0);else G(`WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`);else C?T&&n.texSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,0,h.width,h.height,t.depth,r,p,h.data):n.texImage3D(e.TEXTURE_2D_ARRAY,i,m,h.width,h.height,t.depth,0,r,p,h.data)}else{C&&w&&n.texStorage2D(e.TEXTURE_2D,E,m,y[0].width,y[0].height);for(let t=0,i=y.length;t0){let i=qf(t.width,t.height,o.format,o.type);for(let a of o.layerUpdates){let o=t.data.subarray(a*i/t.data.BYTES_PER_ELEMENT,(a+1)*i/t.data.BYTES_PER_ELEMENT);n.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,a,t.width,t.height,1,r,p,o)}o.clearLayerUpdates()}else n.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,0,t.width,t.height,t.depth,r,p,t.data)}else n.texImage3D(e.TEXTURE_2D_ARRAY,0,m,t.width,t.height,t.depth,0,r,p,t.data);else if(o.isData3DTexture)C?(w&&n.texStorage3D(e.TEXTURE_3D,E,m,t.width,t.height,t.depth),T&&n.texSubImage3D(e.TEXTURE_3D,0,0,0,0,t.width,t.height,t.depth,r,p,t.data)):n.texImage3D(e.TEXTURE_3D,0,m,t.width,t.height,t.depth,0,r,p,t.data);else if(o.isFramebufferTexture){if(w)if(C)n.texStorage2D(e.TEXTURE_2D,E,m,t.width,t.height);else{let i=t.width,a=t.height;for(let t=0;t>=1,a>>=1}}else if(o.isHTMLTexture){if(`texElementImage2D`in e){let n=e.canvas;if(n.hasAttribute(`layoutsubtree`)||n.setAttribute(`layoutsubtree`,`true`),t.parentNode!==n){n.appendChild(t),d.add(o),n.onpaint=e=>{let t=e.changedElements;for(let e of d)t.includes(e.image)&&(e.needsUpdate=!0)},n.requestPaint();return}let r=e.RGBA,i=e.RGBA,a=e.UNSIGNED_BYTE;e.texElementImage2D(e.TEXTURE_2D,0,r,i,a,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}}else if(y.length>0){if(C&&w){let t=Ee(y[0]);n.texStorage2D(e.TEXTURE_2D,E,m,t.width,t.height)}for(let t=0,i=y.length;t0&&D++;let t=Ee(m[0]);n.texStorage2D(e.TEXTURE_CUBE_MAP,D,C,t.width,t.height)}for(let t=0;t<6;t++)if(p){w?E&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,m[t].width,m[t].height,y,x,m[t].data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,C,m[t].width,m[t].height,0,y,x,m[t].data);for(let r=0;r>u),r=Math.max(1,i.height>>u);l===e.TEXTURE_3D||l===e.TEXTURE_2D_ARRAY?n.texImage3D(l,u,p,t,r,i.depth,0,d,f,null):n.texImage2D(l,u,p,t,r,0,d,f,null)}n.bindFramebuffer(e.FRAMEBUFFER,t),we(i)?s.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,c,l,h.__webglTexture,0,Ce(i)):(l===e.TEXTURE_2D||l>=e.TEXTURE_CUBE_MAP_POSITIVE_X&&l<=e.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&e.framebufferTexture2D(e.FRAMEBUFFER,c,l,h.__webglTexture,u),n.bindFramebuffer(e.FRAMEBUFFER,null)}function he(t,n,r){if(e.bindRenderbuffer(e.RENDERBUFFER,t),n.depthBuffer){let i=n.depthTexture,a=i&&i.isDepthTexture?i.type:null,o=x(n.stencilBuffer,a),c=n.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;we(n)?s.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,Ce(n),o,n.width,n.height):r?e.renderbufferStorageMultisample(e.RENDERBUFFER,Ce(n),o,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,o,n.width,n.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,c,e.RENDERBUFFER,t)}else{let t=n.textures;for(let i=0;i{delete i.__boundDepthTexture,delete i.__depthDisposeCallback,e.removeEventListener(`dispose`,t)};e.addEventListener(`dispose`,t),i.__depthDisposeCallback=t}i.__boundDepthTexture=e}if(t.depthTexture&&!i.__autoAllocateDepthBuffer)if(a)for(let e=0;e<6;e++)ge(i.__webglFramebuffer[e],t,e);else{let e=t.texture.mipmaps;e&&e.length>0?ge(i.__webglFramebuffer[0],t,0):ge(i.__webglFramebuffer,t,0)}else if(a){i.__webglDepthbuffer=[];for(let r=0;r<6;r++)if(n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer[r]),i.__webglDepthbuffer[r]===void 0)i.__webglDepthbuffer[r]=e.createRenderbuffer(),he(i.__webglDepthbuffer[r],t,!1);else{let n=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,a=i.__webglDepthbuffer[r];e.bindRenderbuffer(e.RENDERBUFFER,a),e.framebufferRenderbuffer(e.FRAMEBUFFER,n,e.RENDERBUFFER,a)}}else{let r=t.texture.mipmaps;if(r&&r.length>0?n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer[0]):n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer),i.__webglDepthbuffer===void 0)i.__webglDepthbuffer=e.createRenderbuffer(),he(i.__webglDepthbuffer,t,!1);else{let n=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,r=i.__webglDepthbuffer;e.bindRenderbuffer(e.RENDERBUFFER,r),e.framebufferRenderbuffer(e.FRAMEBUFFER,n,e.RENDERBUFFER,r)}}n.bindFramebuffer(e.FRAMEBUFFER,null)}function ve(t,n,i){let a=r.get(t);n!==void 0&&me(a.__webglFramebuffer,t,t.texture,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,0),i!==void 0&&_e(t)}function ye(t){let i=t.texture,s=r.get(t),c=r.get(i);t.addEventListener(`dispose`,k);let l=t.textures,u=t.isWebGLCubeRenderTarget===!0,d=l.length>1;if(d||(c.__webglTexture===void 0&&(c.__webglTexture=e.createTexture()),c.__version=i.version,o.memory.textures++),u){s.__webglFramebuffer=[];for(let t=0;t<6;t++)if(i.mipmaps&&i.mipmaps.length>0){s.__webglFramebuffer[t]=[];for(let n=0;n0){s.__webglFramebuffer=[];for(let t=0;t0&&we(t)===!1){s.__webglMultisampledFramebuffer=e.createFramebuffer(),s.__webglColorRenderbuffer=[],n.bindFramebuffer(e.FRAMEBUFFER,s.__webglMultisampledFramebuffer);for(let n=0;n0)for(let r=0;r0)for(let n=0;n0){if(we(t)===!1){let i=t.textures,a=t.width,o=t.height,s=e.COLOR_BUFFER_BIT,l=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,u=r.get(t),d=i.length>1;if(d)for(let t=0;t0?n.bindFramebuffer(e.DRAW_FRAMEBUFFER,u.__webglFramebuffer[0]):n.bindFramebuffer(e.DRAW_FRAMEBUFFER,u.__webglFramebuffer);for(let n=0;n0&&t.has(`WEBGL_multisampled_render_to_texture`)===!0&&n.__useRenderToTexture!==!1}function Te(e){let t=o.render.frame;u.get(e)!==t&&(u.set(e,t),e.update())}function W(e,t){let n=e.colorSpace,r=e.format,i=e.type;return e.isCompressedTexture===!0||e.isVideoTexture===!0||n!==`srgb-linear`&&n!==``&&(Bn.getTransfer(n)===`srgb`?(r!==1023||i!==1009)&&G(`WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.`):$t(`WebGLTextures: Unsupported texture color space:`,n)),t}function Ee(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement?(l.width=e.naturalWidth||e.width,l.height=e.naturalHeight||e.height):typeof VideoFrame<`u`&&e instanceof VideoFrame?(l.width=e.displayWidth,l.height=e.displayHeight):(l.width=e.width,l.height=e.height),l}this.allocateTextureUnit=z,this.resetTextureUnits=ee,this.getTextureUnits=R,this.setTextureUnits=te,this.setTexture2D=V,this.setTexture2DArray=ne,this.setTexture3D=re,this.setTextureCube=ie,this.rebindTextures=ve,this.setupRenderTarget=ye,this.updateRenderTargetMipmap=be,this.updateMultisampleRenderTarget=U,this.setupDepthRenderbuffer=_e,this.setupFrameBufferTexture=me,this.useMultisampledRTT=we,this.isReversedDepthBuffer=function(){return n.buffers.depth.getReversed()}}function tg(e,t){function n(n,r=``){let i,a=Bn.getTransfer(r);if(n===1009)return e.UNSIGNED_BYTE;if(n===1017)return e.UNSIGNED_SHORT_4_4_4_4;if(n===1018)return e.UNSIGNED_SHORT_5_5_5_1;if(n===35902)return e.UNSIGNED_INT_5_9_9_9_REV;if(n===35899)return e.UNSIGNED_INT_10F_11F_11F_REV;if(n===1010)return e.BYTE;if(n===1011)return e.SHORT;if(n===1012)return e.UNSIGNED_SHORT;if(n===1013)return e.INT;if(n===1014)return e.UNSIGNED_INT;if(n===1015)return e.FLOAT;if(n===1016)return e.HALF_FLOAT;if(n===1021)return e.ALPHA;if(n===1022)return e.RGB;if(n===1023)return e.RGBA;if(n===1026)return e.DEPTH_COMPONENT;if(n===1027)return e.DEPTH_STENCIL;if(n===1028)return e.RED;if(n===1029)return e.RED_INTEGER;if(n===1030)return e.RG;if(n===1031)return e.RG_INTEGER;if(n===1033)return e.RGBA_INTEGER;if(n===33776||n===33777||n===33778||n===33779)if(a===`srgb`)if(i=t.get(`WEBGL_compressed_texture_s3tc_srgb`),i!==null){if(n===33776)return i.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===33777)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===33778)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===33779)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(i=t.get(`WEBGL_compressed_texture_s3tc`),i!==null){if(n===33776)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===33777)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===33778)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===33779)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===35840||n===35841||n===35842||n===35843)if(i=t.get(`WEBGL_compressed_texture_pvrtc`),i!==null){if(n===35840)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===35841)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===35842)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===35843)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===36196||n===37492||n===37496||n===37488||n===37489||n===37490||n===37491)if(i=t.get(`WEBGL_compressed_texture_etc`),i!==null){if(n===36196||n===37492)return a===`srgb`?i.COMPRESSED_SRGB8_ETC2:i.COMPRESSED_RGB8_ETC2;if(n===37496)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:i.COMPRESSED_RGBA8_ETC2_EAC;if(n===37488)return i.COMPRESSED_R11_EAC;if(n===37489)return i.COMPRESSED_SIGNED_R11_EAC;if(n===37490)return i.COMPRESSED_RG11_EAC;if(n===37491)return i.COMPRESSED_SIGNED_RG11_EAC}else return null;if(n===37808||n===37809||n===37810||n===37811||n===37812||n===37813||n===37814||n===37815||n===37816||n===37817||n===37818||n===37819||n===37820||n===37821)if(i=t.get(`WEBGL_compressed_texture_astc`),i!==null){if(n===37808)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:i.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===37809)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:i.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===37810)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:i.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===37811)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:i.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===37812)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:i.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===37813)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:i.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===37814)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:i.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===37815)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:i.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===37816)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:i.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===37817)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:i.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===37818)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:i.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===37819)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:i.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===37820)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:i.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===37821)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:i.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===36492||n===36494||n===36495)if(i=t.get(`EXT_texture_compression_bptc`),i!==null){if(n===36492)return a===`srgb`?i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:i.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===36494)return i.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===36495)return i.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===36283||n===36284||n===36285||n===36286)if(i=t.get(`EXT_texture_compression_rgtc`),i!==null){if(n===36283)return i.COMPRESSED_RED_RGTC1_EXT;if(n===36284)return i.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===36285)return i.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===36286)return i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===1020?e.UNSIGNED_INT_24_8:e[n]===void 0?null:e[n]}return{convert:n}}var ng=` void main() { gl_Position = vec4( position, 1.0 ); }`,rg=` uniform sampler2DArray depthColor; uniform float depthWidth; uniform float depthHeight; void main() { vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight ); if ( coord.x >= 1.0 ) { gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r; } else { gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r; } }`,ig=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new ys(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new yl({vertexShader:ng,fragmentShader:rg,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new La(new Qc(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},ag=class extends rn{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,l=null,u=null,d=null,f=null,p=null,m=typeof XRWebGLBinding<`u`,h=new ig,g={},_=t.getContextAttributes(),v=null,y=null,b=[],x=[],S=new K,C=null,w=new Ou;w.viewport=new Zn;let T=new Ou;T.viewport=new Zn;let E=[w,T],D=new sd,O=null,k=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=b[e];return t===void 0&&(t=new Nr,b[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=b[e];return t===void 0&&(t=new Nr,b[e]=t),t.getGripSpace()},this.getHand=function(e){let t=b[e];return t===void 0&&(t=new Nr,b[e]=t),t.getHandSpace()};function A(e){let t=x.indexOf(e.inputSource);if(t===-1)return;let n=b[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function j(){r.removeEventListener(`select`,A),r.removeEventListener(`selectstart`,A),r.removeEventListener(`selectend`,A),r.removeEventListener(`squeeze`,A),r.removeEventListener(`squeezestart`,A),r.removeEventListener(`squeezeend`,A),r.removeEventListener(`end`,j),r.removeEventListener(`inputsourceschange`,M);for(let e=0;e=0&&(x[r]=null,b[r].disconnect(n))}for(let t=0;t=x.length){x.push(n),r=e;break}else if(x[e]===null){x[e]=n,r=e;break}if(r===-1)break}let i=b[r];i&&i.connect(n)}}let N=new q,P=new q;function F(e,t,n){N.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(n.matrixWorld);let r=N.distanceTo(P),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),i[10]===-1)e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=o+m,n=s+m,i=f-h,a=p+(r-h),u=c*s/n*t,d=l*s/n*t;e.projectionMatrix.makePerspective(i,a,u,d,t,n),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}function I(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;let t=e.near,n=e.far;h.texture!==null&&(h.depthNear>0&&(t=h.depthNear),h.depthFar>0&&(n=h.depthFar)),D.near=T.near=w.near=t,D.far=T.far=w.far=n,(O!==D.near||k!==D.far)&&(r.updateRenderState({depthNear:D.near,depthFar:D.far}),O=D.near,k=D.far),D.layers.mask=e.layers.mask|6,w.layers.mask=D.layers.mask&-5,T.layers.mask=D.layers.mask&-3;let i=e.parent,a=D.cameras;I(D,i);for(let e=0;e0&&(e.alphaTest.value=r.alphaTest);let i=t.get(r),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,e.envMapRotation.value.setFromMatrix4(og.makeRotationFromEuler(o)).transpose(),a.isCubeTexture&&a.isRenderTargetTexture===!1&&e.envMapRotation.value.premultiply(sg),e.reflectivity.value=r.reflectivity,e.ior.value=r.ior,e.refractionRatio.value=r.refractionRatio),r.lightMap&&(e.lightMap.value=r.lightMap,e.lightMapIntensity.value=r.lightMapIntensity,n(r.lightMap,e.lightMapTransform)),r.aoMap&&(e.aoMap.value=r.aoMap,e.aoMapIntensity.value=r.aoMapIntensity,n(r.aoMap,e.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function lg(e,t,n,r){let i={},a={},o=[],s=e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);function c(e,t){let n=t.program;r.uniformBlockBinding(e,n)}function l(e,n){let o=i[e.id];o===void 0&&(m(e),o=u(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let c=t.render.frame;a[e.id]!==c&&(f(e),a[e.id]=c)}function u(t){let n=d();t.__bindingPointIndex=n;let r=e.createBuffer(),i=t.__size,a=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,i,a),e.bindBuffer(e.UNIFORM_BUFFER,null),e.bindBufferBase(e.UNIFORM_BUFFER,n,r),r}function d(){for(let e=0;e0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e){let t={boundary:0,storage:0};return typeof e==`number`||typeof e==`boolean`?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?G(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):ArrayBuffer.isView(e)?(t.boundary=16,t.storage=e.byteLength):G(`WebGLRenderer: Unsupported uniform value type.`,e),t}function g(t){let n=t.target;n.removeEventListener(`dispose`,g);let r=o.indexOf(n.__bindingPointIndex);o.splice(r,1),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);o=[],i={},a={}}return{bind:c,update:l,dispose:_}}var ug=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),dg=null;function fg(){return dg===null&&(dg=new Za(ug,16,16,me,ne),dg.name=`DFG_LUT`,dg.minFilter=M,dg.magFilter=M,dg.wrapS=T,dg.wrapT=T,dg.generateMipmaps=!1,dg.needsUpdate=!0),dg}var pg=class{constructor(e={}){let{canvas:t=Kt(),context:n=null,depth:r=!0,stencil:i=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:c=!1,powerPreference:l=`default`,failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=L}=e;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<`u`&&n instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);p=n.getContextAttributes().alpha}else p=a;let m=f,h=new Set([_e,he,pe]),g=new Set([L,B,te,ae,re,ie]),_=new Uint32Array(4),v=new Int32Array(4),y=new q,b=null,x=null,S=[],C=[],w=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let T=this,E=!1,D=null;this._outputColorSpace=mt;let O=0,k=0,A=null,j=-1,M=null,N=new Zn,P=new Zn,I=null,ee=new Y(0),R=0,z=t.width,V=t.height,oe=1,se=null,ce=null,H=new Zn(0,0,z,V),le=new Zn(0,0,z,V),ue=!1,de=new vo,fe=!1,me=!1,ge=new J,ve=new q,ye=new Zn,be={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},xe=!1;function Se(){return A===null?oe:1}let U=n;function Ce(e,n){return t.getContext(e,n)}try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:s,preserveDrawingBuffer:c,powerPreference:l,failIfMajorPerformanceCaveat:u};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r184`),t.addEventListener(`webglcontextlost`,Je,!1),t.addEventListener(`webglcontextrestored`,Ye,!1),t.addEventListener(`webglcontextcreationerror`,Xe,!1),U===null){let t=`webgl2`;if(U=Ce(t,e),U===null)throw Ce(t)?Error(`Error creating WebGL context with your selected attributes.`):Error(`Error creating WebGL context.`)}}catch(e){throw $t(`WebGLRenderer: `+e.message),e}let we,Te,W,Ee,De,Oe,ke,Ae,je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge;function Ke(){we=new jp(U),we.init(),Ue=new tg(U,we),Te=new sp(U,we,e,Ue),W=new $h(U,we),Te.reversedDepthBuffer&&d&&W.buffers.depth.setReversed(!0),Ee=new Pp(U),De=new Nh,Oe=new eg(U,we,W,De,Te,Ue,Ee),ke=new Ap(T),Ae=new Qf(U),We=new ap(U,Ae),je=new Mp(U,Ae,Ee,We),Me=new Ip(U,je,Ae,We,Ee),Be=new Fp(U,Te,Oe),Le=new cp(De),Ne=new Mh(T,ke,we,Te,We,Le),Pe=new cg(T,De),Fe=new Lh,Ie=new Wh(we),ze=new ip(T,ke,W,Me,p,s),Re=new Qh(T,Me,Te),Ge=new lg(U,Ee,Te,W),Ve=new op(U,we,Ee),He=new Np(U,we,Ee),Ee.programs=Ne.programs,T.capabilities=Te,T.extensions=we,T.properties=De,T.renderLists=Fe,T.shadowMap=Re,T.state=W,T.info=Ee}Ke(),m!==1009&&(w=new Rp(m,t.width,t.height,r,i));let qe=new ag(T,U);this.xr=qe,this.getContext=function(){return U},this.getContextAttributes=function(){return U.getContextAttributes()},this.forceContextLoss=function(){let e=we.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=we.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return oe},this.setPixelRatio=function(e){e!==void 0&&(oe=e,this.setSize(z,V,!1))},this.getSize=function(e){return e.set(z,V)},this.setSize=function(e,n,r=!0){if(qe.isPresenting){G(`WebGLRenderer: Can't change size while VR device is presenting.`);return}z=e,V=n,t.width=Math.floor(e*oe),t.height=Math.floor(n*oe),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),w!==null&&w.setSize(t.width,t.height),this.setViewport(0,0,e,n)},this.getDrawingBufferSize=function(e){return e.set(z*oe,V*oe).floor()},this.setDrawingBufferSize=function(e,n,r){z=e,V=n,oe=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.setEffects=function(e){if(m===1009){$t(`THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.`);return}if(e){for(let t=0;t{function n(){if(r.forEach(function(e){De.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}we.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let tt=null;function nt(e){tt&&tt(e)}function rt(){at.stop()}function it(){at.start()}let at=new Zf;at.setAnimationLoop(nt),typeof self<`u`&&at.setContext(self),this.setAnimationLoop=function(e){tt=e,qe.setAnimationLoop(e),e===null?at.stop():at.start()},qe.addEventListener(`sessionstart`,rt),qe.addEventListener(`sessionend`,it),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){$t(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(E===!0)return;D!==null&&D.renderStart(e,t);let n=qe.enabled===!0&&qe.isPresenting===!0,r=w!==null&&(A===null||n)&&w.begin(T,A);if(e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),qe.enabled===!0&&qe.isPresenting===!0&&(w===null||w.isCompositing()===!1)&&(qe.cameraAutoUpdate===!0&&qe.updateCamera(t),t=qe.getCamera()),e.isScene===!0&&e.onBeforeRender(T,e,t,A),x=Ie.get(e,C.length),x.init(t),x.state.textureUnits=Oe.getTextureUnits(),C.push(x),ge.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),de.setFromProjectionMatrix(ge,Ft,t.reversedDepth),me=this.localClippingEnabled,fe=Le.init(this.clippingPlanes,me),b=Fe.get(e,S.length),b.init(),S.push(b),qe.enabled===!0&&qe.isPresenting===!0){let e=T.xr.getDepthSensingMesh();e!==null&&ot(e,t,-1/0,T.sortObjects)}ot(e,t,0,T.sortObjects),b.finish(),T.sortObjects===!0&&b.sort(se,ce),xe=qe.enabled===!1||qe.isPresenting===!1||qe.hasDepthSensing()===!1,xe&&ze.addToRenderList(b,e),this.info.render.frame++,fe===!0&&Le.beginShadows();let i=x.state.shadowsArray;if(Re.render(i,e,t),fe===!0&&Le.endShadows(),this.info.autoReset===!0&&this.info.reset(),(r&&w.hasRenderPass())===!1){let n=b.opaque,r=b.transmissive;if(x.setupLights(),t.isArrayCamera){let i=t.cameras;if(r.length>0)for(let t=0,a=i.length;t0&&ct(n,r,e,t),xe&&ze.render(e),st(b,e,t)}A!==null&&k===0&&(Oe.updateMultisampleRenderTarget(A),Oe.updateRenderTargetMipmap(A)),r&&w.end(T),e.isScene===!0&&e.onAfterRender(T,e,t),We.resetDefaultState(),j=-1,M=null,C.pop(),C.length>0?(x=C[C.length-1],Oe.setTextureUnits(x.state.textureUnits),fe===!0&&Le.setGlobalState(T.clippingPlanes,x.state.camera)):x=null,S.pop(),b=S.length>0?S[S.length-1]:null,D!==null&&D.renderEnd()};function ot(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLightProbeGrid)x.pushLightProbeGrid(e);else if(e.isLight)x.pushLight(e),e.castShadow&&x.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||de.intersectsSprite(e)){r&&ye.setFromMatrixPosition(e.matrixWorld).applyMatrix4(ge);let t=Me.update(e),i=e.material;i.visible&&b.push(e,t,i,n,ye.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||de.intersectsObject(e))){let t=Me.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),ye.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),ye.copy(e.boundingSphere.center)),ye.applyMatrix4(e.matrixWorld).applyMatrix4(ge)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a0&<(i,t,n),a.length>0&<(a,t,n),o.length>0&<(o,t,n),W.buffers.depth.setTest(!0),W.buffers.depth.setMask(!0),W.buffers.color.setMask(!0),W.setPolygonOffset(!1)}function ct(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;if(x.state.transmissionRenderTarget[r.id]===void 0){let e=we.has(`EXT_color_buffer_half_float`)||we.has(`EXT_color_buffer_float`);x.state.transmissionRenderTarget[r.id]=new $n(1,1,{generateMipmaps:!0,type:e?ne:L,minFilter:F,samples:Math.max(4,Te.samples),stencilBuffer:i,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Bn.workingColorSpace})}let a=x.state.transmissionRenderTarget[r.id],o=r.viewport||N;a.setSize(o.z*T.transmissionResolutionScale,o.w*T.transmissionResolutionScale);let s=T.getRenderTarget(),c=T.getActiveCubeFace(),l=T.getActiveMipmapLevel();T.setRenderTarget(a),T.getClearColor(ee),R=T.getClearAlpha(),R<1&&T.setClearColor(16777215,.5),T.clear(),xe&&ze.render(n);let u=T.toneMapping;T.toneMapping=0;let d=r.viewport;if(r.viewport!==void 0&&(r.viewport=void 0),x.setupLightsView(r),fe===!0&&Le.setGlobalState(T.clippingPlanes,r),lt(e,n,r),Oe.updateMultisampleRenderTarget(a),Oe.updateRenderTargetMipmap(a),we.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let i=0,a=t.length;i0,r.currentProgram=d,r.uniformsList=null,d}function ft(e){if(e.uniformsList===null){let t=e.currentProgram.getUniforms();e.uniformsList=Gm.seqWithValue(t.seq,e.uniforms)}return e.uniformsList}function pt(e,t){let n=De.get(e);n.outputColorSpace=t.outputColorSpace,n.batching=t.batching,n.batchingColor=t.batchingColor,n.instancing=t.instancing,n.instancingColor=t.instancingColor,n.instancingMorph=t.instancingMorph,n.skinning=t.skinning,n.morphTargets=t.morphTargets,n.morphNormals=t.morphNormals,n.morphColors=t.morphColors,n.morphTargetsCount=t.morphTargetsCount,n.numClippingPlanes=t.numClippingPlanes,n.numIntersection=t.numClipIntersection,n.vertexAlphas=t.vertexAlphas,n.vertexTangents=t.vertexTangents,n.toneMapping=t.toneMapping}function ht(e,t){if(e.length===0)return null;if(e.length===1)return e[0].texture===null?null:e[0];y.setFromMatrixPosition(t.matrixWorld);for(let t=0,n=e.length;t0),f=!!n.morphAttributes.position,p=!!n.morphAttributes.normal,m=!!n.morphAttributes.color,h=0;r.toneMapped&&(A===null||A.isXRRenderTarget===!0)&&(h=T.toneMapping);let g=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,_=g===void 0?0:g.length,v=De.get(r),y=x.state.lights;if(fe===!0&&(me===!0||e!==M)){let t=e===M&&r.id===j;Le.setState(r,e,t)}let b=!1;r.version===v.__version?v.needsLights&&v.lightsStateVersion!==y.state.version?b=!0:v.outputColorSpace===s?i.isBatchedMesh&&v.batching===!1||!i.isBatchedMesh&&v.batching===!0||i.isBatchedMesh&&v.batchingColor===!0&&i.colorTexture===null||i.isBatchedMesh&&v.batchingColor===!1&&i.colorTexture!==null||i.isInstancedMesh&&v.instancing===!1||!i.isInstancedMesh&&v.instancing===!0||i.isSkinnedMesh&&v.skinning===!1||!i.isSkinnedMesh&&v.skinning===!0||i.isInstancedMesh&&v.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&v.instancingColor===!1&&i.instanceColor!==null||i.isInstancedMesh&&v.instancingMorph===!0&&i.morphTexture===null||i.isInstancedMesh&&v.instancingMorph===!1&&i.morphTexture!==null?b=!0:v.envMap===l?r.fog===!0&&v.fog!==a||v.numClippingPlanes!==void 0&&(v.numClippingPlanes!==Le.numPlanes||v.numIntersection!==Le.numIntersection)?b=!0:v.vertexAlphas===u&&v.vertexTangents===d&&v.morphTargets===f&&v.morphNormals===p&&v.morphColors===m&&v.toneMapping===h&&v.morphTargetsCount===_?!!v.lightProbeGrid!=x.state.lightProbeGridArray.length>0&&(b=!0):b=!0:b=!0:b=!0:(b=!0,v.__version=r.version);let S=v.currentProgram;b===!0&&(S=dt(r,t,i),D&&r.isNodeMaterial&&D.onUpdateProgram(r,S,v));let C=!1,w=!1,E=!1,O=S.getUniforms(),k=v.uniforms;if(W.useProgram(S.program)&&(C=!0,w=!0,E=!0),r.id!==j&&(j=r.id,w=!0),v.needsLights){let e=ht(x.state.lightProbeGridArray,i);v.lightProbeGrid!==e&&(v.lightProbeGrid=e,w=!0)}if(C||M!==e){W.buffers.depth.getReversed()&&e.reversedDepth!==!0&&(e._reversedDepth=!0,e.updateProjectionMatrix()),O.setValue(U,`projectionMatrix`,e.projectionMatrix),O.setValue(U,`viewMatrix`,e.matrixWorldInverse);let t=O.map.cameraPosition;t!==void 0&&t.setValue(U,ve.setFromMatrixPosition(e.matrixWorld)),Te.logarithmicDepthBuffer&&O.setValue(U,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&O.setValue(U,`isOrthographic`,e.isOrthographicCamera===!0),M!==e&&(M=e,w=!0,E=!0)}if(v.needsLights&&(y.state.directionalShadowMap.length>0&&O.setValue(U,`directionalShadowMap`,y.state.directionalShadowMap,Oe),y.state.spotShadowMap.length>0&&O.setValue(U,`spotShadowMap`,y.state.spotShadowMap,Oe),y.state.pointShadowMap.length>0&&O.setValue(U,`pointShadowMap`,y.state.pointShadowMap,Oe)),i.isSkinnedMesh){O.setOptional(U,i,`bindMatrix`),O.setOptional(U,i,`bindMatrixInverse`);let e=i.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),O.setValue(U,`boneTexture`,e.boneTexture,Oe))}i.isBatchedMesh&&(O.setOptional(U,i,`batchingTexture`),O.setValue(U,`batchingTexture`,i._matricesTexture,Oe),O.setOptional(U,i,`batchingIdTexture`),O.setValue(U,`batchingIdTexture`,i._indirectTexture,Oe),O.setOptional(U,i,`batchingColorTexture`),i._colorsTexture!==null&&O.setValue(U,`batchingColorTexture`,i._colorsTexture,Oe));let N=n.morphAttributes;if((N.position!==void 0||N.normal!==void 0||N.color!==void 0)&&Be.update(i,n,S),(w||v.receiveShadow!==i.receiveShadow)&&(v.receiveShadow=i.receiveShadow,O.setValue(U,`receiveShadow`,i.receiveShadow)),(r.isMeshStandardMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial)&&r.envMap===null&&t.environment!==null&&(k.envMapIntensity.value=t.environmentIntensity),k.dfgLUT!==void 0&&(k.dfgLUT.value=fg()),w){if(O.setValue(U,`toneMappingExposure`,T.toneMappingExposure),v.needsLights&&_t(k,E),a&&r.fog===!0&&Pe.refreshFogUniforms(k,a),Pe.refreshMaterialUniforms(k,r,oe,V,x.state.transmissionRenderTarget[e.id]),v.needsLights&&v.lightProbeGrid){let e=v.lightProbeGrid;k.probesSH.value=e.texture,k.probesMin.value.copy(e.boundingBox.min),k.probesMax.value.copy(e.boundingBox.max),k.probesResolution.value.copy(e.resolution)}Gm.upload(U,ft(v),k,Oe)}if(r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(Gm.upload(U,ft(v),k,Oe),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&O.setValue(U,`center`,i.center),O.setValue(U,`modelViewMatrix`,i.modelViewMatrix),O.setValue(U,`normalMatrix`,i.normalMatrix),O.setValue(U,`modelMatrix`,i.matrixWorld),r.uniformsGroups!==void 0){let e=r.uniformsGroups;for(let t=0,n=e.length;t0&&Oe.useMultisampledRTT(e)===!1?De.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,N.copy(e.viewport),P.copy(e.scissor),I=e.scissorTest}else N.copy(H).multiplyScalar(oe).floor(),P.copy(le).multiplyScalar(oe).floor(),I=ue;if(n!==0&&(r=yt),W.bindFramebuffer(U.FRAMEBUFFER,r)&&W.drawBuffers(e,r),W.viewport(N),W.scissor(P),W.setScissorTest(I),i){let r=De.get(e.texture);U.framebufferTexture2D(U.FRAMEBUFFER,U.COLOR_ATTACHMENT0,U.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(a){let r=t;for(let t=0;t1&&U.readBuffer(U.COLOR_ATTACHMENT0+s),!Te.textureFormatReadable(c)){$t(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.`);return}if(!Te.textureTypeReadable(l)){$t(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.`);return}t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&U.readPixels(t,n,r,i,Ue.convert(c),Ue.convert(l),a)}finally{let e=A===null?null:De.get(A).__webglFramebuffer;W.bindFramebuffer(U.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let c=De.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o]),c)if(t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i){W.bindFramebuffer(U.FRAMEBUFFER,c);let o=e.textures[s],l=o.format,u=o.type;if(e.textures.length>1&&U.readBuffer(U.COLOR_ATTACHMENT0+s),!Te.textureFormatReadable(l))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(!Te.textureTypeReadable(u))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let d=U.createBuffer();U.bindBuffer(U.PIXEL_PACK_BUFFER,d),U.bufferData(U.PIXEL_PACK_BUFFER,a.byteLength,U.STREAM_READ),U.readPixels(t,n,r,i,Ue.convert(l),Ue.convert(u),0);let f=A===null?null:De.get(A).__webglFramebuffer;W.bindFramebuffer(U.FRAMEBUFFER,f);let p=U.fenceSync(U.SYNC_GPU_COMMANDS_COMPLETE,0);return U.flush(),await tn(U,p,4),U.bindBuffer(U.PIXEL_PACK_BUFFER,d),U.getBufferSubData(U.PIXEL_PACK_BUFFER,0,a),U.deleteBuffer(d),U.deleteSync(p),a}else throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;Oe.setTexture2D(e,0),U.copyTexSubImage2D(U.TEXTURE_2D,n,0,0,o,s,i,a),W.unbindTexture()};let bt=U.createFramebuffer(),xt=U.createFramebuffer();this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=0){let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=Ue.convert(t.format),_=Ue.convert(t.type),v;t.isData3DTexture?(Oe.setTexture3D(t,0),v=U.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(Oe.setTexture2DArray(t,0),v=U.TEXTURE_2D_ARRAY):(Oe.setTexture2D(t,0),v=U.TEXTURE_2D),W.activeTexture(U.TEXTURE0),W.pixelStorei(U.UNPACK_FLIP_Y_WEBGL,t.flipY),W.pixelStorei(U.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),W.pixelStorei(U.UNPACK_ALIGNMENT,t.unpackAlignment);let y=W.getParameter(U.UNPACK_ROW_LENGTH),b=W.getParameter(U.UNPACK_IMAGE_HEIGHT),x=W.getParameter(U.UNPACK_SKIP_PIXELS),S=W.getParameter(U.UNPACK_SKIP_ROWS),C=W.getParameter(U.UNPACK_SKIP_IMAGES);W.pixelStorei(U.UNPACK_ROW_LENGTH,h.width),W.pixelStorei(U.UNPACK_IMAGE_HEIGHT,h.height),W.pixelStorei(U.UNPACK_SKIP_PIXELS,l),W.pixelStorei(U.UNPACK_SKIP_ROWS,u),W.pixelStorei(U.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=De.get(e),r=De.get(t),h=De.get(n.__renderTarget),g=De.get(r.__renderTarget);W.bindFramebuffer(U.READ_FRAMEBUFFER,h.__webglFramebuffer),W.bindFramebuffer(U.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;n{var t=d();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,i=t.useState,a=t.useEffect,o=t.useLayoutEffect,s=t.useDebugValue;function c(e,t){var n=t(),r=i({inst:{value:n,getSnapshot:t}}),c=r[0].inst,u=r[1];return o(function(){c.value=n,c.getSnapshot=t,l(c)&&u({inst:c})},[e,n,t]),a(function(){return l(c)&&u({inst:c}),e(function(){l(c)&&u({inst:c})})},[e]),s(n),n}function l(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function u(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?u:c;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),hg=o(((e,t)=>{t.exports=mg()})),gg=o((e=>{var t=d(),n=hg();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=n.useSyncExternalStore,o=t.useRef,s=t.useEffect,c=t.useMemo,l=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,u){var d=o(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=c(function(){function e(e){if(!a){if(a=!0,o=e,e=r(e),u!==void 0&&f.hasValue){var t=f.value;if(u(t,e))return s=t}return s=e}if(t=s,i(o,e))return t;var n=r(e);return u!==void 0&&u(t,n)?(o=e,t):(o=e,s=n)}var a=!1,o,s,c=n===void 0?null:n;return[function(){return e(t())},c===null?void 0:function(){return e(c())}]},[t,n,r,u]);var p=a(e,d[0],d[1]);return s(function(){f.hasValue=!0,f.value=p},[p]),l(p),p}})),_g=l(o(((e,t)=>{t.exports=gg()}))(),1),vg=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},yg=(e=>e?vg(e):vg),{useSyncExternalStoreWithSelector:bg}=_g.default,xg=e=>e;function Sg(e,t=xg,n){let r=bg(e.subscribe,e.getState,e.getInitialState,t,n);return v.useDebugValue(r),r}var Cg=(e,t)=>{let n=yg(e),r=(e,r=t)=>Sg(n,e,r);return Object.assign(r,n),r},wg=((e,t)=>e?Cg(e,t):Cg),Tg=e=>typeof e==`object`&&typeof e.then==`function`,Eg=[];function Dg(e,t,n=(e,t)=>e===t){if(e===t)return!0;if(!e||!t)return!1;let r=e.length;if(t.length!==r)return!1;for(let i=0;i0&&(e.timeout&&clearTimeout(e.timeout),e.timeout=setTimeout(e.remove,r.lifespan)),e.response;if(!n)throw e.promise}let i={keys:t,equal:r.equal,remove:()=>{let e=Eg.indexOf(i);e!==-1&&Eg.splice(e,1)},promise:(Tg(e)?e:e(...t)).then(e=>{i.response=e,r.lifespan&&r.lifespan>0&&(i.timeout=setTimeout(i.remove,r.lifespan))}).catch(e=>i.error=e)};if(Eg.push(i),!n)throw i.promise}var kg=(e,t,n)=>Og(e,t,!1,n),Ag=(e,t,n)=>void Og(e,t,!0,n),jg=e=>{if(e===void 0||e.length===0)Eg.splice(0,Eg.length);else{let t=Eg.find(t=>Dg(e,t.keys,t.equal));t&&t.remove()}},Mg=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Ng=o(((e,t)=>{t.exports=Mg()})),Pg=l(p()),Z=Ng();typeof window<`u`&&(window.document?.createElement||window.navigator?.product===`ReactNative`)?v.useLayoutEffect:v.useEffect;function Fg(e,t,n){if(!e)return;if(n(e)===!0)return e;let r=t?e.return:e.child;for(;r;){let e=Fg(r,t,n);if(e)return e;r=t?null:r.sibling}}function Ig(e){try{return Object.defineProperties(e,{_currentRenderer:{get(){return null},set(){}},_currentRenderer2:{get(){return null},set(){}}})}catch{return e}}var Lg=Ig(v.createContext(null)),Rg=class extends v.Component{render(){return v.createElement(Lg.Provider,{value:this._reactInternals},this.props.children)}};function zg(){let e=v.useContext(Lg);if(e===null)throw Error(`its-fine: useFiber must be called within a !`);let t=v.useId();return v.useMemo(()=>{for(let n of[e,e?.alternate]){if(!n)continue;let e=Fg(n,!1,e=>{let n=e.memoizedState;for(;n;){if(n.memoizedState===t)return!0;n=n.next}});if(e)return e}},[e,t])}var Bg=Symbol.for(`react.context`),Vg=e=>typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===Bg;function Hg(){let e=zg(),[t]=v.useState(()=>new Map);t.clear();let n=e;for(;n;){let e=n.type;Vg(e)&&e!==Lg&&!t.has(e)&&t.set(e,v.use(Ig(e))),n=n.return}return t}function Ug(){let e=Hg();return v.useMemo(()=>Array.from(e.keys()).reduce((t,n)=>r=>v.createElement(t,null,v.createElement(n.Provider,{...r,value:e.get(n)})),e=>v.createElement(Rg,{...e})),[e])}function Wg(e){let t=e.root;for(;t.getState().previousRoot;)t=t.getState().previousRoot;return t}var Gg=e=>e&&e.isOrthographicCamera,Kg=e=>e&&e.hasOwnProperty(`current`),qg=e=>e!=null&&(typeof e==`string`||typeof e==`number`||e.isColor),Jg=((e,t)=>typeof window<`u`&&((e=window.document)?.createElement||(t=window.navigator)?.product===`ReactNative`))()?v.useLayoutEffect:v.useEffect;function Yg(e){let t=v.useRef(e);return Jg(()=>void(t.current=e),[e]),t}function Xg(){let e=zg(),t=Ug();return v.useMemo(()=>({children:n})=>(0,Z.jsx)(Fg(e,!0,e=>e.type===v.StrictMode)?v.StrictMode:v.Fragment,{children:(0,Z.jsx)(t,{children:n})}),[e,t])}function Zg({set:e}){return Jg(()=>(e(new Promise(()=>null)),()=>e(!1)),[e]),null}var Qg=(e=>(e=class extends v.Component{constructor(...e){super(...e),this.state={error:!1}}componentDidCatch(e){this.props.set(e)}render(){return this.state.error?null:this.props.children}},e.getDerivedStateFromError=()=>({error:!0}),e))();function $g(e){let t=typeof window<`u`?window.devicePixelRatio??2:1;return Array.isArray(e)?Math.min(Math.max(e[0],t),e[1]):e}function e_(e){return e.__r3f?.root.getState()}var t_={obj:e=>e===Object(e)&&!t_.arr(e)&&typeof e!=`function`,fun:e=>typeof e==`function`,str:e=>typeof e==`string`,num:e=>typeof e==`number`,boo:e=>typeof e==`boolean`,und:e=>e===void 0,nul:e=>e===null,arr:e=>Array.isArray(e),equ(e,t,{arrays:n=`shallow`,objects:r=`reference`,strict:i=!0}={}){if(typeof e!=typeof t||!!e!=!!t)return!1;if(t_.str(e)||t_.num(e)||t_.boo(e))return e===t;let a=t_.obj(e);if(a&&r===`reference`)return e===t;let o=t_.arr(e);if(o&&n===`reference`)return e===t;if((o||a)&&e===t)return!0;let s;for(s in e)if(!(s in t))return!1;if(a&&n===`shallow`&&r===`shallow`){for(s in i?t:e)if(!t_.equ(e[s],t[s],{strict:i,objects:`reference`}))return!1}else for(s in i?t:e)if(e[s]!==t[s])return!1;if(t_.und(s)){if(o&&e.length===0&&t.length===0||a&&Object.keys(e).length===0&&Object.keys(t).length===0)return!0;if(e!==t)return!1}return!0}};function n_(e){let t={nodes:{},materials:{},meshes:{}};return e&&e.traverse(e=>{e.name&&(t.nodes[e.name]=e),e.material&&!t.materials[e.material.name]&&(t.materials[e.material.name]=e.material),e.isMesh&&!t.meshes[e.name]&&(t.meshes[e.name]=e)}),t}function r_(e){e.type!==`Scene`&&(e.dispose==null||e.dispose());for(let t in e){let n=e[t];n?.type!==`Scene`&&(n==null||n.dispose==null||n.dispose())}}var i_=[`children`,`key`,`ref`];function a_(e){let t={};for(let n in e)i_.includes(n)||(t[n]=e[n]);return t}function o_(e,t,n,r){let i=e,a=i?.__r3f;return a||(a={root:t,type:n,parent:null,children:[],props:a_(r),object:i,eventCount:0,handlers:{},isHidden:!1},i&&(i.__r3f=a)),a}function s_(e,t){if(!t.includes(`-`)||t in e)return{root:e,key:t,target:e[t]};let n=e,r=t.split(`-`);for(let i of r){if(typeof n!=`object`||!n){if(n!==void 0){let e=r.slice(r.indexOf(i)).join(`-`);return{root:n,key:e,target:void 0}}return{root:e,key:t,target:void 0}}t=i,e=n,n=n[t]}return{root:e,key:t,target:n}}var c_=/-\d+$/;function l_(e,t){if(t_.str(t.props.attach)){if(c_.test(t.props.attach)){let n=t.props.attach.replace(c_,``),{root:r,key:i}=s_(e.object,n);Array.isArray(r[i])||(r[i]=[])}let{root:n,key:r}=s_(e.object,t.props.attach);t.previousAttach=n[r],n[r]=t.object}else t_.fun(t.props.attach)&&(t.previousAttach=t.props.attach(e.object,t.object))}function u_(e,t){if(t_.str(t.props.attach)){let{root:n,key:r}=s_(e.object,t.props.attach),i=t.previousAttach;i===void 0?delete n[r]:n[r]=i}else t.previousAttach==null||t.previousAttach(e.object,t.object);delete t.previousAttach}var d_=[...i_,`args`,`dispose`,`attach`,`object`,`onUpdate`,`dispose`],f_=new Map;function p_(e){let t=f_.get(e.constructor);try{t||(t=new e.constructor,f_.set(e.constructor,t))}catch{}return t}function m_(e,t){let n={};for(let r in t)if(!d_.includes(r)&&!t_.equ(t[r],e.props[r])){n[r]=t[r];for(let e in t)e.startsWith(`${r}-`)&&(n[e]=t[e])}for(let r in e.props){if(d_.includes(r)||t.hasOwnProperty(r))continue;let{root:i,key:a}=s_(e.object,r);if(i.constructor&&i.constructor.length===0){let e=p_(i);t_.und(e)||(n[a]=e[a])}else n[a]=0}return n}var h_=[`map`,`emissiveMap`,`sheenColorMap`,`specularColorMap`,`envMap`],g_=/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/;function __(e,t){var n;let r=e.__r3f,i=r&&Wg(r).getState(),a=r?.eventCount;for(let n in t){let a=t[n];if(d_.includes(n))continue;if(r&&g_.test(n)){typeof a==`function`?r.handlers[n]=a:delete r.handlers[n],r.eventCount=Object.keys(r.handlers).length;continue}if(a===void 0)continue;let{root:s,key:c,target:l}=s_(e,n);if(l===void 0&&(typeof s!=`object`||!s))throw Error(`R3F: Cannot set "${n}". Ensure it is an object before setting "${c}".`);if(l instanceof mr&&a instanceof mr)l.mask=a.mask;else if(l instanceof Y&&qg(a))l.set(a);else if(typeof l==`object`&&l&&typeof l.set==`function`&&typeof l.copy==`function`&&a!=null&&a.constructor&&l.constructor===a.constructor)l.copy(a);else if(typeof l==`object`&&l&&typeof l.set==`function`&&Array.isArray(a))typeof l.fromArray==`function`?l.fromArray(a):l.set(...a);else if(typeof l==`object`&&l&&typeof l.set==`function`&&typeof a==`number`)typeof l.setScalar==`function`?l.setScalar(a):l.set(a);else if(s instanceof yl&&c===`uniforms`&&t_.obj(a)){t_.obj(s.uniforms)||(s.uniforms={});let e=s.uniforms,t=a;for(let n in t){let r=t[n],i=e[n];i?Object.assign(i,r):e[n]={...r}}}else{var o;s[c]=a,i&&!i.linear&&h_.includes(c)&&(o=s[c])!=null&&o.isTexture&&s[c].format===1023&&s[c].type===1009&&(s[c].colorSpace=mt)}}if(r!=null&&r.parent&&i!=null&&i.internal&&(n=r.object)!=null&&n.isObject3D&&a!==r.eventCount){let e=r.object,t=i.internal.interaction.indexOf(e);t>-1&&i.internal.interaction.splice(t,1),r.eventCount&&e.raycast!==null&&i.internal.interaction.push(e)}return r&&r.props.attach===void 0&&(r.object.isBufferGeometry?r.props.attach=`geometry`:r.object.isMaterial&&(r.props.attach=`material`)),r&&v_(r),e}function v_(e){var t;if(!e.parent)return;e.props.onUpdate==null||e.props.onUpdate(e.object);let n=(t=e.root)==null||t.getState==null?void 0:t.getState();n&&n.internal.frames===0&&n.invalidate()}function y_(e,t){e.manual||(Gg(e)?(e.left=t.width/-2,e.right=t.width/2,e.top=t.height/2,e.bottom=t.height/-2):e.aspect=t.width/t.height,e.updateProjectionMatrix())}var b_=e=>e?.isObject3D;function x_(e){return(e.eventObject||e.object).uuid+`/`+e.index+e.instanceId}function S_(e,t,n,r){let i=n.get(t);i&&(n.delete(t),n.size===0&&(e.delete(r),i.target.releasePointerCapture(r)))}function C_(e,t,n){let{internal:r}=e.getState();for(let e=0;e{if(e.eventObject===t||e.object===t){r.hovered.delete(i);let a={...e,eventObject:e.eventObject===t?n:e.eventObject,object:e.object===t?n:e.object};r.hovered.set(x_(a),a)}}),r.capturedMap.forEach(e=>{let r=e.get(t);r&&(e.delete(t),e.set(n,r))})}function w_(e,t){let{internal:n}=e.getState();n.interaction=n.interaction.filter(e=>e!==t),n.initialHits=n.initialHits.filter(e=>e!==t),n.hovered.forEach((e,r)=>{(e.eventObject===t||e.object===t)&&n.hovered.delete(r)}),n.capturedMap.forEach((e,r)=>{S_(n.capturedMap,t,e,r)})}function T_(e){function t(t){let{internal:n}=e.getState(),r=t.offsetX-n.initialClick[0],i=t.offsetY-n.initialClick[1];return Math.round(Math.sqrt(r*r+i*i))}function n(e){return e.filter(e=>[`Move`,`Over`,`Enter`,`Out`,`Leave`].some(t=>e.__r3f?.handlers[`onPointer`+t]))}function r(t,n){let r=e.getState(),i=new Set,a=[],o=n?n(r.internal.interaction):r.internal.interaction;for(let e=0;e{let n=e_(e.object),r=e_(t.object);return!n||!r?e.distance-t.distance:r.events.priority-n.events.priority||e.distance-t.distance}).filter(e=>{let t=x_(e);return i.has(t)?!1:(i.add(t),!0)});r.events.filter&&(c=r.events.filter(c,r));for(let e of c){let t=e.object;for(;t;){var l;(l=t.__r3f)!=null&&l.eventCount&&a.push({...e,eventObject:t}),t=t.parent}}if(`pointerId`in t&&r.internal.capturedMap.has(t.pointerId))for(let e of r.internal.capturedMap.get(t.pointerId).values())i.has(x_(e.intersection))||a.push(e.intersection);return a}function i(e,t,n,r){if(e.length){let i={stopped:!1};for(let o of e){let s=e_(o.object);if(s||o.object.traverseAncestors(e=>{let t=e_(e);if(t)return s=t,!1}),s){let{raycaster:c,pointer:l,camera:u,internal:d}=s,f=new q(l.x,l.y,0).unproject(u),p=e=>d.capturedMap.get(e)?.has(o.eventObject)??!1,m=e=>{let n={intersection:o,target:t.target};d.capturedMap.has(e)?d.capturedMap.get(e).set(o.eventObject,n):d.capturedMap.set(e,new Map([[o.eventObject,n]])),t.target.setPointerCapture(e)},h=e=>{let t=d.capturedMap.get(e);t&&S_(d.capturedMap,o.eventObject,t,e)},g={};for(let e in t){let n=t[e];typeof n!=`function`&&(g[e]=n)}let _={...o,...g,pointer:l,intersections:e,stopped:i.stopped,delta:n,unprojectedPoint:f,ray:c.ray,camera:u,stopPropagation(){let n=`pointerId`in t&&d.capturedMap.get(t.pointerId);(!n||n.has(o.eventObject))&&(_.stopped=i.stopped=!0,d.hovered.size&&Array.from(d.hovered.values()).find(e=>e.eventObject===o.eventObject)&&a([...e.slice(0,e.indexOf(o)),o]))},target:{hasPointerCapture:p,setPointerCapture:m,releasePointerCapture:h},currentTarget:{hasPointerCapture:p,setPointerCapture:m,releasePointerCapture:h},nativeEvent:t};if(r(_),i.stopped===!0)break}}}return e}function a(t){let{internal:n}=e.getState();for(let e of n.hovered.values())if(!t.length||!t.find(t=>t.object===e.object&&t.index===e.index&&t.instanceId===e.instanceId)){let r=e.eventObject.__r3f;if(n.hovered.delete(x_(e)),r!=null&&r.eventCount){let n=r.handlers,i={...e,intersections:t};n.onPointerOut==null||n.onPointerOut(i),n.onPointerLeave==null||n.onPointerLeave(i)}}}function o(e,t){for(let n=0;na([]);case`onLostPointerCapture`:return t=>{let{internal:n}=e.getState();`pointerId`in t&&n.capturedMap.has(t.pointerId)&&requestAnimationFrame(()=>{n.capturedMap.has(t.pointerId)&&(n.capturedMap.delete(t.pointerId),a([]))})}}return function(c){let{onPointerMissed:l,internal:u}=e.getState();u.lastEvent.current=c;let d=s===`onPointerMove`,f=s===`onClick`||s===`onContextMenu`||s===`onDoubleClick`,p=r(c,d?n:void 0),m=f?t(c):0;s===`onPointerDown`&&(u.initialClick=[c.offsetX,c.offsetY],u.initialHits=p.map(e=>e.eventObject)),f&&!p.length&&m<=2&&(o(c,u.interaction),l&&l(c)),d&&a(p);function h(e){let t=e.eventObject,n=t.__r3f;if(!(n!=null&&n.eventCount))return;let r=n.handlers;if(d){if(r.onPointerOver||r.onPointerEnter||r.onPointerOut||r.onPointerLeave){let t=x_(e),n=u.hovered.get(t);n?n.stopped&&e.stopPropagation():(u.hovered.set(t,e),r.onPointerOver==null||r.onPointerOver(e),r.onPointerEnter==null||r.onPointerEnter(e))}r.onPointerMove==null||r.onPointerMove(e)}else{let n=r[s];n?(!f||u.initialHits.includes(t))&&(o(c,u.interaction.filter(e=>!u.initialHits.includes(e))),n(e)):f&&u.initialHits.includes(t)&&o(c,u.interaction.filter(e=>!u.initialHits.includes(e)))}}i(p,c,m,h)}}return{handlePointer:s}}var E_=e=>!!(e!=null&&e.render),D_=v.createContext(null),O_=(e,t)=>{let n=wg((n,r)=>{let i=new q,a=new q,o=new q;function s(e=r().camera,t=a,n=r().size){let{width:s,height:c,top:l,left:u}=n,d=s/c;t.isVector3?o.copy(t):o.set(...t);let f=e.getWorldPosition(i).distanceTo(o);if(Gg(e))return{width:s/e.zoom,height:c/e.zoom,top:l,left:u,factor:1,distance:f,aspect:d};{let t=e.fov*Math.PI/180,n=2*Math.tan(t/2)*f,r=s/c*n;return{width:r,height:n,top:l,left:u,factor:s/r,distance:f,aspect:d}}}let c,l=e=>n(t=>({performance:{...t.performance,current:e}})),u=new K;return{set:n,get:r,gl:null,camera:null,raycaster:null,events:{priority:1,enabled:!0,connected:!1},scene:null,xr:null,invalidate:(t=1)=>e(r(),t),advance:(e,n)=>t(e,n,r()),legacy:!1,linear:!1,flat:!1,controls:null,clock:new Xd,pointer:u,mouse:u,frameloop:`always`,onPointerMissed:void 0,performance:{current:1,min:.5,max:1,debounce:200,regress:()=>{let e=r();c&&clearTimeout(c),e.performance.current!==e.performance.min&&l(e.performance.min),c=setTimeout(()=>l(r().performance.max),e.performance.debounce)}},size:{width:0,height:0,top:0,left:0},viewport:{initialDpr:0,dpr:0,width:0,height:0,top:0,left:0,aspect:0,distance:0,factor:0,getCurrentViewport:s},setEvents:e=>n(t=>({...t,events:{...t.events,...e}})),setSize:(e,t,i=0,o=0)=>{let c=r().camera,l={width:e,height:t,top:i,left:o};n(e=>({size:l,viewport:{...e.viewport,...s(c,a,l)}}))},setDpr:e=>n(t=>{let n=$g(e);return{viewport:{...t.viewport,dpr:n,initialDpr:t.viewport.initialDpr||n}}}),setFrameloop:(e=`always`)=>{let t=r().clock;t.stop(),t.elapsedTime=0,e!==`never`&&(t.start(),t.elapsedTime=0),n(()=>({frameloop:e}))},previousRoot:void 0,internal:{interaction:[],hovered:new Map,subscribers:[],initialClick:[0,0],initialHits:[],capturedMap:new Map,lastEvent:v.createRef(),active:!1,frames:0,priority:0,subscribe:(e,t,n)=>{let i=r().internal;return i.priority+=+(t>0),i.subscribers.push({ref:e,priority:t,store:n}),i.subscribers=i.subscribers.sort((e,t)=>e.priority-t.priority),()=>{let n=r().internal;n!=null&&n.subscribers&&(n.priority-=+(t>0),n.subscribers=n.subscribers.filter(t=>t.ref!==e))}}}}}),r=n.getState(),i=r.size,a=r.viewport.dpr,o=r.camera;return n.subscribe(()=>{let{camera:e,size:t,viewport:r,gl:s,set:c}=n.getState();if(t.width!==i.width||t.height!==i.height||r.dpr!==a){i=t,a=r.dpr,y_(e,t),r.dpr>0&&s.setPixelRatio(r.dpr);let n=typeof HTMLCanvasElement<`u`&&s.domElement instanceof HTMLCanvasElement;s.setSize(t.width,t.height,n)}e!==o&&(o=e,c(t=>({viewport:{...t.viewport,...t.viewport.getCurrentViewport(e)}})))}),n.subscribe(t=>e(t)),n};function k_(){let e=v.useContext(D_);if(!e)throw Error(`R3F: Hooks can only be used within the Canvas component!`);return e}function A_(e=e=>e,t){return k_()(e,t)}function j_(e,t=0){let n=k_(),r=n.getState().internal.subscribe,i=Yg(e);return Jg(()=>r(i,t,n),[t,r,n]),null}var M_=new WeakMap,N_=e=>typeof e==`function`&&e?.prototype?.constructor===e;function P_(e,t){return function(n,...r){let i;return N_(n)?(i=M_.get(n),i||(i=new n,M_.set(n,i))):i=n,e&&e(i),Promise.all(r.map(e=>new Promise((n,r)=>i.load(e,e=>{b_(e?.scene)&&Object.assign(e,n_(e.scene)),n(e)},t,t=>r(Error(`Could not load ${e}: ${t?.message}`))))))}}function F_(e,t,n,r){let i=Array.isArray(t)?t:[t],a=kg(P_(n,r),[e,...i],{equal:t_.equ});return Array.isArray(t)?a:a[0]}F_.preload=function(e,t,n){let r=Array.isArray(t)?t:[t];return Ag(P_(n),[e,...r])},F_.clear=function(e,t){return jg([e,...Array.isArray(t)?t:[t]])};var I_=1,L_=8,R_=32,z_=2,B_={name:`@react-three/fiber`,version:`9.6.1`,description:`A React renderer for Threejs`,keywords:[`react`,`renderer`,`fiber`,`three`,`threejs`],author:`Paul Henschel (https://github.com/drcmda)`,license:`MIT`,maintainers:[`Josh Ellis (https://github.com/joshuaellis)`,`Cody Bennett (https://github.com/codyjasonbennett)`,`Kris Baumgarter (https://github.com/krispya)`],bugs:{url:`https://github.com/pmndrs/react-three-fiber/issues`},homepage:`https://github.com/pmndrs/react-three-fiber#readme`,repository:{type:`git`,url:`git+https://github.com/pmndrs/react-three-fiber.git`},collective:{type:`opencollective`,url:`https://opencollective.com/react-three-fiber`},main:`dist/react-three-fiber.cjs.js`,module:`dist/react-three-fiber.esm.js`,types:`dist/react-three-fiber.cjs.d.ts`,"react-native":`native/dist/react-three-fiber-native.cjs.js`,sideEffects:!1,preconstruct:{entrypoints:[`index.tsx`,`native.tsx`]},scripts:{prebuild:`cp ../../readme.md readme.md`},devDependencies:{"@types/react-reconciler":`^0.32.3`,"react-reconciler":`^0.33.0`},dependencies:{"@babel/runtime":`^7.17.8`,"@types/webxr":`*`,"base64-js":`^1.5.1`,buffer:`^6.0.3`,"its-fine":`^2.0.0`,"react-use-measure":`^2.1.7`,scheduler:`^0.27.0`,"suspend-react":`^0.1.3`,"use-sync-external-store":`^1.4.0`,zustand:`^5.0.3`},peerDependencies:{expo:`>=43.0`,"expo-asset":`>=8.4`,"expo-file-system":`>=11.0`,"expo-gl":`>=11.0`,react:`>=19 <19.3`,"react-dom":`>=19 <19.3`,"react-native":`>=0.78`,three:`>=0.156`},peerDependenciesMeta:{"react-dom":{optional:!0},"react-native":{optional:!0},expo:{optional:!0},"expo-asset":{optional:!0},"expo-file-system":{optional:!0},"expo-gl":{optional:!0}}};function V_(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}var H_={exports:{}},U_={exports:{}};U_.exports;var W_;function G_(){return W_||(W_=1,function(e){e.exports=function(e){function t(e,t,n,r){return new aa(e,t,n,r)}function n(){}function r(e){var t=`https://react.dev/errors/`+e;if(1lc||(e.current=cc[lc],cc[lc]=null,lc--)}function p(e,t){lc++,cc[lc]=e.current,e.current=t}function m(e){return e>>>=0,e===0?32:31-(fc(e)/pc|0)|0}function h(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function g(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=h(n))):i=h(o):i=h(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=h(n))):i=h(o)):i=h(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function _(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function y(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function b(){var e=gc;return gc<<=1,!(gc&62914560)&&(gc=4194304),e}function x(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function S(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function C(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0)`:-1i||c[r]!==l[i]){var u=` `+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(``)&&(u=u.replace(``,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{Fc=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?j(n):``}function N(e,t){switch(e.tag){case 26:case 27:case 5:return j(e.type);case 16:return j(`Lazy`);case 13:return e.child!==t&&t!==null?j(`Suspense Fallback`):j(`Suspense`);case 19:return j(`SuspenseList`);case 0:case 15:return M(e.type,!1);case 11:return M(e.type.render,!1);case 1:return M(e.type,!0);case 31:return j(`Activity`);default:return``}}function P(e){try{var t=``,n=null;do t+=N(e,n),n=e,e=e.return;while(e);return t}catch(e){return` Error generating stack: `+e.message+` `+e.stack}}function F(e,t){if(typeof e==`object`&&e){var n=Ic.get(e);return n===void 0?(t={value:e,source:t,stack:P(t)},Ic.set(e,t),t):n}return{value:e,source:t,stack:P(t)}}function I(e,t){Lc[Rc++]=Bc,Lc[Rc++]=zc,zc=e,Bc=t}function L(e,t,n){Vc[Hc++]=Wc,Vc[Hc++]=Gc,Vc[Hc++]=Uc,Uc=e;var r=Wc;e=Gc;var i=32-dc(r)-1;r&=~(1<>=o,i-=o,Wc=1<<32-dc(t)+i|n<f?(p=d,d=null):p=d.sibling;var _=h(t,d,o[f],c);if(_===null){d===null&&(d=p);break}e&&d&&_.alternate===null&&n(t,d),r=s(_,r,f),u===null?l=_:u.sibling=_,u=_,d=p}if(f===o.length)return i(t,d),Qc&&I(t,f),l;if(d===null){for(;fp?(_=f,f=null):_=f.sibling;var y=h(t,f,v.value,l);if(y===null){f===null&&(f=_);break}e&&f&&y.alternate===null&&n(t,f),o=s(y,o,p),d===null?u=y:d.sibling=y,d=y,f=_}if(v.done)return i(t,f),Qc&&I(t,p),u;if(f===null){for(;!v.done;p++,v=c.next())v=m(t,v.value,l),v!==null&&(o=s(v,o,p),d===null?u=v:d.sibling=v,d=v);return Qc&&I(t,p),u}for(f=a(f);!v.done;p++,v=c.next())v=g(f,t,p,v.value,l),v!==null&&(e&&v.alternate!==null&&f.delete(v.key===null?p:v.key),o=s(v,o,p),d===null?u=v:d.sibling=v,d=v);return e&&f.forEach(function(e){return n(t,e)}),Qc&&I(t,p),u}function y(e,t,a,s){if(typeof a==`object`&&a&&a.type===Oa&&a.key===null&&(a=a.props.children),typeof a==`object`&&a){switch(a.$$typeof){case Ea:e:{for(var u=a.key;t!==null;){if(t.key===u){if(u=a.type,u===Oa){if(t.tag===7){i(e,t.sibling),s=o(t,a.props.children),s.return=e,e=s;break e}}else if(t.elementType===u||typeof u==`object`&&u&&u.$$typeof===La&&Re(u)===t.type){i(e,t.sibling),s=o(t,a.props),He(s,a),s.return=e,e=s;break e}i(e,t);break}else n(e,t);t=t.sibling}a.type===Oa?(s=ua(a.props.children,e.mode,s,a.key),s.return=e,e=s):(s=la(a.type,a.key,a.props,null,e.mode,s),He(s,a),s.return=e,e=s)}return c(e);case Da:e:{for(u=a.key;t!==null;){if(t.key===u)if(t.tag===4&&t.stateNode.containerInfo===a.containerInfo&&t.stateNode.implementation===a.implementation){i(e,t.sibling),s=o(t,a.children||[]),s.return=e,e=s;break e}else{i(e,t);break}else n(e,t);t=t.sibling}s=pa(a,e.mode,s),s.return=e,e=s}return c(e);case La:return a=Re(a),y(e,t,a,s)}if(Ha(a))return _(e,t,a,s);if(l(a)){if(u=l(a),typeof u!=`function`)throw Error(r(150));return a=u.call(a),v(e,t,a,s)}if(typeof a.then==`function`)return y(e,t,Ve(a),s);if(a.$$typeof===Ma)return y(e,t,_e(e,a),s);Ue(e,a)}return typeof a==`string`&&a!==``||typeof a==`number`||typeof a==`bigint`?(a=``+a,t!==null&&t.tag===6?(i(e,t.sibling),s=o(t,a),s.return=e,e=s):(i(e,t),s=da(a,e.mode,s),s.return=e,e=s),c(e)):i(e,t)}return function(e,n,r,i){try{Dl=0;var a=y(e,n,r,i);return El=null,a}catch(n){if(n===xl||n===Cl)throw n;var o=t(29,n,null,e.mode);return o.lanes=i,o.return=e,o}}}function Ge(){for(var e=jl,t=Ml=jl=0;ta?a:8);var o=Ua.T,s={};Ua.T=s,Dn(e,!1,t,n);try{var c=i(),l=Ua.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?En(e,t,je(c,r),bi(e)):En(e,t,r,bi(e))}catch(n){En(e,t,{then:function(){},status:`rejected`,reason:n},bi())}finally{po(a),o!==null&&s.types!==null&&(o.types=s.types),Ua.T=o}}function yn(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:To,baseState:To,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:jt,lastRenderedState:To},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:jt,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function bn(){return ge(Eo)}function xn(){return Et().memoizedState}function Sn(){return Et().memoizedState}function Cn(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=bi();e=$e(n);var r=et(t,e,n);r!==null&&(Si(r,t,n),tt(r,t,n)),t={cache:ye()},e.payload=t;return}t=t.return}}function wn(e,t,n){var r=bi();n={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},On(e)?kn(t,n):(n=qe(e,t,n,r),n!==null&&(Si(n,e,r),An(n,t,r)))}function Tn(e,t,n){En(e,t,n,bi())}function En(e,t,n,r){var i={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null};if(On(e))kn(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,Ac(s,o))return Ke(e,t,i,0),Cu===null&&Ge(),!1}catch{}if(n=qe(e,t,i,r),n!==null)return Si(n,e,r),An(n,t,r),!0}return!1}function Dn(e,t,n,i){if(i={lane:2,revertLane:Oe(),gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null},On(e)){if(t)throw Error(r(479))}else t=qe(e,n,i,2),t!==null&&Si(t,e,2)}function On(e){var t=e.alternate;return e===Vl||t!==null&&t===Vl}function kn(e,t){Gl=Wl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function An(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,T(e,n)}}function jn(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:wa({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}function K(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!Fe(n,r)||!Fe(i,a):!0}function Mn(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&tu.enqueueReplaceState(t,t.state,null)}function q(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=wa({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}function Nn(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Pn(e,t,n){try{var r=e.onCaughtError;r(n.value,{componentStack:n.stack,errorBoundary:t.tag===1?t.stateNode:null})}catch(e){setTimeout(function(){throw e})}}function Fn(e,t,n){return n=$e(n),n.tag=3,n.payload={element:null},n.callback=function(){Nn(e,t)},n}function In(e){return e=$e(e),e.tag=3,e}function Ln(e,t,n,r){var i=n.type.getDerivedStateFromError;if(typeof i==`function`){var a=r.value;e.payload=function(){return i(a)},e.callback=function(){Pn(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Pn(t,n,r),typeof i!=`function`&&(Gu===null?Gu=new Set([this]):Gu.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function Rn(e,t,n,i,a){if(n.flags|=32768,typeof i==`object`&&i&&typeof i.then==`function`){if(t=n.alternate,t!==null&&pe(t,n,a,!0),n=Ll.current,n!==null){switch(n.tag){case 31:case 13:return Rl===null?Pi():n.alternate===null&&Mu===0&&(Mu=3),n.flags&=-257,n.flags|=65536,n.lanes=a,i===wl?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([i]):t.add(i),$i(e,i,a)),!1;case 22:return n.flags|=65536,i===wl?n.flags|=16384:(t=n.updateQueue,t===null?(t={transitions:null,markerInstances:null,retryQueue:new Set([i])},n.updateQueue=t):(n=t.retryQueue,n===null?t.retryQueue=new Set([i]):n.add(i)),$i(e,i,a)),!1}throw Error(r(435,n.tag))}return $i(e,i,a),Pi(),!1}if(Qc)return t=Ll.current,t===null?(i!==tl&&(t=Error(r(423),{cause:i}),H(F(t,n))),e=e.current.alternate,e.flags|=65536,a&=-a,e.lanes|=a,i=F(i,n),a=Fn(e.stateNode,i,a),nt(e,a),Mu!==4&&(Mu=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=a,i!==tl&&(e=Error(r(422),{cause:i}),H(F(e,n)))),!1;var o=Error(r(520),{cause:i});if(o=F(o,n),Ru===null?Ru=[o]:Ru.push(o),Mu!==4&&(Mu=2),t===null)return!0;i=F(i,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=a&-a,n.lanes|=e,e=Fn(n.stateNode,i,e),nt(n,e),!1;case 1:if(t=n.type,o=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||o!==null&&typeof o.componentDidCatch==`function`&&(Gu===null||!Gu.has(o))))return n.flags|=65536,a&=-a,n.lanes|=a,a=In(a),Ln(a,e,n,i),nt(n,a),!1}n=n.return}while(n!==null);return!1}function zn(e,t,n,r){t.child=e===null?kl(t,null,n,r):Ol(t,e.child,n,r)}function Bn(e,t,n,r,i){n=n.render;var a=t.ref;if(`ref`in r){var o={};for(var s in r)s!==`ref`&&(o[s]=r[s])}else o=r;return he(t),r=vt(e,t,n,o,a,i),s=St(),e!==null&&!ru?(Ct(e,t,i),cr(e,t,i)):(Qc&&s&&ee(t),t.flags|=1,zn(e,t,r,i),t.child)}function Vn(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!oa(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,Hn(e,t,a,r,i)):(e=la(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!lr(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?Fe:n,n(o,r)&&e.ref===t.ref)return cr(e,t,i)}return t.flags|=1,e=sa(a,r),e.ref=t.ref,e.return=t,t.child=e}function Hn(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(Fe(a,r)&&e.ref===t.ref)if(ru=!1,t.pendingProps=r=a,lr(e,i))e.flags&131072&&(ru=!0);else return t.lanes=e.lanes,cr(e,t,i)}return Xn(e,t,n,r,i)}function Un(e,t,n,r){var i=r.children,a=e===null?null:e.memoizedState;if(e===null&&t.stateNode===null&&(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),r.mode===`hidden`){if(t.flags&128){if(a=a===null?n:a.baseLanes|n,e!==null){for(r=t.child=e.child,i=0;r!==null;)i=i|r.lanes|r.childLanes,r=r.sibling;r=i&~a}else r=0,t.child=null;return Gn(e,t,a,n,r)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&Ne(t,a===null?null:a.cachePool),a===null?ct():st(t,a),ft(t);else return r=t.lanes=536870912,Gn(e,t,a===null?n:a.baseLanes|n,n,r)}else a===null?(e!==null&&Ne(t,null),ct(),pt()):(Ne(t,a.cachePool),st(t,a),pt(),t.memoizedState=null);return zn(e,t,i,n),t.child}function Wn(e,t){return e!==null&&e.tag===22||t.stateNode!==null||(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),t.sibling}function Gn(e,t,n,r,i){var a=Me();return a=a===null?null:{parent:oo?cl._currentValue:cl._currentValue2,pool:a},t.memoizedState={baseLanes:n,cachePool:a},e!==null&&Ne(t,null),ct(),ft(t),e!==null&&pe(e,t,r,!0),t.childLanes=i,null}function Kn(e,t){return t=J({mode:t.mode,children:t.children},e.mode),t.ref=e.ref,e.child=t,t.return=e,t}function qn(e,t,n){return Ol(t,e.child,null,n),e=Kn(t,t.pendingProps),e.flags|=2,mt(t),t.memoizedState=null,e}function Jn(e,t,n){var i=t.pendingProps,a=(t.flags&128)!=0;if(t.flags&=-129,e===null){if(Qc){if(i.mode===`hidden`)return e=Kn(t,i),t.lanes=536870912,Wn(null,e);if(dt(t),(e=Zc)?(e=xs(e,el),e!==null&&(t.memoizedState={dehydrated:e,treeContext:Uc===null?null:{id:Wc,overflow:Gc},retryLane:536870912,hydrationErrors:null},n=fa(e),n.return=t,t.child=n,Xc=t,Zc=null)):e=null,e===null)throw re(t);return t.lanes=536870912,null}return Kn(t,i)}var o=e.memoizedState;if(o!==null){var s=o.dehydrated;if(dt(t),a)if(t.flags&256)t.flags&=-257,t=qn(e,t,n);else if(t.memoizedState!==null)t.child=e.child,t.flags|=128,t=null;else throw Error(r(558));else if(ru||pe(e,t,n,!1),a=(n&e.childLanes)!==0,ru||a){if(i=Cu,i!==null&&(s=E(i,n),s!==0&&s!==o.retryLane))throw o.retryLane=s,Je(e,s),Si(i,e,s),nu;Pi(),t=qn(e,t,n)}else e=o.treeContext,lo&&(Zc=gs(s),Xc=t,Qc=!0,$c=null,el=!1,e!==null&&te(t,e)),t=Kn(t,i),t.flags|=4096;return t}return e=sa(e.child,{mode:i.mode,children:i.children}),e.ref=t.ref,t.child=e,e.return=t,e}function Yn(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(r(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function Xn(e,t,n,r,i){return he(t),n=vt(e,t,n,r,void 0,i),r=St(),e!==null&&!ru?(Ct(e,t,i),cr(e,t,i)):(Qc&&r&&ee(t),t.flags|=1,zn(e,t,n,i),t.child)}function Zn(e,t,n,r,i,a){return he(t),t.updateQueue=null,n=bt(t,r,n,i),yt(e),r=St(),e!==null&&!ru?(Ct(e,t,a),cr(e,t,a)):(Qc&&r&&ee(t),t.flags|=1,zn(e,t,n,a),t.child)}function Qn(e,t,n,r,i){if(he(t),t.stateNode===null){var a=uc,o=n.contextType;typeof o==`object`&&o&&(a=ge(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=tu,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},Ze(t),o=n.contextType,a.context=typeof o==`object`&&o?ge(o):uc,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(jn(t,n,o,r),a.state=t.memoizedState),typeof n.getDerivedStateFromProps==`function`||typeof a.getSnapshotBeforeUpdate==`function`||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(o=a.state,typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount(),o!==a.state&&tu.enqueueReplaceState(a,a.state,null),it(t,r,a,i),rt(),a.state=t.memoizedState),typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!0}else if(e===null){a=t.stateNode;var s=t.memoizedProps,c=q(n,s);a.props=c;var l=a.context,u=n.contextType;o=uc,typeof u==`object`&&u&&(o=ge(u));var d=n.getDerivedStateFromProps;u=typeof d==`function`||typeof a.getSnapshotBeforeUpdate==`function`,s=t.pendingProps!==s,u||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(s||l!==o)&&Mn(t,a,r,o),Nl=!1;var f=t.memoizedState;a.state=f,it(t,r,a,i),rt(),l=t.memoizedState,s||f!==l||Nl?(typeof d==`function`&&(jn(t,n,d,r),l=t.memoizedState),(c=Nl||K(t,n,c,r,f,l,o))?(u||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount==`function`&&(t.flags|=4194308)):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),a.props=r,a.state=l,a.context=o,r=c):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,Qe(e,t),o=t.memoizedProps,u=q(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=uc,typeof l==`object`&&l&&(c=ge(l)),s=n.getDerivedStateFromProps,(l=typeof s==`function`||typeof a.getSnapshotBeforeUpdate==`function`)||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(o!==d||f!==c)&&Mn(t,a,r,c),Nl=!1,f=t.memoizedState,a.state=f,it(t,r,a,i),rt();var p=t.memoizedState;o!==d||f!==p||Nl||e!==null&&e.dependencies!==null&&me(e.dependencies)?(typeof s==`function`&&(jn(t,n,s,r),p=t.memoizedState),(u=Nl||K(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&me(e.dependencies))?(l||typeof a.UNSAFE_componentWillUpdate!=`function`&&typeof a.componentWillUpdate!=`function`||(typeof a.componentWillUpdate==`function`&&a.componentWillUpdate(r,p,c),typeof a.UNSAFE_componentWillUpdate==`function`&&a.UNSAFE_componentWillUpdate(r,p,c)),typeof a.componentDidUpdate==`function`&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=c,r=u):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return a=r,Yn(e,t),r=(t.flags&128)!=0,a||r?(a=t.stateNode,n=r&&typeof n.getDerivedStateFromError!=`function`?null:a.render(),t.flags|=1,e!==null&&r?(t.child=Ol(t,e.child,null,i),t.child=Ol(t,null,n,i)):zn(e,t,n,i),t.memoizedState=a.state,e=t.child):e=cr(e,t,i),e}function $n(e,t,n,r){return se(),t.flags|=256,zn(e,t,n,r),t.child}function er(e){return{baseLanes:e,cachePool:Pe()}}function tr(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=Iu),e}function nr(e,t,n){var i=t.pendingProps,a=!1,o=(t.flags&128)!=0,s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:(zl.current&2)!=0),s&&(a=!0,t.flags&=-129),s=(t.flags&32)!=0,t.flags&=-33,e===null){if(Qc){if(a?ut(t):pt(),(e=Zc)?(e=Ss(e,el),e!==null&&(t.memoizedState={dehydrated:e,treeContext:Uc===null?null:{id:Wc,overflow:Gc},retryLane:536870912,hydrationErrors:null},n=fa(e),n.return=t,t.child=n,Xc=t,Zc=null)):e=null,e===null)throw re(t);return ss(e)?t.lanes=32:t.lanes=536870912,null}var c=i.children;return i=i.fallback,a?(pt(),a=t.mode,c=J({mode:`hidden`,children:c},a),i=ua(i,a,n,null),c.return=t,i.return=t,c.sibling=i,t.child=c,i=t.child,i.memoizedState=er(n),i.childLanes=tr(e,s,n),t.memoizedState=iu,Wn(null,i)):(ut(t),rr(t,c))}var l=e.memoizedState;if(l!==null&&(c=l.dehydrated,c!==null)){if(o)t.flags&256?(ut(t),t.flags&=-257,t=ir(e,t,n)):t.memoizedState===null?(pt(),c=i.fallback,a=t.mode,i=J({mode:`visible`,children:i.children},a),c=ua(c,a,n,null),c.flags|=2,i.return=t,c.return=t,i.sibling=c,t.child=i,Ol(t,e.child,null,n),i=t.child,i.memoizedState=er(n),i.childLanes=tr(e,s,n),t.memoizedState=iu,t=Wn(null,i)):(pt(),t.child=e.child,t.flags|=128,t=null);else if(ut(t),ss(c))s=cs(c).digest,i=Error(r(419)),i.stack=``,i.digest=s,H({value:i,source:null,stack:null}),t=ir(e,t,n);else if(ru||pe(e,t,n,!1),s=(n&e.childLanes)!==0,ru||s){if(s=Cu,s!==null&&(i=E(s,n),i!==0&&i!==l.retryLane))throw l.retryLane=i,Je(e,i),Si(s,e,i),nu;os(c)||Pi(),t=ir(e,t,n)}else os(c)?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,lo&&(Zc=_s(c),Xc=t,Qc=!0,$c=null,el=!1,e!==null&&te(t,e)),t=rr(t,i.children),t.flags|=4096);return t}return a?(pt(),c=i.fallback,a=t.mode,l=e.child,o=l.sibling,i=sa(l,{mode:`hidden`,children:i.children}),i.subtreeFlags=l.subtreeFlags&65011712,o===null?(c=ua(c,a,n,null),c.flags|=2):c=sa(o,c),c.return=t,i.return=t,i.sibling=c,t.child=i,Wn(null,i),i=t.child,c=e.child.memoizedState,c===null?c=er(n):(a=c.cachePool,a===null?a=Pe():(l=oo?cl._currentValue:cl._currentValue2,a=a.parent===l?a:{parent:l,pool:l}),c={baseLanes:c.baseLanes|n,cachePool:a}),i.memoizedState=c,i.childLanes=tr(e,s,n),t.memoizedState=iu,Wn(e.child,i)):(ut(t),n=e.child,e=n.sibling,n=sa(n,{mode:`visible`,children:i.children}),n.return=t,n.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=n,t.memoizedState=null,n)}function rr(e,t){return t=J({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function J(e,n){return e=t(22,e,null,n),e.lanes=0,e}function ir(e,t,n){return Ol(t,e.child,null,n),e=rr(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function ar(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),de(e.return,t,n)}function or(e,t,n,r,i,a){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i,treeForkCount:a}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=i,o.treeForkCount=a)}function sr(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;r=r.children;var o=zl.current,s=(o&2)!=0;if(s?(o=o&1|2,t.flags|=128):o&=1,p(zl,o),zn(e,t,r,n),r=Qc?Bc:0,!s&&e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&ar(e,n,t);else if(e.tag===19)ar(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}switch(i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&ht(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),or(t,!1,i,n,a,r);break;case`backwards`:case`unstable_legacy-backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&ht(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}or(t,!0,n,null,a,r);break;case`together`:or(t,!1,null,null,void 0,r);break;default:t.memoizedState=null}return t.child}function cr(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Nu|=t.lanes,(n&t.childLanes)===0)if(e!==null){if(pe(e,t,n,!1),(n&t.childLanes)===0)return null}else return null;if(e!==null&&t.child!==e.child)throw Error(r(153));if(t.child!==null){for(e=t.child,n=sa(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=sa(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function lr(e,t){return(e.lanes&t)===0?(e=e.dependencies,!!(e!==null&&me(e))):!0}function ur(e,t,n){switch(t.tag){case 3:z(t,t.stateNode.containerInfo),le(t,cl,e.memoizedState.cache),se();break;case 27:case 5:V(t);break;case 4:z(t,t.stateNode.containerInfo);break;case 10:le(t,t.type,t.memoizedProps.value);break;case 31:if(t.memoizedState!==null)return t.flags|=128,dt(t),null;break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(ut(t),e=cr(e,t,n),e===null?null:e.sibling):nr(e,t,n):(ut(t),t.flags|=128,null);ut(t);break;case 19:var i=(e.flags&128)!=0;if(r=(n&t.childLanes)!==0,r||=(pe(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return sr(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),p(zl,zl.current),r)break;return null;case 22:return t.lanes=0,Un(e,t,n,t.pendingProps);case 24:le(t,cl,e.memoizedState.cache)}return cr(e,t,n)}function dr(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps)ru=!0;else{if(!lr(e,n)&&!(t.flags&128))return ru=!1,ur(e,t,n);ru=(e.flags&131072)!=0}else ru=!1,Qc&&t.flags&1048576&&L(t,Bc,t.index);switch(t.lanes=0,t.tag){case 16:e:{var i=t.pendingProps;if(e=Re(t.elementType),t.type=e,typeof e==`function`)oa(e)?(i=q(e,i),t.tag=1,t=Qn(null,t,e,i,n)):(t.tag=0,t=Xn(null,t,e,i,n));else{if(e!=null){var a=e.$$typeof;if(a===Na){t.tag=11,t=Bn(null,t,e,i,n);break e}else if(a===Ia){t.tag=14,t=Vn(null,t,e,i,n);break e}}throw t=u(e)||e,Error(r(306,t,``))}}return t;case 0:return Xn(e,t,t.type,t.pendingProps,n);case 1:return i=t.type,a=q(i,t.pendingProps),Qn(e,t,i,a,n);case 3:e:{if(z(t,t.stateNode.containerInfo),e===null)throw Error(r(387));var o=t.pendingProps;a=t.memoizedState,i=a.element,Qe(e,t),it(t,o,null,n);var s=t.memoizedState;if(o=s.cache,le(t,cl,o),o!==a.cache&&fe(t,[cl],n,!0),rt(),o=s.element,lo&&a.isDehydrated)if(a={element:o,isDehydrated:!1,cache:s.cache},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){t=$n(e,t,o,n);break e}else if(o!==i){i=F(Error(r(424)),t),H(i),t=$n(e,t,o,n);break e}else for(lo&&(Zc=hs(t.stateNode.containerInfo),Xc=t,Qc=!0,$c=null,el=!0),n=kl(t,null,o,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(se(),o===i){t=cr(e,t,n);break e}zn(e,t,o,n)}t=t.child}return t;case 26:if(Hs)return Yn(e,t),e===null?(n=Gs(t.type,null,t.pendingProps,null))?t.memoizedState=n:Qc||(t.stateNode=Zs(t.type,t.pendingProps,Jc.current,t)):t.memoizedState=Gs(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:if(nc)return V(t),e===null&&nc&&Qc&&(i=t.stateNode=rc(t.type,t.pendingProps,Jc.current,Kc.current,!1),Xc=t,el=!0,Zc=vs(t.type,i,Zc)),zn(e,t,t.pendingProps.children,n),Yn(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&Qc&&(Bs(t.type,t.pendingProps,Kc.current),(a=i=Zc)&&(i=ys(i,t.type,t.pendingProps,el),i===null?a=!1:(t.stateNode=i,Xc=t,Zc=ms(i),el=!1,a=!0)),a||re(t)),V(t),a=t.type,o=t.pendingProps,s=e===null?null:e.memoizedProps,i=o.children,to(a,o)?i=null:s!==null&&to(a,s)&&(t.flags|=32),t.memoizedState!==null&&(a=vt(e,t,xt,null,null,n),oo?Eo._currentValue=a:Eo._currentValue2=a),Yn(e,t),zn(e,t,i,n),t.child;case 6:return e===null&&Qc&&(Vs(t.pendingProps,Kc.current),(e=n=Zc)&&(n=bs(n,t.pendingProps,el),n===null?e=!1:(t.stateNode=n,Xc=t,Zc=null,e=!0)),e||re(t)),null;case 13:return nr(e,t,n);case 4:return z(t,t.stateNode.containerInfo),i=t.pendingProps,e===null?t.child=Ol(t,null,i,n):zn(e,t,i,n),t.child;case 11:return Bn(e,t,t.type,t.pendingProps,n);case 7:return zn(e,t,t.pendingProps,n),t.child;case 8:return zn(e,t,t.pendingProps.children,n),t.child;case 12:return zn(e,t,t.pendingProps.children,n),t.child;case 10:return i=t.pendingProps,le(t,t.type,i.value),zn(e,t,i.children,n),t.child;case 9:return a=t.type._context,i=t.pendingProps.children,he(t),a=ge(a),i=i(a),t.flags|=1,zn(e,t,i,n),t.child;case 14:return Vn(e,t,t.type,t.pendingProps,n);case 15:return Hn(e,t,t.type,t.pendingProps,n);case 19:return sr(e,t,n);case 31:return Jn(e,t,n);case 22:return Un(e,t,n,t.pendingProps);case 24:return he(t),i=ge(cl),e===null?(a=Me(),a===null&&(a=Cu,o=ye(),a.pooledCache=o,o.refCount++,o!==null&&(a.pooledCacheLanes|=n),a=o),t.memoizedState={parent:i,cache:a},Ze(t),le(t,cl,a)):((e.lanes&n)!==0&&(Qe(e,t),it(t,null,null,n),rt()),a=e.memoizedState,o=t.memoizedState,a.parent===i?(i=o.cache,le(t,cl,i),i!==a.cache&&fe(t,[cl],n,!0)):(a={parent:i,cache:i},t.memoizedState=a,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=a),le(t,cl,i))),zn(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(r(156,t.tag))}function fr(e){e.flags|=4}function pr(e){co&&(e.flags|=8)}function mr(e,t){if(e!==null&&e.child===t.child)return!1;if(t.flags&16)return!0;for(e=t.child;e!==null;){if(e.flags&8218||e.subtreeFlags&8218)return!0;e=e.sibling}return!1}function hr(e,t,n,r){if(so)for(n=t.child;n!==null;){if(n.tag===5||n.tag===6)$a(e,n.stateNode);else if(!(n.tag===4||nc&&n.tag===27)&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}else if(co)for(var i=t.child;i!==null;){if(i.tag===5){var a=i.stateNode;n&&r&&(a=is(a,i.type,i.memoizedProps)),$a(e,a)}else if(i.tag===6)a=i.stateNode,n&&r&&(a=as(a,i.memoizedProps)),$a(e,a);else if(i.tag!==4){if(i.tag===22&&i.memoizedState!==null)a=i.child,a!==null&&(a.return=i),hr(e,i,!0,!0);else if(i.child!==null){i.child.return=i,i=i.child;continue}}if(i===t)break;for(;i.sibling===null;){if(i.return===null||i.return===t)return;i=i.return}i.sibling.return=i.return,i=i.sibling}}function gr(e,t,n,r){var i=!1;if(co)for(var a=t.child;a!==null;){if(a.tag===5){var o=a.stateNode;n&&r&&(o=is(o,a.type,a.memoizedProps)),ts(e,o)}else if(a.tag===6)o=a.stateNode,n&&r&&(o=as(o,a.memoizedProps)),ts(e,o);else if(a.tag!==4){if(a.tag===22&&a.memoizedState!==null)i=a.child,i!==null&&(i.return=a),gr(e,a,!0,!0),i=!0;else if(a.child!==null){a.child.return=a,a=a.child;continue}}if(a===t)break;for(;a.sibling===null;){if(a.return===null||a.return===t)return i;a=a.return}a.sibling.return=a.return,a=a.sibling}return i}function _r(e,t){if(co&&mr(e,t)){e=t.stateNode;var n=e.containerInfo,r=es();gr(r,t,!1,!1),e.pendingChildren=r,fr(t),ns(n,r)}}function vr(e,t,n,r){if(so)e.memoizedProps!==r&&fr(t);else if(co){var i=e.stateNode,a=e.memoizedProps;if((e=mr(e,t))||a!==r){var o=Kc.current;a=$o(i,n,a,r,!e,null),a===i?t.stateNode=i:(pr(t),eo(a,n,r,o)&&fr(t),t.stateNode=a,e&&hr(a,t,!1,!1))}else t.stateNode=i}}function yr(e,t,n,r,i){if(e.mode&32&&(n===null?vo(t,r):yo(t,n,r))){if(e.flags|=16777216,(i&335544128)===i||bo(t,r))if(xo(e.stateNode,t,r))e.flags|=8192;else if(ji())e.flags|=8192;else throw Tl=wl,Sl}else e.flags&=-16777217}function br(e,t){if($s(t)){if(e.flags|=16777216,!ec(t))if(ji())e.flags|=8192;else throw Tl=wl,Sl}else e.flags&=-16777217}function xr(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:b(),e.lanes|=t,Lu|=t)}function Sr(e,t){if(!Qc)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Cr(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&65011712,r|=i.flags&65011712,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function wr(e,t,n){var i=t.pendingProps;switch(R(t),t.tag){case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Cr(t),null;case 1:return Cr(t),null;case 3:return n=t.stateNode,i=null,e!==null&&(i=e.memoizedState.cache),t.memoizedState.cache!==i&&(t.flags|=2048),ue(cl),B(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(oe(t)?fr(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,ce())),_r(e,t),Cr(t),null;case 26:if(Hs){var a=t.type,o=t.memoizedState;return e===null?(fr(t),o===null?(Cr(t),yr(t,a,null,i,n)):(Cr(t),br(t,o))):o?o===e.memoizedState?(Cr(t),t.flags&=-16777217):(fr(t),Cr(t),br(t,o)):(o=e.memoizedProps,so?o!==i&&fr(t):vr(e,t,a,i),Cr(t),yr(t,a,o,i,n)),null}case 27:if(nc){if(ne(t),n=Jc.current,a=t.type,e!==null&&t.stateNode!=null)so?e.memoizedProps!==i&&fr(t):vr(e,t,a,i);else{if(!i){if(t.stateNode===null)throw Error(r(166));return Cr(t),null}e=Kc.current,oe(t)?ie(t,e):(e=rc(a,i,n,e,!0),t.stateNode=e,fr(t))}return Cr(t),null}case 5:if(ne(t),a=t.type,e!==null&&t.stateNode!=null)vr(e,t,a,i);else{if(!i){if(t.stateNode===null)throw Error(r(166));return Cr(t),null}if(o=Kc.current,oe(t))ie(t,o),Ns(t.stateNode,a,i,o)&&(t.flags|=64);else{var s=Qa(a,i,Jc.current,o,t);pr(t),hr(s,t,!1,!1),t.stateNode=s,eo(s,a,i,o)&&fr(t)}}return Cr(t),yr(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,n),null;case 6:if(e&&t.stateNode!=null)n=e.memoizedProps,so?n!==i&&fr(t):co&&(n===i?t.stateNode=e.stateNode:(e=Jc.current,n=Kc.current,pr(t),t.stateNode=no(i,e,n,t)));else{if(typeof i!=`string`&&t.stateNode===null)throw Error(r(166));if(e=Jc.current,n=Kc.current,oe(t)){if(!lo)throw Error(r(176));if(e=t.stateNode,n=t.memoizedProps,i=null,a=Xc,a!==null)switch(a.tag){case 27:case 5:i=a.memoizedProps}ws(e,n,t,i)||re(t,!0)}else pr(t),t.stateNode=no(i,e,n,t)}return Cr(t),null;case 31:if(n=t.memoizedState,e===null||e.memoizedState!==null){if(i=oe(t),n!==null){if(e===null){if(!i)throw Error(r(318));if(!lo)throw Error(r(556));if(e=t.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(r(557));Ts(e,t)}else se(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Cr(t),e=!1}else n=ce(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=n),e=!0;if(!e)return t.flags&256?(mt(t),t):(mt(t),null);if(t.flags&128)throw Error(r(558))}return Cr(t),null;case 13:if(i=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=oe(t),i!==null&&i.dehydrated!==null){if(e===null){if(!a)throw Error(r(318));if(!lo)throw Error(r(344));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(r(317));Es(a,t)}else se(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Cr(t),a=!1}else a=ce(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(mt(t),t):(mt(t),null)}return mt(t),t.flags&128?(t.lanes=n,t):(n=i!==null,e=e!==null&&e.memoizedState!==null,n&&(i=t.child,a=null,i.alternate!==null&&i.alternate.memoizedState!==null&&i.alternate.memoizedState.cachePool!==null&&(a=i.alternate.memoizedState.cachePool.pool),o=null,i.memoizedState!==null&&i.memoizedState.cachePool!==null&&(o=i.memoizedState.cachePool.pool),o!==a&&(i.flags|=2048)),n!==e&&n&&(t.child.flags|=8192),xr(t,t.updateQueue),Cr(t),null);case 4:return B(),_r(e,t),e===null&&fo(t.stateNode.containerInfo),Cr(t),null;case 10:return ue(t.type),Cr(t),null;case 19:if(f(zl),i=t.memoizedState,i===null)return Cr(t),null;if(a=(t.flags&128)!=0,o=i.rendering,o===null)if(a)Sr(i,!1);else{if(Mu!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=ht(e),o!==null){for(t.flags|=128,Sr(i,!1),e=o.updateQueue,t.updateQueue=e,xr(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)ca(n,e),n=n.sibling;return p(zl,zl.current&1|2),Qc&&I(t,i.treeForkCount),t.child}e=e.sibling}i.tail!==null&&xc()>Uu&&(t.flags|=128,a=!0,Sr(i,!1),t.lanes=4194304)}else{if(!a)if(e=ht(o),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,xr(t,e),Sr(i,!0),i.tail===null&&i.tailMode===`hidden`&&!o.alternate&&!Qc)return Cr(t),null}else 2*xc()-i.renderingStartTime>Uu&&n!==536870912&&(t.flags|=128,a=!0,Sr(i,!1),t.lanes=4194304);i.isBackwards?(o.sibling=t.child,t.child=o):(e=i.last,e===null?t.child=o:e.sibling=o,i.last=o)}return i.tail===null?(Cr(t),null):(e=i.tail,i.rendering=e,i.tail=e.sibling,i.renderingStartTime=xc(),e.sibling=null,n=zl.current,p(zl,a?n&1|2:n&1),Qc&&I(t,i.treeForkCount),e);case 22:case 23:return mt(t),lt(),i=t.memoizedState!==null,e===null?i&&(t.flags|=8192):e.memoizedState!==null!==i&&(t.flags|=8192),i?n&536870912&&!(t.flags&128)&&(Cr(t),t.subtreeFlags&6&&(t.flags|=8192)):Cr(t),n=t.updateQueue,n!==null&&xr(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),i=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(i=t.memoizedState.cachePool.pool),i!==n&&(t.flags|=2048),e!==null&&f(bl),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),ue(cl),Cr(t),null;case 25:return null;case 30:return null}throw Error(r(156,t.tag))}function Tr(e,t){switch(R(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return ue(cl),B(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return ne(t),null;case 31:if(t.memoizedState!==null){if(mt(t),t.alternate===null)throw Error(r(340));se()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(mt(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(r(340));se()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return f(zl),null;case 4:return B(),null;case 10:return ue(t.type),null;case 22:case 23:return mt(t),lt(),e!==null&&f(bl),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return ue(cl),null;case 25:return null;default:return null}}function Er(e,t){switch(R(t),t.tag){case 3:ue(cl),B();break;case 26:case 27:case 5:ne(t);break;case 4:B();break;case 31:t.memoizedState!==null&&mt(t);break;case 13:mt(t);break;case 19:f(zl);break;case 10:ue(t.type);break;case 22:case 23:mt(t),lt(),e!==null&&f(bl);break;case 24:ue(cl)}}function Dr(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){Qi(t,t.return,e)}}function Or(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){Qi(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Qi(t,t.return,e)}}function kr(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{ot(t,n)}catch(t){Qi(e,e.return,t)}}}function Ar(e,t,n){n.props=q(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Qi(e,t,n)}}function jr(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=qa(e.stateNode);break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){Qi(e,t,n)}}function Mr(e,t){var n=e.ref,r=e.refCleanup;if(n!==null)if(typeof r==`function`)try{r()}catch(n){Qi(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){Qi(e,t,n)}else n.current=null}function Nr(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{Vo(r,t,n,e)}catch(t){Qi(e,e.return,t)}}function Pr(e,t,n){try{Ho(e.stateNode,e.type,n,t,e)}catch(t){Qi(e,e.return,t)}}function Fr(e){return e.tag===5||e.tag===3||(Hs?e.tag===26:!1)||(nc?e.tag===27&&sc(e.type):!1)||e.tag===4}function Ir(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Fr(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(nc&&e.tag===27&&sc(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Lr(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?Wo(n,e,t):zo(n,e);else if(r!==4&&(nc&&r===27&&sc(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(Lr(e,t,n),e=e.sibling;e!==null;)Lr(e,t,n),e=e.sibling}function Y(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?Uo(n,e,t):Ro(n,e);else if(r!==4&&(nc&&r===27&&sc(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(Y(e,t,n),e=e.sibling;e!==null;)Y(e,t,n),e=e.sibling}function Rr(e,t,n){e=e.containerInfo;try{rs(e,n)}catch(e){Qi(t,t.return,e)}}function zr(e){var t=e.stateNode,n=e.memoizedProps;try{ic(e.type,n,t,e)}catch(t){Qi(e,e.return,t)}}function Br(e,t){for(Xa(e.containerInfo),lu=t;lu!==null;)if(e=lu,t=e.child,e.subtreeFlags&1028&&t!==null)t.return=e,lu=t;else for(;lu!==null;){e=lu;var n=e.alternate;switch(t=e.flags,e.tag){case 0:if(t&4&&(t=e.updateQueue,t=t===null?null:t.events,t!==null))for(var i=0;i`;case gu:return`:has(`+(_i(e)||``)+`)`;case _u:return`[role="`+e.value+`"]`;case yu:return`"`+e.value+`"`;case vu:return`[data-testname="`+e.value+`"]`;default:throw Error(r(365))}}function vi(e,t){var n=[];e=[e,0];for(var r=0;rn?32:n;n=Ua.T;var a=mo();try{po(i),Ua.T=null,i=Zu,Zu=null;var o=qu,s=Yu;if(Ku=0,Ju=qu=null,Yu=0,Su&6)throw Error(r(331));var c=Su;if(Su|=4,fi(o.current),ai(o,o.current,s,i),Su=c,U(0,!1),kc&&typeof kc.onPostCommitFiberRoot==`function`)try{kc.onPostCommitFiberRoot(Oc,o)}catch{}return!0}finally{po(a),Ua.T=n,Ji(e,t)}}function Zi(e,t,n){t=F(n,t),t=Fn(e.stateNode,t,2),e=et(e,t,2),e!==null&&(S(e,2),Se(e))}function Qi(e,t,n){if(e.tag===3)Zi(e,e,n);else for(;t!==null;){if(t.tag===3){Zi(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(Gu===null||!Gu.has(r))){e=F(n,e),n=In(2),r=et(t,n,2),r!==null&&(Ln(n,r,t,e),S(r,2),Se(r));break}}t=t.return}}function $i(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new xu;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Au=!0,i.add(n),e=ea.bind(null,e,t,n),t.then(e,e))}function ea(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,Cu===e&&(Tu&n)===n&&(Mu===4||Mu===3&&(Tu&62914560)===Tu&&300>xc()-Vu?!(Su&2)&&ki(e,0):Fu|=n,Lu===Tu&&(Lu=0)),Se(e)}function ta(e,t){t===0&&(t=b()),e=Je(e,t),e!==null&&(S(e,t),Se(e))}function na(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),ta(e,n)}function ra(e,t){var n=0;switch(e.tag){case 31:case 13:var i=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:i=e.stateNode;break;case 22:i=e.stateNode._retryCache;break;default:throw Error(r(314))}i!==null&&i.delete(t),ta(e,n)}function ia(e,t){return _c(e,t)}function aa(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function oa(e){return e=e.prototype,!(!e||!e.isReactComponent)}function sa(e,n){var r=e.alternate;return r===null?(r=t(e.tag,n,e.key,e.mode),r.elementType=e.elementType,r.type=e.type,r.stateNode=e.stateNode,r.alternate=e,e.alternate=r):(r.pendingProps=n,r.type=e.type,r.flags=0,r.subtreeFlags=0,r.deletions=null),r.flags=e.flags&65011712,r.childLanes=e.childLanes,r.lanes=e.lanes,r.child=e.child,r.memoizedProps=e.memoizedProps,r.memoizedState=e.memoizedState,r.updateQueue=e.updateQueue,n=e.dependencies,r.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},r.sibling=e.sibling,r.index=e.index,r.ref=e.ref,r.refCleanup=e.refCleanup,r}function ca(e,t){e.flags&=65011714;var n=e.alternate;return n===null?(e.childLanes=0,e.lanes=t,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=n.childLanes,e.lanes=n.lanes,e.child=n.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=n.memoizedProps,e.memoizedState=n.memoizedState,e.updateQueue=n.updateQueue,e.type=n.type,t=n.dependencies,e.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),e}function la(e,n,i,a,o,s){var c=0;if(a=e,typeof e==`function`)oa(e)&&(c=1);else if(typeof e==`string`)c=Hs&&nc?Us(e,i,Kc.current)?26:oc(e)?27:5:Hs?Us(e,i,Kc.current)?26:5:nc&&oc(e)?27:5;else e:switch(e){case Ra:return e=t(31,i,n,o),e.elementType=Ra,e.lanes=s,e;case Oa:return ua(i.children,o,s,n);case ka:c=8,o|=24;break;case Aa:return e=t(12,i,n,o|2),e.elementType=Aa,e.lanes=s,e;case Pa:return e=t(13,i,n,o),e.elementType=Pa,e.lanes=s,e;case Fa:return e=t(19,i,n,o),e.elementType=Fa,e.lanes=s,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case Ma:c=10;break e;case ja:c=9;break e;case Na:c=11;break e;case Ia:c=14;break e;case La:c=16,a=null;break e}c=29,i=Error(r(130,e===null?`null`:typeof e,``)),a=null}return n=t(c,i,n,o),n.elementType=e,n.type=a,n.lanes=s,n}function ua(e,n,r,i){return e=t(7,e,i,n),e.lanes=r,e}function da(e,n,r){return e=t(6,e,null,n),e.lanes=r,e}function fa(e){var n=t(18,null,null,0);return n.stateNode=e,n}function pa(e,n,r){return n=t(4,e.children===null?[]:e.children,e.key,n),n.lanes=r,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function ma(e,t,n,r,i,a,o,s,c){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=ao,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=x(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=x(0),this.hiddenUpdates=x(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=c,this.incompleteTransitions=new Map}function ha(e,n,r,i,a,o,s,c,l,u,d,f){return e=new ma(e,n,r,s,l,u,d,f,c),n=1,o===!0&&(n|=24),o=t(3,null,null,n),e.current=o,o.stateNode=e,n=ye(),n.refCount++,e.pooledCache=n,n.refCount++,o.memoizedState={element:i,isDehydrated:r,cache:n},Ze(o),e}function ga(e){return e?(e=uc,e):uc}function _a(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(r(188)):(e=Object.keys(e).join(`,`),Error(r(268,e)));return e=o(t),e=e===null?null:s(e),e===null?null:qa(e.stateNode)}function va(e,t,n,r,i,a){i=ga(i),r.context===null?r.context=i:r.pendingContext=i,r=$e(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=et(e,r,t),n!==null&&(Si(n,e,t),tt(n,e,t))}function ya(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n=u&&o>=f&&a<=d&&s<=p){e.splice(t,1);break}else if(i!==u||n.width!==l.width||ps){if(!(o!==f||n.height!==l.height||da)){u>i&&(l.width+=u-i,l.x=i),do&&(l.height+=f-o,l.y=o),pn&&(n=c)),c `)+` No matching component was found for: `)+e.join(` > `)}return null},xa.getPublicRootInstance=function(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 27:case 5:return qa(e.child.stateNode);default:return e.child.stateNode}},xa.injectIntoDevTools=function(){var e={bundleType:0,version:Wa,rendererPackageName:Ga,currentDispatcherRef:Ua,reconcilerVersion:`19.2.0`};if(Ka!==null&&(e.rendererConfig=Ka),typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`)e=!1;else{var t=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(t.isDisabled||!t.supportsFiber)e=!0;else{try{Oc=t.inject(e),kc=t}catch{}e=!!t.checkDCE}}return e},xa.isAlreadyRendering=function(){return(Su&6)!=0},xa.observeVisibleRects=function(e,t,n,i){if(!Ao)throw Error(r(363));e=yi(e,t);var a=Lo(e,n,i).disconnect;return{disconnect:function(){a()}}},xa.shouldError=function(){return null},xa.shouldSuspend=function(){return!1},xa.startHostTransition=function(e,t,i,a){if(e.tag!==5)throw Error(r(476));var o=yn(e).queue;vn(e,o,t,To,i===null?n:function(){var t=yn(e);return t.next===null&&(t=e.alternate.memoizedState),En(e,t.next.queue,{},bi()),i(a)})},xa.updateContainer=function(e,t,n,r){var i=t.current,a=bi();return va(i,a,e,t,n,r),a},xa.updateContainerSync=function(e,t,n,r){return va(t.current,2,e,t,n,r),2},xa},e.exports.default=e.exports,Object.defineProperty(e.exports,"__esModule",{value:!0})}(U_)),U_.exports}({exports:{}}).exports;var K_;function q_(){return K_||(K_=1,H_.exports=G_()),H_.exports}var J_=V_(q_());function Y_(e){let t=J_(e);return t.injectIntoDevTools(),t}var X_=0,Z_={},Q_=/^three(?=[A-Z])/,$_=e=>`${e[0].toUpperCase()}${e.slice(1)}`,ev=0,tv=e=>typeof e==`function`;function nv(e){if(tv(e)){let t=`${ev++}`;return Z_[t]=e,t}else Object.assign(Z_,e)}function rv(e,t){let n=$_(e),r=Z_[n];if(e!==`primitive`&&!r)throw Error(`R3F: ${n} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`);if(e===`primitive`&&!t.object)throw Error(`R3F: Primitives without 'object' are invalid!`);if(t.args!==void 0&&!Array.isArray(t.args))throw Error(`R3F: The args prop must be an array!`)}function iv(e,t,n){var r;return e=$_(e)in Z_?e:e.replace(Q_,``),rv(e,t),e===`primitive`&&(r=t.object)!=null&&r.__r3f&&delete t.object.__r3f,o_(t.object,n,e,t)}function av(e){if(!e.isHidden){var t;e.props.attach&&(t=e.parent)!=null&&t.object?u_(e.parent,e):b_(e.object)&&(e.object.visible=!1),e.isHidden=!0,v_(e)}}function ov(e){if(e.isHidden){var t;e.props.attach&&(t=e.parent)!=null&&t.object?l_(e.parent,e):b_(e.object)&&e.props.visible!==!1&&(e.object.visible=!0),e.isHidden=!1,v_(e)}}function sv(e,t,n){let r=t.root.getState();if(!(!e.parent&&e.object!==r.scene)){if(!t.object){let e=Z_[$_(t.type)];t.object=t.props.object??new e(...t.props.args??[]),t.object.__r3f=t}if(__(t.object,t.props),t.props.attach)l_(e,t);else if(b_(t.object)&&b_(e.object)){let r=e.object.children.indexOf(n?.object);if(n&&r!==-1){let n=e.object.children.indexOf(t.object);if(n!==-1){e.object.children.splice(n,1);let i=n{try{e.dispose()}catch{}};typeof IS_REACT_ACT_ENVIRONMENT<`u`?t():(0,Pg.unstable_scheduleCallback)(Pg.unstable_IdlePriority,t)}}function dv(e,t,n){if(!t)return;t.parent=null;let r=e.children.indexOf(t);r!==-1&&e.children.splice(r,1),t.props.attach?u_(e,t):b_(t.object)&&b_(e.object)&&(e.object.remove(t.object),w_(Wg(t),t.object));let i=t.props.dispose!==null&&n!==!1;for(let e=t.children.length-1;e>=0;e--){let n=t.children[e];dv(t,n,i)}t.children.length=0,delete t.object.__r3f,i&&t.type!==`primitive`&&t.object.type!==`Scene`&&uv(t.object),n===void 0&&v_(t)}function fv(e,t){for(let n of[e,e.alternate])if(n!==null)if(typeof n.ref==`function`){n.refCleanup==null||n.refCleanup();let e=n.ref(t);typeof e==`function`&&(n.refCleanup=e)}else n.ref&&(n.ref.current=t)}var pv=[];function mv(){for(let[e]of pv){let t=e.parent;if(t){e.props.attach?u_(t,e):b_(e.object)&&b_(t.object)&&t.object.remove(e.object);for(let t of e.children)t.props.attach?u_(e,t):b_(t.object)&&b_(e.object)&&e.object.remove(t.object)}e.isHidden&&ov(e),e.object.__r3f&&delete e.object.__r3f,e.type!==`primitive`&&uv(e.object)}for(let[e,t,n]of pv){e.props=t;let r=e.parent;if(r){let t=Z_[$_(e.type)],i=e.object;e.object=e.props.object??new t(...e.props.args??[]),e.object.__r3f=e,fv(n,e.object),C_(Wg(e),i,e.object),__(e.object,e.props),e.props.attach?l_(r,e):b_(e.object)&&b_(r.object)&&r.object.add(e.object);for(let t of e.children)t.props.attach?l_(e,t):b_(t.object)&&b_(e.object)&&e.object.add(t.object);v_(e)}}pv.length=0}var hv=()=>{},gv={},_v=X_,vv=0,yv=4,bv=Y_({isPrimaryRenderer:!1,warnsIfNotActing:!1,supportsMutation:!0,supportsPersistence:!1,supportsHydration:!1,createInstance:iv,removeChild:dv,appendChild:cv,appendInitialChild:cv,insertBefore:lv,appendChildToContainer(e,t){let n=e.getState().scene.__r3f;!t||!n||cv(n,t)},removeChildFromContainer(e,t){let n=e.getState().scene.__r3f;!t||!n||dv(n,t)},insertInContainerBefore(e,t,n){let r=e.getState().scene.__r3f;!t||!n||!r||lv(r,t,n)},getRootHostContext:()=>gv,getChildHostContext:()=>gv,commitUpdate(e,t,n,r,i){var a;rv(t,r);let o=!1;if(e.type===`primitive`&&n.object!==r.object?o=!0:r.args?.length===n.args?.length?(a=r.args)!=null&&a.some((e,t)=>e!==n.args?.[t])&&(o=!0):o=!0,o)pv.push([e,{...r},i]);else{let t=m_(e,r);Object.keys(t).length&&(Object.assign(e.props,t),__(e.object,t))}(i.sibling===null||(i.flags&yv)===vv)&&mv()},finalizeInitialChildren:()=>!1,commitMount(){},getPublicInstance:e=>e?.object,prepareForCommit:()=>null,preparePortalMount:e=>o_(e.getState().scene,e,``,{}),resetAfterCommit:()=>{},shouldSetTextContent:()=>!1,clearContainer:()=>!1,hideInstance:av,unhideInstance:ov,createTextInstance:hv,hideTextInstance:hv,unhideTextInstance:hv,scheduleTimeout:typeof setTimeout==`function`?setTimeout:void 0,cancelTimeout:typeof clearTimeout==`function`?clearTimeout:void 0,noTimeout:-1,getInstanceFromNode:()=>null,beforeActiveInstanceBlur(){},afterActiveInstanceBlur(){},detachDeletedInstance(){},prepareScopeUpdate(){},getInstanceFromScope:()=>null,shouldAttemptEagerTransition:()=>!1,trackSchedulerEvent:()=>{},resolveEventType:()=>null,resolveEventTimeStamp:()=>-1.1,requestPostPaintCallback(){},maySuspendCommit:()=>!1,preloadInstance:()=>!0,suspendInstance(){},waitForCommitToBeReady:()=>null,NotPendingTransition:null,HostTransitionContext:v.createContext(null),setCurrentUpdatePriority(e){_v=e},getCurrentUpdatePriority(){return _v},resolveUpdatePriority(){if(_v!==X_)return _v;switch(typeof window<`u`&&window.event?.type){case`click`:case`contextmenu`:case`dblclick`:case`pointercancel`:case`pointerdown`:case`pointerup`:return z_;case`pointermove`:case`pointerout`:case`pointerover`:case`pointerenter`:case`pointerleave`:case`wheel`:return L_;default:return R_}},resetFormInstance(){},rendererPackageName:`@react-three/fiber`,rendererVersion:B_.version,applyViewTransitionName(e,t,n){},restoreViewTransitionName(e,t){},cancelViewTransitionName(e,t,n){},cancelRootViewTransitionName(e){},restoreRootViewTransitionName(e){},InstanceMeasurement:null,measureInstance:e=>null,wasInstanceInViewport:e=>!0,hasInstanceChanged:(e,t)=>!1,hasInstanceAffectedParent:(e,t)=>!1,suspendOnActiveViewTransition(e,t){},startGestureTransition:()=>null,startViewTransition:()=>null,stopViewTransition(e){},createViewTransitionInstance:e=>null,getCurrentGestureOffset(e){throw Error(`startGestureTransition is not yet supported in react-three-fiber.`)},cloneMutableInstance(e,t){return e},cloneMutableTextInstance(e){return e},cloneRootViewTransitionContainer(e){throw Error(`Not implemented.`)},removeRootViewTransitionClone(e,t){throw Error(`Not implemented.`)},createFragmentInstance:e=>null,updateFragmentInstanceFiber(e,t){},commitNewChildToFragmentInstance(e,t){},deleteChildFromFragmentInstance(e,t){},measureClonedInstance:e=>null,maySuspendCommitOnUpdate:(e,t,n)=>!1,maySuspendCommitInSyncRender:(e,t)=>!1,startSuspendingCommit:()=>null,getSuspendedCommitReason:(e,t)=>null}),xv=new Map,Sv={objects:`shallow`,strict:!1};function Cv(e,t){if(!t&&typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement&&e.parentElement){let{width:t,height:n,top:r,left:i}=e.parentElement.getBoundingClientRect();return{width:t,height:n,top:r,left:i}}else if(!t&&typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas)return{width:e.width,height:e.height,top:0,left:0};return{width:0,height:0,top:0,left:0,...t}}function wv(e){let t=xv.get(e),n=t?.fiber,r=t?.store;t&&console.warn(`R3F.createRoot should only be called once!`);let i=typeof reportError==`function`?reportError:console.error,a=r||O_(Uv,Wv),o=n||bv.createContainer(a,I_,null,!1,null,``,i,i,i,null);t||xv.set(e,{fiber:o,store:a});let s,c,l=!1,u=null;return{async configure(t={}){let n;u=new Promise(e=>n=e);let{gl:r,size:i,scene:o,events:d,onCreated:f,shadows:p=!1,linear:m=!1,flat:h=!1,legacy:g=!1,orthographic:_=!1,frameloop:v=`always`,dpr:y=[1,2],performance:b,raycaster:x,camera:S,onPointerMissed:C}=t,w=a.getState(),T=w.gl;if(!w.gl){let t={canvas:e,powerPreference:`high-performance`,antialias:!0,alpha:!0},n=typeof r==`function`?await r(t):r;T=E_(n)?n:new pg({...t,...r}),w.set({gl:T})}let E=w.raycaster;E||w.set({raycaster:E=new qd});let{params:D,...O}=x||{};if(t_.equ(O,E,Sv)||__(E,{...O}),t_.equ(D,E.params,Sv)||__(E,{params:{...E.params,...D}}),!w.camera||w.camera===c&&!t_.equ(c,S,Sv)){c=S;let e=S?.isCamera,t=e?S:_?new Nu(0,0,0,0,.1,1e3):new Ou(75,0,.1,1e3);e||(t.position.z=5,S&&(__(t,S),t.manual||(`aspect`in S||`left`in S||`right`in S||`bottom`in S||`top`in S)&&(t.manual=!0,t.updateProjectionMatrix())),!w.camera&&!(S!=null&&S.rotation)&&t.lookAt(0,0,0)),w.set({camera:t}),E.camera=t}if(!w.scene){let e;o!=null&&o.isScene?(e=o,o_(e,a,``,{})):(e=new Vr,o_(e,a,``,{}),o&&__(e,o)),w.set({scene:e})}d&&!w.events.handlers&&w.set({events:d(a)});let k=Cv(e,i);if(t_.equ(k,w.size,Sv)||w.setSize(k.width,k.height,k.top,k.left),y&&w.viewport.dpr!==$g(y)&&w.setDpr(y),w.frameloop!==v&&w.setFrameloop(v),w.onPointerMissed||w.set({onPointerMissed:C}),b&&!t_.equ(b,w.performance,Sv)&&w.set(e=>({performance:{...e.performance,...b}})),!w.xr){let e=(e,t)=>{let n=a.getState();n.frameloop!==`never`&&Wv(e,!0,n,t)},t=()=>{let t=a.getState();t.gl.xr.enabled=t.gl.xr.isPresenting,t.gl.xr.setAnimationLoop(t.gl.xr.isPresenting?e:null),t.gl.xr.isPresenting||Uv(t)},n={connect(){let e=a.getState().gl;e.xr.addEventListener(`sessionstart`,t),e.xr.addEventListener(`sessionend`,t)},disconnect(){let e=a.getState().gl;e.xr.removeEventListener(`sessionstart`,t),e.xr.removeEventListener(`sessionend`,t)}};typeof T.xr?.addEventListener==`function`&&n.connect(),w.set({xr:n})}if(T.shadowMap){let e=T.shadowMap.enabled,t=T.shadowMap.type;if(T.shadowMap.enabled=!!p,t_.boo(p))T.shadowMap.type=2;else if(t_.str(p)){let e={basic:0,percentage:1,soft:2,variance:3};T.shadowMap.type=e[p]??2}else t_.obj(p)&&Object.assign(T.shadowMap,p);(e!==T.shadowMap.enabled||t!==T.shadowMap.type)&&(T.shadowMap.needsUpdate=!0)}return Bn.enabled=!g,l||(T.outputColorSpace=m?ht:mt,T.toneMapping=h?0:4),w.legacy!==g&&w.set(()=>({legacy:g})),w.linear!==m&&w.set(()=>({linear:m})),w.flat!==h&&w.set(()=>({flat:h})),r&&!t_.fun(r)&&!E_(r)&&!t_.equ(r,T,Sv)&&__(T,r),s=f,l=!0,n(),this},render(t){return!l&&!u&&this.configure(),u.then(()=>{bv.updateContainer((0,Z.jsx)(Tv,{store:a,children:t,onCreated:s,rootElement:e}),o,null,()=>void 0)}),a},unmount(){Ev(e)}}}function Tv({store:e,children:t,onCreated:n,rootElement:r}){return Jg(()=>{let t=e.getState();t.set(e=>({internal:{...e.internal,active:!0}})),n&&n(t),e.getState().events.connected||t.events.connect==null||t.events.connect(r)},[]),(0,Z.jsx)(D_.Provider,{value:e,children:t})}function Ev(e,t){let n=xv.get(e),r=n?.fiber;if(r){let i=n?.store.getState();i&&(i.internal.active=!1),bv.updateContainer(null,r,null,()=>{i&&setTimeout(()=>{try{var n,r,a,o;i.events.disconnect==null||i.events.disconnect(),(n=i.gl)==null||(r=n.renderLists)==null||r.dispose==null||r.dispose(),(a=i.gl)==null||a.forceContextLoss==null||a.forceContextLoss(),(o=i.gl)!=null&&o.xr&&i.xr.disconnect(),r_(i.scene),xv.delete(e),t&&t(e)}catch{}},500)})}}function Dv(e,t,n){return(0,Z.jsx)(Ov,{children:e,container:t,state:n})}function Ov({state:e={},children:t,container:n}){let{events:r,size:i,...a}=e,o=k_(),[s]=v.useState(()=>new qd),[c]=v.useState(()=>new K),l=Yg((e,t)=>{let a;if(t.camera&&i){let n=t.camera;a=e.viewport.getCurrentViewport(n,new q,i),n!==e.camera&&y_(n,i)}return{...e,...t,scene:n,raycaster:s,pointer:c,mouse:c,previousRoot:o,events:{...e.events,...t.events,...r},size:{...e.size,...i},viewport:{...e.viewport,...a},setEvents:e=>t.set(t=>({...t,events:{...t.events,...e}}))}}),u=v.useMemo(()=>{let e=wg((e,t)=>({...a,set:e,get:t})),t=t=>e.setState(e=>l.current(t,e));return t(o.getState()),o.subscribe(t),e},[o,n]);return(0,Z.jsx)(Z.Fragment,{children:bv.createPortal((0,Z.jsx)(D_.Provider,{value:u,children:t}),u,null)})}var kv=new Set,Av=new Set,jv=new Set;function Mv(e,t){if(e.size)for(let{callback:n}of e.values())n(t)}function Nv(e,t){switch(e){case`before`:return Mv(kv,t);case`after`:return Mv(Av,t);case`tail`:return Mv(jv,t)}}var Pv,Fv;function Iv(e,t,n){let r=t.clock.getDelta();t.frameloop===`never`&&typeof e==`number`&&(r=e-t.clock.elapsedTime,t.clock.oldTime=t.clock.elapsedTime,t.clock.elapsedTime=e),Pv=t.internal.subscribers;for(let e=0;e0)&&!((t=Vv.gl.xr)!=null&&t.isPresenting)&&(zv+=Iv(e,Vv))}if(Rv=!1,Nv(`after`,e),zv===0)return Nv(`tail`,e),Lv=!1,cancelAnimationFrame(Bv)}function Uv(e,t=1){var n;if(!e)return xv.forEach(e=>Uv(e.store.getState(),t));(n=e.gl.xr)!=null&&n.isPresenting||!e.internal.active||e.frameloop===`never`||(t>1?e.internal.frames=Math.min(60,e.internal.frames+t):Rv?e.internal.frames=2:e.internal.frames=1,Lv||(Lv=!0,requestAnimationFrame(Hv)))}function Wv(e,t=!0,n,r){if(t&&Nv(`before`,e),n)Iv(e,n,r);else for(let t of xv.values())Iv(e,t.store.getState());t&&Nv(`after`,e)}var Gv={onClick:[`click`,!1],onContextMenu:[`contextmenu`,!1],onDoubleClick:[`dblclick`,!1],onWheel:[`wheel`,!0],onPointerDown:[`pointerdown`,!0],onPointerUp:[`pointerup`,!0],onPointerLeave:[`pointerleave`,!0],onPointerMove:[`pointermove`,!0],onPointerCancel:[`pointercancel`,!0],onLostPointerCapture:[`lostpointercapture`,!0]};function Kv(e){let{handlePointer:t}=T_(e);return{priority:1,enabled:!0,compute(e,t,n){t.pointer.set(e.offsetX/t.size.width*2-1,-(e.offsetY/t.size.height)*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)},connected:void 0,handlers:Object.keys(Gv).reduce((e,n)=>({...e,[n]:t(n)}),{}),update:()=>{var t;let{events:n,internal:r}=e.getState();(t=r.lastEvent)!=null&&t.current&&n.handlers&&n.handlers.onPointerMove(r.lastEvent.current)},connect:t=>{let{set:n,events:r}=e.getState();if(r.disconnect==null||r.disconnect(),n(e=>({events:{...e.events,connected:t}})),r.handlers)for(let e in r.handlers){let n=r.handlers[e],[i,a]=Gv[e];t.addEventListener(i,n,{passive:a})}},disconnect:()=>{let{set:t,events:n}=e.getState();if(n.connected){if(n.handlers)for(let e in n.handlers){let t=n.handlers[e],[r]=Gv[e];n.connected.removeEventListener(r,t)}t(e=>({events:{...e.events,connected:void 0}}))}}}}function qv(e,t){let n;return(...r)=>{window.clearTimeout(n),n=window.setTimeout(()=>e(...r),t)}}function Jv({debounce:e,scroll:t,polyfill:n,offsetSize:r}={debounce:0,scroll:!1,offsetSize:!1}){let i=n||(typeof window>`u`?class{}:window.ResizeObserver);if(!i)throw Error(`This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills`);let[a,o]=(0,v.useState)({left:0,top:0,width:0,height:0,bottom:0,right:0,x:0,y:0}),s=(0,v.useRef)({element:null,scrollContainers:null,resizeObserver:null,lastBounds:a,orientationHandler:null}),c=e?typeof e==`number`?e:e.scroll:null,l=e?typeof e==`number`?e:e.resize:null,u=(0,v.useRef)(!1);(0,v.useEffect)(()=>(u.current=!0,()=>void(u.current=!1)));let[d,f,p]=(0,v.useMemo)(()=>{let e=()=>{if(!s.current.element)return;let{left:e,top:t,width:n,height:i,bottom:a,right:c,x:l,y:d}=s.current.element.getBoundingClientRect(),f={left:e,top:t,width:n,height:i,bottom:a,right:c,x:l,y:d};s.current.element instanceof HTMLElement&&r&&(f.height=s.current.element.offsetHeight,f.width=s.current.element.offsetWidth),Object.freeze(f),u.current&&!$v(s.current.lastBounds,f)&&o(s.current.lastBounds=f)};return[e,l?qv(e,l):e,c?qv(e,c):e]},[o,r,c,l]);function m(){s.current.scrollContainers&&(s.current.scrollContainers.forEach(e=>e.removeEventListener(`scroll`,p,!0)),s.current.scrollContainers=null),s.current.resizeObserver&&(s.current.resizeObserver.disconnect(),s.current.resizeObserver=null),s.current.orientationHandler&&(`orientation`in screen&&`removeEventListener`in screen.orientation?screen.orientation.removeEventListener(`change`,s.current.orientationHandler):`onorientationchange`in window&&window.removeEventListener(`orientationchange`,s.current.orientationHandler))}function h(){s.current.element&&(s.current.resizeObserver=new i(p),s.current.resizeObserver.observe(s.current.element),t&&s.current.scrollContainers&&s.current.scrollContainers.forEach(e=>e.addEventListener(`scroll`,p,{capture:!0,passive:!0})),s.current.orientationHandler=()=>{p()},`orientation`in screen&&`addEventListener`in screen.orientation?screen.orientation.addEventListener(`change`,s.current.orientationHandler):`onorientationchange`in window&&window.addEventListener(`orientationchange`,s.current.orientationHandler))}return Xv(p,!!t),Yv(f),(0,v.useEffect)(()=>{m(),h()},[t,p,f]),(0,v.useEffect)(()=>m,[]),[e=>{!e||e===s.current.element||(m(),s.current.element=e,s.current.scrollContainers=Zv(e),h())},a,d]}function Yv(e){(0,v.useEffect)(()=>{let t=e;return window.addEventListener(`resize`,t),()=>void window.removeEventListener(`resize`,t)},[e])}function Xv(e,t){(0,v.useEffect)(()=>{if(t){let t=e;return window.addEventListener(`scroll`,t,{capture:!0,passive:!0}),()=>void window.removeEventListener(`scroll`,t,!0)}},[e,t])}function Zv(e){let t=[];if(!e||e===document.body)return t;let{overflow:n,overflowX:r,overflowY:i}=window.getComputedStyle(e);return[n,r,i].some(e=>e===`auto`||e===`scroll`)&&t.push(e),[...t,...Zv(e.parentElement)]}var Qv=[`x`,`y`,`top`,`bottom`,`left`,`right`,`width`,`height`],$v=(e,t)=>Qv.every(n=>e[n]===t[n]);function ey({ref:e,children:t,fallback:n,resize:r,style:i,gl:a,events:o=Kv,eventSource:s,eventPrefix:c,shadows:l,linear:u,flat:d,legacy:f,orthographic:p,frameloop:m,dpr:h,performance:g,raycaster:_,camera:y,scene:b,onPointerMissed:x,onCreated:S,...C}){v.useMemo(()=>nv(Xf),[]);let w=Xg(),[T,E]=Jv({scroll:!0,debounce:{scroll:50,resize:0},...r}),D=v.useRef(null),O=v.useRef(null);v.useImperativeHandle(e,()=>D.current);let k=Yg(x),[A,j]=v.useState(!1),[M,N]=v.useState(!1);if(A)throw A;if(M)throw M;let P=v.useRef(null);return Jg(()=>{let e=D.current;if(E.width>0&&E.height>0&&e){P.current||=wv(e);async function n(){await P.current.configure({gl:a,scene:b,events:o,shadows:l,linear:u,flat:d,legacy:f,orthographic:p,frameloop:m,dpr:h,performance:g,raycaster:_,camera:y,size:E,onPointerMissed:(...e)=>k.current==null?void 0:k.current(...e),onCreated:e=>{e.events.connect==null||e.events.connect(s?Kg(s)?s.current:s:O.current),c&&e.setEvents({compute:(e,t)=>{let n=e[c+`X`],r=e[c+`Y`];t.pointer.set(n/t.size.width*2-1,-(r/t.size.height)*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)}}),S?.(e)}}),P.current.render((0,Z.jsx)(w,{children:(0,Z.jsx)(Qg,{set:N,children:(0,Z.jsx)(v.Suspense,{fallback:(0,Z.jsx)(Zg,{set:j}),children:t??null})})}))}n()}}),v.useEffect(()=>{let e=D.current;if(e)return()=>Ev(e)},[]),(0,Z.jsx)(`div`,{ref:O,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,pointerEvents:s?`none`:`auto`,...i},...C,children:(0,Z.jsx)(`div`,{ref:T,style:{width:`100%`,height:`100%`},children:(0,Z.jsx)(`canvas`,{ref:D,style:{display:`block`},children:n})})})}function ty(e){return(0,Z.jsx)(Rg,{children:(0,Z.jsx)(ey,{...e})})}function ny(){return ny=Object.assign?Object.assign.bind():function(e){for(var t=1;tMath.PI/2}function ly(e,t,n,r){let i=ry.setFromMatrixPosition(e.matrixWorld),a=i.clone();a.project(t),oy.set(a.x,a.y),n.setFromCamera(oy,t);let o=n.intersectObjects(r,!0);if(o.length){let e=o[0].distance;return i.distanceTo(n.ray.origin)Math.abs(e)<1e-10?0:e;function py(e,t,n=``){let r=`matrix3d(`;for(let n=0;n!==16;n++)r+=fy(t[n]*e.elements[n])+(n===15?`)`:`,`);return n+r}var my=(e=>t=>py(t,e))([1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1]),hy=(e=>(t,n)=>py(t,e(n),`translate(-50%,-50%)`))(e=>[1/e,1/e,1/e,1,-1/e,-1/e,-1/e,-1,1/e,1/e,1/e,1,1,1,1,1]);function gy(e){return e&&typeof e==`object`&&`current`in e}var _y=v.forwardRef(({children:e,eps:t=.001,style:n,className:r,prepend:i,center:a,fullscreen:o,portal:s,distanceFactor:c,sprite:l=!1,transform:u=!1,occlude:d,onOcclude:f,castShadow:p,receiveShadow:m,material:h,geometry:g,zIndexRange:_=[16777271,0],calculatePosition:b=sy,as:x=`div`,wrapperClass:S,pointerEvents:C=`auto`,...w},T)=>{let{gl:E,camera:D,scene:O,size:k,raycaster:A,events:j,viewport:M}=A_(),[N]=v.useState(()=>document.createElement(x)),P=v.useRef(null),F=v.useRef(null),I=v.useRef(0),L=v.useRef([0,0]),ee=v.useRef(null),R=v.useRef(null),te=s?.current||j.connected||E.domElement.parentNode,z=v.useRef(null),B=v.useRef(!1),V=v.useMemo(()=>d&&d!==`blending`||Array.isArray(d)&&d.length&&gy(d[0]),[d]);v.useLayoutEffect(()=>{let e=E.domElement;d&&d===`blending`?(e.style.zIndex=`${Math.floor(_[0]/2)}`,e.style.position=`absolute`,e.style.pointerEvents=`none`):(e.style.zIndex=null,e.style.position=null,e.style.pointerEvents=null)},[d]),v.useLayoutEffect(()=>{if(F.current){let e=P.current=y.createRoot(N);if(O.updateMatrixWorld(),u)N.style.cssText=`position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;`;else{let e=b(F.current,D,k);N.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${e[0]}px,${e[1]}px,0);transform-origin:0 0;`}return te&&(i?te.prepend(N):te.appendChild(N)),()=>{te&&te.removeChild(N),e.unmount()}}},[te,u]),v.useLayoutEffect(()=>{S&&(N.className=S)},[S]);let ne=v.useMemo(()=>u?{position:`absolute`,top:0,left:0,width:k.width,height:k.height,transformStyle:`preserve-3d`,pointerEvents:`none`}:{position:`absolute`,transform:a?`translate3d(-50%,-50%,0)`:`none`,...o&&{top:-k.height/2,left:-k.width/2,width:k.width,height:k.height},...n},[n,a,o,k,u]),re=v.useMemo(()=>({position:`absolute`,pointerEvents:C}),[C]);v.useLayoutEffect(()=>{if(B.current=!1,u){var t;(t=P.current)==null||t.render(v.createElement(`div`,{ref:ee,style:ne},v.createElement(`div`,{ref:R,style:re},v.createElement(`div`,{ref:T,className:r,style:n,children:e}))))}else{var i;(i=P.current)==null||i.render(v.createElement(`div`,{ref:T,style:ne,className:r,children:e}))}});let ie=v.useRef(!0);j_(e=>{if(F.current){D.updateMatrixWorld(),F.current.updateWorldMatrix(!0,!1);let e=u?L.current:b(F.current,D,k);if(u||Math.abs(I.current-D.zoom)>t||Math.abs(L.current[0]-e[0])>t||Math.abs(L.current[1]-e[1])>t){let t=cy(F.current,D),n=!1;V&&(Array.isArray(d)?n=d.map(e=>e.current):d!==`blending`&&(n=[O]));let r=ie.current;n?ie.current=ly(F.current,D,A,n)&&!t:ie.current=!t,r!==ie.current&&(f?f(!ie.current):N.style.display=ie.current?`block`:`none`);let i=Math.floor(_[0]/2),a=d?V?[_[0],i]:[i-1,0]:_;if(N.style.zIndex=`${dy(F.current,D,a)}`,u){let[e,t]=[k.width/2,k.height/2],n=D.projectionMatrix.elements[5]*t,{isOrthographicCamera:r,top:i,left:a,bottom:o,right:s}=D,u=my(D.matrixWorldInverse),d=r?`scale(${n})translate(${fy(-(s+a)/2)}px,${fy((i+o)/2)}px)`:`translateZ(${n}px)`,f=F.current.matrixWorld;l&&(f=D.matrixWorldInverse.clone().transpose().copyPosition(f).scale(F.current.scale),f.elements[3]=f.elements[7]=f.elements[11]=0,f.elements[15]=1),N.style.width=k.width+`px`,N.style.height=k.height+`px`,N.style.perspective=r?``:`${n}px`,ee.current&&R.current&&(ee.current.style.transform=`${d}${u}translate(${e}px,${t}px)`,R.current.style.transform=hy(f,1/((c||10)/400)))}else{let t=c===void 0?1:uy(F.current,D)*c;N.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}L.current=e,I.current=D.zoom}}if(!V&&z.current&&!B.current)if(u){if(ee.current){let e=ee.current.children[0];if(e!=null&&e.clientWidth&&e!=null&&e.clientHeight){let{isOrthographicCamera:t}=D;if(t||g)w.scale&&(Array.isArray(w.scale)?w.scale instanceof q?z.current.scale.copy(w.scale.clone().divideScalar(1)):z.current.scale.set(1/w.scale[0],1/w.scale[1],1/w.scale[2]):z.current.scale.setScalar(1/w.scale));else{let t=(c||10)/400,n=e.clientWidth*t,r=e.clientHeight*t;z.current.scale.set(n,r,1)}B.current=!0}}}else{let t=N.children[0];if(t!=null&&t.clientWidth&&t!=null&&t.clientHeight){let e=1/M.factor,n=t.clientWidth*e,r=t.clientHeight*e;z.current.scale.set(n,r,1),B.current=!0}z.current.lookAt(e.camera.position)}});let ae=v.useMemo(()=>({vertexShader:u?void 0:` /* This shader is from the THREE's SpriteMaterial. We need to turn the backing plane into a Sprite (make it always face the camera) if "transfrom" is false. */ #include void main() { vec2 center = vec2(0., 1.); float rotation = 0.0; // This is somewhat arbitrary, but it seems to work well // Need to figure out how to derive this dynamically if it even matters float size = 0.03; vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); vec2 scale; scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) ); scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) ); bool isPerspective = isPerspectiveMatrix( projectionMatrix ); if ( isPerspective ) scale *= - mvPosition.z; vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size; vec2 rotatedPosition; rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; mvPosition.xy += rotatedPosition; gl_Position = projectionMatrix * mvPosition; } `,fragmentShader:` void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } `}),[u]);return v.createElement(`group`,ny({},w,{ref:F}),d&&!V&&v.createElement(`mesh`,{castShadow:p,receiveShadow:m,ref:z},g||v.createElement(`planeGeometry`,null),h||v.createElement(`shaderMaterial`,{side:2,vertexShader:ae.vertexShader,fragmentShader:ae.fragmentShader})))});function vy(e,t=`pointer`,n=`auto`,r=document.body){v.useEffect(()=>{if(e)return r.style.cursor=t,()=>void(r.style.cursor=n)},[e])}var yy=e=>e;function by(e,t=yy){let n=v.useSyncExternalStore(e.subscribe,v.useCallback(()=>t(e.getState()),[e,t]),v.useCallback(()=>t(e.getInitialState()),[e,t]));return v.useDebugValue(n),n}var xy=e=>{let t=yg(e),n=e=>by(t,e);return Object.assign(n,t),n},Sy=(e=>e?xy(e):xy),Cy=parseInt(`184`.replace(/\D+/g,``)),wy=Cy>=125?`uv1`:`uv2`,Ty=Object.defineProperty,Ey=(e,t,n)=>t in e?Ty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dy=(e,t,n)=>(Ey(e,typeof t==`symbol`?t:t+``,n),n),Oy=class{constructor(){Dy(this,`_listeners`)}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){if(this._listeners===void 0)return!1;let n=this._listeners;return n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;let n=this._listeners[e];if(n!==void 0){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}dispatchEvent(e){if(this._listeners===void 0)return;let t=this._listeners[e.type];if(t!==void 0){e.target=this;let n=t.slice(0);for(let t=0,r=n.length;tt in e?ky(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jy=(e,t,n)=>(Ay(e,typeof t==`symbol`?t:t+``,n),n),My=new wa,Ny=new mo,Py=Math.cos(Math.PI/180*70),Fy=(e,t)=>(e%t+t)%t,Iy=class extends Oy{constructor(e,t){super(),jy(this,`object`),jy(this,`domElement`),jy(this,`enabled`,!0),jy(this,`target`,new q),jy(this,`minDistance`,0),jy(this,`maxDistance`,1/0),jy(this,`minZoom`,0),jy(this,`maxZoom`,1/0),jy(this,`minPolarAngle`,0),jy(this,`maxPolarAngle`,Math.PI),jy(this,`minAzimuthAngle`,-1/0),jy(this,`maxAzimuthAngle`,1/0),jy(this,`enableDamping`,!1),jy(this,`dampingFactor`,.05),jy(this,`enableZoom`,!0),jy(this,`zoomSpeed`,1),jy(this,`enableRotate`,!0),jy(this,`rotateSpeed`,1),jy(this,`enablePan`,!0),jy(this,`panSpeed`,1),jy(this,`screenSpacePanning`,!0),jy(this,`keyPanSpeed`,7),jy(this,`zoomToCursor`,!1),jy(this,`autoRotate`,!1),jy(this,`autoRotateSpeed`,2),jy(this,`reverseOrbit`,!1),jy(this,`reverseHorizontalOrbit`,!1),jy(this,`reverseVerticalOrbit`,!1),jy(this,`keys`,{LEFT:`ArrowLeft`,UP:`ArrowUp`,RIGHT:`ArrowRight`,BOTTOM:`ArrowDown`}),jy(this,`mouseButtons`,{LEFT:b.ROTATE,MIDDLE:b.DOLLY,RIGHT:b.PAN}),jy(this,`touches`,{ONE:x.ROTATE,TWO:x.DOLLY_PAN}),jy(this,`target0`),jy(this,`position0`),jy(this,`zoom0`),jy(this,`_domElementKeyEvents`,null),jy(this,`getPolarAngle`),jy(this,`getAzimuthalAngle`),jy(this,`setPolarAngle`),jy(this,`setAzimuthalAngle`),jy(this,`getDistance`),jy(this,`getZoomScale`),jy(this,`listenToKeyEvents`),jy(this,`stopListenToKeyEvents`),jy(this,`saveState`),jy(this,`reset`),jy(this,`update`),jy(this,`connect`),jy(this,`dispose`),jy(this,`dollyIn`),jy(this,`dollyOut`),jy(this,`getScale`),jy(this,`setScale`),this.object=e,this.domElement=t,this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.getPolarAngle=()=>l.phi,this.getAzimuthalAngle=()=>l.theta,this.setPolarAngle=e=>{let t=Fy(e,2*Math.PI),r=l.phi;r<0&&(r+=2*Math.PI),t<0&&(t+=2*Math.PI);let i=Math.abs(t-r);2*Math.PI-i{let t=Fy(e,2*Math.PI),r=l.theta;r<0&&(r+=2*Math.PI),t<0&&(t+=2*Math.PI);let i=Math.abs(t-r);2*Math.PI-in.object.position.distanceTo(n.target),this.listenToKeyEvents=e=>{e.addEventListener(`keydown`,Se),this._domElementKeyEvents=e},this.stopListenToKeyEvents=()=>{this._domElementKeyEvents.removeEventListener(`keydown`,Se),this._domElementKeyEvents=null},this.saveState=()=>{n.target0.copy(n.target),n.position0.copy(n.object.position),n.zoom0=n.object.zoom},this.reset=()=>{n.target.copy(n.target0),n.object.position.copy(n.position0),n.object.zoom=n.zoom0,n.object.updateProjectionMatrix(),n.dispatchEvent(r),n.update(),s=o.NONE},this.update=(()=>{let t=new q,i=new q(0,1,0),a=new Mn().setFromUnitVectors(e.up,i),p=a.clone().invert(),m=new q,h=new Mn,g=2*Math.PI;return function(){let _=n.object.position;a.setFromUnitVectors(e.up,i),p.copy(a).invert(),t.copy(_).sub(n.target),t.applyQuaternion(a),l.setFromVector3(t),n.autoRotate&&s===o.NONE&&j(k()),n.enableDamping?(l.theta+=u.theta*n.dampingFactor,l.phi+=u.phi*n.dampingFactor):(l.theta+=u.theta,l.phi+=u.phi);let v=n.minAzimuthAngle,y=n.maxAzimuthAngle;isFinite(v)&&isFinite(y)&&(v<-Math.PI?v+=g:v>Math.PI&&(v-=g),y<-Math.PI?y+=g:y>Math.PI&&(y-=g),v<=y?l.theta=Math.max(v,Math.min(y,l.theta)):l.theta=l.theta>(v+y)/2?Math.max(v,l.theta):Math.min(y,l.theta)),l.phi=Math.max(n.minPolarAngle,Math.min(n.maxPolarAngle,l.phi)),l.makeSafe(),n.enableDamping===!0?n.target.addScaledVector(f,n.dampingFactor):n.target.add(f),n.zoomToCursor&&E||n.object.isOrthographicCamera?l.radius=te(l.radius):l.radius=te(l.radius*d),t.setFromSpherical(l),t.applyQuaternion(p),_.copy(n.target).add(t),n.object.matrixAutoUpdate||n.object.updateMatrix(),n.object.lookAt(n.target),n.enableDamping===!0?(u.theta*=1-n.dampingFactor,u.phi*=1-n.dampingFactor,f.multiplyScalar(1-n.dampingFactor)):(u.set(0,0,0),f.set(0,0,0));let b=!1;if(n.zoomToCursor&&E){let r=null;if(n.object instanceof Ou&&n.object.isPerspectiveCamera){let e=t.length();r=te(e*d);let i=e-r;n.object.position.addScaledVector(w,i),n.object.updateMatrixWorld()}else if(n.object.isOrthographicCamera){let e=new q(T.x,T.y,0);e.unproject(n.object),n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/d)),n.object.updateProjectionMatrix(),b=!0;let i=new q(T.x,T.y,0);i.unproject(n.object),n.object.position.sub(i).add(e),n.object.updateMatrixWorld(),r=t.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),n.zoomToCursor=!1;r!==null&&(n.screenSpacePanning?n.target.set(0,0,-1).transformDirection(n.object.matrix).multiplyScalar(r).add(n.object.position):(My.origin.copy(n.object.position),My.direction.set(0,0,-1).transformDirection(n.object.matrix),Math.abs(n.object.up.dot(My.direction))c||8*(1-h.dot(n.object.quaternion))>c?(n.dispatchEvent(r),m.copy(n.object.position),h.copy(n.object.quaternion),b=!1,!0):!1}})(),this.connect=e=>{n.domElement=e,n.domElement.style.touchAction=`none`,n.domElement.addEventListener(`contextmenu`,we),n.domElement.addEventListener(`pointerdown`,ge),n.domElement.addEventListener(`pointercancel`,ve),n.domElement.addEventListener(`wheel`,xe)},this.dispose=()=>{var e,t,r,i,a,o;n.domElement&&(n.domElement.style.touchAction=`auto`),(e=n.domElement)==null||e.removeEventListener(`contextmenu`,we),(t=n.domElement)==null||t.removeEventListener(`pointerdown`,ge),(r=n.domElement)==null||r.removeEventListener(`pointercancel`,ve),(i=n.domElement)==null||i.removeEventListener(`wheel`,xe),(a=n.domElement)==null||a.ownerDocument.removeEventListener(`pointermove`,_e),(o=n.domElement)==null||o.ownerDocument.removeEventListener(`pointerup`,ve),n._domElementKeyEvents!==null&&n._domElementKeyEvents.removeEventListener(`keydown`,Se)};let n=this,r={type:`change`},i={type:`start`},a={type:`end`},o={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},s=o.NONE,c=1e-6,l=new Zd,u=new Zd,d=1,f=new q,p=new K,m=new K,h=new K,g=new K,_=new K,v=new K,y=new K,S=new K,C=new K,w=new q,T=new K,E=!1,D=[],O={};function k(){return 2*Math.PI/60/60*n.autoRotateSpeed}function A(){return .95**n.zoomSpeed}function j(e){n.reverseOrbit||n.reverseHorizontalOrbit?u.theta+=e:u.theta-=e}function M(e){n.reverseOrbit||n.reverseVerticalOrbit?u.phi+=e:u.phi-=e}let N=(()=>{let e=new q;return function(t,n){e.setFromMatrixColumn(n,0),e.multiplyScalar(-t),f.add(e)}})(),P=(()=>{let e=new q;return function(t,r){n.screenSpacePanning===!0?e.setFromMatrixColumn(r,1):(e.setFromMatrixColumn(r,0),e.crossVectors(n.object.up,e)),e.multiplyScalar(t),f.add(e)}})(),F=(()=>{let e=new q;return function(t,r){let i=n.domElement;if(i&&n.object instanceof Ou&&n.object.isPerspectiveCamera){let a=n.object.position;e.copy(a).sub(n.target);let o=e.length();o*=Math.tan(n.object.fov/2*Math.PI/180),N(2*t*o/i.clientHeight,n.object.matrix),P(2*r*o/i.clientHeight,n.object.matrix)}else i&&n.object instanceof Nu&&n.object.isOrthographicCamera?(N(t*(n.object.right-n.object.left)/n.object.zoom/i.clientWidth,n.object.matrix),P(r*(n.object.top-n.object.bottom)/n.object.zoom/i.clientHeight,n.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),n.enablePan=!1)}})();function I(e){n.object instanceof Ou&&n.object.isPerspectiveCamera||n.object instanceof Nu&&n.object.isOrthographicCamera?d=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),n.enableZoom=!1)}function L(e){I(d/e)}function ee(e){I(d*e)}function R(e){if(!n.zoomToCursor||!n.domElement)return;E=!0;let t=n.domElement.getBoundingClientRect(),r=e.clientX-t.left,i=e.clientY-t.top,a=t.width,o=t.height;T.x=r/a*2-1,T.y=-(i/o)*2+1,w.set(T.x,T.y,1).unproject(n.object).sub(n.object.position).normalize()}function te(e){return Math.max(n.minDistance,Math.min(n.maxDistance,e))}function z(e){p.set(e.clientX,e.clientY)}function B(e){R(e),y.set(e.clientX,e.clientY)}function V(e){g.set(e.clientX,e.clientY)}function ne(e){m.set(e.clientX,e.clientY),h.subVectors(m,p).multiplyScalar(n.rotateSpeed);let t=n.domElement;t&&(j(2*Math.PI*h.x/t.clientHeight),M(2*Math.PI*h.y/t.clientHeight)),p.copy(m),n.update()}function re(e){S.set(e.clientX,e.clientY),C.subVectors(S,y),C.y>0?L(A()):C.y<0&&ee(A()),y.copy(S),n.update()}function ie(e){_.set(e.clientX,e.clientY),v.subVectors(_,g).multiplyScalar(n.panSpeed),F(v.x,v.y),g.copy(_),n.update()}function ae(e){R(e),e.deltaY<0?ee(A()):e.deltaY>0&&L(A()),n.update()}function oe(e){let t=!1;switch(e.code){case n.keys.UP:F(0,n.keyPanSpeed),t=!0;break;case n.keys.BOTTOM:F(0,-n.keyPanSpeed),t=!0;break;case n.keys.LEFT:F(n.keyPanSpeed,0),t=!0;break;case n.keys.RIGHT:F(-n.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),n.update())}function se(){if(D.length==1)p.set(D[0].pageX,D[0].pageY);else{let e=.5*(D[0].pageX+D[1].pageX),t=.5*(D[0].pageY+D[1].pageY);p.set(e,t)}}function ce(){if(D.length==1)g.set(D[0].pageX,D[0].pageY);else{let e=.5*(D[0].pageX+D[1].pageX),t=.5*(D[0].pageY+D[1].pageY);g.set(e,t)}}function H(){let e=D[0].pageX-D[1].pageX,t=D[0].pageY-D[1].pageY,n=Math.sqrt(e*e+t*t);y.set(0,n)}function le(){n.enableZoom&&H(),n.enablePan&&ce()}function ue(){n.enableZoom&&H(),n.enableRotate&&se()}function de(e){if(D.length==1)m.set(e.pageX,e.pageY);else{let t=De(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);m.set(n,r)}h.subVectors(m,p).multiplyScalar(n.rotateSpeed);let t=n.domElement;t&&(j(2*Math.PI*h.x/t.clientHeight),M(2*Math.PI*h.y/t.clientHeight)),p.copy(m)}function fe(e){if(D.length==1)_.set(e.pageX,e.pageY);else{let t=De(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);_.set(n,r)}v.subVectors(_,g).multiplyScalar(n.panSpeed),F(v.x,v.y),g.copy(_)}function pe(e){let t=De(e),r=e.pageX-t.x,i=e.pageY-t.y,a=Math.sqrt(r*r+i*i);S.set(0,a),C.set(0,(S.y/y.y)**+n.zoomSpeed),L(C.y),y.copy(S)}function me(e){n.enableZoom&&pe(e),n.enablePan&&fe(e)}function he(e){n.enableZoom&&pe(e),n.enableRotate&&de(e)}function ge(e){var t,r;n.enabled!==!1&&(D.length===0&&((t=n.domElement)==null||t.ownerDocument.addEventListener(`pointermove`,_e),(r=n.domElement)==null||r.ownerDocument.addEventListener(`pointerup`,ve)),Te(e),e.pointerType===`touch`?U(e):ye(e))}function _e(e){n.enabled!==!1&&(e.pointerType===`touch`?Ce(e):be(e))}function ve(e){var t,r,i;W(e),D.length===0&&((t=n.domElement)==null||t.releasePointerCapture(e.pointerId),(r=n.domElement)==null||r.ownerDocument.removeEventListener(`pointermove`,_e),(i=n.domElement)==null||i.ownerDocument.removeEventListener(`pointerup`,ve)),n.dispatchEvent(a),s=o.NONE}function ye(e){let t;switch(e.button){case 0:t=n.mouseButtons.LEFT;break;case 1:t=n.mouseButtons.MIDDLE;break;case 2:t=n.mouseButtons.RIGHT;break;default:t=-1}switch(t){case b.DOLLY:if(n.enableZoom===!1)return;B(e),s=o.DOLLY;break;case b.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(n.enablePan===!1)return;V(e),s=o.PAN}else{if(n.enableRotate===!1)return;z(e),s=o.ROTATE}break;case b.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(n.enableRotate===!1)return;z(e),s=o.ROTATE}else{if(n.enablePan===!1)return;V(e),s=o.PAN}break;default:s=o.NONE}s!==o.NONE&&n.dispatchEvent(i)}function be(e){if(n.enabled!==!1)switch(s){case o.ROTATE:if(n.enableRotate===!1)return;ne(e);break;case o.DOLLY:if(n.enableZoom===!1)return;re(e);break;case o.PAN:if(n.enablePan===!1)return;ie(e);break}}function xe(e){n.enabled===!1||n.enableZoom===!1||s!==o.NONE&&s!==o.ROTATE||(e.preventDefault(),n.dispatchEvent(i),ae(e),n.dispatchEvent(a))}function Se(e){n.enabled===!1||n.enablePan===!1||oe(e)}function U(e){switch(Ee(e),D.length){case 1:switch(n.touches.ONE){case x.ROTATE:if(n.enableRotate===!1)return;se(),s=o.TOUCH_ROTATE;break;case x.PAN:if(n.enablePan===!1)return;ce(),s=o.TOUCH_PAN;break;default:s=o.NONE}break;case 2:switch(n.touches.TWO){case x.DOLLY_PAN:if(n.enableZoom===!1&&n.enablePan===!1)return;le(),s=o.TOUCH_DOLLY_PAN;break;case x.DOLLY_ROTATE:if(n.enableZoom===!1&&n.enableRotate===!1)return;ue(),s=o.TOUCH_DOLLY_ROTATE;break;default:s=o.NONE}break;default:s=o.NONE}s!==o.NONE&&n.dispatchEvent(i)}function Ce(e){switch(Ee(e),s){case o.TOUCH_ROTATE:if(n.enableRotate===!1)return;de(e),n.update();break;case o.TOUCH_PAN:if(n.enablePan===!1)return;fe(e),n.update();break;case o.TOUCH_DOLLY_PAN:if(n.enableZoom===!1&&n.enablePan===!1)return;me(e),n.update();break;case o.TOUCH_DOLLY_ROTATE:if(n.enableZoom===!1&&n.enableRotate===!1)return;he(e),n.update();break;default:s=o.NONE}}function we(e){n.enabled!==!1&&e.preventDefault()}function Te(e){D.push(e)}function W(e){delete O[e.pointerId];for(let t=0;t{ee(e),n.update()},this.dollyOut=(e=A())=>{L(e),n.update()},this.getScale=()=>d,this.setScale=e=>{I(e),n.update()},this.getZoomScale=()=>A(),t!==void 0&&this.connect(t),this.update()}},Ly=new ni,Ry=new q,zy=class extends Hu{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type=`LineSegmentsGeometry`,this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute(`position`,new Pi([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute(`uv`,new Pi([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(e){let t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));let n=new Wd(t,6,1);return this.setAttribute(`instanceStart`,new Yi(n,3,0)),this.setAttribute(`instanceEnd`,new Yi(n,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e,t=3){let n;e instanceof Float32Array?n=e:Array.isArray(e)&&(n=new Float32Array(e));let r=new Wd(n,t*2,1);return this.setAttribute(`instanceColorStart`,new Yi(r,t,0)),this.setAttribute(`instanceColorEnd`,new Yi(r,t,t)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new sl(e.geometry)),this}fromLineSegments(e){let t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ni);let e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Ly.setFromBufferAttribute(t),this.boundingBox.union(Ly))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Ri),this.boundingBox===null&&this.computeBoundingBox();let e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){let n=this.boundingSphere.center;this.boundingBox.getCenter(n);let r=0;for(let i=0,a=e.count;i #include #include #include uniform float linewidth; uniform vec2 resolution; attribute vec3 instanceStart; attribute vec3 instanceEnd; #ifdef USE_COLOR #ifdef USE_LINE_COLOR_ALPHA varying vec4 vLineColor; attribute vec4 instanceColorStart; attribute vec4 instanceColorEnd; #else varying vec3 vLineColor; attribute vec3 instanceColorStart; attribute vec3 instanceColorEnd; #endif #endif #ifdef WORLD_UNITS varying vec4 worldPos; varying vec3 worldStart; varying vec3 worldEnd; #ifdef USE_DASH varying vec2 vUv; #endif #else varying vec2 vUv; #endif #ifdef USE_DASH uniform float dashScale; attribute float instanceDistanceStart; attribute float instanceDistanceEnd; varying float vLineDistance; #endif void trimSegment( const in vec4 start, inout vec4 end ) { // trim end segment so it terminates between the camera plane and the near plane // conservative estimate of the near plane float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column float nearEstimate = - 0.5 * b / a; float alpha = ( nearEstimate - start.z ) / ( end.z - start.z ); end.xyz = mix( start.xyz, end.xyz, alpha ); } void main() { #ifdef USE_COLOR vLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd; #endif #ifdef USE_DASH vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd; vUv = uv; #endif float aspect = resolution.x / resolution.y; // camera space vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 ); vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 ); #ifdef WORLD_UNITS worldStart = start.xyz; worldEnd = end.xyz; #else vUv = uv; #endif // special case for perspective projection, and segments that terminate either in, or behind, the camera plane // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space // but we need to perform ndc-space calculations in the shader, so we must address this issue directly // perhaps there is a more elegant solution -- WestLangley bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column if ( perspective ) { if ( start.z < 0.0 && end.z >= 0.0 ) { trimSegment( start, end ); } else if ( end.z < 0.0 && start.z >= 0.0 ) { trimSegment( end, start ); } } // clip space vec4 clipStart = projectionMatrix * start; vec4 clipEnd = projectionMatrix * end; // ndc space vec3 ndcStart = clipStart.xyz / clipStart.w; vec3 ndcEnd = clipEnd.xyz / clipEnd.w; // direction vec2 dir = ndcEnd.xy - ndcStart.xy; // account for clip-space aspect ratio dir.x *= aspect; dir = normalize( dir ); #ifdef WORLD_UNITS // get the offset direction as perpendicular to the view vector vec3 worldDir = normalize( end.xyz - start.xyz ); vec3 offset; if ( position.y < 0.5 ) { offset = normalize( cross( start.xyz, worldDir ) ); } else { offset = normalize( cross( end.xyz, worldDir ) ); } // sign flip if ( position.x < 0.0 ) offset *= - 1.0; float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) ); // don't extend the line if we're rendering dashes because we // won't be rendering the endcaps #ifndef USE_DASH // extend the line bounds to encompass endcaps start.xyz += - worldDir * linewidth * 0.5; end.xyz += worldDir * linewidth * 0.5; // shift the position of the quad so it hugs the forward edge of the line offset.xy -= dir * forwardOffset; offset.z += 0.5; #endif // endcaps if ( position.y > 1.0 || position.y < 0.0 ) { offset.xy += dir * 2.0 * forwardOffset; } // adjust for linewidth offset *= linewidth * 0.5; // set the world position worldPos = ( position.y < 0.5 ) ? start : end; worldPos.xyz += offset; // project the worldpos vec4 clip = projectionMatrix * worldPos; // shift the depth of the projected points so the line // segments overlap neatly vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd; clip.z = clipPose.z * clip.w; #else vec2 offset = vec2( dir.y, - dir.x ); // undo aspect ratio adjustment dir.x /= aspect; offset.x /= aspect; // sign flip if ( position.x < 0.0 ) offset *= - 1.0; // endcaps if ( position.y < 0.0 ) { offset += - dir; } else if ( position.y > 1.0 ) { offset += dir; } // adjust for linewidth offset *= linewidth; // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ... offset /= resolution.y; // select end vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd; // back to clip space offset *= clip.w; clip.xy += offset; #endif gl_Position = clip; vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation #include #include #include } `,fragmentShader:` uniform vec3 diffuse; uniform float opacity; uniform float linewidth; #ifdef USE_DASH uniform float dashOffset; uniform float dashSize; uniform float gapSize; #endif varying float vLineDistance; #ifdef WORLD_UNITS varying vec4 worldPos; varying vec3 worldStart; varying vec3 worldEnd; #ifdef USE_DASH varying vec2 vUv; #endif #else varying vec2 vUv; #endif #include #include #include #include #ifdef USE_COLOR #ifdef USE_LINE_COLOR_ALPHA varying vec4 vLineColor; #else varying vec3 vLineColor; #endif #endif vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) { float mua; float mub; vec3 p13 = p1 - p3; vec3 p43 = p4 - p3; vec3 p21 = p2 - p1; float d1343 = dot( p13, p43 ); float d4321 = dot( p43, p21 ); float d1321 = dot( p13, p21 ); float d4343 = dot( p43, p43 ); float d2121 = dot( p21, p21 ); float denom = d2121 * d4343 - d4321 * d4321; float numer = d1343 * d4321 - d1321 * d4343; mua = numer / denom; mua = clamp( mua, 0.0, 1.0 ); mub = ( d1343 + d4321 * ( mua ) ) / d4343; mub = clamp( mub, 0.0, 1.0 ); return vec2( mua, mub ); } void main() { #include #ifdef USE_DASH if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX #endif float alpha = opacity; #ifdef WORLD_UNITS // Find the closest points on the view ray and the line segment vec3 rayEnd = normalize( worldPos.xyz ) * 1e5; vec3 lineDir = worldEnd - worldStart; vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd ); vec3 p1 = worldStart + lineDir * params.x; vec3 p2 = rayEnd * params.y; vec3 delta = p1 - p2; float len = length( delta ); float norm = len / linewidth; #ifndef USE_DASH #ifdef USE_ALPHA_TO_COVERAGE float dnorm = fwidth( norm ); alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm ); #else if ( norm > 0.5 ) { discard; } #endif #endif #else #ifdef USE_ALPHA_TO_COVERAGE // artifacts appear on some hardware if a derivative is taken within a conditional float a = vUv.x; float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0; float len2 = a * a + b * b; float dlen = fwidth( len2 ); if ( abs( vUv.y ) > 1.0 ) { alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 ); } #else if ( abs( vUv.y ) > 1.0 ) { float a = vUv.x; float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0; float len2 = a * a + b * b; if ( len2 > 1.0 ) discard; } #endif #endif vec4 diffuseColor = vec4( diffuse, alpha ); #ifdef USE_COLOR #ifdef USE_LINE_COLOR_ALPHA diffuseColor *= vLineColor; #else diffuseColor.rgb *= vLineColor; #endif #endif #include gl_FragColor = diffuseColor; #include #include <${Cy>=154?`colorspace_fragment`:`encodings_fragment`}> #include #include } `,clipping:!0}),this.isLineMaterial=!0,this.onBeforeCompile=function(){this.transparent?this.defines.USE_LINE_COLOR_ALPHA=`1`:delete this.defines.USE_LINE_COLOR_ALPHA},Object.defineProperties(this,{color:{enumerable:!0,get:function(){return this.uniforms.diffuse.value},set:function(e){this.uniforms.diffuse.value=e}},worldUnits:{enumerable:!0,get:function(){return`WORLD_UNITS`in this.defines},set:function(e){e===!0?this.defines.WORLD_UNITS=``:delete this.defines.WORLD_UNITS}},linewidth:{enumerable:!0,get:function(){return this.uniforms.linewidth.value},set:function(e){this.uniforms.linewidth.value=e}},dashed:{enumerable:!0,get:function(){return`USE_DASH`in this.defines},set(e){!!e!=`USE_DASH`in this.defines&&(this.needsUpdate=!0),e===!0?this.defines.USE_DASH=``:delete this.defines.USE_DASH}},dashScale:{enumerable:!0,get:function(){return this.uniforms.dashScale.value},set:function(e){this.uniforms.dashScale.value=e}},dashSize:{enumerable:!0,get:function(){return this.uniforms.dashSize.value},set:function(e){this.uniforms.dashSize.value=e}},dashOffset:{enumerable:!0,get:function(){return this.uniforms.dashOffset.value},set:function(e){this.uniforms.dashOffset.value=e}},gapSize:{enumerable:!0,get:function(){return this.uniforms.gapSize.value},set:function(e){this.uniforms.gapSize.value=e}},opacity:{enumerable:!0,get:function(){return this.uniforms.opacity.value},set:function(e){this.uniforms.opacity.value=e}},resolution:{enumerable:!0,get:function(){return this.uniforms.resolution.value},set:function(e){this.uniforms.resolution.value.copy(e)}},alphaToCoverage:{enumerable:!0,get:function(){return`USE_ALPHA_TO_COVERAGE`in this.defines},set:function(e){!!e!=`USE_ALPHA_TO_COVERAGE`in this.defines&&(this.needsUpdate=!0),e===!0?(this.defines.USE_ALPHA_TO_COVERAGE=``,this.extensions.derivatives=!0):(delete this.defines.USE_ALPHA_TO_COVERAGE,this.extensions.derivatives=!1)}}}),this.setValues(e)}},Hy=new Zn,Uy=new q,Wy=new q,Gy=new Zn,Ky=new Zn,qy=new Zn,Jy=new q,Yy=new J,Xy=new uf,Zy=new q,Qy=new ni,$y=new Ri,eb=new Zn,tb,nb;function rb(e,t,n){return eb.set(0,0,-t,1).applyMatrix4(e.projectionMatrix),eb.multiplyScalar(1/eb.w),eb.x=nb/n.width,eb.y=nb/n.height,eb.applyMatrix4(e.projectionMatrixInverse),eb.multiplyScalar(1/eb.w),Math.abs(Math.max(eb.x,eb.y))}function ib(e,t){let n=e.matrixWorld,r=e.geometry,i=r.attributes.instanceStart,a=r.attributes.instanceEnd,o=Math.min(r.instanceCount,i.count);for(let r=0,s=o;ru&&Ky.z>u)continue;if(Gy.z>u){let e=Gy.z-Ky.z,t=(Gy.z-u)/e;Gy.lerp(Ky,t)}else if(Ky.z>u){let e=Ky.z-Gy.z,t=(Ky.z-u)/e;Ky.lerp(Gy,t)}Gy.applyMatrix4(r),Ky.applyMatrix4(r),Gy.multiplyScalar(1/Gy.w),Ky.multiplyScalar(1/Ky.w),Gy.x*=i.x/2,Gy.y*=i.y/2,Ky.x*=i.x/2,Ky.y*=i.y/2,Xy.start.copy(Gy),Xy.start.z=0,Xy.end.copy(Ky),Xy.end.z=0;let o=Xy.closestPointToPointParameter(Jy,!0);Xy.at(o,Zy);let l=jn.lerp(Gy.z,Ky.z,o),d=l>=-1&&l<=1,f=Jy.distanceTo(Zy){let r=n.width/2,i=n.height/2;t.updateMatrixWorld(!1);let a=e.project(t);return a.x=a.x*r+r,a.y=-(a.y*i)+i,a},fb=(e,t,n,r=1)=>{let i=cb.set(e.x/n.width*2-1,-(e.y/n.height)*2+1,r);return i.unproject(t),i},pb=(e,t,n,r)=>{let i=db(ub.copy(e),n,r),a=0;for(let o=0;o<2;++o){let s=lb.copy(i).setComponent(o,i.getComponent(o)+t),c=fb(s,n,r,s.z);a=Math.max(a,e.distanceTo(c))}return a},mb=v.forwardRef(function({points:e,color:t=16777215,vertexColors:n,linewidth:r,lineWidth:i,segments:a,dashed:o,...s},c){var l;let u=A_(e=>e.size),d=v.useMemo(()=>a?new ob:new sb,[a]),[f]=v.useState(()=>new Vy),p=(n==null||(l=n[0])==null?void 0:l.length)===4?4:3,m=v.useMemo(()=>{let r=a?new zy:new By,i=e.map(e=>{let t=Array.isArray(e);return e instanceof q||e instanceof Zn?[e.x,e.y,e.z]:e instanceof K?[e.x,e.y,0]:t&&e.length===3?[e[0],e[1],e[2]]:t&&e.length===2?[e[0],e[1],0]:e});if(r.setPositions(i.flat()),n){t=16777215;let e=n.map(e=>e instanceof Y?e.toArray():e);r.setColors(e.flat(),p)}return r},[e,a,n,p]);return v.useLayoutEffect(()=>{d.computeLineDistances()},[e,d]),v.useLayoutEffect(()=>{o?f.defines.USE_DASH=``:delete f.defines.USE_DASH,f.needsUpdate=!0},[o,f]),v.useEffect(()=>()=>{m.dispose(),f.dispose()},[m]),v.createElement(`primitive`,ny({object:d,ref:c},s),v.createElement(`primitive`,{object:m,attach:`geometry`}),v.createElement(`primitive`,ny({object:f,attach:`material`,color:t,vertexColors:!!n,resolution:[u.width,u.height],linewidth:r??i??1,dashed:o,transparent:p===4},s)))});function hb(e,t,n,r){var i;return i=class extends yl{constructor(i){super({vertexShader:t,fragmentShader:n,...i});for(let t in e)this.uniforms[t]=new Vd(e[t]),Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(e){this.uniforms[t].value=e}});this.uniforms=gl.clone(this.uniforms),r?.(this)}},i.key=jn.generateUUID(),i}var gb=parseInt(`184`.replace(/\D+/g,``));function _b(e,t,n){let r=A_(e=>e.size),i=A_(e=>e.viewport),a=typeof e==`number`?e:r.width*i.dpr,o=typeof t==`number`?t:r.height*i.dpr,s=(typeof e==`number`?n:e)||{},{samples:c=0,depth:l,...u}=s,d=l??s.depthBuffer,f=v.useMemo(()=>{let e=new $n(a,o,{minFilter:M,magFilter:M,type:ne,...u});return d&&(e.depthTexture=new _s(a,o,V)),e.samples=c,e},[]);return v.useLayoutEffect(()=>{f.setSize(a,o),c&&(f.samples=c)},[c,f,a,o]),v.useEffect(()=>()=>f.dispose(),[]),f}var vb=e=>typeof e==`function`,yb=v.forwardRef(({envMap:e,resolution:t=256,frames:n=1/0,children:r,makeDefault:i,...a},o)=>{let s=A_(({set:e})=>e),c=A_(({camera:e})=>e),l=A_(({size:e})=>e),u=v.useRef(null);v.useImperativeHandle(o,()=>u.current,[]);let d=v.useRef(null),f=_b(t);v.useLayoutEffect(()=>{a.manual||u.current.updateProjectionMatrix()},[l,a]),v.useLayoutEffect(()=>{u.current.updateProjectionMatrix()}),v.useLayoutEffect(()=>{if(i){let e=c;return s(()=>({camera:u.current})),()=>s(()=>({camera:e}))}},[u,i,s]);let p=0,m=null,h=vb(r);return j_(t=>{h&&(n===1/0||ptypeof e==`function`,xb=v.forwardRef(({envMap:e,resolution:t=256,frames:n=1/0,makeDefault:r,children:i,...a},o)=>{let s=A_(({set:e})=>e),c=A_(({camera:e})=>e),l=A_(({size:e})=>e),u=v.useRef(null);v.useImperativeHandle(o,()=>u.current,[]);let d=v.useRef(null),f=_b(t);v.useLayoutEffect(()=>{a.manual||(u.current.aspect=l.width/l.height)},[l,a]),v.useLayoutEffect(()=>{u.current.updateProjectionMatrix()});let p=0,m=null,h=bb(i);return j_(t=>{h&&(n===1/0||p{if(r){let e=c;return s(()=>({camera:u.current})),()=>s(()=>({camera:e}))}},[u,r,s]),v.createElement(v.Fragment,null,v.createElement(`perspectiveCamera`,ny({ref:u},a),!h&&i),v.createElement(`group`,{ref:d},h&&i(f.texture)))}),Sb=v.forwardRef(({makeDefault:e,camera:t,regress:n,domElement:r,enableDamping:i=!0,keyEvents:a=!1,onChange:o,onStart:s,onEnd:c,...l},u)=>{let d=A_(e=>e.invalidate),f=A_(e=>e.camera),p=A_(e=>e.gl),m=A_(e=>e.events),h=A_(e=>e.setEvents),g=A_(e=>e.set),_=A_(e=>e.get),y=A_(e=>e.performance),b=t||f,x=r||m.connected||p.domElement,S=v.useMemo(()=>new Iy(b),[b]);return j_(()=>{S.enabled&&S.update()},-1),v.useEffect(()=>(a&&S.connect(a===!0?x:a),S.connect(x),()=>void S.dispose()),[a,x,n,S,d]),v.useEffect(()=>{let e=e=>{d(),n&&y.regress(),o&&o(e)},t=e=>{s&&s(e)},r=e=>{c&&c(e)};return S.addEventListener(`change`,e),S.addEventListener(`start`,t),S.addEventListener(`end`,r),()=>{S.removeEventListener(`start`,t),S.removeEventListener(`end`,r),S.removeEventListener(`change`,e)}},[o,s,c,S,d,h]),v.useEffect(()=>{if(e){let e=_().controls;return g({controls:S}),()=>g({controls:e})}},[e,S]),v.createElement(`primitive`,ny({ref:u,object:S,enableDamping:i},l))});function Cb({defaultScene:e,defaultCamera:t,renderPriority:n=1}){let{gl:r,scene:i,camera:a}=A_(),o;return j_(()=>{o=r.autoClear,n===1&&(r.autoClear=!0,r.render(e,t)),r.autoClear=!1,r.clearDepth(),r.render(i,a),r.autoClear=o},n),v.createElement(`group`,{onPointerOver:()=>null})}function wb({children:e,renderPriority:t=1}){let{scene:n,camera:r}=A_(),[i]=v.useState(()=>new Vr);return v.createElement(v.Fragment,null,Dv(v.createElement(v.Fragment,null,e,v.createElement(Cb,{defaultScene:n,defaultCamera:r,renderPriority:t})),i,{events:{priority:t+1}}))}var Tb=v.createContext({}),Eb=()=>v.useContext(Tb),Db=2*Math.PI,Ob=new Ar,kb=new J,[Ab,jb]=[new Mn,new Mn],Mb=new q,Nb=new q,Pb=e=>`minPolarAngle`in e,Fb=e=>`getTarget`in e,Ib=({alignment:e=`bottom-right`,margin:t=[80,80],renderPriority:n=1,onUpdate:r,onTarget:i,children:a})=>{let o=A_(e=>e.size),s=A_(e=>e.camera),c=A_(e=>e.controls),l=A_(e=>e.invalidate),u=v.useRef(null),d=v.useRef(null),f=v.useRef(!1),p=v.useRef(0),m=v.useRef(new q(0,0,0)),h=v.useRef(new q(0,0,0));v.useEffect(()=>{h.current.copy(s.up),Ob.up.copy(s.up)},[s]);let g=v.useCallback(e=>{f.current=!0,(c||i)&&(m.current=i?.()||(Fb(c)?c.getTarget(m.current):c?.target)),p.current=s.position.distanceTo(Mb),Ab.copy(s.quaternion),Nb.copy(e).multiplyScalar(p.current).add(Mb),Ob.lookAt(Nb),jb.copy(Ob.quaternion),l()},[c,s,i,l]);j_((e,t)=>{if(d.current&&u.current){var n;if(f.current)if(Ab.angleTo(jb)<.01)f.current=!1,Pb(c)&&s.up.copy(h.current);else{let e=t*Db;Ab.rotateTowards(jb,e),s.position.set(0,0,1).applyQuaternion(Ab).multiplyScalar(p.current).add(m.current),s.up.set(0,1,0).applyQuaternion(Ab).normalize(),s.quaternion.copy(Ab),Fb(c)&&c.setPosition(s.position.x,s.position.y,s.position.z),r?r():c&&c.update(t),l()}kb.copy(s.matrix).invert(),(n=u.current)==null||n.quaternion.setFromRotationMatrix(kb)}});let _=v.useMemo(()=>({tweenCamera:g}),[g]),[y,b]=t,x=e.endsWith(`-center`)?0:e.endsWith(`-left`)?-o.width/2+y:o.width/2-y,S=e.startsWith(`center-`)?0:e.startsWith(`top-`)?o.height/2-b:-o.height/2+b;return v.createElement(wb,{renderPriority:n},v.createElement(Tb.Provider,{value:_},v.createElement(yb,{makeDefault:!0,ref:d,position:[0,0,200]}),v.createElement(`group`,{ref:u,position:[x,S,0]},a)))};function Lb({scale:e=[.8,.05,.05],color:t,rotation:n}){return v.createElement(`group`,{rotation:n},v.createElement(`mesh`,{position:[.4,0,0]},v.createElement(`boxGeometry`,{args:e}),v.createElement(`meshBasicMaterial`,{color:t,toneMapped:!1})))}function Rb({onClick:e,font:t,disabled:n,arcStyle:r,label:i,labelColor:a,axisHeadScale:o=1,...s}){let c=A_(e=>e.gl),l=v.useMemo(()=>{let e=document.createElement(`canvas`);e.width=64,e.height=64;let n=e.getContext(`2d`);return n.beginPath(),n.arc(32,32,16,0,2*Math.PI),n.closePath(),n.fillStyle=r,n.fill(),i&&(n.font=t,n.textAlign=`center`,n.fillStyle=a,n.fillText(i,32,41)),new hs(e)},[r,i,a,t]),[u,d]=v.useState(!1),f=(i?1:.75)*(u?1.2:1)*o;return v.createElement(`sprite`,ny({scale:f,onPointerOver:n?void 0:e=>{e.stopPropagation(),d(!0)},onPointerOut:n?void 0:e||(e=>{e.stopPropagation(),d(!1)})},s),v.createElement(`spriteMaterial`,{map:l,"map-anisotropy":c.capabilities.getMaxAnisotropy()||1,alphaTest:.3,opacity:i?1:.75,toneMapped:!1}))}var zb=({hideNegativeAxes:e,hideAxisHeads:t,disabled:n,font:r=`18px Inter var, Arial, sans-serif`,axisColors:i=[`#ff2060`,`#20df80`,`#2080ff`],axisHeadScale:a=1,axisScale:o,labels:s=[`X`,`Y`,`Z`],labelColor:c=`#000`,onClick:l,...u})=>{let[d,f,p]=i,{tweenCamera:m}=Eb(),h={font:r,disabled:n,labelColor:c,onClick:l,axisHeadScale:a,onPointerDown:n?void 0:e=>{m(e.object.position),e.stopPropagation()}};return v.createElement(`group`,ny({scale:40},u),v.createElement(Lb,{color:d,rotation:[0,0,0],scale:o}),v.createElement(Lb,{color:f,rotation:[0,0,Math.PI/2],scale:o}),v.createElement(Lb,{color:p,rotation:[0,-Math.PI/2,0],scale:o}),!t&&v.createElement(v.Fragment,null,v.createElement(Rb,ny({arcStyle:d,position:[1,0,0],label:s[0]},h)),v.createElement(Rb,ny({arcStyle:f,position:[0,1,0],label:s[1]},h)),v.createElement(Rb,ny({arcStyle:p,position:[0,0,1],label:s[2]},h)),!e&&v.createElement(v.Fragment,null,v.createElement(Rb,ny({arcStyle:d,position:[-1,0,0]},h)),v.createElement(Rb,ny({arcStyle:f,position:[0,-1,0]},h)),v.createElement(Rb,ny({arcStyle:p,position:[0,0,-1]},h)))))},Bb=hb({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,fadeFrom:1,cellThickness:.5,sectionThickness:1,cellColor:new Y,sectionColor:new Y,infiniteGrid:!1,followCamera:!1,worldCamProjPosition:new q,worldPlanePosition:new q},` varying vec3 localPosition; varying vec4 worldPosition; uniform vec3 worldCamProjPosition; uniform vec3 worldPlanePosition; uniform float fadeDistance; uniform bool infiniteGrid; uniform bool followCamera; void main() { localPosition = position.xzy; if (infiniteGrid) localPosition *= 1.0 + fadeDistance; worldPosition = modelMatrix * vec4(localPosition, 1.0); if (followCamera) { worldPosition.xyz += (worldCamProjPosition - worldPlanePosition); localPosition = (inverse(modelMatrix) * worldPosition).xyz; } gl_Position = projectionMatrix * viewMatrix * worldPosition; } `,` varying vec3 localPosition; varying vec4 worldPosition; uniform vec3 worldCamProjPosition; uniform float cellSize; uniform float sectionSize; uniform vec3 cellColor; uniform vec3 sectionColor; uniform float fadeDistance; uniform float fadeStrength; uniform float fadeFrom; uniform float cellThickness; uniform float sectionThickness; float getGrid(float size, float thickness) { vec2 r = localPosition.xz / size; vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r); float line = min(grid.x, grid.y) + 1.0 - thickness; return 1.0 - min(line, 1.0); } void main() { float g1 = getGrid(cellSize, cellThickness); float g2 = getGrid(sectionSize, sectionThickness); vec3 from = worldCamProjPosition*vec3(fadeFrom); float dist = distance(from, worldPosition.xyz); float d = 1.0 - min(dist / fadeDistance, 1.0); vec3 color = mix(cellColor, sectionColor, min(1.0, sectionThickness * g2)); gl_FragColor = vec4(color, (g1 + g2) * pow(d, fadeStrength)); gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2); if (gl_FragColor.a <= 0.0) discard; #include #include <${gb>=154?`colorspace_fragment`:`encodings_fragment`}> } `),Vb=v.forwardRef(({args:e,cellColor:t=`#000000`,sectionColor:n=`#2080ff`,cellSize:r=.5,sectionSize:i=1,followCamera:a=!1,infiniteGrid:o=!1,fadeDistance:s=100,fadeStrength:c=1,fadeFrom:l=1,cellThickness:u=.5,sectionThickness:d=1,side:f=1,...p},m)=>{nv({GridMaterial:Bb});let h=v.useRef(null);v.useImperativeHandle(m,()=>h.current,[]);let g=new mo,_=new q(0,1,0),y=new q(0,0,0);j_(e=>{g.setFromNormalAndCoplanarPoint(_,y).applyMatrix4(h.current.matrixWorld);let t=h.current.material,n=t.uniforms.worldCamProjPosition,r=t.uniforms.worldPlanePosition;g.projectPoint(e.camera.position,n.value),r.value.set(0,0,0).applyMatrix4(h.current.matrixWorld)});let b={cellSize:r,sectionSize:i,cellColor:t,sectionColor:n,cellThickness:u,sectionThickness:d},x={fadeDistance:s,fadeStrength:c,fadeFrom:l,infiniteGrid:o,followCamera:a};return v.createElement(`mesh`,ny({ref:h,frustumCulled:!1},p),v.createElement(`gridMaterial`,ny({transparent:!0,"extensions-derivatives":!0,side:f},b,x)),v.createElement(`planeGeometry`,{args:e}))}),Hb=`modulepreload`,Ub=function(e){return`/`+e},Wb={},Gb=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=Ub(t,n),t in Wb)return;Wb[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:Hb,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Kb=v.createContext(null),qb=new q,Jb=new q,Yb=(e,t,n,r)=>{let i=t.dot(t),a=t.dot(e)-t.dot(n),o=t.dot(r);return o===0?-a/i:(qb.copy(r).multiplyScalar(i/o).sub(t),Jb.copy(r).multiplyScalar(a/o).add(n).sub(e),-qb.dot(Jb)/qb.dot(qb))},Xb=new q(0,1,0),Zb=new J,Qb=({direction:e,axis:t})=>{let{translation:n,translationLimits:r,annotations:i,annotationsClass:a,depthTest:o,scale:s,lineWidth:c,fixed:l,axisColors:u,hoveredColor:d,opacity:f,renderOrder:p,onDragStart:m,onDrag:h,onDragEnd:g,userData:_}=v.useContext(Kb),y=A_(e=>e.controls),b=v.useRef(null),x=v.useRef(null),S=v.useRef(null),C=v.useRef(0),[w,T]=v.useState(!1),E=v.useCallback(r=>{i&&(b.current.innerText=`${n.current[t].toFixed(2)}`,b.current.style.display=`block`),r.stopPropagation();let a=new J().extractRotation(x.current.matrixWorld),o=r.point.clone(),s=new q().setFromMatrixPosition(x.current.matrixWorld),c=e.clone().applyMatrix4(a).normalize();S.current={clickPoint:o,dir:c},C.current=n.current[t],m({component:`Arrow`,axis:t,origin:s,directions:[c]}),y&&(y.enabled=!1),r.target.setPointerCapture(r.pointerId)},[i,e,y,m,n,t]),D=v.useCallback(e=>{if(e.stopPropagation(),w||T(!0),S.current){let{clickPoint:a,dir:o}=S.current,[s,c]=r?.[t]||[void 0,void 0],l=Yb(a,o,e.ray.origin,e.ray.direction);s!==void 0&&(l=Math.max(l,s-C.current)),c!==void 0&&(l=Math.min(l,c-C.current)),n.current[t]=C.current+l,i&&(b.current.innerText=`${n.current[t].toFixed(2)}`),Zb.makeTranslation(o.x*l,o.y*l,o.z*l),h(Zb)}},[i,h,w,n,r,t]),O=v.useCallback(e=>{i&&(b.current.style.display=`none`),e.stopPropagation(),S.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)},[i,y,g]),k=v.useCallback(e=>{e.stopPropagation(),T(!1)},[]),{cylinderLength:A,coneWidth:j,coneLength:M,matrixL:N}=v.useMemo(()=>{let t=l?c/s*1.6:s/20,n=l?.2:s/5,r=l?1-n:s-n,i=new Mn().setFromUnitVectors(Xb,e.clone().normalize());return{cylinderLength:r,coneWidth:t,coneLength:n,matrixL:new J().makeRotationFromQuaternion(i)}},[e,s,c,l]),P=w?d:u[t];return v.createElement(`group`,{ref:x},v.createElement(`group`,{matrix:N,matrixAutoUpdate:!1,onPointerDown:E,onPointerMove:D,onPointerUp:O,onPointerOut:k},i&&v.createElement(_y,{position:[0,-M,0]},v.createElement(`div`,{style:{display:`none`,background:`#151520`,color:`white`,padding:`6px 8px`,borderRadius:7,whiteSpace:`nowrap`},className:a,ref:b})),v.createElement(`mesh`,{visible:!1,position:[0,(A+M)/2,0],userData:_},v.createElement(`cylinderGeometry`,{args:[j*1.4,j*1.4,A+M,8,1]})),v.createElement(mb,{transparent:!0,raycast:()=>null,depthTest:o,points:[0,0,0,0,A,0],lineWidth:c,side:2,color:P,opacity:f,polygonOffset:!0,renderOrder:p,polygonOffsetFactor:-10,fog:!1}),v.createElement(`mesh`,{raycast:()=>null,position:[0,A+M/2,0],renderOrder:p},v.createElement(`coneGeometry`,{args:[j,M,24,1]}),v.createElement(`meshBasicMaterial`,{transparent:!0,depthTest:o,color:P,opacity:f,polygonOffset:!0,polygonOffsetFactor:-10,fog:!1}))))},$b=new q,ex=new q,tx=e=>e*180/Math.PI,nx=e=>e*Math.PI/180,rx=(e,t,n,r,i)=>{$b.copy(e).sub(n),ex.copy(t).sub(n);let a=r.dot(r),o=i.dot(i),s=$b.dot(r)/a,c=$b.dot(i)/o,l=ex.dot(r)/a,u=ex.dot(i)/o;return Math.atan2(u,l)-Math.atan2(c,s)},ix=(e,t)=>{let n=Math.floor(e/t);return n=n<0?n+1:n,e-n*t},ax=e=>{let t=ix(e,2*Math.PI);return Math.abs(t)<1e-6?0:(t<0&&(t+=2*Math.PI),t)},ox=new J,sx=new q,cx=new wa,lx=new q,ux=({dir1:e,dir2:t,axis:n})=>{let{rotationLimits:r,annotations:i,annotationsClass:a,depthTest:o,scale:s,lineWidth:c,fixed:l,axisColors:u,hoveredColor:d,renderOrder:f,opacity:p,onDragStart:m,onDrag:h,onDragEnd:g,userData:_}=v.useContext(Kb),y=A_(e=>e.controls),b=v.useRef(null),x=v.useRef(null),S=v.useRef(0),C=v.useRef(0),w=v.useRef(null),[T,E]=v.useState(!1),D=v.useCallback(e=>{i&&(b.current.innerText=`${tx(C.current).toFixed(0)}º`,b.current.style.display=`block`),e.stopPropagation();let t=e.point.clone(),r=new q().setFromMatrixPosition(x.current.matrixWorld),a=new q().setFromMatrixColumn(x.current.matrixWorld,0).normalize(),o=new q().setFromMatrixColumn(x.current.matrixWorld,1).normalize(),s=new q().setFromMatrixColumn(x.current.matrixWorld,2).normalize();w.current={clickPoint:t,origin:r,e1:a,e2:o,normal:s,plane:new mo().setFromNormalAndCoplanarPoint(s,r)},m({component:`Rotator`,axis:n,origin:r,directions:[a,o,s]}),y&&(y.enabled=!1),e.target.setPointerCapture(e.pointerId)},[i,y,m,n]),O=v.useCallback(e=>{if(e.stopPropagation(),T||E(!0),w.current){let{clickPoint:t,origin:a,e1:o,e2:s,normal:c,plane:l}=w.current,[u,d]=r?.[n]||[void 0,void 0];cx.copy(e.ray),cx.intersectPlane(l,lx),cx.direction.negate(),cx.intersectPlane(l,lx);let f=rx(t,lx,a,o,s),p=tx(f);e.shiftKey&&(p=Math.round(p/10)*10,f=nx(p)),u!==void 0&&d!==void 0&&d-u<2*Math.PI?(f=ax(f),f=f>Math.PI?f-2*Math.PI:f,f=jn.clamp(f,u-S.current,d-S.current),C.current=S.current+f):(C.current=ax(S.current+f),C.current=C.current>Math.PI?C.current-2*Math.PI:C.current),i&&(p=tx(C.current),b.current.innerText=`${p.toFixed(0)}º`),ox.makeRotationAxis(c,f),sx.copy(a).applyMatrix4(ox).sub(a).negate(),ox.setPosition(sx),h(ox)}},[i,h,T,r,n]),k=v.useCallback(e=>{i&&(b.current.style.display=`none`),e.stopPropagation(),S.current=C.current,w.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)},[i,y,g]),A=v.useCallback(e=>{e.stopPropagation(),E(!1)},[]),j=v.useMemo(()=>{let n=e.clone().normalize(),r=t.clone().normalize();return new J().makeBasis(n,r,n.clone().cross(r))},[e,t]),M=l?.65:s*.65,N=v.useMemo(()=>{let e=[];for(let t=0;t<=32;t++){let n=Math.PI/2*t/32;e.push(new q(Math.cos(n)*M,Math.sin(n)*M,0))}return e},[M]);return v.createElement(`group`,{ref:x,onPointerDown:D,onPointerMove:O,onPointerUp:k,onPointerOut:A,matrix:j,matrixAutoUpdate:!1},i&&v.createElement(_y,{position:[M,M,0]},v.createElement(`div`,{style:{display:`none`,background:`#151520`,color:`white`,padding:`6px 8px`,borderRadius:7,whiteSpace:`nowrap`},className:a,ref:b})),v.createElement(mb,{points:N,lineWidth:c*4,visible:!1,userData:_}),v.createElement(mb,{transparent:!0,raycast:()=>null,depthTest:o,points:N,lineWidth:c,side:2,color:T?d:u[n],opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,renderOrder:f,fog:!1}))},dx=(e,t,n)=>{let r=Math.abs(e.x)>=Math.abs(e.y)&&Math.abs(e.x)>=Math.abs(e.z)?0:Math.abs(e.y)>=Math.abs(e.x)&&Math.abs(e.y)>=Math.abs(e.z)?1:2,i=[0,1,2].sort((e,n)=>Math.abs(t.getComponent(n))-Math.abs(t.getComponent(e))),a=r===i[0]?i[1]:i[0],o=e.getComponent(r),s=e.getComponent(a),c=t.getComponent(r),l=t.getComponent(a),u=n.getComponent(r),d=(n.getComponent(a)-s/o*u)/(l-s/o*c);return[(u-d*c)/o,d]},fx=new wa,px=new q,mx=new J,hx=({dir1:e,dir2:t,axis:n})=>{let{translation:r,translationLimits:i,annotations:a,annotationsClass:o,depthTest:s,scale:c,lineWidth:l,fixed:u,axisColors:d,hoveredColor:f,opacity:p,renderOrder:m,onDragStart:h,onDrag:g,onDragEnd:_,userData:y}=v.useContext(Kb),b=A_(e=>e.controls),x=v.useRef(null),S=v.useRef(null),C=v.useRef(null),w=v.useRef(0),T=v.useRef(0),[E,D]=v.useState(!1),O=v.useCallback(e=>{a&&(x.current.innerText=`${r.current[(n+1)%3].toFixed(2)}, ${r.current[(n+2)%3].toFixed(2)}`,x.current.style.display=`block`),e.stopPropagation();let t=e.point.clone(),i=new q().setFromMatrixPosition(S.current.matrixWorld),o=new q().setFromMatrixColumn(S.current.matrixWorld,0).normalize(),s=new q().setFromMatrixColumn(S.current.matrixWorld,1).normalize(),c=new q().setFromMatrixColumn(S.current.matrixWorld,2).normalize();C.current={clickPoint:t,e1:o,e2:s,plane:new mo().setFromNormalAndCoplanarPoint(c,i)},w.current=r.current[(n+1)%3],T.current=r.current[(n+2)%3],h({component:`Slider`,axis:n,origin:i,directions:[o,s,c]}),b&&(b.enabled=!1),e.target.setPointerCapture(e.pointerId)},[a,b,h,n]),k=v.useCallback(e=>{if(e.stopPropagation(),E||D(!0),C.current){let{clickPoint:t,e1:o,e2:s,plane:c}=C.current,[l,u]=i?.[(n+1)%3]||[void 0,void 0],[d,f]=i?.[(n+2)%3]||[void 0,void 0];fx.copy(e.ray),fx.intersectPlane(c,px),fx.direction.negate(),fx.intersectPlane(c,px),px.sub(t);let[p,m]=dx(o,s,px);l!==void 0&&(p=Math.max(p,l-w.current)),u!==void 0&&(p=Math.min(p,u-w.current)),d!==void 0&&(m=Math.max(m,d-T.current)),f!==void 0&&(m=Math.min(m,f-T.current)),r.current[(n+1)%3]=w.current+p,r.current[(n+2)%3]=T.current+m,a&&(x.current.innerText=`${r.current[(n+1)%3].toFixed(2)}, ${r.current[(n+2)%3].toFixed(2)}`),mx.makeTranslation(p*o.x+m*s.x,p*o.y+m*s.y,p*o.z+m*s.z),g(mx)}},[a,g,E,r,i,n]),A=v.useCallback(e=>{a&&(x.current.style.display=`none`),e.stopPropagation(),C.current=null,_(),b&&(b.enabled=!0),e.target.releasePointerCapture(e.pointerId)},[a,b,_]),j=v.useCallback(e=>{e.stopPropagation(),D(!1)},[]),M=v.useMemo(()=>{let n=e.clone().normalize(),r=t.clone().normalize();return new J().makeBasis(n,r,n.clone().cross(r))},[e,t]),N=u?1/7:c/7,P=u?.225:c*.225,F=E?f:d[n],I=v.useMemo(()=>[new q(0,0,0),new q(0,P,0),new q(P,P,0),new q(P,0,0),new q(0,0,0)],[P]);return v.createElement(`group`,{ref:S,matrix:M,matrixAutoUpdate:!1},a&&v.createElement(_y,{position:[0,0,0]},v.createElement(`div`,{style:{display:`none`,background:`#151520`,color:`white`,padding:`6px 8px`,borderRadius:7,whiteSpace:`nowrap`},className:o,ref:x})),v.createElement(`group`,{position:[N*1.7,N*1.7,0]},v.createElement(`mesh`,{visible:!0,onPointerDown:O,onPointerMove:k,onPointerUp:A,onPointerOut:j,scale:P,userData:y,renderOrder:m},v.createElement(`planeGeometry`,null),v.createElement(`meshBasicMaterial`,{transparent:!0,depthTest:s,color:F,polygonOffset:!0,polygonOffsetFactor:-10,side:2,fog:!1})),v.createElement(mb,{position:[-P/2,-P/2,0],transparent:!0,depthTest:s,points:I,lineWidth:l,color:F,opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,userData:y,fog:!1,renderOrder:m})))},gx=new q,_x=new q,vx=(e,t,n,r)=>{let i=t.dot(t),a=t.dot(e)-t.dot(n),o=t.dot(r);return o===0?-a/i:(gx.copy(r).multiplyScalar(i/o).sub(t),_x.copy(r).multiplyScalar(a/o).add(n).sub(e),-gx.dot(_x)/gx.dot(gx))},yx=new q(0,1,0),bx=new q,xx=new J,Sx=({direction:e,axis:t})=>{let{scaleLimits:n,annotations:r,annotationsClass:i,depthTest:a,scale:o,lineWidth:s,fixed:c,axisColors:l,hoveredColor:u,opacity:d,renderOrder:f,onDragStart:p,onDrag:m,onDragEnd:h,userData:g}=v.useContext(Kb),_=A_(e=>e.size),y=A_(e=>e.controls),b=v.useRef(null),x=v.useRef(null),S=v.useRef(null),C=v.useRef(1),w=v.useRef(1),T=v.useRef(null),[E,D]=v.useState(!1),O=c?1.2:1.2*o,k=v.useCallback(n=>{r&&(b.current.innerText=`${w.current.toFixed(2)}`,b.current.style.display=`block`),n.stopPropagation();let i=new J().extractRotation(x.current.matrixWorld),a=n.point.clone(),s=new q().setFromMatrixPosition(x.current.matrixWorld),l=e.clone().applyMatrix4(i).normalize(),u=x.current.matrixWorld.clone();T.current={clickPoint:a,dir:l,mPLG:u,mPLGInv:u.clone().invert(),offsetMultiplier:c?1/pb(x.current.getWorldPosition(gx),o,n.camera,_):1},p({component:`Sphere`,axis:t,origin:s,directions:[l]}),y&&(y.enabled=!1),n.target.setPointerCapture(n.pointerId)},[r,y,e,p,t,c,o,_]),A=v.useCallback(e=>{if(e.stopPropagation(),E||D(!0),T.current){let{clickPoint:i,dir:a,mPLG:s,mPLGInv:l,offsetMultiplier:u}=T.current,[d,f]=n?.[t]||[1e-5,void 0],p=vx(i,a,e.ray.origin,e.ray.direction)*u,h=2**((c?p:p/o)*.2);e.shiftKey&&(h=Math.round(h*10)/10),h=Math.max(h,d/C.current),f!==void 0&&(h=Math.min(h,f/C.current)),w.current=C.current*h,S.current.position.set(0,O+p,0),r&&(b.current.innerText=`${w.current.toFixed(2)}`),bx.set(1,1,1),bx.setComponent(t,h),xx.makeScale(bx.x,bx.y,bx.z).premultiply(s).multiply(l),m(xx)}},[r,O,m,E,n,t]),j=v.useCallback(e=>{r&&(b.current.style.display=`none`),e.stopPropagation(),C.current=w.current,T.current=null,S.current.position.set(0,O,0),h(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)},[r,y,h,O]),M=v.useCallback(e=>{e.stopPropagation(),D(!1)},[]),{radius:N,matrixL:P}=v.useMemo(()=>{let t=c?s/o*1.8:o/22.5,n=new Mn().setFromUnitVectors(yx,e.clone().normalize());return{radius:t,matrixL:new J().makeRotationFromQuaternion(n)}},[e,o,s,c]),F=E?u:l[t];return v.createElement(`group`,{ref:x},v.createElement(`group`,{matrix:P,matrixAutoUpdate:!1,onPointerDown:k,onPointerMove:A,onPointerUp:j,onPointerOut:M},r&&v.createElement(_y,{position:[0,O/2,0]},v.createElement(`div`,{style:{display:`none`,background:`#151520`,color:`white`,padding:`6px 8px`,borderRadius:7,whiteSpace:`nowrap`},className:i,ref:b})),v.createElement(`mesh`,{ref:S,position:[0,O,0],renderOrder:f,userData:g},v.createElement(`sphereGeometry`,{args:[N,12,12]}),v.createElement(`meshBasicMaterial`,{transparent:!0,depthTest:a,color:F,opacity:d,polygonOffset:!0,polygonOffsetFactor:-10}))))},Cx=new J,wx=new J,Tx=new J,Ex=new J,Dx=new J,Ox=new J,kx=new J,Ax=new J,jx=new J,Mx=new ni,Nx=new ni,Px=new q,Fx=new q,Ix=new q,Lx=new q,Rx=new q,zx=new q(1,0,0),Bx=new q(0,1,0),Vx=new q(0,0,1),Hx=v.forwardRef(({enabled:e=!0,matrix:t,onDragStart:n,onDrag:r,onDragEnd:i,autoTransform:a=!0,anchor:o,disableAxes:s=!1,disableSliders:c=!1,disableRotations:l=!1,disableScaling:u=!1,activeAxes:d=[!0,!0,!0],offset:f=[0,0,0],rotation:p=[0,0,0],scale:m=1,lineWidth:h=4,fixed:g=!1,translationLimits:_,rotationLimits:y,scaleLimits:b,depthTest:x=!0,renderOrder:S=500,axisColors:C=[`#ff2060`,`#20df80`,`#2080ff`],hoveredColor:w=`#ffff40`,annotations:T=!1,annotationsClass:E,opacity:D=1,visible:O=!0,userData:k,children:A,...j},M)=>{let N=A_(e=>e.invalidate),P=v.useRef(null),F=v.useRef(null),I=v.useRef(null),L=v.useRef(null),ee=v.useRef([0,0,0]),R=v.useRef(new q(1,1,1)),te=v.useRef(new q(1,1,1));v.useLayoutEffect(()=>{o&&(L.current.updateWorldMatrix(!0,!0),Ex.copy(L.current.matrixWorld).invert(),Mx.makeEmpty(),L.current.traverse(e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),Ox.copy(e.matrixWorld).premultiply(Ex),Nx.copy(e.geometry.boundingBox),Nx.applyMatrix4(Ox),Mx.union(Nx))}),Px.copy(Mx.max).add(Mx.min).multiplyScalar(.5),Fx.copy(Mx.max).sub(Mx.min).multiplyScalar(.5),Ix.copy(Fx).multiply(new q(...o)).add(Px),Lx.set(...f).add(Ix),I.current.position.copy(Lx),N())});let z=v.useMemo(()=>({onDragStart:e=>{Cx.copy(F.current.matrix),wx.copy(F.current.matrixWorld),n&&n(e),N()},onDrag:e=>{Tx.copy(P.current.matrixWorld),Ex.copy(Tx).invert(),Dx.copy(wx).premultiply(e),Ox.copy(Dx).premultiply(Ex),kx.copy(Cx).invert(),Ax.copy(Ox).multiply(kx),a&&F.current.matrix.copy(Ox),r&&r(Ox,Ax,Dx,e),N()},onDragEnd:()=>{i&&i(),N()},translation:ee,translationLimits:_,rotationLimits:y,axisColors:C,hoveredColor:w,opacity:D,scale:m,lineWidth:h,fixed:g,depthTest:x,renderOrder:S,userData:k,annotations:T,annotationsClass:E}),[n,r,i,ee,_,y,b,x,m,h,g,...C,w,D,k,a,T,E]),B=new q;return j_(e=>{if(g){let t=pb(I.current.getWorldPosition(B),m,e.camera,e.size);R.current.setScalar(t)}t&&t instanceof J&&(F.current.matrix=t),F.current.updateWorldMatrix(!0,!0),jx.makeRotationFromEuler(I.current.rotation).setPosition(I.current.position).premultiply(F.current.matrixWorld),te.current.setFromMatrixScale(jx),Rx.copy(R.current).divide(te.current),(Math.abs(I.current.scale.x-Rx.x)>1e-4||Math.abs(I.current.scale.y-Rx.y)>1e-4||Math.abs(I.current.scale.z-Rx.z)>1e-4)&&(I.current.scale.copy(Rx),e.invalidate())}),v.useImperativeHandle(M,()=>F.current,[]),v.createElement(Kb.Provider,{value:z},v.createElement(`group`,{ref:P},v.createElement(`group`,ny({ref:F,matrix:t,matrixAutoUpdate:!1},j),v.createElement(`group`,{visible:O,ref:I,position:f,rotation:p},e&&v.createElement(v.Fragment,null,!s&&d[0]&&v.createElement(Qb,{axis:0,direction:zx}),!s&&d[1]&&v.createElement(Qb,{axis:1,direction:Bx}),!s&&d[2]&&v.createElement(Qb,{axis:2,direction:Vx}),!c&&d[0]&&d[1]&&v.createElement(hx,{axis:2,dir1:zx,dir2:Bx}),!c&&d[0]&&d[2]&&v.createElement(hx,{axis:1,dir1:Vx,dir2:zx}),!c&&d[2]&&d[1]&&v.createElement(hx,{axis:0,dir1:Bx,dir2:Vx}),!l&&d[0]&&d[1]&&v.createElement(ux,{axis:2,dir1:zx,dir2:Bx}),!l&&d[0]&&d[2]&&v.createElement(ux,{axis:1,dir1:Vx,dir2:zx}),!l&&d[2]&&d[1]&&v.createElement(ux,{axis:0,dir1:Bx,dir2:Vx}),!u&&d[0]&&v.createElement(Sx,{axis:0,direction:zx}),!u&&d[1]&&v.createElement(Sx,{axis:1,direction:Bx}),!u&&d[2]&&v.createElement(Sx,{axis:2,direction:Vx}))),v.createElement(`group`,{ref:L},A))))}),Ux=.5,Wx=[.5,.75,1,1.25,1.5,2,3,4],Gx=e=>.05+e*.055,Kx=e=>e*Math.PI/180;function qx(e){let t=Ux,n=Kx(e.angle??90)-Math.PI/2;return[{id:`a`,pos:[0,0,0],dir:[-1,0,0]},{id:`b`,pos:[t*Math.cos(n),t*Math.sin(n)+t,0],dir:[-Math.sin(n),Math.cos(n),0]}]}function Jx(e){let t=Wx[0],n=Math.abs(e-t);for(let r of Wx){let i=Math.abs(e-r);i[{id:`a`,pos:[-e.length/2,0,0],dir:[-1,0,0]},{id:`b`,pos:[e.length/2,0,0],dir:[1,0,0]}]},coupling:{type:`coupling`,label:`Coupling`,category:`Plumbing`,description:`Straight fitting for joining two pipe ends`,color:`#aeb7c2`,defaults:{diameter:1},params:{diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.3,0,0],dir:[-1,0,0]},{id:`b`,pos:[.3,0,0],dir:[1,0,0]}]},reducer:{type:`reducer`,label:`Reducer`,category:`Plumbing`,description:`Inline reducer fitting between two pipe diameters`,color:`#a8b2bf`,defaults:{diameterA:1.5,diameterB:1},params:{diameterA:{label:`Diameter A`,min:.5,max:4,step:.25,unit:`in`},diameterB:{label:`Diameter B`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.35,0,0],dir:[-1,0,0]},{id:`b`,pos:[.35,0,0],dir:[1,0,0]}]},cap:{type:`cap`,label:`Cap`,category:`Plumbing`,description:`End cap that terminates a pipe run`,color:`#9aa3b0`,defaults:{diameter:1},params:{diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`in`,pos:[-.22,0,0],dir:[-1,0,0]}]},elbow:{type:`elbow`,label:`Elbow`,category:`Plumbing`,description:`Bend fitting (15–180°)`,color:`#9aa3b0`,defaults:{angle:90,diameter:1},params:{angle:{label:`Bend angle`,min:15,max:180,step:15,unit:`°`},diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:qx},tee:{type:`tee`,label:`T-Joint`,category:`Plumbing`,description:`3-way splitter fitting`,color:`#9aa3b0`,defaults:{diameter:1},params:{diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.6,0,0],dir:[-1,0,0]},{id:`b`,pos:[.6,0,0],dir:[1,0,0]},{id:`c`,pos:[0,0,.6],dir:[0,0,1]}]},valve:{type:`valve`,label:`Valve`,category:`Flow Control`,description:`Inline ball valve (0–100% open)`,color:`#e0564f`,defaults:{diameter:1,open:100},params:{open:{label:`Open`,min:0,max:100,step:5,unit:`%`},diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.35,0,0],dir:[-1,0,0]},{id:`b`,pos:[.35,0,0],dir:[1,0,0]}]},pump:{type:`pump`,label:`Pump`,category:`Flow Control`,description:`Submersible/inline pump — pressure source`,color:`#3d7bfa`,defaults:{gph:400,maxHeadFt:8,on:1},params:{gph:{label:`Rated flow`,min:50,max:2e3,step:25,unit:`GPH`},maxHeadFt:{label:`Max head`,min:2,max:30,step:1,unit:`ft`}},getConnectors:()=>[{id:`in`,pos:[-.45,.25,0],dir:[-1,0,0]},{id:`out`,pos:[.45,.25,0],dir:[1,0,0]}]},reservoir:{type:`reservoir`,label:`Reservoir`,category:`Flow Control`,description:`Water tank — source & return sink`,color:`#2a3950`,defaults:{width:2,depth:1.4,height:1,level:70,ph:6,ec:1.2},params:{width:{label:`Width`,min:1,max:6,step:.5,unit:`ft`},depth:{label:`Depth`,min:1,max:6,step:.5,unit:`ft`},height:{label:`Height`,min:.5,max:4,step:.25,unit:`ft`},level:{label:`Fill level`,min:0,max:100,step:5,unit:`%`},ph:{label:`Water pH`,min:4,max:8.5,step:.1,unit:``},ec:{label:`Water EC`,min:0,max:3,step:.1,unit:`mS/cm`}},getConnectors:e=>[{id:`a`,pos:[-e.width/2,.25,0],dir:[-1,0,0]},{id:`b`,pos:[e.width/2,.25,0],dir:[1,0,0]},{id:`c`,pos:[0,.25,-e.depth/2],dir:[0,0,-1]},{id:`d`,pos:[0,.25,e.depth/2],dir:[0,0,1]}]},tower:{type:`tower`,label:`Grow Tower`,category:`Growing`,description:`Vertical NFT tower with plant sites`,color:`#e8eaed`,defaults:{height:4,sites:6},params:{height:{label:`Height`,min:2,max:10,step:.5,unit:`ft`},sites:{label:`Plant sites`,min:2,max:16,step:1}},getConnectors:e=>[{id:`in`,pos:[0,e.height,0],dir:[0,1,0]},{id:`out`,pos:[.45,.15,0],dir:[1,0,0]}]},tray:{type:`tray`,label:`Grow Tray`,category:`Growing`,description:`Flood/NFT channel tray`,color:`#d7dce2`,defaults:{length:3,width:1.2},params:{length:{label:`Length`,min:1,max:8,step:.5,unit:`ft`},width:{label:`Width`,min:.5,max:4,step:.25,unit:`ft`}},getConnectors:e=>[{id:`in`,pos:[-e.length/2,.15,0],dir:[-1,0,0]},{id:`out`,pos:[e.length/2,.15,0],dir:[1,0,0]}]},wallPanel:{type:`wallPanel`,label:`Wall Panel`,category:`Growing`,description:`Vertical grow wall with pockets`,color:`#3b7a57`,defaults:{width:3,height:4,rows:4,cols:5},params:{width:{label:`Width`,min:1,max:8,step:.5,unit:`ft`},height:{label:`Height`,min:1,max:8,step:.5,unit:`ft`},rows:{label:`Pocket rows`,min:1,max:8,step:1},cols:{label:`Pocket cols`,min:1,max:10,step:1}},getConnectors:e=>[{id:`in`,pos:[0,e.height,0],dir:[0,1,0]},{id:`out`,pos:[0,.05,0],dir:[0,-1,0]}]},lattice:{type:`lattice`,label:`Lattice`,category:`Structure`,description:`Structural lattice frame (no flow)`,color:`#8a7a5c`,defaults:{width:2.5,height:3},params:{width:{label:`Width`,min:1,max:8,step:.5,unit:`ft`},height:{label:`Height`,min:1,max:8,step:.5,unit:`ft`}},getConnectors:()=>[]},netPot:{type:`netPot`,label:`Net Pot`,category:`Growing`,description:`Plant cup with seedling (decorative)`,color:`#222a33`,defaults:{size:1},params:{size:{label:`Size`,min:.5,max:2,step:.25}},getConnectors:()=>[]},emitter:{type:`emitter`,label:`Emitter`,category:`Flow Control`,description:`Drip/spray outlet — terminates a line`,color:`#46c0e8`,defaults:{},params:{},getConnectors:()=>[{id:`in`,pos:[.2,0,0],dir:[1,0,0]}]},drain:{type:`drain`,label:`Drain`,category:`Flow Control`,description:`Floor drain — limited-capacity exit point`,color:`#64748b`,defaults:{capacityGph:250},params:{capacityGph:{label:`Capacity`,min:50,max:2e3,step:25,unit:`GPH`}},getConnectors:()=>[{id:`in`,pos:[-.35,.25,0],dir:[-1,0,0]}]},growTent:{type:`growTent`,label:`Grow Tent`,category:`Environment`,description:`Room/tent enclosure for planning air exchange and equipment`,color:`#475569`,defaults:{width:7,depth:5,height:4,sealed:0},params:{width:{label:`Width`,min:2,max:20,step:.5,unit:`ft`},depth:{label:`Depth`,min:2,max:20,step:.5,unit:`ft`},height:{label:`Height`,min:2,max:12,step:.5,unit:`ft`},sealed:{label:`Sealed room`,min:0,max:1,step:1}},getConnectors:()=>[]},inlineFan:{type:`inlineFan`,label:`Inline Fan`,category:`Environment`,description:`Duct fan for room exhaust/intake calculations`,color:`#0f766e`,defaults:{cfm:600,diameter:6,exhaust:1},params:{cfm:{label:`Airflow`,min:50,max:4e3,step:25,unit:`CFM`},diameter:{label:`Duct size`,min:4,max:14,step:2,unit:`in`},exhaust:{label:`Exhaust mode`,min:0,max:1,step:1}},getConnectors:()=>[]},circulationFan:{type:`circulationFan`,label:`Circulation Fan`,category:`Environment`,description:`Internal airflow fan for canopy mixing`,color:`#2563eb`,defaults:{cfm:250,sweep:90},params:{cfm:{label:`Airflow`,min:50,max:1500,step:25,unit:`CFM`},sweep:{label:`Sweep`,min:0,max:180,step:15,unit:`°`}},getConnectors:()=>[]},growLight:{type:`growLight`,label:`Grow Light`,category:`Environment`,description:`Overhead grow fixture for room planning`,color:`#fbbf24`,defaults:{width:2,depth:2,watts:650,hangingHeight:1.5,photoperiod:18},params:{width:{label:`Width`,min:.5,max:6,step:.25,unit:`ft`},depth:{label:`Depth`,min:.5,max:6,step:.25,unit:`ft`},watts:{label:`Power`,min:50,max:1500,step:25,unit:`W`},hangingHeight:{label:`Hang height`,min:.25,max:6,step:.25,unit:`ft`},photoperiod:{label:`Hours On`,min:0,max:24,step:1,unit:`h`}},getConnectors:()=>[]},co2Tank:{type:`co2Tank`,label:`CO₂ Tank`,category:`Environment`,description:`CO₂ cylinder for sealed-room enrichment planning`,color:`#22c55e`,defaults:{pounds:20,regulatorCfh:20},params:{pounds:{label:`Tank size`,min:5,max:100,step:5,unit:`lb`},regulatorCfh:{label:`Release rate`,min:1,max:100,step:1,unit:`CFH`}},getConnectors:()=>[]},airCompressor:{type:`airCompressor`,label:`Air Compressor`,category:`Flow Control`,description:`Aerate reservoir water with an attached airstone`,color:`#0ea5e9`,defaults:{gph:120,frequency:5,on:1},params:{gph:{label:`Air Flow`,min:20,max:400,step:10,unit:`GPH`},frequency:{label:`Bubble Freq`,min:1,max:10,step:1,unit:`Hz`}},getConnectors:()=>[]},reducingTee:{type:`reducingTee`,label:`Reducing Tee`,category:`Plumbing`,description:`Tee branch with a reduced secondary outlet size`,color:`#8b9bb4`,defaults:{diameterA:1.5,diameterB:1},params:{diameterA:{label:`Main Run Diameter`,min:.5,max:4,step:.25,unit:`in`},diameterB:{label:`Branch Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.6,0,0],dir:[-1,0,0]},{id:`b`,pos:[.6,0,0],dir:[1,0,0]},{id:`c`,pos:[0,0,.6],dir:[0,0,1]}]},reducingElbow:{type:`reducingElbow`,label:`Reducing Elbow`,category:`Plumbing`,description:`90-degree elbow transitioning between two diameters`,color:`#9aa3b0`,defaults:{diameterA:1.5,diameterB:1},params:{diameterA:{label:`Diameter A`,min:.5,max:4,step:.25,unit:`in`},diameterB:{label:`Diameter B`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[0,0,0],dir:[-1,0,0]},{id:`b`,pos:[.18,.18,0],dir:[0,1,0]}]},bulkhead:{type:`bulkhead`,label:`Bulkhead Fitting`,category:`Plumbing`,description:`Tank wall pass-through connector`,color:`#27272a`,defaults:{diameter:1},params:{diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.2,0,0],dir:[-1,0,0]},{id:`b`,pos:[.2,0,0],dir:[1,0,0]}]},waterChiller:{type:`waterChiller`,label:`Water Chiller`,category:`Flow Control`,description:`Thermoelectric water chiller to keep reservoirs cool`,color:`#0891b2`,defaults:{targetTemp:68,on:1,diameter:1},params:{targetTemp:{label:`Target Temp`,min:45,max:80,step:1,unit:`°F`},diameter:{label:`Port Size`,min:.5,max:2,step:.25,unit:`in`}},getConnectors:()=>[{id:`in`,pos:[-.2,1.05,0],dir:[0,1,0]},{id:`out`,pos:[.2,1.05,0],dir:[0,1,0]}]},reverseOsmosis:{type:`reverseOsmosis`,label:`RO Filter`,category:`Plumbing`,description:`Reverse osmosis filter to purify source water`,color:`#3b82f6`,defaults:{diameter:1},params:{diameter:{label:`Diameter`,min:.5,max:4,step:.25,unit:`in`}},getConnectors:()=>[{id:`a`,pos:[-.3,0,0],dir:[-1,0,0]},{id:`b`,pos:[.3,0,0],dir:[1,0,0]}]}},Xx=[{name:`Plumbing`,types:[`pipe`,`coupling`,`reducer`,`cap`,`elbow`,`tee`,`reducingTee`,`reducingElbow`,`bulkhead`,`reverseOsmosis`]},{name:`Flow Control`,types:[`pump`,`reservoir`,`valve`,`emitter`,`drain`,`airCompressor`,`waterChiller`]},{name:`Growing`,types:[`tower`,`tray`,`wallPanel`,`netPot`]},{name:`Structure`,types:[`lattice`]},{name:`Environment`,types:[`growTent`,`inlineFan`,`circulationFan`,`growLight`,`co2Tank`]}],Zx=new Set([`pipe`,`coupling`,`reducer`,`cap`,`elbow`,`tee`,`valve`,`pump`,`reservoir`,`tower`,`tray`,`wallPanel`,`emitter`,`drain`,`reducingTee`,`reducingElbow`,`bulkhead`,`waterChiller`,`reverseOsmosis`]),Qx=new Set([`pipe`,`coupling`,`reducer`,`elbow`,`tee`,`valve`,`pump`,`reducingTee`,`reducingElbow`,`bulkhead`,`waterChiller`,`reverseOsmosis`]),$x=.8,eS=new pr,tS=new q;function nS(e){let t=Yx[e.type];return eS.set(e.rotation[0],e.rotation[1],e.rotation[2],`XYZ`),t.getConnectors(e.params).map(t=>{let n=tS.set(...t.pos).applyEuler(eS).toArray();n[0]+=e.position[0],n[1]+=e.position[1],n[2]+=e.position[2];let r=new q(...t.dir).applyEuler(eS).toArray();return{key:`${e.id}:${t.id}`,partId:e.id,connectorId:t.id,partType:e.type,pos:n,dir:r}})}var rS=(e,t)=>Math.hypot(e[0]-t[0],e[1]-t[1],e[2]-t[2]);function iS(e,t){let n=nS(e);if(!n.length)return null;let r=null;for(let i of t)if(i.id!==e.id)for(let e of nS(i))for(let t of n){let n=rS(t.pos,e.pos);n<.8&&(!r||ne.connectorId===`a`),o=t.find(e=>e.connectorId===`b`);if(!a||!o)continue;let s=a.pos[0],c=a.pos[2],l=o.pos[0],u=o.pos[2],d=l-s,f=u-c,p=d*d+f*f;if(p<1e-6)continue;let m=e[0]-s,h=e[2]-c,g=(m*d+h*f)/p;if(g<=.15||g>=.85)continue;let _=s+d*g,v=c+f*g,y=Math.hypot(e[0]-_,e[2]-v);if(y>n)continue;let b=i.rotation[1],x=e[0]-_,S=e[2]-v,C=Math.atan2(-S,x)-b,w=b+Math.round(C/(Math.PI/2))*(Math.PI/2)+Math.PI/2;w=Math.atan2(Math.sin(w),Math.cos(w));let T=nS({id:`__tap__`,type:`tee`,position:[_,i.position[1],v],rotation:[0,w,0],params:{...Yx.tee.defaults,diameter:i.params.diameter??1}}).find(e=>e.connectorId===`c`);if(!T)continue;let E={partId:i.id,pos:[_,i.position[1],v],branchPos:T.pos,rotationY:w,diameter:i.params.diameter??1,d:y};(!r||y0:!1}function fS(e,t){let[n,r,i]=e.position,a=e.params??{},o=.2,s=[e.position,...t.map(e=>e.pos)],c=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];for(let e of s)for(let t=0;t<3;t++)c[t]=Math.min(c[t],e[t]-o),l[t]=Math.max(l[t],e[t]+o);let u=(a.width??0)/2;u>0&&(c[0]=Math.min(c[0],n-u),l[0]=Math.max(l[0],n+u));let d=(a.length??0)/2;d>0&&(c[0]=Math.min(c[0],n-d),l[0]=Math.max(l[0],n+d));let f=(a.depth??a.width??0)/2;return f>0&&(c[2]=Math.min(c[2],i-f),l[2]=Math.max(l[2],i+f)),(a.height??0)>0&&(c[1]=Math.min(c[1],r),l[1]=Math.max(l[1],r+a.height)),{min:c,max:l}}var pS=class{parent=new Map;find(e){let t=this.parent.get(e)??e;return t!==e&&(t=this.find(t),this.parent.set(e,t)),t}union(e,t){let n=this.find(e),r=this.find(t);n!==r&&this.parent.set(n,r)}};function mS(e){let t=new Map,n=[];for(let r of e){let e=cS(r);t.set(r.id,e),n.push(...e)}let r=[],i=new Set,a=new pS;for(let e=0;e{let n=o.get(e);n||o.set(e,n=new Set),n.add(t)};for(let{a:e,b:t}of r)s(e.partId,t.partId),s(t.partId,e.partId);let c=[],l=new Map;for(let n of e){if(!t.get(n.id)?.length||l.has(n.id))continue;let e=new Set,r=[n.id];for(l.set(n.id,c.length);r.length;){let t=r.pop();e.add(t);for(let e of o.get(t)??[])l.has(e)||(l.set(e,c.length),r.push(e))}c.push(e)}let u=new Map,d=new Map,f=(e,t)=>{let n=u.get(e);return n||(n={id:e,pos:t,edges:[]},u.set(e,n)),n};for(let n of e){let e=t.get(n.id)??[];if(!e.length)continue;let r=f(`P:${n.id}`,n.position);for(let t of e){let e=`N:${a.find(t.key)}`;d.set(t.key,e),f(e,t.pos).edges.push({to:r.id,partId:n.id}),r.edges.push({to:e,partId:n.id})}}return{connectorsByPart:t,joints:r,joinedKeys:i,neighbors:o,componentOf:l,components:c,nodes:u,nodeOfConnector:d}}var hS=()=>Math.random().toString(36).substring(2,10);function gS(e){if(e.type!==`growTent`&&e.type!==`reservoir`&&e.type!==`tray`&&e.type!==`wallPanel`&&e.type!==`tower`)return null;let t=1,n=1,r=1;e.type===`tray`?(t=e.params.length??3,n=e.params.width??1.2,r=.25):e.type===`wallPanel`?(t=e.params.width??3,n=.5,r=e.params.height??4):e.type===`tower`?(t=1,n=1,r=e.params.height??4):(t=e.params.width??2,n=e.params.depth??1.4,r=e.params.height??1);let i=new ni(new q(-t/2,0,-n/2),new q(t/2,r,n/2)),a=new q(...e.position),o=new pr(...e.rotation,`XYZ`),s=new J().compose(a,new Mn().setFromEuler(o),new q(1,1,1));return i.applyMatrix4(s),i}function _S(e,t,n){let r=e instanceof q?e.clone():new q(...e),i=t instanceof q?t.clone():new q(...t),a=Math.round(r.x*2),o=Math.round(r.y*2),s=Math.round(r.z*2),c=Math.round(i.x*2),l=Math.round(i.y*2),u=Math.round(i.z*2),d=`${a},${o},${s}`,f=`${c},${l},${u}`,p=Math.min(a,c)-12,m=Math.max(a,c)+12,h=Math.min(o,l)-12,g=Math.max(o,l)+12,_=Math.min(s,u)-12,v=Math.max(s,u)+12;h=Math.max(h,-4);for(let e of n)p=Math.min(p,Math.round((e.min.x-2)*2)),m=Math.max(m,Math.round((e.max.x+2)*2)),h=Math.min(h,Math.round((e.min.y-2)*2)),g=Math.max(g,Math.round((e.max.y+2)*2)),_=Math.min(_,Math.round((e.min.z-2)*2)),v=Math.max(v,Math.round((e.max.z+2)*2));let y=new Set([d]),b=new Map,x=new Map,S=new Map;x.set(d,0);let C=(e,t,n,r,i,a)=>Math.abs(e-r)+Math.abs(t-i)+Math.abs(n-a);S.set(d,C(a,o,s,c,l,u));let w=0;for(;y.size>0&&(w++,!(w>3e4));){let e=``,t=1/0;for(let n of y){let r=S.get(n)??1/0;r.05&&a.push(e);return a[a.length-1].distanceTo(i)>.05&&a.push(i.clone()),a}y.delete(e);let w=[[a+1,o,s],[a-1,o,s],[a,o+1,s],[a,o-1,s],[a,o,s+1],[a,o,s-1]];for(let[t,r,i]of w){if(tm||rg||i<_||i>v)continue;let w=`${t},${r},${i}`,T=new q(t/2,r/2,i/2);if(w!==f&&w!==d){let e=!1;for(let t of n)if(t.clone().expandByScalar(.08).containsPoint(T)){e=!0;break}if(e)continue}let E=x.get(e)??1/0,D=t-a,O=r-o,k=i-s,A=!1,j=b.get(e);if(j){let[e,t,n]=j.split(`,`).map(Number),r=a-e,i=o-t,c=s-n;(r!==D||i!==O||c!==k)&&(A=!0)}let M=E+(.5+(A?5:0));M<(x.get(w)??1/0)&&(b.set(w,e),x.set(w,M),S.set(w,M+C(t,r,i,c,l,u)),y.add(w))}}return null}function vS(e,t,n){if(e.length<2)return[];let r=[e[0]];for(let t=1;t.05){let e=l.clone().add(u).multiplyScalar(.5),r=new Mn().setFromUnitVectors(new q(1,0,0),c),a=new pr().setFromQuaternion(r,`XYZ`);i.push({id:`pipe-${hS()}`,type:`pipe`,position:[e.x,e.y,e.z],rotation:[a.x,a.y,a.z],params:{length:d,diameter:t},roomId:n})}if(a[e+1]){let a=s,o=r[e+2],l=c,u=o.clone().sub(a).normalize(),d=a.clone().addScaledVector(l,-.5),f=new J().makeBasis(l,u,new q().crossVectors(l,u).normalize()),p=new pr().setFromRotationMatrix(f,`XYZ`);i.push({id:`elbow-${hS()}`,type:`elbow`,position:[d.x,d.y,d.z],rotation:[p.x,p.y,p.z],params:{angle:90,diameter:t},roomId:n})}}return i}var yS=Sy((e,t)=>({toasts:[],addToast:(n,r)=>{let i=typeof crypto.randomUUID==`function`?crypto.randomUUID().slice(0,8):Math.random().toString(36).substring(2,10);e({toasts:[...t().toasts,{id:i,message:n,type:r}]}),setTimeout(()=>t().dismissToast(i),3e3)},dismissToast:n=>{e({toasts:t().toasts.map(e=>e.id===n?{...e,exiting:!0}:e)}),setTimeout(()=>e({toasts:t().toasts.filter(e=>e.id!==n)}),300)}})),bS=yS.getState().addToast,xS={success:`border-l-emerald-500`,error:`border-l-rose-500`,info:`border-l-sky-500`};function SS(){let e=yS(e=>e.toasts),t=yS(e=>e.dismissToast);return e.length===0?null:(0,Z.jsx)(`div`,{className:`pointer-events-none fixed bottom-4 right-4 z-[200] flex flex-col-reverse gap-2`,children:e.map(e=>(0,Z.jsx)(CS,{toast:e,onDismiss:t},e.id))})}function CS({toast:e,onDismiss:t}){return(0,Z.jsxs)(`div`,{className:`pointer-events-auto flex items-start gap-2 rounded-lg border-l-4 bg-zinc-900 px-4 py-3 shadow-2xl ${xS[e.type]} ${e.exiting?`animate-toast-out`:`animate-toast-in`}`,children:[(0,Z.jsx)(`span`,{className:`text-sm text-zinc-200`,children:e.message}),(0,Z.jsx)(`button`,{onClick:()=>t(e.id),className:`ml-2 shrink-0 text-zinc-500 hover:text-zinc-200 transition cursor-pointer text-xs leading-none mt-0.5`,children:`✕`})]})}var wS=()=>crypto.randomUUID().slice(0,8),TS=new Mn,ES=new pr,DS=new q,OS=new q,kS=1,AS=.18,jS=new Set([`inlineFan`,`circulationFan`,`growLight`,`co2Tank`]),MS={tag:``,time:0},NS=(e,t)=>Math.round(e/t)*t;function PS(e,t,n){return t===`diameter`||t===`diameterA`||t===`diameterB`?Jx(n):n}function FS(e,t,n){return Math.max(t,Math.min(n,e))}function IS(e,t,n){if(!jS.has(e.type))return null;let r=null;for(let i of Object.values(n)){if(i.id===e.id||i.type!==`growTent`||i.roomId!==e.roomId)continue;let n=i.params.width??0,a=i.params.depth??0,o=i.params.height??0,s=Math.max(0,Math.abs(t[0]-i.position[0])-n/2),c=Math.max(0,Math.abs(t[2]-i.position[2])-a/2),l=t[1]i.position[1]+o?t[1]-(i.position[1]+o):0,u=s+c+l,d=s<=kS&&c<=kS&&l<=Math.max(kS,o);(t[0]>=i.position[0]-n/2&&t[0]<=i.position[0]+n/2&&t[2]>=i.position[2]-a/2&&t[2]<=i.position[2]+a/2&&t[1]>=i.position[1]&&t[1]<=i.position[1]+o||d)&&(!r||ue.d-t.d)[0]?.kind;return e.type===`inlineFan`?v===`left`?{position:[c,Math.max(f+.5,p-.45),FS(t[2],u+.25,d-.25)],rotation:[0,0,0]}:v===`right`?{position:[l,Math.max(f+.5,p-.45),FS(t[2],u+.25,d-.25)],rotation:[0,Math.PI,0]}:v===`front`?{position:[FS(t[0],c+.25,l-.25),Math.max(f+.5,p-.45),u],rotation:[0,-Math.PI/2,0]}:{position:[FS(t[0],c+.25,l-.25),Math.max(f+.5,p-.45),d],rotation:[0,Math.PI/2,0]}:e.type===`circulationFan`?v===`left`?{position:[c,f+s*.6,FS(t[2],u+.35,d-.35)],rotation:[0,0,0]}:v===`right`?{position:[l,f+s*.6,FS(t[2],u+.35,d-.35)],rotation:[0,Math.PI,0]}:v===`front`?{position:[FS(t[0],c+.35,l-.35),f+s*.6,u],rotation:[0,-Math.PI/2,0]}:{position:[FS(t[0],c+.35,l-.35),f+s*.6,d],rotation:[0,Math.PI/2,0]}:null}function RS(e,t,n){let r=t.type===`reducer`?e.connectorId===`a`?t.params.diameterA:t.params.diameterB:t.params.diameter??Yx.cap.defaults.diameter??1,i=new q(-e.dir[0],-e.dir[1],-e.dir[2]).normalize();return TS.setFromUnitVectors(new q(-1,0,0),i),ES.setFromQuaternion(TS,`XYZ`),DS.set(-.22,0,0).applyQuaternion(TS),OS.set(e.pos[0],e.pos[1],e.pos[2]).sub(DS),{id:wS(),type:`cap`,position:[OS.x,OS.y,OS.z],rotation:[ES.x,ES.y,ES.z],params:{...Yx.cap.defaults,diameter:r},roomId:n??t.roomId}}function zS(e,t,n){let r=new q(-e.dir[0],-e.dir[1],-e.dir[2]).normalize();return TS.setFromUnitVectors(new q(1,0,0),r),ES.setFromQuaternion(TS,`XYZ`),DS.set(.2,0,0).applyQuaternion(TS),OS.set(e.pos[0],e.pos[1],e.pos[2]).sub(DS),{id:wS(),type:`emitter`,position:[OS.x,OS.y,OS.z],rotation:[ES.x,ES.y,ES.z],params:{...Yx.emitter.defaults},label:`${t.label??Yx[t.type].label} outlet`,roomId:n??t.roomId}}var Q=Sy((e,t)=>({parts:{},selectedIds:[],placingType:null,draggingId:null,gizmoDragging:!1,snapTargetKey:null,colorPopover:null,tool:`select`,viewMode:`orbit`,renderMode:`builder`,showFlow:!0,heatmapMode:!1,simRunning:!0,snapToGrid:!0,gridSize:.25,measurePoints:[],pipeRunPoints:[],projectName:`Untitled system`,growthStage:`vegetative`,focusTarget:null,scene:null,rooms:[{id:`room-1`,name:`Room 1`}],activeRoomId:`room-1`,past:[],future:[],pushHistory:(t=``)=>{let n=Date.now();if(t&&t===MS.tag&&n-MS.time<400){MS.time=n;return}MS={tag:t,time:n},e(e=>({past:[...e.past.slice(-99),e.parts],future:[]}))},undo:()=>e(e=>{if(!e.past.length)return e;let t=e.past[e.past.length-1];return{parts:t,past:e.past.slice(0,-1),future:[e.parts,...e.future],selectedIds:e.selectedIds.filter(e=>t[e])}}),redo:()=>e(e=>{if(!e.future.length)return e;let t=e.future[0];return{parts:t,past:[...e.past,e.parts],future:e.future.slice(1),selectedIds:e.selectedIds.filter(e=>t[e])}}),addRoom:t=>{let n=wS();e(e=>({rooms:[...e.rooms,{id:n,name:t}],activeRoomId:n}))},removeRoom:n=>{let r=t();if(r.rooms.length<=1)return;r.pushHistory(`remove-room`);let i=r.rooms.filter(e=>e.id!==n),a=r.activeRoomId===n?i[0].id:r.activeRoomId,o=Object.fromEntries(Object.entries(r.parts).filter(([e,t])=>t.roomId!==n));e({rooms:i,activeRoomId:a,parts:o,selectedIds:r.selectedIds.filter(e=>o[e])})},setActiveRoomId:t=>e({activeRoomId:t}),syncParts:t=>e({parts:t}),addPart:(n,r,i)=>{t().pushHistory();let a=wS(),o={id:a,type:n,position:r,rotation:[0,0,0],params:{...Yx[n].defaults},roomId:t().activeRoomId},s=LS(o,o.position,o.rotation,t().parts);return s&&(o={...o,...s}),e(e=>({parts:{...e.parts,[a]:o},selectedIds:[a]})),i?.snap!==!1&&t().snapPartToConnectors(a),a},spawnPipeAtConnector:n=>{let r=t(),[i,a]=n.split(`:`),o=r.parts[i];if(!o)return;let s=nS(o).find(e=>e.connectorId===a);if(!s)return;r.pushHistory(`spawn-pipe`);let c=wS(),l=o.params.diameter??1,u=new Mn().setFromUnitVectors(new q(1,0,0),new q(...s.dir).normalize()),d=new pr().setFromQuaternion(u,`XYZ`),f={id:c,type:`pipe`,position:[s.pos[0]+s.dir[0]*(2/2),s.pos[1]+s.dir[1]*(2/2),s.pos[2]+s.dir[2]*(2/2)],rotation:[d.x,d.y,d.z],params:{length:2,diameter:l},roomId:r.activeRoomId};e(e=>({parts:{...e.parts,[c]:f},selectedIds:[c]}))},extendPipeRun:(n,r)=>{let i=t(),a=i.pipeRunPoints,o={},s=new Set,c=(e,t,n,r)=>{let i=t[0]-e[0],a=t[2]-e[2],o=Math.hypot(i,a);return o<.1?null:{...r,id:wS(),position:[(e[0]+t[0])/2,r.position[1],(e[2]+t[2])/2],rotation:[0,Math.atan2(-a,i),0],params:{...r.params,length:o,diameter:n}}},l=e=>{if(!e.tapPipeId||e.tapRotationY===void 0)return e;let t=i.parts[e.tapPipeId];if(!t||t.type!==`pipe`)return e;let n=wS(),r={id:n,type:`tee`,position:e.pos,rotation:[0,e.tapRotationY,0],params:{...Yx.tee.defaults,diameter:e.tapDiameter??Yx.tee.defaults.diameter??1},roomId:i.activeRoomId};o[n]=r;let a=nS(r),l=a.find(e=>e.connectorId===`c`),u=a.find(e=>e.connectorId===`a`),d=a.find(e=>e.connectorId===`b`),f=nS(t),p=f.find(e=>e.connectorId===`a`),m=f.find(e=>e.connectorId===`b`);if(u&&d&&p&&m){s.add(t.id);let e=c(p.pos,u.pos,r.params.diameter??1,t),n=c(d.pos,m.pos,r.params.diameter??1,t);e&&(o[e.id]=e),n&&(o[n.id]=n)}return{pos:l?l.pos:e.pos,connectorKey:l?.key??`${n}:c`}};if(a.length===0){let t=l(n);Object.keys(o).length>0?(i.pushHistory(`pipe-run-start`),e(e=>({parts:{...Object.fromEntries(Object.entries(e.parts).filter(([e])=>!s.has(e))),...o},pipeRunPoints:[t],selectedIds:Object.keys(o)}))):e({pipeRunPoints:[t]});return}let u=a[a.length-1],d=l(n),f=d.pos[0]-u.pos[0],p=d.pos[2]-u.pos[2],m=Math.hypot(f,p);if(m<1e-6)return;i.pushHistory(`pipe-run`);let h=Yx.pipe.params.length,g=Math.min(h.max,Math.max(h.min,m)),_=Math.atan2(-p,f),v=e=>{if(!e)return;let[t,n]=e.split(`:`),r=i.parts[t];if(r)return r.type===`reducer`?n===`a`?r.params.diameterA:r.params.diameterB:r.params.diameter},y=v(u.connectorKey),b=v(d.connectorKey),x=y??b??Yx.pipe.defaults.diameter??1,S=wS();if(o[S]={id:S,type:`pipe`,position:[(u.pos[0]+d.pos[0])/2,.25,(u.pos[2]+d.pos[2])/2],rotation:[0,_,0],params:{...Yx.pipe.defaults,length:g,diameter:x},roomId:i.activeRoomId},a.length>=2){let e=a[a.length-2],t=u.pos[0]-e.pos[0],n=u.pos[2]-e.pos[2],r=Math.hypot(t,n);if((r>1e-6?(t*f+n*p)/(r*m):1)<.96){let e=wS();o[e]={id:e,type:`elbow`,position:[u.pos[0],.25,u.pos[2]],rotation:[Math.PI/2,Math.atan2(-n,t)+Math.PI,0],params:{...Yx.elbow.defaults,angle:90,diameter:x},roomId:i.activeRoomId}}}if(b!==void 0&&Math.abs(b-x)>1e-6){let e=wS(),t=Math.cos(_),n=-Math.sin(_);o[e]={id:e,type:`reducer`,position:[d.pos[0]-t*.35,.25,d.pos[2]-n*.35],rotation:[0,_,0],params:{...Yx.reducer.defaults,diameterA:x,diameterB:b},roomId:i.activeRoomId}}e(e=>({parts:{...Object.fromEntries(Object.entries(e.parts).filter(([e])=>!s.has(e))),...o},selectedIds:[S],pipeRunPoints:r?[...a,d]:[]}))},updatePart:(t,n)=>e(e=>{let r=e.parts[t];if(!r)return e;let i={...r,...n};if(n.position&&jS.has(r.type)){let t=LS(i,n.position,n.rotation??i.rotation,e.parts);t&&(i={...i,...t})}return{parts:{...e.parts,[t]:i}}}),setParam:(n,r,i)=>{t().pushHistory(`param:${n}:${r}`),e(e=>{let t=e.parts[n];if(!t)return e;let a=PS(t,r,i);return{parts:{...e.parts,[n]:{...t,params:{...t.params,[r]:a}}}}})},removeParts:n=>{n.length&&(t().pushHistory(),e(e=>{let t=new Set(n);return{parts:Object.fromEntries(Object.entries(e.parts).filter(([e])=>!t.has(e))),selectedIds:e.selectedIds.filter(e=>!t.has(e))}}))},duplicateParts:(n,r)=>{let i=t(),a=n.map(e=>i.parts[e]).filter(Boolean);if(!a.length)return[];i.pushHistory();let o=r?.offset??[1,0,1],s=a.map(e=>({...e,id:wS(),position:[e.position[0]+o[0],e.position[1]+o[1],e.position[2]+o[2]],rotation:[...e.rotation],params:{...e.params},roomId:i.activeRoomId}));return e(e=>({parts:{...e.parts,...Object.fromEntries(s.map(e=>[e.id,e]))},selectedIds:s.map(e=>e.id)})),s.map(e=>e.id)},rotateParts:(n,r,i)=>{n.length&&(t().pushHistory(`rotate:${n.join(`+`)}`),e(e=>{let t={...e.parts};for(let e of n){let n=t[e];if(!n)continue;let a=[...n.rotation];a[r]+=i,t[e]={...n,rotation:a}}return{parts:t}}))},translateParts:(n,r,i)=>{if(!n.length)return;let a=t();i&&a.pushHistory(i);let o=1/0;for(let e of n){let t=a.parts[e];t&&(o=Math.min(o,t.position[1]))}let s=Number.isFinite(o)?Math.max(r[1],-o):r[1];e(e=>{let t={...e.parts};for(let e of n){let n=t[e];if(!n)continue;let i={...n,position:[n.position[0]+r[0],n.position[1]+s,n.position[2]+r[2]]},a=LS(i,i.position,i.rotation,t);a&&(i={...i,...a}),t[e]=i}return{parts:t}})},setPositions:t=>e(e=>{let n={...e.parts};for(let[e,r]of Object.entries(t)){let t=n[e];if(!t)continue;let i={...t,position:r},a=LS(i,r,i.rotation,n);a&&(i={...i,...a}),n[e]=i}return{parts:n}}),setPipeStretch:(t,n,r)=>e(e=>{let i=e.parts[t];return!i||i.type!==`pipe`?e:{parts:{...e.parts,[t]:{...i,position:n,params:{...i.params,length:r}}}}}),applyColor:(n,r)=>{n.length&&(t().pushHistory(`color:${n.join(`+`)}`),e(e=>{let t={...e.parts};for(let e of n){let n=t[e];if(!n)continue;let i={...n};r===void 0?delete i.color:i.color=r,t[e]=i}return{parts:t}}))},snapPartToConnectors:e=>{let n=t(),r=n.parts[e];if(!r)return;let i=iS(r,Object.values(n.parts));i&&n.updatePart(e,{position:[r.position[0]+i[0],r.position[1]+i[1],r.position[2]+i[2]]})},snapGroupToConnectors:(e,n)=>{let r=t(),i=r.parts[n];if(!i)return;let a=new Set(e),o=iS(i,Object.values(r.parts).filter(e=>!a.has(e.id)));o&&r.translateParts(e,o)},selectConnectedRun:n=>{let r=t(),i=Object.values(r.parts);if(!r.parts[n])return;let a=mS(i),o=a.componentOf.get(n);if(o===void 0){e({selectedIds:[n]});return}let s=a.components[o],c=i.filter(e=>s.has(e.id)&&(a.connectorsByPart.get(e.id)?.length??0)>0).map(e=>e.id);e({selectedIds:c.length?c:[n]})},autoCapOpenEnds:()=>{let n=t(),r=Object.values(n.parts),i=mS(r),a=[];for(let e of r){if(!Qx.has(e.type)||e.type===`pump`)continue;let t=i.connectorsByPart.get(e.id)??[];for(let n of t)i.joinedKeys.has(n.key)||a.push(RS(n,e))}return a.length?(n.pushHistory(`auto-cap`),e(e=>({parts:{...e.parts,...Object.fromEntries(a.map(e=>[e.id,e]))},selectedIds:a.map(e=>e.id)})),a.length):0},fixDeadLeg:n=>{let r=t(),i=mS(Object.values(r.parts)),a=new Set(n),o=[...n];for(;o.length;){let e=o.shift();for(let t of i.neighbors.get(e)??[]){let e=r.parts[t];!e||a.has(t)||e.type===`pump`||e.type===`reservoir`||e.type===`drain`||(a.add(t),o.push(t))}}let s=null,c=[...a];for(let e=0;ei.joinedKeys.has(e.key)).length;for(let t of a)i.joinedKeys.has(t.key)||(!s||os.idx)&&(s={part:n,conn:t,joinedCount:o,idx:e})}if(s){let t=zS(s.conn,s.part);return r.pushHistory(`fix-dead-leg`),e(e=>({parts:{...e.parts,[t.id]:t},selectedIds:[t.id]})),t.id}return null},fixDiameterMismatch:n=>{let r=t(),i=n.map(e=>r.parts[e]).filter(e=>e?typeof e.params.diameter==`number`:!1);if(i.length<2)return null;let a=Math.max(...i.map(e=>e.params.diameter??0)),o=0;return r.pushHistory(`fix-diameter`),e(e=>{let t={...e.parts};for(let e of i)(e.params.diameter??0)!==a&&(t[e.id]={...e,params:{...e.params,diameter:a}},o++);return{parts:t,selectedIds:i.map(e=>e.id)}}),o},fixPumpDeadEnd:n=>{let r=t(),i=r.parts[n];if(!i||i.type!==`pump`)return null;let a=mS(Object.values(r.parts)),o=a.connectorsByPart.get(n)??[],s=o.find(e=>e.connectorId===`out`)??o[o.length-1];if(!s)return null;let c=new Set([n]),l=[];for(let{a:e,b:t}of a.joints)e.key===s.key&&l.push(t.partId),t.key===s.key&&l.push(e.partId);for(;l.length;){let e=l.shift();if(!c.has(e)){c.add(e);for(let t of a.neighbors.get(e)??[])!c.has(t)&&r.parts[t]?.type!==`reservoir`&&l.push(t)}}let u=null;for(let e of c){if(e===n)continue;let t=r.parts[e];if(!t)continue;let i=a.connectorsByPart.get(e)??[],o=i.filter(e=>a.joinedKeys.has(e.key)).length;for(let e of i){let n=!a.joinedKeys.has(e.key),r=t.type===`cap`&&a.joinedKeys.has(e.key);if(!n&&!r)continue;let i=(r?10:0)+(t.type===`cap`?5:0)-o;(!u||i>u.score)&&(u={part:t,conn:e,replace:r,score:i})}}if(!u)return null;let d=zS(u.conn,u.part,r.activeRoomId);return r.pushHistory(`fix-pump-dead-end`),e(e=>{let t={...e.parts};return u?.replace&&delete t[u.part.id],t[d.id]=d,{parts:t,selectedIds:[d.id]}}),d.id},selectAll:()=>e({selectedIds:Object.keys(t().parts)}),pasteParts:n=>{let r=t();if(!n.length)return[];r.pushHistory(`paste`);let i=[1,0,1],a=n.map(e=>({...e,id:wS(),position:[e.position[0]+i[0],e.position[1]+i[1],e.position[2]+i[2]],rotation:[...e.rotation],params:{...e.params},roomId:r.activeRoomId}));return e(e=>({parts:{...e.parts,...Object.fromEntries(a.map(e=>[e.id,e]))},selectedIds:a.map(e=>e.id)})),a.map(e=>e.id)},setSelected:t=>e({selectedIds:t?[t]:[]}),toggleSelected:t=>e(e=>({selectedIds:e.selectedIds.includes(t)?e.selectedIds.filter(e=>e!==t):[...e.selectedIds,t]})),setPlacingType:t=>e(e=>({placingType:t,selectedIds:t?[]:e.selectedIds})),setDraggingId:t=>e({draggingId:t}),setGizmoDragging:t=>e({gizmoDragging:t}),setSnapTargetKey:t=>e(e=>e.snapTargetKey===t?e:{snapTargetKey:t}),openColorPopover:(t,n)=>e({colorPopover:{x:t,y:n}}),closeColorPopover:()=>e({colorPopover:null}),setTool:t=>e({tool:t,placingType:null,measurePoints:[],pipeRunPoints:[]}),setViewMode:t=>e({viewMode:t}),setRenderMode:t=>e({renderMode:t}),toggleFlow:()=>e(e=>({showFlow:!e.showFlow})),toggleHeatmapMode:()=>e(e=>({heatmapMode:!e.heatmapMode})),toggleSimRunning:()=>e(e=>({simRunning:!e.simRunning})),toggleSnap:()=>e(e=>({snapToGrid:!e.snapToGrid})),addMeasurePoint:t=>e(e=>({measurePoints:e.measurePoints.length>=2?[t]:[...e.measurePoints,t]})),clearMeasure:()=>e({measurePoints:[]}),setFocusTarget:t=>e({focusTarget:t}),loadParts:(t,n)=>{let r=Array.from(new Set(t.map(e=>e.roomId).filter(Boolean)));r.length===0&&(r=[`room-1`]);let i=r.map((e,t)=>({id:e,name:e===`room-1`?`Room 1`:`Room ${t+1}`})),a=t.map(e=>({...e,roomId:e.roomId||`room-1`}));e({parts:Object.fromEntries(a.map(e=>[e.id,e])),selectedIds:[],placingType:null,colorPopover:null,pipeRunPoints:[],past:[],future:[],rooms:i,activeRoomId:r[0],...n?{projectName:n}:{}})},clearAll:()=>{t().pushHistory(),e({parts:{},selectedIds:[],colorPopover:null,pipeRunPoints:[],rooms:[{id:`room-1`,name:`Room 1`}],activeRoomId:`room-1`})},setProjectName:t=>e({projectName:t}),setGrowthStage:t=>e({growthStage:t}),setScene:t=>e({scene:t}),autoRoute:(n,r)=>{let i=t(),[a,o]=n.split(`:`),[s,c]=r.split(`:`),l=i.parts[a],u=i.parts[s];if(!l||!u)return;let d=nS(l),f=nS(u),p=d.find(e=>e.connectorId===o),m=f.find(e=>e.connectorId===c);if(!p||!m){bS(`Auto-route: connector not found.`,`error`);return}let h=[];for(let e of Object.values(i.parts)){if(e.id===a||e.id===s||e.roomId!==i.activeRoomId)continue;let t=gS(e);t&&h.push(t)}let g=_S(p.pos,m.pos,h);if(!g){bS(`No valid path found avoiding obstacles.`,`error`);return}let _=vS(g,l.params.diameter??l.params.diameterA??l.params.diameterB??1,i.activeRoomId);_.length>0?(i.pushHistory(`auto-route`),e(e=>{let t={...e.parts};for(let e of _)t[e.id]=e;return{parts:t,selectedIds:_.map(e=>e.id)}}),bS(`Path successfully routed with ${_.length} parts.`,`success`)):bS(`Path could not be converted to parts.`,`error`)}})),BS=.4,VS=new Set([`reservoir`,`emitter`,`drain`,`tower`,`tray`,`wallPanel`]),HS=class{parent=new Map;find(e){let t=this.parent.get(e)??e;return t!==e&&(t=this.find(t),this.parent.set(e,t)),t}union(e,t){let n=this.find(e),r=this.find(t);n!==r&&this.parent.set(n,r)}};function US(e){let t=e.params,n=Math.max(.25,t.diameter??1);switch(e.type){case`pipe`:return(t.length??2)/n**4;case`coupling`:return .15/n**2;case`reducer`:{let e=Math.max(.25,t.diameterA??1.5),n=Math.max(.25,t.diameterB??1),r=Math.min(e,n);return(.35+Math.abs(e-n)/Math.max(e,n))/r**2}case`cap`:return .25/n**2;case`elbow`:return 1.2*((t.angle??90)/90)/n**2;case`tee`:return .8/n**2;case`valve`:{let e=t.open??100;return e<=0?null:.3+(100-e)/e*8}case`tower`:return .5;case`tray`:return .3;case`wallPanel`:return .6;case`emitter`:return 1.5;case`drain`:return .6;default:return .1}}function WS(e){let t=e.params;switch(e.type){case`pipe`:return t.length??2;case`coupling`:return .6;case`reducer`:return .7;case`cap`:return .25;case`elbow`:return Ux*((t.angle??90)*Math.PI/180);case`tee`:return .9;case`valve`:return .7;case`pump`:return .9;case`reservoir`:return Math.max(t.width??2,t.depth??1.4)*.5;case`tower`:return t.height??4;case`tray`:return t.length??3;case`wallPanel`:return t.height??4;case`emitter`:return .4;case`drain`:return .4;default:return .5}}function GS(e){switch(e.type){case`pipe`:case`coupling`:case`reducer`:case`cap`:case`elbow`:case`tee`:case`valve`:return e.position[1]+Gx(e.params.diameter??e.params.diameterA??1);case`tray`:return e.position[1]+.24;case`tower`:return e.position[1]+.45;default:return e.position[1]+.25}}function KS(e,t,n){let r=e[0]-t[0],i=e[2]-t[2],a=n[0]-t[0],o=n[2]-t[2],s=a*a+o*o;if(s<=1e-6)return Math.hypot(r,i);let c=Math.max(0,Math.min(1,(r*a+i*o)/s)),l=t[0]+a*c,u=t[2]+o*c;return Math.hypot(e[0]-l,e[2]-u)}function qS(e,t){let n=nS(e);if(n.length>=2){if(e.type===`tee`)return Math.min(...n.map(n=>KS(t,e.position,n.pos)));let r=1/0;for(let e=0;eZx.has(e.type)),o=a.flatMap(nS),s=new HS,c=0;for(let e=0;e{let n=l.get(e);return n||(n={pos:t,edges:[],members:[]},l.set(e,n)),n};for(let e of a){let t=`P:${e.id}`;u(t,e.position);for(let n of nS(e)){let r=s.find(n.key),i=u(r,n.pos);i.members.push(n),i.edges.push({to:t,partId:e.id}),l.get(t).edges.push({to:r,partId:e.id})}}let d=(t,n,r)=>{let i=new Set([n,r]),a=[n];for(;a.length;){let n=a.shift();if(n.startsWith(`P:`)){let t=n.slice(2);if(e[t]?.type===`reservoir`)return t}for(let e of t.get(n)?.edges??[])i.has(e.to)||(i.add(e.to),a.push(e.to))}},f=[],p=new Map,m=e=>{f.push(e),p.has(e.u)||p.set(e.u,[]),p.has(e.v)||p.set(e.v,[]),p.get(e.u).push(e),p.get(e.v).push(e)},h=a.filter(e=>e.type===`pump`);a.filter(e=>e.type===`reservoir`);for(let e of a){let t=`P:${e.id}`,n=nS(e);if(e.type===`pump`){let n=(e.params.on??e.params.enabled??1)===0,r=s.find(`${e.id}:in`),i=s.find(`${e.id}:out`),a=e.params.gph??400,o=e.params.maxHeadFt??8;n?(m({u:r,v:t,partId:e.id,r:1e10,baseR:1e10,isPump:!1,pumpBoost:0,pumpMaxGph:0}),m({u:t,v:i,partId:e.id,r:1e10,baseR:1e10,isPump:!1,pumpBoost:0,pumpMaxGph:0})):(m({u:r,v:t,partId:e.id,r:.01,baseR:.01,isPump:!1,pumpBoost:0,pumpMaxGph:0}),m({u:t,v:i,partId:e.id,r:.01+o/a,baseR:.01+o/a,isPump:!0,pumpBoost:o,pumpMaxGph:a}))}else if(e.type===`reservoir`)for(let r of n)m({u:s.find(r.key),v:t,partId:e.id,r:.01,baseR:.01,isPump:!1,pumpBoost:0,pumpMaxGph:0});else{let r=US(e),i=r===null?1e10:Math.max(1e-4,r);for(let r of n)m({u:s.find(r.key),v:t,partId:e.id,r:i/2,baseR:i/2,isPump:!1,pumpBoost:0,pumpMaxGph:0})}}let g=new Set,_=new Map;for(let[t,n]of l.entries())if(t.startsWith(`P:`)){let n=e[t.slice(2)];n&&VS.has(n.type)&&(g.add(t),_.set(t,n.position[1]))}else n.members.length===1&&Qx.has(n.members[0].partType)&&(g.add(t),_.set(t,n.pos[1]));let v={};for(let[e,t]of l.entries())g.has(e)?v[e]=_.get(e):v[e]=t.pos[1];let y=a.filter(e=>e.type===`drain`),b=new Map;for(let e of y){let t=US(e)??.6;b.set(e.id,t)}let x=!1,S=new Map;for(let e=0;e<4;e++){for(let e=0;e<200;e++){let e=0;for(let[t,n]of l.entries()){if(g.has(t))continue;let n=v[t]??0,r=0,i=0,a=p.get(t)||[];for(let e of a){let n=v[e.u===t?e.v:e.u]??0,a=e.r,o=n;if(e.isPump){let n=e.pumpBoost,r=e.r,i=e.u,s=e.v,c=l.get(i).pos[1],u=l.get(s).pos[1],d=v[i]??0,f=v[s]??0;t===i?d+u-c+n-f>0?(a=r,o=f-u+c-n):(a=1e10,o=f):d+u-c+n-f>0?(a=r,o=d+u-c+n):(a=1e10,o=d)}r+=o/a,i+=1/a}if(i>0){let a=r/i;e=Math.max(e,Math.abs(a-n)),v[t]=a}}if(e<1e-5)break}for(let e of a)r[e.id]=0;for(let[e,t]of p.entries()){if(!e.startsWith(`P:`))continue;let n=e.slice(2),i=0;for(let e of t){let t=0,n=e.u,r=e.v,a=v[n]??0,o=v[r]??0;if(e.isPump){let i=e.pumpBoost,s=e.r,c=l.get(n).pos[1],u=l.get(r).pos[1];t=Math.max(0,(a+u-c+i-o)/s)}else{let n=e.r;t=Math.abs(a-o)/n}i+=t}r[n]=i/2}x=!1;for(let t of y){let n=r[t.id]??0;e===0&&S.set(t.id,n);let i=t.params.capacityGph??250;if(n>i*1.001){x=!0;let e=(n/i)**2,r=p.get(`P:`+t.id)||[];for(let n of r)n.r=(b.get(t.id)??.6)*e/2}}if(!x)break}let C=new Set,w=[];for(let e of y){let t=r[e.id]??0,i=S.get(e.id)??t,a=e.params.capacityGph??250,o=i>a*1.001;if(w.push({partId:e.id,inflowGph:o?i:t,capacityGph:a,overflowing:o}),o){n.push({level:`error`,partId:e.id,message:`${e.label??`Drain`} undersized: receiving ${Math.round(i)} GPH, capacity ${Math.round(a)} GPH — line is backing up.`});let t=new Set,r=[`P:`+e.id];for(t.add(`P:`+e.id);r.length>0;){let e=r.shift();e.startsWith(`P:`)&&C.add(e.slice(2));let n=p.get(e)||[];for(let i of n){let n=i.u===e?i.v:i.u;if(t.has(n))continue;let a=i.u,o=i.v,s=v[a]??0,c=v[o]??0,u=!1;if(i.isPump){let t=i.pumpBoost,n=i.r,r=l.get(a).pos[1],d=l.get(o).pos[1],f=Math.max(0,(s+d-r+t-c)/n);e===o&&f>.05&&(u=!0)}else e===o&&(s-c)/i.r>.05&&(u=!0),e===a&&(c-s)/i.r>.05&&(u=!0);u&&(t.add(n),r.push(n))}}}}let T=new Set;for(let t of h){if((r[t.id]??0)<=0)continue;let n=s.find(`${t.id}:out`),i=[n],a=new Set([`P:${t.id}`,n]);for(;i.length>0;){let t=i.shift(),n=l.get(t);if(n)for(let t of n.edges){let n=e[t.partId];if(n&&US(n)!==null&&(a.has(t.to)||(a.add(t.to),i.push(t.to)),t.to.startsWith(`P:`))){let e=t.to.slice(2);(r[e]??0)<.05&&n.type!==`pump`&&n.type!==`reservoir`&&T.add(e)}}}}if(T.size>0){n.push({level:`warning`,message:`${T.size} part${T.size>1?`s`:``} on a dead-end branch — water is trapped and backing up.`});for(let e of T)C.add(e)}let E=[];for(let t of h){let r=t.label??`Pump`,a=t.params.gph??400,o=t.params.maxHeadFt??8,c=`P:${t.id}`;if((t.params.on??t.params.enabled??1)===0){n.push({level:`info`,partId:t.id,message:`${r} is switched off.`}),E.push({pumpId:t.id,ratedGph:a,gph:0,headFt:0,maxHeadFt:o,resistance:0,running:!1,opPoint:{gph:0,headFt:0},phase:`continuous`});continue}let u=s.find(`${t.id}:in`),f=s.find(`${t.id}:out`),m=d(l,u,c),h=m!==void 0,g=(p.get(c)||[]).find(e=>e.isPump&&e.v===f),_=0,y=0;if(g&&h){let e=g.u,t=g.v,n=v[e]??0,r=v[t]??0,i=l.get(e).pos[1],a=l.get(t).pos[1];_=Math.max(0,(n+a-i+o-r)/g.r),y=Math.max(0,r-a-(n-i))}let b=new Set([c]),x=new Set,S=[f];b.add(f);let C=0,w=t.position[1],T=!1,D=!1,O=0,k=!1,A=nS(t).find(e=>e.connectorId===`out`);for(A&&!i.has(A.key)&&O++;S.length;){let n=S.shift(),r=l.get(n);if(r){w=Math.max(w,r.pos[1]),!n.startsWith(`P:`)&&r.members.length===1&&Qx.has(r.members[0].partType)&&r.members[0].partId!==t.id&&O++;for(let t of r.edges){if(t.to===c)continue;if(b.has(t.to)){!x.has(t.partId)&&t.to!==n&&(T=!0);continue}let r=e[t.partId];if(!x.has(t.partId)&&r){let e=US(r);if(e===null){D=!0;continue}C+=e,x.add(t.partId),VS.has(r.type)&&(k=!0)}b.add(t.to),S.push(t.to)}}}let j=x.size>0;if(h||n.push({level:`error`,partId:t.id,message:`${r}: inlet is not connected to a reservoir — no water source.`}),j||n.push({level:`error`,partId:t.id,message:`${r}: outlet is not connected to anything.`}),h&&j){let e=Math.max(0,w-t.position[1]);e>o?(_=0,n.push({level:`error`,partId:t.id,message:`${r} is too weak: system rises ${e.toFixed(1)} ft but max head is ${o} ft.`})):e>.65*o&&n.push({level:`warning`,partId:t.id,message:`${r}: high head (${e.toFixed(1)} / ${o} ft) — flow significantly reduced.`}),_>0&&_<.2*a&&n.push({level:`warning`,partId:t.id,message:`${r}: bottleneck — long/narrow pipes & fittings are choking flow (R=${C.toFixed(1)}).`}),O>0&&n.push({level:`warning`,partId:t.id,message:`${O} open pipe end${O>1?`s`:``} downstream — water will leak out.`}),!k&&O===0&&_>0&&n.push({level:`warning`,partId:t.id,message:`${r}: dead end — water has nowhere to go (no reservoir, emitter, drain or tray downstream).`}),D&&n.push({level:`info`,message:`A closed valve is blocking part of the network.`}),T&&n.push({level:`info`,message:`Loop detected — flow split is approximated.`})}E.push({pumpId:t.id,ratedGph:a,gph:_,headFt:y,maxHeadFt:o,resistance:C,running:_>.05,opPoint:{gph:_,headFt:y},phase:`continuous`,sourceReservoirId:m})}let D=[],O=new Set;for(let[t,n]of p.entries()){if(!t.startsWith(`P:`))continue;let i=t.slice(2),a=e[i];if(!a)continue;let o=r[i]??0;if(!(o<=.05))for(let e of n){let t=e.u,n=e.v,r=v[t]??0,s=v[n]??0,c=!0;if(e.isPump){let i=e.pumpBoost,a=e.r,o=l.get(t).pos[1];c=(r+l.get(n).pos[1]-o+i-s)/a>0}else c=r>s;let u=c?l.get(t).pos:l.get(n).pos,d=c?l.get(n).pos:l.get(t).pos,f=`${i}:${u.join(`,`)}:${d.join(`,`)}`;O.has(f)||(O.add(f),D.push({partId:i,from:u,to:d,gph:o,diameter:a.params.diameter??1}))}}let k={},A={},j={},M={},N={},P={},F={},I=0;for(let e of a)A[e.id]=WS(e);let L=new Set,ee=[];for(let e of h){if((r[e.id]??0)<=0)continue;let t=s.find(`${e.id}:out`),n=s.find(`${e.id}:in`);k[e.id]=0,j[e.id]=`in`,I=Math.max(I,A[e.id]),ee.push({nodeId:t,dist:A[e.id],fromPartId:e.id}),L.add(`P:${e.id}`),L.add(t),L.add(n)}for(;ee.length>0;){let{nodeId:t,dist:n,fromPartId:i}=ee.shift(),a=l.get(t);if(a){for(let t of a.edges)if(t.to.startsWith(`P:`)){let o=t.to.slice(2);if(!e[o]||(r[o]??0)<=.05)continue;if(!L.has(t.to)){L.add(t.to),k[o]=n,i&&(M[o]=i);let e=a.members.find(e=>e.partId===o);e&&(j[o]=e.connectorId),I=Math.max(I,n+A[o]),ee.push({nodeId:t.to,dist:n,fromPartId:o})}}else if(!L.has(t.to)){L.add(t.to);let e=n+(i?A[i]:0);ee.push({nodeId:t.to,dist:e,fromPartId:i})}}}for(let e of a){let t=r[e.id]??0;if(t<=0)continue;let n=Math.max(.25,e.params.diameter??1),i=Math.PI*(n/24)**2,a=t/7.48/3600;N[e.id]=a/i;let o=v[`P:${e.id}`]??e.position[1];if(P[e.id]=Math.max(0,(o-e.position[1])*.433),VS.has(e.type)){let n=F[e.id]??{inGph:0,exits:[],unlimited:!1};n.inGph+=t,n.unlimited=e.type===`reservoir`||e.type===`emitter`,F[e.id]=n}}for(let t of w){let n=e[t.partId];if(!n)continue;let r=M[t.partId];if(!r)continue;let i=F[r]??{inGph:0,exits:[],unlimited:!1};i.exits.push({partId:t.partId,type:n.type,capacityGph:t.capacityGph}),F[r]=i}let R=new Set([`pipe`,`coupling`,`reducer`,`cap`,`elbow`,`tee`,`valve`,`tray`,`tower`]),te=[];for(let e of t){if(e.type!==`netPot`)continue;let t=e.params.size??1,n=e.position[1]+.22*t,i=.24*t,o;for(let t of a){if(!R.has(t.type))continue;let a=r[t.id]??0;if(a<=.1||!C.has(t.id))continue;let s=qS(t,e.position);if(s>i)continue;let c=GS(t)+(P[t.id]??0)/.433;n-c>BS||(!o||so.inflow)&&(o={part:t,inflow:a,waterHeight:c,d:s})}o&&te.push({partId:e.id,sourcePartId:o.part.id,inflowGph:o.inflow,rimHeightFt:n,waterHeightFt:o.waterHeight,overflowing:o.waterHeight>=n-.02})}for(let e of te)e.overflowing&&n.push({level:`warning`,partId:e.partId,message:`Net pot is sitting over a backed-up line and will spill from the rim (${Math.round(e.inflowGph)} GPH below).`});return{flows:r,pumps:E,segments:D.filter(e=>e.gph>.05),warnings:n,connectedKeys:i,connectionCount:c,totalGph:E.reduce((e,t)=>e+t.gph,0),fillDistance:k,fillLength:A,totalPathLength:I,entryConnector:j,backedUp:C,drains:w,netPots:te,velocities:N,pressures:P,upstream:M,vesselIO:F,reservoirRuntime:{}}}function YS(){let e=Q(e=>e.parts),t=Q(e=>e.simRunning),[n,r]=(0,v.useState)(0),i=(0,v.useMemo)(()=>JS(e),[e]);return(0,v.useEffect)(()=>{if(!t)return;let e=window.setInterval(()=>r(e=>e+1),250);return()=>window.clearInterval(e)},[t]),(0,v.useMemo)(()=>tC(i,e,t,n),[i,e,t,n])}var XS=new Map,ZS=``;function QS(e){let t=e.params.width??2,n=e.params.depth??1.4,r=e.params.height??1;return Math.max(.1,t*n*r*7.48)}function $S(e){return QS(e)*((e.params.level??70)/100)}function eC(e){return Object.values(e).filter(e=>e.type===`reservoir`).map(e=>`${e.id}:${e.params.width}:${e.params.depth}:${e.params.height}:${e.params.level}`).sort().join(`|`)}function tC(e,t,n,r){let i=eC(t),a=Date.now();if(i!==ZS){ZS=i,XS.clear();for(let e of Object.values(t)){if(e.type!==`reservoir`)continue;let t=$S(e);XS.set(e.id,{current:t,initial:t,capacity:QS(e),lastTs:a})}}let o={},s={};for(let t of e.pumps)!t.sourceReservoirId||t.gph<=0||(s[t.sourceReservoirId]=(s[t.sourceReservoirId]??0)+t.gph);for(let i of Object.values(t)){if(i.type!==`reservoir`)continue;let t=$S(i),c=QS(i),l=XS.get(i.id)??{current:t,initial:t,capacity:c,lastTs:a};(Math.abs(l.initial-t)>1e-6||Math.abs(l.capacity-c)>1e-6)&&(l.initial=t,l.capacity=c,l.current=Math.min(c,t),l.lastTs=a);let u=e.vesselIO[i.id]?.inGph??0,d=s[i.id]??0,f=Math.max(0,d-u);if(n&&r>=0){let e=Math.max(0,a-l.lastTs)/36e5;e>0&&f>0&&(l.current=Math.max(0,l.current-f*e)),l.lastTs=a}else l.lastTs=a;XS.set(i.id,l);let p=l.current<=.01&&f>0;o[i.id]={partId:i.id,gallonsInitial:l.initial,gallonsCurrent:l.current,gallonsCapacity:l.capacity,netOutflowGph:f,minutesRemaining:f>0?l.current/f*60:null,empty:p}}let c=new Set(Object.values(o).filter(e=>e.empty).map(e=>e.partId));if(!c.size)return{...e,reservoirRuntime:o};let l=e.pumps.map(e=>!e.sourceReservoirId||!c.has(e.sourceReservoirId)?e:{...e,gph:0,running:!1,opPoint:{gph:0,headFt:e.headFt}}),u=new Set;for(let e of l)e.running||u.add(e.pumpId);let d=new Set;for(let[t]of Object.entries(e.flows)){let n=t,r=0;for(;n&&r++<200;){if(u.has(n)){d.add(t);break}n=e.upstream[n]}}for(let e of u)d.add(e);let f={...e.flows};for(let e of d)f[e]=0;let p=e.segments.map(e=>d.has(e.partId)?{...e,gph:0}:e).filter(e=>e.gph>0),m=[...e.warnings];for(let e of c){let n=t[e];m.push({level:`warning`,partId:e,message:`${n?.label??`Reservoir`} has run dry under load.`})}return{...e,totalGph:l.reduce((e,t)=>e+t.gph,0),pumps:l,flows:f,segments:p,warnings:m,reservoirRuntime:o}}function nC(e,t){let n=Object.values(t),r=e.params.width??2,i=e.params.depth??1.4,a=e.params.height??1,o=e.params.level??70,s=Math.max(1,r*i*a*(o/100)*7.48),c=0;for(let t of n)if(t.type===`airCompressor`&&(t.params.on??1)>0){let r=null,i=1/0;for(let e of n)if(e.type===`reservoir`){let n=Math.hypot(e.position[0]-t.position[0],e.position[1]-t.position[1],e.position[2]-t.position[2]);n0&&s>0){let e=c/s;l=5.5+3.7*(1-Math.exp(-e*2))}let u=0,d=0,f=[];for(let e of n)e.type===`pump`&&(e.params.on??1)>0?u++:e.type===`airCompressor`&&(e.params.on??1)>0?d++:e.type===`waterChiller`&&(e.params.on??1)>0&&f.push(e);let p=75+(u*.5+d*.2),m=p;f.length>0&&(m=p-(p-Math.min(...f.map(e=>e.params.targetTemp??68)))*.85);let h=!1,g=new Map,_=n.flatMap(e=>nS(e).map(t=>({...t,partId:e.id})));for(let e=0;e<_.length;e++)for(let t=e+1;t<_.length;t++){let n=_[e],r=_[t];n.partId!==r.partId&&rS(n.pos,r.pos)<.35&&(g.has(n.partId)||g.set(n.partId,[]),g.has(r.partId)||g.set(r.partId,[]),g.get(n.partId).push(r.partId),g.get(r.partId).push(n.partId))}let v=new Set([e.id]),y=[e.id];for(;y.length>0;){let e=y.shift();if(t[e]?.type===`reverseOsmosis`){h=!0;break}let n=g.get(e);if(n)for(let e of n)v.has(e)||(v.add(e),y.push(e))}let b=h?0:e.params.ec??1.2;return{id:e.id,label:e.label||`Reservoir #${e.id}`,volGal:s,activeAerationGph:c,tdo:l,tempF:m,ph:e.params.ph??6,ec:b}}var rC={grabOffset:[0,0,0],pushed:!1,mode:`body`,groupIds:[],startPositions:{},connectorKey:null,pipeStretch:null,planeKey:``,planeAnchor:[0,0,0]};function iC(e){let t=Q.getState(),n=t.parts[e.partId];if(!n)return;let r=t.selectedIds.includes(e.partId)?[...t.selectedIds]:[e.partId];rC.mode=e.mode,rC.connectorKey=e.connectorKey??null,rC.pipeStretch=null,rC.grabOffset=[e.grabPoint[0]-n.position[0],e.grabPoint[1]-n.position[1],e.grabPoint[2]-n.position[2]],rC.groupIds=r,rC.startPositions={};for(let e of r){let n=t.parts[e];n&&(rC.startPositions[e]=[...n.position])}if(e.mode===`handle`&&n.type===`pipe`&&e.connectorKey){let t=e.connectorKey.split(`:`)[1],r=t===`a`?`b`:t===`b`?`a`:null;if(r){let i=nS(n),a=i.find(e=>e.connectorId===t),o=i.find(e=>e.connectorId===r);if(a&&o){let t=a.pos[0]-o.pos[0],i=a.pos[1]-o.pos[1],s=a.pos[2]-o.pos[2],c=Math.hypot(t,i,s)||(n.params.length??2);rC.pipeStretch={anchorConnectorId:r,anchorPos:[...o.pos],axis:[t/c,i/c,s/c],startLength:n.params.length??c},rC.groupIds=[e.partId]}}}rC.pushed=!1,rC.planeKey=``,rC.planeAnchor=[...e.grabPoint],t.setDraggingId(e.partId)}var aC=new Map;function oC(e){return aC.get(e)}var sC=0,cC=0;function lC(e){cC=e,sC+=e}function uC(){cC=0}var dC=()=>sC,fC=()=>cC;function pC(e){let t=aC.get(e);return t||(t={fill:0,flow:0,backedUp:!1,overflow:!1,spill:!1,state:`empty`},aC.set(e,t)),t}var mC=Math.PI/2,hC=new Y(`#38bdf8`),gC=new Y(`#0c4a6e`),_C=new Y(`#f59e0b`),vC=new Y(`#ef4444`),yC=new Y(`#556b2f`),bC=new Y(`#1e2e0a`);function xC(e,t,n,r=!1,i=0,a=0){if(Q.getState().heatmapMode)if(a<5)e.color.copy(yC),e.emissive.copy(bC),e.emissiveIntensity=.12;else if(i>3)e.color.copy(vC),e.emissive.copy(vC).multiplyScalar(.5),e.emissiveIntensity=.5;else{let t=new Y(`#22c55e`),n=new Y(`#eab308`);if(i>=1){let r=Math.min(1,Math.max(0,(i-1)/2));e.color.copy(t).lerp(n,r)}else{let n=Math.min(1,Math.max(0,i));e.color.copy(yC).lerp(t,n)}e.emissive.copy(e.color).multiplyScalar(.4),e.emissiveIntensity=.3}else if(t?.backedUp){let t=.5+.5*Math.sin(n*5);e.color.copy(_C).lerp(vC,t),e.emissive.copy(_C),e.emissiveIntensity=.3+.35*t}else r?(e.color.copy(yC),e.emissive.copy(bC),e.emissiveIntensity=.12):(e.color.copy(hC),e.emissive.copy(gC),e.emissiveIntensity=.25)}var SC=e=>.4+Math.min(3,e/120),CC=null;function wC(){if(!CC){let e=document.createElement(`canvas`);e.width=64,e.height=256;let t=e.getContext(`2d`);t.fillStyle=`#0284c7`,t.fillRect(0,0,64,256);let n=(e,n,r)=>{t.strokeStyle=r,t.lineWidth=n,t.beginPath(),t.moveTo(e,0);for(let n=0;n<=256;n+=20){let r=e+Math.sin(n*.05)*6;t.lineTo(r,n)}t.stroke()};n(12,3,`#0369a1`),n(32,5,`#0ea5e9`),n(48,2,`#38bdf8`),n(22,4,`#7dd3fc`);let r=(e,n,r)=>{t.fillStyle=`rgba(255, 255, 255, 0.35)`,t.beginPath(),t.arc(e,n,r,0,Math.PI*2),t.fill(),t.strokeStyle=`rgba(255, 255, 255, 0.7)`,t.lineWidth=.8,t.stroke()};for(let e=0;e<24;e++){let e=Math.random()*64,n=Math.random()*256,i=1.2+Math.random()*2.2;r(e,n,i),t.fillStyle=`rgba(255, 255, 255, 0.15)`,t.fillRect(e-i/2,n-i*2,i,i*3)}CC=new hs(e),CC.wrapS=CC.wrapT=w}return CC}function TC(e){let t=(0,v.useMemo)(()=>{let t=wC().clone();return t.needsUpdate=!0,t.repeat.set(1,Math.max(1,Math.round(e))),t},[e]);return(0,v.useEffect)(()=>()=>t.dispose(),[t]),t}var EC=null;function DC(){if(!EC){let e=document.createElement(`canvas`);e.width=256,e.height=256;let t=e.getContext(`2d`);t.fillStyle=`#0284c7`,t.fillRect(0,0,256,256),t.strokeStyle=`#0369a1`,t.lineWidth=4;for(let e=20;e<240;e+=30)t.beginPath(),t.arc(128,128,e,0,Math.PI*2),t.stroke();t.strokeStyle=`#0ea5e9`,t.lineWidth=3;for(let e=35;e<240;e+=45)t.beginPath(),t.arc(128,128,e,0,Math.PI*1.5),t.stroke();t.strokeStyle=`#38bdf8`,t.lineWidth=2;for(let e=50;e<240;e+=60)t.beginPath(),t.arc(128,128,e,Math.PI*.5,Math.PI*1.8),t.stroke();let n=(e,n,r)=>{t.fillStyle=`rgba(255, 255, 255, 0.35)`,t.beginPath(),t.arc(e,n,r,0,Math.PI*2),t.fill(),t.strokeStyle=`rgba(255, 255, 255, 0.65)`,t.lineWidth=.5,t.stroke()};for(let e=0;e<50;e++){let e=Math.random()*256,r=Math.random()*256,i=1+Math.random()*3.5;n(e,r,i),t.fillStyle=`rgba(255, 255, 255, 0.12)`,t.fillRect(e-i,r-i*1.5,i*2,i*3)}EC=new hs(e),EC.wrapS=EC.wrapT=w}return EC}function OC(){let e=(0,v.useMemo)(()=>{let e=DC().clone();return e.needsUpdate=!0,e.repeat.set(2,2),e.center.set(.5,.5),e},[]);return(0,v.useEffect)(()=>()=>e.dispose(),[e]),e}function kC({partId:e,length:t,radius:n}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),a=TC(t*2),o=YS();return j_(()=>{let t=r.current,n=i.current;if(!t||!n)return;let s=oC(e),c=s?.fill??0;if(c<=.002){t.visible=!1;return}t.visible=!0,s?.entry,t.scale.y=Math.max(.002,c);let l=o.velocities[e]??0,u=s?.flow??0;if(u>0){let e=l>0?l/2.5:1;a.offset.y-=fC()*SC(u)*e*c,a.offset.x=Math.sin(dC()*6)*.08}else a.offset.x=0;xC(n,s,dC(),!1,l,u)}),(0,Z.jsxs)(`mesh`,{ref:r,rotation:[0,0,mC],visible:!1,renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[n,n,t,12]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:i,map:a,color:`#38bdf8`,transparent:!0,opacity:.88,roughness:.03,metalness:.18,emissive:`#0369a1`,emissiveIntensity:.5,depthWrite:!1})]})}function AC(){return(0,Z.jsx)(`meshStandardMaterial`,{color:`#38bdf8`,transparent:!0,opacity:0,roughness:.15,depthWrite:!1,emissive:`#0c4a6e`,emissiveIntensity:.25})}function jC({partId:e,maxOpacity:t=.85,children:n}){let r=(0,v.useRef)(null),i=YS();return j_(()=>{let n=r.current;if(!n)return;let a=oC(e),o=a?.fill??0;if(n.visible=o>.02,!n.visible)return;let s=dC(),c=a?.flow??0,l=i.pumps.some(e=>e.running)&&c<5,u=i.velocities[e]??0;n.traverse(e=>{let n=e.material;n?.isMeshStandardMaterial&&(n.opacity=t*o,xC(n,a,s,l,u,c))})}),(0,Z.jsx)(`group`,{ref:r,visible:!1,children:n})}function MC({partId:e,radius:t,arc:n}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),a=(0,v.useRef)(-1),o=YS();return j_(()=>{let s=r.current,c=i.current;if(!s||!c)return;let l=oC(e),u=l?.fill??0;if(u<=.02){s.visible=!1;return}s.visible=!0;let d=l?.entry!==`b`,f=Math.max(.05,n*u);Math.abs(a.current-f)>.04&&(s.geometry.dispose(),s.geometry=new il(Ux,t,10,20,f),a.current=f),s.rotation.z=d?-mC:-mC+n*(1-u);let p=l?.flow??0,m=o.pumps.some(e=>e.running)&&p<5,h=o.velocities[e]??0;xC(c,l,dC(),m,h,p),c.opacity=.88}),(0,Z.jsxs)(`mesh`,{ref:r,position:[0,Ux,0],rotation:[0,0,-mC],visible:!1,renderOrder:1,children:[(0,Z.jsx)(`torusGeometry`,{args:[Ux,t,10,20,n]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:i,color:`#38bdf8`,transparent:!0,opacity:0,roughness:.15,depthWrite:!1,emissive:`#0c4a6e`,emissiveIntensity:.25})]})}function NC({partId:e,radius:t}){let n=(0,v.useRef)(null),r=YS();return j_(()=>{let t=n.current;if(!t)return;let i=oC(e),a=i?.fill??0;if(t.visible=a>.02,!t.visible)return;let o=dC(),s=i?.entry??`a`,c=s===`a`||s===`b`||s===`c`?s:`a`,l=i?.flow??0,u=Math.min(1,a/.34),d=a<=.34?0:Math.min(1,(a-.34)/.66),f=Math.min(1,.55+l/900),p=i?.flow??0,m=r.pumps.some(e=>e.running)&&p<5,h=r.velocities[e]??0;t.children.forEach(e=>{let t=e,n=t.userData.role,r=t.material;if(!n||!r)return;if(xC(r,i,o,m,h,p),n===`core`){t.visible=u>.02,t.scale.setScalar(Math.max(.001,u)),r.opacity=.5+.3*u;return}let a=n===c,s=a?Math.max(u,d*.8):d*f;if(t.visible=s>.02,t.visible){if(n===`a`||n===`b`){t.scale.set(1,Math.max(.001,s),1);let e=n===`a`?-1:1;t.position.x=e*(.29+.29*s),t.position.z=0}else t.scale.set(1,Math.max(.001,s),1),t.position.x=0,t.position.z=.15+.15*s;r.opacity=a?.88:.72}})}),(0,Z.jsxs)(`group`,{ref:n,visible:!1,children:[(0,Z.jsxs)(`mesh`,{userData:{role:`a`},position:[-.58,0,0],rotation:[0,0,mC],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.58,12]}),(0,Z.jsx)(AC,{})]}),(0,Z.jsxs)(`mesh`,{userData:{role:`b`},position:[.58,0,0],rotation:[0,0,mC],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.58,12]}),(0,Z.jsx)(AC,{})]}),(0,Z.jsxs)(`mesh`,{userData:{role:`c`},position:[0,0,.3],rotation:[mC,0,0],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.3,12]}),(0,Z.jsx)(AC,{})]}),(0,Z.jsxs)(`mesh`,{userData:{role:`core`},renderOrder:1,children:[(0,Z.jsx)(`sphereGeometry`,{args:[t*1.28,12,12]}),(0,Z.jsx)(AC,{})]})]})}function PC({partId:e,radius:t}){return(0,Z.jsx)(jC,{partId:e,children:(0,Z.jsxs)(`mesh`,{rotation:[0,0,mC],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.66,12]}),(0,Z.jsx)(AC,{})]})})}var FC=e=>new Mn().setFromUnitVectors(new q(0,1,0),new q(...e).normalize());function IC({partId:e,dir:t,radius:n}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=(0,v.useRef)(null),s=(0,v.useMemo)(()=>FC(t),[t[0],t[1],t[2]]),c=YS();return j_(()=>{let t=r.current;if(!t)return;let s=oC(e),l=s?.fill??0,u=s?.flow??0,d=u>.1&&l>.35;if(t.visible=d,!d)return;let f=dC(),p=fC(),m=Math.min(1,u/600),h=.35+m*.55,g=c.pumps.some(e=>e.running)&&u<5,_=c.velocities[e]??0;i.current&&a.current&&(i.current.position.y=h/2,i.current.scale.set(1+m*.4,h,1+m*.4),a.current.opacity=.45+.25*Math.sin(f*10)*m,xC(a.current,s,f,g,_,u));let v=o.current;v&&v.children.forEach((e,t)=>{let r=(f*(1.5+m*2.5)+t*.23)%1;e.position.set(Math.sin(t*3.1+f*4)*n*.9*r,.12+r*(h+.35),Math.cos(t*2.7+f*3)*n*.9*r),e.scale.setScalar(.45+r*.65),e.rotation.x+=p*2})}),(0,Z.jsxs)(`group`,{ref:r,quaternion:s,visible:!1,children:[(0,Z.jsxs)(`mesh`,{ref:i,position:[0,.25,0],renderOrder:3,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[n*.28,n*.55,1,8,1,!0]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:a,color:`#7dd3fc`,transparent:!0,opacity:.5,roughness:.05,depthWrite:!1,side:2})]}),(0,Z.jsx)(`group`,{ref:o,children:Array.from({length:5},(e,t)=>(0,Z.jsxs)(`mesh`,{renderOrder:3,children:[(0,Z.jsx)(`sphereGeometry`,{args:[Math.max(.018,n*.22),6,6]}),(0,Z.jsx)(`meshStandardMaterial`,{color:`#bae6fd`,transparent:!0,opacity:.85,roughness:.05,depthWrite:!1})]},t))})]})}function LC({partId:e}){let t=(0,v.useRef)(null),n=(0,v.useRef)(null),r=(0,v.useRef)(null),i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=(0,v.useRef)(null),s=YS();return j_(()=>{let c=t.current;if(!c)return;let l=oC(e),u=l?.fill??0,d=l?.flow??0;if(c.visible=u>.05,!c.visible)return;let f=dC(),p=s.pumps.some(e=>e.running)&&d<5,m=s.velocities[e]??0;if(n.current&&(n.current.opacity=.75*u,xC(n.current,l,f,p,m,d)),r.current&&i.current&&(r.current.rotation.z+=fC()*(2.5+d/30),i.current.opacity=(d>0?.7:.25)*u),a.current&&o.current){let e=l?.overflow??!1;if(a.current.visible=e,e){let e=.5+.5*Math.sin(f*4.5);a.current.scale.setScalar(1+.18*e),o.current.opacity=.3+.3*e}}}),(0,Z.jsxs)(`group`,{ref:t,visible:!1,children:[(0,Z.jsxs)(`mesh`,{position:[0,.315,0],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.26,.2,.05,18]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:n,color:`#38bdf8`,transparent:!0,opacity:0,roughness:.1,depthWrite:!1})]}),(0,Z.jsxs)(`mesh`,{ref:r,position:[0,.35,0],rotation:[mC+.13,0,0],renderOrder:2,children:[(0,Z.jsx)(`torusGeometry`,{args:[.15,.025,6,24]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:i,color:`#bae6fd`,transparent:!0,opacity:0,roughness:.08,depthWrite:!1})]}),(0,Z.jsxs)(`mesh`,{ref:a,position:[0,.3,0],visible:!1,renderOrder:2,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.42,.47,.035,22]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:o,color:`#f59e0b`,transparent:!0,opacity:0,roughness:.25,depthWrite:!1,emissive:`#b45309`,emissiveIntensity:.5})]})]})}function RC({partId:e,length:t}){let n=(0,v.useRef)(null),r=(0,v.useRef)(null),i=(0,v.useRef)(null);return j_(()=>{let a=n.current;if(!a)return;let o=oC(e),s=o?.flow??0,c=s>0&&(o?.fill??0)>.4&&t>.1;if(a.visible=c,!c)return;let l=dC();r.current&&(r.current.opacity=.4+.12*Math.sin(l*9));let u=i.current;if(u){let e=1.2+s/150;u.children.forEach((n,r)=>{let i=(l*e+r*.37)%1;n.position.set(.06*Math.sin(r*2.4+l*2)*i,-.2-i*t,.06*Math.cos(r*1.7+l*2)*i),n.scale.setScalar(.6+.5*i)})}}),(0,Z.jsxs)(`group`,{ref:n,visible:!1,children:[(0,Z.jsxs)(`mesh`,{position:[0,-.2-t/2,0],renderOrder:1,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.025,.075,t,8,1,!0]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:r,color:`#7dd3fc`,transparent:!0,opacity:.45,roughness:.05,depthWrite:!1,side:2})]}),(0,Z.jsx)(`group`,{ref:i,children:Array.from({length:6},(e,t)=>(0,Z.jsxs)(`mesh`,{renderOrder:1,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.03,6,6]}),(0,Z.jsx)(`meshStandardMaterial`,{color:`#bae6fd`,transparent:!0,opacity:.85,roughness:.05,depthWrite:!1})]},t))})]})}function zC({partId:e,length:t,width:n}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),a=YS();return j_(()=>{let t=r.current,n=i.current;if(!t||!n)return;let o=oC(e),s=o?.fill??0;if(t.visible=s>.02,!t.visible)return;let c=dC();n.opacity=.55*s;let l=o?.flow??0;xC(n,o,c,a.pumps.some(e=>e.running)&&l<5,a.velocities[e]??0,l),t.position.y=.21+(l>0?.006*Math.sin(c*3):0)}),(0,Z.jsxs)(`mesh`,{ref:r,position:[0,.21,0],visible:!1,renderOrder:1,children:[(0,Z.jsx)(`boxGeometry`,{args:[t-.15,.1,n-.15]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:i,color:`#38bdf8`,transparent:!0,opacity:0,roughness:.15,depthWrite:!1})]})}function BC({partId:e,width:t,depth:n,surfaceY:r}){let i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=(0,v.useRef)(null),s=OC(),c=Q(e=>e.parts),l=YS();return j_((t,n)=>{let u=i.current,d=o.current;if(!u||!a.current)return;let f=oC(e),p=l.reservoirRuntime[e],m=p?Math.max(0,Math.min(1,p.gallonsCurrent/Math.max(.1,p.gallonsCapacity))):.7,h=Math.max(.03,(r-.1)*m)+.03,g=+((f?.flow??0)>0),_=0,v=[u.position.x,h,u.position.z];for(let e of Object.values(c))e.type===`airCompressor`&&(e.params.on??1)>0&&Math.hypot(e.position[0]-v[0],e.position[1]-v[1],e.position[2]-v[2])<10&&(_+=e.params.gph??120);let y=+(_>0),b=g||y,x=dC(),S=.012*Math.sin(x*2.6)*g+.004*Math.sin(x*12)*y;if(u.position.y=h+S,g>0){let e=Math.min(.1,n);s.offset.x+=e*.16,s.offset.y+=e*.12,s.rotation=x*.05}else if(y>0){let e=Math.min(.1,n);s.offset.x+=e*.06,s.offset.y+=e*.08,s.rotation=x*.025}if(d&&b>0){let e=d.attributes.position;for(let t=0;t0){let e=Math.hypot(n,r),t=.008*Math.sin(e*22-x*16)*Math.exp(-e*1.8)*y;i+=t}e.setZ(t,i)}e.needsUpdate=!0,d.computeVertexNormals()}else if(d){let e=d.attributes.position;for(let t=0;t{let o=oC(e),s=o?.spill??!1;if(n.current&&(n.current.visible=s),i.current&&(i.current.visible=s),!s)return;let c=dC(),l=fC(),u=o?.flow??0,d=a.pumps.some(e=>e.running)&&u<5,f=a.velocities[e]??0;r.current&&(r.current.opacity=.45+.18*(.5+.5*Math.sin(c*6)),xC(r.current,o,c,d,f,u)),i.current&&i.current.children.forEach((e,n)=>{let r=(c*(1.8+(o?.flow??0)/260)+n*.29)%1,a=e,s=n/Math.max(1,i.current.children.length)*Math.PI*2;a.position.set(Math.cos(s)*.12*t,.26*t-r*.38*t,Math.sin(s)*.12*t),a.scale.setScalar(.55+.5*(1-r)),a.rotation.x+=l*2})}),(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{ref:n,position:[0,.225*t,0],visible:!1,renderOrder:2,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.16*t,.1*t,.035*t,16]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:r,color:`#38bdf8`,transparent:!0,opacity:0,roughness:.08,depthWrite:!1,emissive:`#0c4a6e`,emissiveIntensity:.25})]}),(0,Z.jsx)(`group`,{ref:i,visible:!1,children:Array.from({length:6},(e,n)=>(0,Z.jsxs)(`mesh`,{renderOrder:2,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.024*t,6,6]}),(0,Z.jsx)(`meshStandardMaterial`,{color:`#7dd3fc`,transparent:!0,opacity:.85,roughness:.05,depthWrite:!1})]},n))})]})}function HC({startPos:e,maxY:t,index:n,count:r,active:i,frequency:a}){let o=(0,v.useRef)(null);return j_(()=>{let s=o.current;if(!s)return;if(!i){s.visible=!1;return}s.visible=!0;let c=dC(),l=(c*(1+a/10*.6)*.4+n/r)%1;s.position.y=e.y+l*(t-e.y);let u=c*7+n*1.5;s.position.x=e.x+Math.sin(u)*.05,s.position.z=e.z+Math.cos(u*.8)*.05,s.scale.setScalar(.45+.9*l)}),(0,Z.jsxs)(`mesh`,{ref:o,renderOrder:3,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.015,6,6]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#e0f2fe`,transparent:!0,opacity:.65})]})}function UC(){let e=Q(e=>e.parts);return(0,Z.jsx)(Z.Fragment,{children:Object.values(e).filter(e=>e.type===`airCompressor`).map(e=>(0,Z.jsx)(WC,{comp:e},e.id))})}function WC({comp:e}){let t=Q(e=>e.parts),n=(e.params.on??1)>0,r=e.params.frequency??5,i=(0,v.useMemo)(()=>{let n=null,r=1/0,i=e.position;for(let e of Object.values(t))if(e.type===`reservoir`){let t=Math.hypot(e.position[0]-i[0],e.position[1]-i[1],e.position[2]-i[2]);t0?1:-1,p=d>0?1:-1,m=i.position[0]+f*(a/2+.04),h=i.position[2]+p*(o/2+.04),g=[[c.x,c.y,c.z],[c.x,.02,c.z],[m,.02,c.z],[m,.02,h],[m,i.position[1]+s+.03,h],[i.position[0]+f*(a/2-.08),i.position[1]+s+.03,i.position[2]+p*(o/2-.08)],[l.x,l.y,l.z]],_=Math.max(.02,(s-.1)*((i.params.level??70)/100)),y=i.position[1]+_+.02;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsx)(mb,{points:g,color:`#1e293b`,lineWidth:3}),(0,Z.jsxs)(`mesh`,{position:l,rotation:[0,0,mC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.04,.04,.12,10]}),(0,Z.jsx)(`meshStandardMaterial`,{color:`#64748b`,roughness:.8})]}),Array.from({length:12},(e,t)=>(0,Z.jsx)(HC,{startPos:l,maxY:y,index:t,count:12,active:n,frequency:r},t))]})}function GC({partId:e,width:t,depth:n,height:r}){let i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=Q(e=>e.parts),s=YS();return j_(()=>{if(!i.current||!a.current)return;let t=oC(e),n=s.reservoirRuntime[e],c=n?Math.max(0,Math.min(1,n.gallonsCurrent/Math.max(.1,n.gallonsCapacity))):.7,l=Math.max(.02,(r-.1)*c);i.current.scale.y=l,i.current.position.y=l/2+.02;let u=+((t?.flow??0)>0),d=0,f=[i.current.position.x,l,i.current.position.z];for(let e of Object.values(o))e.type===`airCompressor`&&(e.params.on??1)>0&&Math.hypot(e.position[0]-f[0],e.position[1]-f[1],e.position[2]-f[2])<10&&(d+=e.params.gph??120);let p=!u&&!+(d>0);xC(a.current,t,dC(),p,0,t?.flow??0)}),(0,Z.jsxs)(`mesh`,{ref:i,position:[0,r/2+.02,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[t,1,n]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:a,color:`#1d4ed8`,transparent:!0,opacity:.6,roughness:.1,depthWrite:!1})]})}var KC=Math.PI/2,qC=(0,v.createContext)({ghost:!1,selected:!1});function $({color:e,metalness:t=.25,roughness:n=.55,opacity:r,transparent:i,physical:a=!1,transmission:o=.9,thickness:s=.4}){let{ghost:c,selected:l}=(0,v.useContext)(qC),u=Q(e=>e.renderMode),d=u===`water`?.06:u===`xray`?Math.min(r??1,.2):r,f=c||i||d!==void 0||u!==`builder`||a;return a&&u===`builder`?(0,Z.jsx)(`meshPhysicalMaterial`,{color:e,metalness:.05,roughness:.08,transmission:o,thickness:s,ior:1.45,transparent:!0,opacity:c?.45:1,depthWrite:!1,emissive:l?`#0ea5e9`:`#000000`,emissiveIntensity:l?.4:0}):(0,Z.jsx)(`meshStandardMaterial`,{color:e,metalness:t,roughness:n,transparent:f,opacity:c?.4:d??1,depthWrite:!f,emissive:l?`#0ea5e9`:`#000000`,emissiveIntensity:l?.4:0})}function JC(e,t){if(t<=0)return e;let n=new Y(e);return n.lerp(new Y(`#3b82f6`),Math.min(.55,.25+t/800)),`#${n.getHexString()}`}var YC=new Y(`#34d399`),XC=new Y(`#f59e0b`),ZC=new Y(`#22d3ee`),QC=new Y(`#67e8f9`);function $C({partId:e,pos:t,joined:n,seed:r}){let i=(0,v.useRef)(null),a=(0,v.useRef)(null);return j_(()=>{let t=i.current,o=a.current;if(!t)return;if(!n){t.color.copy(XC),t.emissive.copy(XC),t.emissiveIntensity=.45,o&&(o.visible=!1);return}let s=oC(e);if((s?.flow??0)>0&&(s?.fill??0)>.05){let e=.5+.5*Math.sin(dC()*3.2+r);if(t.color.copy(ZC),t.emissive.copy(ZC),t.emissiveIntensity=1.1+1*e,o){o.visible=!0,o.scale.setScalar(1+.35*e);let t=o.material;t.color.copy(QC),t.opacity=.2+.25*e}}else t.color.copy(YC),t.emissive.copy(YC),t.emissiveIntensity=.7,o&&(o.visible=!1)}),(0,Z.jsxs)(`group`,{position:t,children:[(0,Z.jsxs)(`mesh`,{children:[(0,Z.jsx)(`sphereGeometry`,{args:[.06,10,10]}),(0,Z.jsx)(`meshStandardMaterial`,{ref:i,color:`#f59e0b`,emissive:`#f59e0b`,emissiveIntensity:.45,toneMapped:!1})]}),(0,Z.jsxs)(`mesh`,{ref:a,visible:!1,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.11,10,10]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#67e8f9`,transparent:!0,opacity:.25,blending:2,depthWrite:!1,toneMapped:!1})]})]})}function ew({part:e,connectedKeys:t,radius:n}){return(0,Z.jsx)(Z.Fragment,{children:Yx[e.type].getConnectors(e.params).map(r=>t?.has(`${e.id}:${r.id}`)?null:(0,Z.jsx)(`group`,{position:r.pos,children:(0,Z.jsx)(IC,{partId:e.id,dir:r.dir,radius:n})},r.id))})}function tw({part:e,connectedKeys:t}){return(0,Z.jsx)(Z.Fragment,{children:Yx[e.type].getConnectors(e.params).map((n,r)=>(0,Z.jsx)($C,{partId:e.id,pos:n.pos,joined:t?.has(`${e.id}:${n.id}`)??!1,seed:r*1.7},n.id))})}function nw({width:e,depth:t,height:n,on:r}){let i=(0,v.useRef)(null);return j_(()=>{if(i.current){if(!r){i.current.opacity=0;return}let e=dC();i.current.opacity=.03+.015*Math.sin(e*1.5)*Math.cos(e*.7)}}),r?(0,Z.jsxs)(`mesh`,{position:[0,-n/2-.08,0],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[e*.45,e*1.25,n,16,1,!0]}),(0,Z.jsx)(`meshBasicMaterial`,{ref:i,color:`#fef08a`,transparent:!0,opacity:.03,depthWrite:!1,side:2})]}):null}function rw({w:e,d:t,floorY:n,watts:r,selected:i}){let a=.5*Math.abs(n),o=Math.max(e,t)*.4+a*.3,s=Math.max(e,t)*.8+a*.6,c=Math.max(e,t)*1.3+a*1,l=(0,v.useMemo)(()=>{let e=[];for(let t=0;t<=64;t++){let n=t/64*Math.PI*2;e.push([Math.cos(n)*o,0,Math.sin(n)*o])}return e},[o]),u=(0,v.useMemo)(()=>{let e=[];for(let t=0;t<=64;t++){let n=t/64*Math.PI*2;e.push([Math.cos(n)*s,0,Math.sin(n)*s])}return e},[s]),d=(0,v.useMemo)(()=>{let e=[];for(let t=0;t<=64;t++){let n=t/64*Math.PI*2;e.push([Math.cos(n)*c,0,Math.sin(n)*c])}return e},[c]),f=[[e/2,-.06,t/2],[-e/2,-.06,t/2],[-e/2,-.06,-t/2],[e/2,-.06,-t/2]],p=[[c*.707,n+.01,c*.707],[-c*.707,n+.01,c*.707],[-c*.707,n+.01,-c*.707],[c*.707,n+.01,-c*.707]],m=i?1:.45;return(0,Z.jsxs)(`group`,{children:[f.map((e,t)=>(0,Z.jsx)(mb,{points:[e,p[t]],color:`#fde68a`,lineWidth:i?1.2:.6,dashed:!0,dashScale:2,transparent:!0,opacity:.2*m},t)),(0,Z.jsxs)(`group`,{position:[0,n+.01,0],children:[(0,Z.jsxs)(`mesh`,{rotation:[-Math.PI/2,0,0],children:[(0,Z.jsx)(`circleGeometry`,{args:[o,32]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#fbbf24`,transparent:!0,opacity:.16*m,depthWrite:!1})]}),(0,Z.jsx)(mb,{points:l,color:`#fbbf24`,lineWidth:i?2:1,transparent:!0,opacity:.3*m}),(0,Z.jsxs)(`mesh`,{rotation:[-Math.PI/2,0,0],children:[(0,Z.jsx)(`ringGeometry`,{args:[o,s,32]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#f59e0b`,transparent:!0,opacity:.09*m,depthWrite:!1})]}),(0,Z.jsx)(mb,{points:u,color:`#f59e0b`,lineWidth:i?1.5:.8,transparent:!0,opacity:.2*m}),(0,Z.jsxs)(`mesh`,{rotation:[-Math.PI/2,0,0],children:[(0,Z.jsx)(`ringGeometry`,{args:[s,c,32]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#eab308`,transparent:!0,opacity:.04*m,depthWrite:!1})]}),(0,Z.jsx)(mb,{points:d,color:`#eab308`,lineWidth:i?1:.5,transparent:!0,opacity:.1*m})]})]})}function iw({baseColor:e,on:t}){let n=(0,v.useRef)(null);return j_(()=>{if(n.current&&t){let e=dC();n.current.position.y=Math.sin(e*60)*.0025,n.current.position.x=Math.cos(e*50)*.0018}else n.current&&n.current.position.set(0,0,0)}),(0,Z.jsxs)(`group`,{ref:n,children:[(0,Z.jsxs)(`mesh`,{position:[0,.2,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.6,.35,.4]}),(0,Z.jsx)($,{color:e,metalness:.4,roughness:.3})]}),(0,Z.jsxs)(`mesh`,{position:[-.2,.02,-.12],children:[(0,Z.jsx)(`sphereGeometry`,{args:[.04,8,8]}),(0,Z.jsx)($,{color:`#0f172a`})]}),(0,Z.jsxs)(`mesh`,{position:[.2,.02,-.12],children:[(0,Z.jsx)(`sphereGeometry`,{args:[.04,8,8]}),(0,Z.jsx)($,{color:`#0f172a`})]}),(0,Z.jsxs)(`mesh`,{position:[-.2,.02,.12],children:[(0,Z.jsx)(`sphereGeometry`,{args:[.04,8,8]}),(0,Z.jsx)($,{color:`#0f172a`})]}),(0,Z.jsxs)(`mesh`,{position:[.2,.02,.12],children:[(0,Z.jsx)(`sphereGeometry`,{args:[.04,8,8]}),(0,Z.jsx)($,{color:`#0f172a`})]}),(0,Z.jsxs)(`mesh`,{position:[.28,.22,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.02,.02,.08,10]}),(0,Z.jsx)($,{color:`#d97706`,metalness:.8,roughness:.2})]})]})}function aw({part:e,flow:t,connectedKeys:n}){let r=e.params,i=Yx[e.type],a=e.color||i.color,o=Q(e=>e.renderMode),s=o===`water`?.15:o===`xray`?.42:.8;switch(e.type){case`pipe`:{let i=Gx(r.diameter??1),o=r.length??2;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,o,16]}),(0,Z.jsx)($,{color:JC(a,t),opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsx)(kC,{partId:e.id,length:o,radius:i*.78}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`coupling`:{let i=Gx(r.diameter??1);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i*1.18,i*1.18,.6,16]}),(0,Z.jsx)($,{color:JC(a,t),opacity:.65,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[-.22,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[i*1.18,.018,8,18]}),(0,Z.jsx)($,{color:`#7c8794`})]}),(0,Z.jsxs)(`mesh`,{position:[.22,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[i*1.18,.018,8,18]}),(0,Z.jsx)($,{color:`#7c8794`})]}),(0,Z.jsx)(kC,{partId:e.id,length:.6,radius:i*.72}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`reducer`:{let i=Gx(r.diameterA??1.5),o=Gx(r.diameterB??1),s=Math.min(i,o),c=JC(a,t);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[o*1.15,i*1.15,.7,20]}),(0,Z.jsx)($,{color:c,opacity:.65,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[-.28,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[i*1.15,.018,8,18]}),(0,Z.jsx)($,{color:`#7c8794`})]}),(0,Z.jsxs)(`mesh`,{position:[.28,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[o*1.15,.018,8,18]}),(0,Z.jsx)($,{color:`#7c8794`})]}),(0,Z.jsx)(kC,{partId:e.id,length:.7,radius:s*.72}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:Math.max(i,o)})]})}case`cap`:{let e=Gx(r.diameter??1);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[.05,0,0],rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[e*1.2,e*1.2,.45,16]}),(0,Z.jsx)($,{color:JC(a,t),opacity:.75,roughness:.38})]}),(0,Z.jsxs)(`mesh`,{position:[.28,0,0],rotation:[0,KC,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[e*1.2,e*1.2,.04,16]}),(0,Z.jsx)($,{color:`#6b7280`,roughness:.35})]}),(0,Z.jsxs)(`mesh`,{position:[-.12,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[e*1.2,.018,8,18]}),(0,Z.jsx)($,{color:`#7c8794`})]})]})}case`elbow`:{let i=Gx(r.diameter??1),o=Ux,s=(r.angle??90)*Math.PI/180;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,o,0],rotation:[0,0,-KC],castShadow:!0,children:[(0,Z.jsx)(`torusGeometry`,{args:[o,i,12,24,s]}),(0,Z.jsx)($,{color:JC(a,t),opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsx)(MC,{partId:e.id,radius:i*.78,arc:s}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`tee`:{let i=Gx(r.diameter??1),o=JC(a,t);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,1.2,16]}),(0,Z.jsx)($,{color:o,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,.3],rotation:[KC,0,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,.6,16]}),(0,Z.jsx)($,{color:o,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsx)(NC,{partId:e.id,radius:i*.75}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`valve`:{let i=Gx(r.diameter??1)*1.25,o=(r.open??100)>0;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,.7,16]}),(0,Z.jsx)($,{color:JC(`#8b939e`,t),metalness:.5,roughness:.35,opacity:.75,physical:!0,transmission:.9,thickness:.4})]}),(0,Z.jsx)(PC,{partId:e.id,radius:Gx(r.diameter??1)*.78}),(0,Z.jsxs)(`mesh`,{position:[0,.22,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.07,.28,.07]}),(0,Z.jsx)($,{color:`#6b7280`})]}),(0,Z.jsxs)(`mesh`,{position:[0,.4,0],rotation:[KC,0,0],children:[(0,Z.jsx)(`torusGeometry`,{args:[.16,.04,8,20]}),(0,Z.jsx)($,{color:o?a:`#991b1b`})]}),o&&(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:Gx(r.diameter??1)})]})}case`pump`:return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,.25,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.8,.5,.6]}),(0,Z.jsx)($,{color:a,metalness:.4,roughness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,.56,0],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.14,.14,.14,16]}),(0,Z.jsx)($,{color:`#1e3a8a`})]}),(0,Z.jsxs)(`mesh`,{position:[-.43,.25,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.1,.1,.2,12]}),(0,Z.jsx)($,{color:`#64748b`})]}),(0,Z.jsxs)(`mesh`,{position:[.43,.25,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.1,.1,.2,12]}),(0,Z.jsx)($,{color:`#64748b`})]})]});case`reservoir`:{let t=r.width??2,n=r.depth??1.4,i=r.height??1;return Math.max(.02,(i-.1)*((r.level??70)/100)),(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,i/2,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[t,i,n]}),(0,Z.jsx)($,{color:`#44607e`,opacity:.3,roughness:.3})]}),(0,Z.jsx)(GC,{partId:e.id,width:t-.12,depth:n-.12,height:i}),(0,Z.jsx)(BC,{partId:e.id,width:t-.12,depth:n-.12,surfaceY:i}),(0,Z.jsxs)(`mesh`,{position:[0,i,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[t+.06,.06,n+.06]}),(0,Z.jsx)($,{color:a})]})]})}case`tower`:{let e=r.height??4,t=Math.max(1,Math.round(r.sites??6)),n=[];for(let r=0;r(0,Z.jsxs)(`mesh`,{position:[0,.295,e],children:[(0,Z.jsx)(`boxGeometry`,{args:[2*Math.sqrt(Math.max(.012,.0784-e*e)),.03,.045]}),(0,Z.jsx)($,{color:`#334155`,metalness:.5,roughness:.45})]},e)),(0,Z.jsxs)(`mesh`,{position:[-.26,.25,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.1,.1,.2,12]}),(0,Z.jsx)($,{color:`#8b939e`})]}),(0,Z.jsx)(LC,{partId:e.id})]});case`growTent`:{let e=r.width??7,t=r.depth??5,n=r.height??4,i=(r.sealed??0)>0;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,n/2,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[e,n,t]}),(0,Z.jsx)($,{color:i?`#164e63`:`#334155`,opacity:.08,roughness:.9})]}),(0,Z.jsxs)(`lineSegments`,{position:[0,n/2,0],children:[(0,Z.jsx)(`edgesGeometry`,{args:[new bs(e,n,t)]}),(0,Z.jsx)(`lineBasicMaterial`,{color:i?`#22d3ee`:`#94a3b8`,transparent:!0,opacity:s})]}),(0,Z.jsxs)(`mesh`,{position:[0,n/2,t/2+.01],children:[(0,Z.jsx)(`planeGeometry`,{args:[e*.22,n*.8]}),(0,Z.jsx)($,{color:`#0f172a`,opacity:.22})]})]})}case`inlineFan`:return(0,Z.jsx)(ow,{baseColor:a,cfm:r.cfm??600});case`circulationFan`:return(0,Z.jsx)(sw,{baseColor:a,cfm:r.cfm??250,sweep:r.sweep??90});case`growLight`:{let t=r.width??2,n=r.depth??2,i=r.watts??650,{selected:o}=(0,v.useContext)(qC);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[t,.12,n]}),(0,Z.jsx)($,{color:a,metalness:.35,roughness:.35})]}),(0,Z.jsxs)(`mesh`,{position:[0,-.07,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[t*.88,.03,n*.88]}),(0,Z.jsx)($,{color:`#fde68a`,opacity:.55})]}),(0,Z.jsx)(`pointLight`,{position:[0,-.15,0],intensity:i/100,distance:16,decay:1.8,castShadow:!0,"shadow-mapSize":[512,512]}),(0,Z.jsx)(nw,{width:t,depth:n,height:6,on:i>0}),i>0&&(0,Z.jsx)(rw,{w:t,d:n,floorY:-e.position[1],watts:i,selected:o})]})}case`co2Tank`:return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,.7,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.18,.2,1.4,20]}),(0,Z.jsx)($,{color:a,metalness:.35,roughness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,1.48,0],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.07,.07,.12,12]}),(0,Z.jsx)($,{color:`#e2e8f0`})]}),(0,Z.jsxs)(`mesh`,{position:[.14,1.5,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.03,.03,.18,12]}),(0,Z.jsx)($,{color:`#cbd5e1`})]})]});case`airCompressor`:return(0,Z.jsx)(`group`,{children:(0,Z.jsx)(iw,{baseColor:a,on:(r.on??1)>0})});case`reducingTee`:{let i=Gx(r.diameterA??1.5),o=Gx(r.diameterB??1),s=JC(a,t);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,1.2,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,.15],rotation:[KC,0,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[o,i,.3,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,.4],rotation:[KC,0,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[o,o,.2,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsx)(NC,{partId:e.id,radius:i*.75}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`reducingElbow`:{let i=Gx(r.diameterA??1.5),o=Gx(r.diameterB??1),s=JC(a,t);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,-.15,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,.3,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[0,.05,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[o,i,.1,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[-.1,.1,0],rotation:[0,0,-KC],castShadow:!0,children:[(0,Z.jsx)(`torusGeometry`,{args:[.1,o,12,16,KC]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsxs)(`mesh`,{position:[-.25,.2,0],rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[o,o,.3,16]}),(0,Z.jsx)($,{color:s,opacity:.55,roughness:.35,physical:!0,transmission:.92,thickness:.4})]}),(0,Z.jsx)(MC,{partId:e.id,radius:o*.78,arc:KC}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:i})]})}case`bulkhead`:{let t=Gx(r.diameter??1),i=t*1.5;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.4,16]}),(0,Z.jsx)($,{color:`#27272a`,metalness:.2,roughness:.8})]}),(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[i,i,.08,16]}),(0,Z.jsx)($,{color:`#18181b`,metalness:.1,roughness:.9})]}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:t})]})}case`waterChiller`:{let e=(r.on??1)>0;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,.5,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.8,1,.8]}),(0,Z.jsx)($,{color:`#3f3f46`,metalness:.6,roughness:.25})]}),(0,Z.jsxs)(`mesh`,{position:[0,.5,.41],children:[(0,Z.jsx)(`boxGeometry`,{args:[.6,.4,.01]}),(0,Z.jsx)($,{color:`#18181b`,roughness:.9})]}),(0,Z.jsxs)(`mesh`,{position:[0,.85,.41],children:[(0,Z.jsx)(`boxGeometry`,{args:[.3,.15,.01]}),(0,Z.jsx)($,{color:`#09090b`,roughness:.9})]}),e&&(0,Z.jsxs)(`mesh`,{position:[0,.85,.415],children:[(0,Z.jsx)(`planeGeometry`,{args:[.26,.11]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#22c55e`})]}),(0,Z.jsxs)(`mesh`,{position:[-.2,1.05,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.08,.08,.15,12]}),(0,Z.jsx)($,{color:`#71717a`,metalness:.8,roughness:.2})]}),(0,Z.jsxs)(`mesh`,{position:[.2,1.05,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.08,.08,.15,12]}),(0,Z.jsx)($,{color:`#71717a`,metalness:.8,roughness:.2})]}),(0,Z.jsx)(`group`,{position:[0,.5,-.41],rotation:[KC,0,0],children:(0,Z.jsx)(cw,{active:e})})]})}case`reverseOsmosis`:{let t=Gx(r.diameter??1);return(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t,t,.6,16]}),(0,Z.jsx)($,{color:`#e2e8f0`,roughness:.4})]}),(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,receiveShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t*2.2,t*2.2,.38,20]}),(0,Z.jsx)($,{color:`#ffffff`,roughness:.3})]}),(0,Z.jsxs)(`mesh`,{position:[-.19,0,0],rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t*2.3,t*2.3,.04,20]}),(0,Z.jsx)($,{color:`#cbd5e1`,metalness:.8,roughness:.2})]}),(0,Z.jsxs)(`mesh`,{position:[.19,0,0],rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[t*2.3,t*2.3,.04,20]}),(0,Z.jsx)($,{color:`#cbd5e1`,metalness:.8,roughness:.2})]}),(0,Z.jsx)(ew,{part:e,connectedKeys:n,radius:t})]})}default:return(0,Z.jsxs)(`mesh`,{castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.5,.5,.5]}),(0,Z.jsx)($,{color:`#888888`})]})}}function ow({baseColor:e,cfm:t}){let n=(0,v.useRef)(null);return j_(e=>{if(n.current){let r=15+t/400*20;n.current.rotation.y=e.clock.getElapsedTime()*r}}),(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.25,.25,.7,16,1,!0]}),(0,Z.jsx)($,{color:e,metalness:.5,roughness:.3})]}),(0,Z.jsxs)(`mesh`,{position:[-.34,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[.25,.02,8,16]}),(0,Z.jsx)($,{color:`#64748b`})]}),(0,Z.jsxs)(`mesh`,{position:[.34,0,0],rotation:[0,0,KC],children:[(0,Z.jsx)(`torusGeometry`,{args:[.25,.02,8,16]}),(0,Z.jsx)($,{color:`#64748b`})]}),(0,Z.jsxs)(`mesh`,{position:[0,.22,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.16,.08,.16]}),(0,Z.jsx)($,{color:`#334155`})]}),(0,Z.jsxs)(`mesh`,{rotation:[0,0,KC],children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.08,.08,.25,12]}),(0,Z.jsx)($,{color:`#475569`,metalness:.4})]}),(0,Z.jsx)(`group`,{ref:n,children:(0,Z.jsxs)(`group`,{rotation:[0,0,KC],children:[(0,Z.jsxs)(`mesh`,{rotation:[.3,0,0],position:[0,.14,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.04,.12,.005]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.3,0,Math.PI/2],position:[-.14,0,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.04,.12,.005]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.3,0,Math.PI],position:[0,-.14,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.04,.12,.005]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.3,0,-Math.PI/2],position:[.14,0,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.04,.12,.005]}),(0,Z.jsx)($,{color:`#f1f5f9`})]})]})})]})}function sw({baseColor:e,cfm:t,sweep:n}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null);return j_(e=>{if(i.current){let n=10+t/200*15;i.current.rotation.z=e.clock.getElapsedTime()*n}if(r.current&&n>0){let t=n*Math.PI/180;r.current.rotation.y=Math.sin(e.clock.getElapsedTime()*1.5)*(t/2)}}),(0,Z.jsxs)(`group`,{children:[(0,Z.jsxs)(`mesh`,{position:[0,.02,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.2,.22,.04,16]}),(0,Z.jsx)($,{color:`#1e293b`,metalness:.1,roughness:.8})]}),(0,Z.jsxs)(`mesh`,{position:[0,.3,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.02,.02,.55,12]}),(0,Z.jsx)($,{color:`#94a3b8`,metalness:.6,roughness:.2})]}),(0,Z.jsxs)(`group`,{ref:r,position:[0,.6,0],children:[(0,Z.jsxs)(`mesh`,{position:[0,-.05,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.06,.08,.06]}),(0,Z.jsx)($,{color:`#475569`})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,-.08],rotation:[KC,0,0],castShadow:!0,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.07,.07,.16,16]}),(0,Z.jsx)($,{color:e,metalness:.2,roughness:.5})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,.05],children:[(0,Z.jsx)(`sphereGeometry`,{args:[.26,16,12]}),(0,Z.jsx)(`meshBasicMaterial`,{wireframe:!0,color:`#64748b`,transparent:!0,opacity:.25})]}),(0,Z.jsxs)(`mesh`,{position:[0,0,.05],rotation:[KC,0,0],children:[(0,Z.jsx)(`torusGeometry`,{args:[.26,.012,8,24]}),(0,Z.jsx)($,{color:`#64748b`})]}),(0,Z.jsxs)(`group`,{ref:i,position:[0,0,.05],children:[(0,Z.jsxs)(`mesh`,{castShadow:!0,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.04,12,12]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.25,0,0],position:[0,.12,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.06,.22,.008]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.25,0,Math.PI*2/3],position:[-.104,-.06,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.06,.22,.008]}),(0,Z.jsx)($,{color:`#f1f5f9`})]}),(0,Z.jsxs)(`mesh`,{rotation:[.25,0,-Math.PI*2/3],position:[.104,-.06,0],castShadow:!0,children:[(0,Z.jsx)(`boxGeometry`,{args:[.06,.22,.008]}),(0,Z.jsx)($,{color:`#f1f5f9`})]})]})]})]})}function cw({active:e}){let t=(0,v.useRef)(null);return j_(n=>{t.current&&e&&(t.current.rotation.z=n.clock.getElapsedTime()*15)}),(0,Z.jsxs)(`group`,{ref:t,children:[(0,Z.jsxs)(`mesh`,{castShadow:!0,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.03,10,10]}),(0,Z.jsx)($,{color:`#18181b`})]}),Array.from({length:4}).map((e,t)=>(0,Z.jsx)(`group`,{rotation:[0,0,t*Math.PI/2],children:(0,Z.jsxs)(`mesh`,{position:[0,.1,0],rotation:[.2,0,0],children:[(0,Z.jsx)(`boxGeometry`,{args:[.03,.12,.004]}),(0,Z.jsx)($,{color:`#27272a`})]})},t))]})}function lw(e){let t=new ni;e.updateWorldMatrix(!0,!0);let n=new J().copy(e.matrixWorld).invert(),r=new J,i=new ni,a=a=>{e.traverse(e=>{let o=e;!o.isMesh||a&&!o.castShadow||(o.geometry.boundingBox||o.geometry.computeBoundingBox(),o.geometry.boundingBox&&(i.copy(o.geometry.boundingBox),r.multiplyMatrices(n,o.matrixWorld),i.applyMatrix4(r),t.union(i)))})};return a(!0),t.isEmpty()&&a(!1),t}var uw=e=>Math.max(e+.22,.5),dw=(0,v.memo)(function({part:e,flow:t=0,selected:n=!1,ghost:r=!1,connectedKeys:i}){let a=(0,v.useRef)(null),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(null);vy(o&&!r);let u=JSON.stringify(e.params);(0,v.useEffect)(()=>{if(r)return;let e=requestAnimationFrame(()=>{let e=a.current;if(!e)return;let t=lw(e);if(t.isEmpty()){l({center:[0,.25,0],size:[.5,.5,.5]});return}let n=t.getCenter(new q),r=t.getSize(new q);l({center:[n.x,n.y,n.z],size:[r.x,r.y,r.z]})});return()=>cancelAnimationFrame(e)},[e.type,u,r]);let d=(0,v.useMemo)(()=>{if(!c||r)return null;let e=new bs(c.size[0]+.1,c.size[1]+.1,c.size[2]+.1),t=new js(e);return e.dispose(),t},[c,r]);return(0,v.useEffect)(()=>()=>d?.dispose(),[d]),(0,Z.jsx)(qC.Provider,{value:{ghost:r,selected:n},children:(0,Z.jsxs)(`group`,{position:e.position,rotation:e.rotation,onPointerDown:t=>{if(r)return;let n=Q.getState();if(n.placingType||n.tool===`measure`)return;let i=t.intersections.find(e=>e.object.userData?.connectorHandle);if(i&&i.distance<=t.distance+.5)return;t.stopPropagation();let a=t.nativeEvent;if(a.metaKey||a.ctrlKey){n.selectedIds.includes(e.id)||n.setSelected(e.id),n.openColorPopover(a.clientX,a.clientY);return}if(a.shiftKey){n.toggleSelected(e.id);return}if(n.selectedIds.includes(e.id)||n.setSelected(e.id),t.button===0){if(a.altKey){let r=n.selectedIds.includes(e.id)?[...n.selectedIds]:[e.id],i=n.duplicateParts(r,{offset:[0,0,0]}),a=i[r.indexOf(e.id)]??i[0];if(!a)return;iC({partId:a,grabPoint:[t.point.x,t.point.y,t.point.z],mode:`body`});return}iC({partId:e.id,grabPoint:[t.point.x,t.point.y,t.point.z],mode:`body`})}},onDoubleClick:t=>{if(r)return;t.stopPropagation();let n=Q.getState();n.placingType||n.tool===`measure`||(Zx.has(e.type)?n.selectConnectedRun(e.id):n.setSelected(e.id),e.type===`pump`&&window.dispatchEvent(new CustomEvent(`hydro:flash-pump`,{detail:e.id})))},onPointerOver:e=>{if(r)return;let t=Q.getState();t.placingType||t.tool===`measure`||t.draggingId||e.intersections[0]?.eventObject===e.eventObject&&s(!0)},onPointerOut:()=>s(!1),children:[(0,Z.jsxs)(`group`,{ref:a,children:[(0,Z.jsx)(`group`,{name:`part-body-mesh`,userData:{partId:e.id},children:(0,Z.jsx)(aw,{part:e,flow:t,connectedKeys:i})}),!r&&(0,Z.jsx)(tw,{part:e,connectedKeys:i})]}),!r&&c&&(0,Z.jsxs)(`mesh`,{position:c.center,children:[(0,Z.jsx)(`boxGeometry`,{args:[uw(c.size[0]),uw(c.size[1]),uw(c.size[2])]}),(0,Z.jsx)(`meshBasicMaterial`,{visible:!1})]}),!r&&o&&!n&&c&&d&&(0,Z.jsx)(`lineSegments`,{geometry:d,position:c.center,children:(0,Z.jsx)(`lineBasicMaterial`,{color:`#38bdf8`,transparent:!0,opacity:.55,depthWrite:!1})})]})})});function fw(){let e=Q(e=>e.showFlow),t=Q(e=>e.parts),n=YS();return(0,Z.jsxs)(`group`,{children:[(0,Z.jsx)(vw,{sim:n,parts:t}),e&&n.segments.map((e,t)=>(0,Z.jsx)(bw,{seg:e},`${e.partId}-${t}`))]})}var pw=0,mw=e=>e<0?0:e>1?1:e,hw=(e,t,n)=>en?n:e,gw=7.48;function _w(e,t){let n=e.params,r=Math.max(.25,n.diameter??1);switch(e.type){case`pipe`:case`elbow`:case`tee`:case`valve`:return Math.PI*(r/24)**2*t*gw;case`pump`:return .06;case`tower`:return .1*(n.height??4);case`tray`:return .08*(n.length??3)*(n.width??1.2);case`wallPanel`:return .25;case`emitter`:return .02;case`drain`:return .05;case`reservoir`:return 2;default:return .1}}function vw({sim:e,parts:t}){let n=(0,v.useRef)(e);n.current=e;let r=(0,v.useMemo)(()=>{let n=Object.keys(e.fillLength),r=[];for(let i of n){let n=e.fillDistance[i],a=e.flows[i]??0,o=t[i];if(n===void 0||a<=0||!o)continue;let s=Math.max(.2,e.fillLength[i]),c=Math.max(.004,_w(o,s));r.push({dist:n,len:s,speed:hw(a/3600*s/c,.5,5)})}return{partIds:n,spans:r}},[e,t]),i=(0,v.useRef)(r);return i.current=r,j_((e,t)=>{if(!Q.getState().simRunning){uC();return}let r=n.current,a=Math.min(t,.1);if(lC(a),r.totalGph>.5){let e=1/0;for(let t of i.current.spans)pw>=t.dist&&pw0&&o!==void 0?t.fill=mw((pw-o)/s):i?t.fill=Math.min(1,t.fill+a*.6):t.fill=Math.max(0,t.fill-a*.9),t.flow=n,t.backedUp=i,t.overflow=!1,t.spill=!1,t.entry=r.entryConnector[e],t.state=i?`backedUp`:t.fill<=.002?`empty`:t.fill>=.998?`full`:`filling`}for(let e of r.drains){if(!e.overflowing)continue;let t=aC.get(e.partId);t&&(t.overflow=!0)}for(let e of r.netPots){if(!e.overflowing)continue;let t=pC(e.partId);t.fill=1,t.flow=e.inflowGph,t.backedUp=!0,t.overflow=!1,t.spill=!0,t.state=`backedUp`}}),null}var yw=new q(0,1,0);function bw({seg:e}){let t=(0,v.useRef)(null),{from:n,dir:r,len:i,quat:a,count:o,speed:s}=(0,v.useMemo)(()=>{let t=new q(...e.from),n=new q(...e.to).clone().sub(t),r=n.length();n.normalize();let i=Math.max(.5,e.diameter??1);return{from:t,dir:n,len:r,quat:new Mn().setFromUnitVectors(yw,n),count:Math.max(1,Math.round(r/.55)),speed:.35+Math.min(2.5,e.gph/(i*i)/220)}},[e]);return j_(()=>{let a=t.current;if(!a)return;let c=dC()*s,l=oC(e.partId)?.fill??1;a.children.forEach((e,t)=>{let a=((t+c)%o+o)%o/o;e.position.copy(n).addScaledVector(r,a*i);let s=e.material;s.opacity=.85*l*Math.min(1,Math.min(a,1-a)*4+.15)})}),i<.2?null:(0,Z.jsx)(`group`,{ref:t,children:Array.from({length:o},(e,t)=>(0,Z.jsxs)(`mesh`,{quaternion:a,children:[(0,Z.jsx)(`coneGeometry`,{args:[.05,.14,8]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#38bdf8`,toneMapped:!1,transparent:!0,opacity:.85})]},t))})}function xw(){let e=Q(e=>e.selectedIds),t=Q(e=>e.parts),n=Q(e=>e.placingType),r=Q(e=>e.tool);if(n||r===`measure`||!e.length)return null;let i=[];for(let n of e){let e=t[n];e&&i.push(...nS(e))}return(0,Z.jsxs)(Z.Fragment,{children:[e.filter(e=>t[e]?.type===`pipe`).map(e=>(0,Z.jsx)(ww,{partId:e},`pipe-stretch-${e}`)),i.map(e=>(0,Z.jsx)(Cw,{conn:e,dimmed:t[e.partId]?.type===`pipe`},e.key)),(0,Z.jsx)(Ew,{})]})}var Sw=e=>new Mn().setFromUnitVectors(new q(0,0,1),new q(...e).normalize());function Cw({conn:e,dimmed:t=!1}){let n=Q(e=>e.draggingId),[r,i]=(0,v.useState)(!1);vy(r,`grab`);let a=(0,v.useMemo)(()=>Sw(e.dir),[e.dir[0],e.dir[1],e.dir[2]]),o=n!==null&&rC.connectorKey===e.key,s=r||o;return(0,Z.jsxs)(`group`,{position:e.pos,children:[(0,Z.jsxs)(`mesh`,{userData:{connectorHandle:!0},onPointerDown:t=>{if(t.button!==0)return;let n=Q.getState();if(n.placingType||n.tool===`measure`)return;t.stopPropagation();let r=t.clientX,i=t.clientY,a=t=>{window.removeEventListener(`pointerup`,a);let o=t.clientX-r,s=t.clientY-i;Math.hypot(o,s)<4&&n.spawnPipeAtConnector(e.key)};window.addEventListener(`pointerup`,a),iC({partId:e.partId,grabPoint:e.pos,mode:`handle`,connectorKey:e.key})},onPointerOver:e=>{if(Q.getState().draggingId)return;let t=e.intersections.find(e=>e.object.userData?.connectorHandle);t?.object!==e.object||t.distance>(e.intersections[0]?.distance??1/0)+.5||i(!0)},onPointerOut:()=>i(!1),children:[(0,Z.jsx)(`sphereGeometry`,{args:[.22,10,10]}),(0,Z.jsx)(`meshBasicMaterial`,{visible:!1})]}),(0,Z.jsxs)(`mesh`,{scale:s?1.4:1,renderOrder:998,children:[(0,Z.jsx)(`sphereGeometry`,{args:[t?.05:.075,14,14]}),(0,Z.jsx)(`meshBasicMaterial`,{color:s?`#bae6fd`:`#38bdf8`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:t?s?.85:.45:.95})]}),(0,Z.jsxs)(`mesh`,{quaternion:a,scale:s?1.25:1,renderOrder:998,children:[(0,Z.jsx)(`torusGeometry`,{args:[t?.11:.15,t?.014:.018,8,24]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#38bdf8`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:t?s?.8:.35:s?.95:.55})]})]})}function ww({partId:e}){let t=Q(t=>t.parts[e]),n=Q(e=>e.draggingId);if(!t||t.type!==`pipe`)return null;let r=nS(t),i=r.find(e=>e.connectorId===`a`),a=r.find(e=>e.connectorId===`b`);if(!i||!a)return null;let o=t.params.length??0,s=[(i.pos[0]+a.pos[0])/2,(i.pos[1]+a.pos[1])/2+.28,(i.pos[2]+a.pos[2])/2],c=n===e&&!!rC.pipeStretch;return(0,Z.jsxs)(`group`,{children:[(0,Z.jsx)(mb,{points:[i.pos,a.pos],color:c?`#7dd3fc`:`#38bdf8`,lineWidth:2,transparent:!0,opacity:c?.95:.55}),(0,Z.jsx)(Tw,{conn:i}),(0,Z.jsx)(Tw,{conn:a}),(0,Z.jsx)(_y,{position:s,center:!0,distanceFactor:12,children:(0,Z.jsxs)(`div`,{className:`rounded-full border px-2 py-1 text-[10px] font-semibold whitespace-nowrap shadow-lg backdrop-blur ${c?`border-sky-400 bg-sky-300/95 text-sky-950`:`border-zinc-700 bg-zinc-950/90 text-zinc-200`}`,children:[o.toFixed(2),` ft`,(0,Z.jsx)(`span`,{className:`ml-1 text-zinc-400`,children:c?`stretching`:`drag ends to stretch`})]})})]})}function Tw({conn:e}){let t=Q(e=>e.draggingId),[n,r]=(0,v.useState)(!1);vy(n,`grab`);let i=(0,v.useMemo)(()=>Sw(e.dir),[e.dir[0],e.dir[1],e.dir[2]]),a=n||t!==null&&rC.connectorKey===e.key;return(0,Z.jsxs)(`group`,{position:e.pos,children:[(0,Z.jsxs)(`mesh`,{userData:{connectorHandle:!0},onPointerDown:t=>{if(t.button!==0)return;let n=Q.getState();n.placingType||n.tool===`measure`||(t.stopPropagation(),iC({partId:e.partId,grabPoint:e.pos,mode:`handle`,connectorKey:e.key}))},onPointerOver:e=>{if(Q.getState().draggingId)return;let t=e.intersections.find(e=>e.object.userData?.connectorHandle);t?.object!==e.object||t.distance>(e.intersections[0]?.distance??1/0)+.5||r(!0)},onPointerOut:()=>r(!1),children:[(0,Z.jsx)(`sphereGeometry`,{args:[.28,12,12]}),(0,Z.jsx)(`meshBasicMaterial`,{visible:!1})]}),(0,Z.jsxs)(`mesh`,{quaternion:i,scale:a?1.12:1,renderOrder:998,children:[(0,Z.jsx)(`cylinderGeometry`,{args:[.05,.1,.18,12]}),(0,Z.jsx)(`meshBasicMaterial`,{color:a?`#e0f2fe`:`#7dd3fc`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:.98})]}),(0,Z.jsxs)(`mesh`,{quaternion:i,position:[0,0,.11],scale:a?1.18:1,renderOrder:998,children:[(0,Z.jsx)(`coneGeometry`,{args:[.08,.16,12]}),(0,Z.jsx)(`meshBasicMaterial`,{color:a?`#38bdf8`:`#0ea5e9`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:.95})]})]})}function Ew(){let e=Q(e=>e.snapTargetKey),t=Q(e=>e.parts),n=(0,v.useRef)(null);if(j_(({clock:e})=>{if(n.current){let t=1+.18*Math.sin(e.elapsedTime*7);n.current.scale.setScalar(t)}}),!e)return null;let r=t[e.split(`:`)[0]];if(!r)return null;let i=nS(r).find(t=>t.key===e);return i?(0,Z.jsx)(`group`,{position:i.pos,children:(0,Z.jsxs)(`group`,{ref:n,children:[(0,Z.jsxs)(`mesh`,{quaternion:Sw(i.dir),renderOrder:999,children:[(0,Z.jsx)(`torusGeometry`,{args:[.24,.035,10,28]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#34d399`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:.95})]}),(0,Z.jsxs)(`mesh`,{renderOrder:999,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.1,12,12]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#6ee7b7`,toneMapped:!1,depthTest:!1,transparent:!0,opacity:.9})]})]})}):null}function Dw(){let e=Q(e=>e.selectedIds),t=Q(e=>e.parts),n=Q(e=>e.draggingId),r=Q(e=>e.placingType),i=Q(e=>e.tool),a=(0,v.useMemo)(()=>new J,[]),o=(0,v.useRef)(!1),s=(0,v.useRef)(null),c=e.map(e=>t[e]).filter(Boolean),l=[0,0,0];for(let e of c)l[0]+=e.position[0]/c.length,l[1]+=e.position[1]/c.length,l[2]+=e.position[2]/c.length;return(0,v.useLayoutEffect)(()=>{o.current||a.setPosition(l[0],l[1],l[2])}),!c.length||n||r||i===`measure`?null:(0,Z.jsx)(Hx,{matrix:a,autoTransform:!1,fixed:!0,scale:72,lineWidth:3,depthTest:!1,disableRotations:!0,disableScaling:!0,axisColors:[`#f87171`,`#4ade80`,`#60a5fa`],hoveredColor:`#fbbf24`,onDragStart:()=>{o.current=!0;let e=Q.getState();e.pushHistory(),e.setGizmoDragging(!0);let t={};for(let n of e.selectedIds){let r=e.parts[n];r&&(t[n]=[...r.position])}s.current={centroid:[...l],positions:t}},onDrag:e=>{let t=s.current;if(!t)return;let n=Q.getState();a.copy(e);let r=new q().setFromMatrixPosition(e),i=e=>n.snapToGrid?NS(e,n.gridSize):e,o=[i(r.x-t.centroid[0]),i(r.y-t.centroid[1]),i(r.z-t.centroid[2])],c=1/0;for(let e of Object.values(t.positions))c=Math.min(c,e[1]);Number.isFinite(c)&&(o[1]=Math.max(o[1],-c));let l={};for(let[e,n]of Object.entries(t.positions))l[e]=[n[0]+o[0],n[1]+o[1],n[2]+o[2]];n.setPositions(l)},onDragEnd:()=>{o.current=!1,s.current=null,Q.getState().setGizmoDragging(!1)}})}var Ow=Math.PI/2;function kw(e){switch(e){case`pipe`:case`elbow`:case`tee`:case`valve`:case`emitter`:return .25;default:return 0}}var Aw={camera:null,el:null};function jw(e,t){let{camera:n,el:r}=Aw;if(!n||!r)return null;let i=r.getBoundingClientRect(),a=new K((e-i.left)/i.width*2-1,-((t-i.top)/i.height)*2+1),o=new qd;o.setFromCamera(a,n);let s=new q;return o.ray.intersectPlane(new mo(new q(0,1,0),0),s)?[s.x,s.y,s.z]:null}function Mw(){let e=A_(e=>e.camera),t=A_(e=>e.gl.domElement),n=A_(e=>e.scene),r=Q(e=>e.setScene);return(0,v.useEffect)(()=>{Aw.camera=e,Aw.el=t},[e,t]),(0,v.useEffect)(()=>(r(n),()=>r(null)),[n,r]),null}var Nw={orbit:{pos:[9,7,11],up:[0,1,0],target:[0,1,0]},top:{pos:[0,60,0],up:[0,0,-1],target:[0,0,0]},front:{pos:[0,2,60],up:[0,1,0],target:[0,2,0]},side:{pos:[60,2,0],up:[0,1,0],target:[0,2,0]}};function Pw(e){switch(e){case`xray`:return{background:`#071019`,fogFar:180,ambient:.72,hemi:.82,dir:1.15,gridCell:`#15384a`,gridSection:`#1f536d`};case`water`:return{background:`#04131c`,fogFar:210,ambient:.3,hemi:.42,dir:.9,gridCell:`#0c2a3b`,gridSection:`#134764`};default:return{background:`#0a0e13`,fogFar:140,ambient:.45,hemi:.5,dir:1.4,gridCell:`#1b2531`,gridSection:`#2c3d52`}}}function Fw(){let e=Q(e=>e.viewMode),t=A_(e=>e.camera),n=A_(e=>e.controls);return(0,v.useEffect)(()=>{let r=Nw[e];t.position.set(...r.pos),t.up.set(...r.up),t.lookAt(...r.target),n&&(n.target.set(...r.target),n.update())},[e,t,n]),null}function Iw(){let e=Q(e=>e.placingType),t=Q(e=>e.tool),n=Q(e=>e.snapToGrid),r=Q(e=>e.gridSize),i=Q(e=>e.measurePoints),a=Q(e=>e.pipeRunPoints),o=Q(e=>e.parts),s=Q(e=>e.activeRoomId),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),f=(0,v.useMemo)(()=>Object.values(o).filter(e=>e.roomId===s),[o,s]),p=e=>n?NS(e,r):e,m=t=>[p(t.point.x),e?kw(e):0,p(t.point.z)],h=n=>{if(e&&l(m(n)),t===`pipeRun`){let e=m(n),t=aS(e,f,new Set,Bw);if(t)Q.getState().setSnapTargetKey(t.key),d(t.pos);else{let t=oS(e,f,Bw);Q.getState().setSnapTargetKey(null),d(t?t.branchPos:e)}}else Q.getState().snapTargetKey&&Q.getState().setSnapTargetKey(null)},g=n=>{if(n.delta>6)return;let r=Q.getState();if(e){r.addPart(e,m(n)),n.nativeEvent.shiftKey||r.setPlacingType(null);return}if(t===`measure`){r.addMeasurePoint([n.point.x,Math.max(0,n.point.y),n.point.z]);return}if(t===`pipeRun`){let e=m(n),t=aS(e,f,new Set,Bw);if(t)r.setSnapTargetKey(t.key),r.extendPipeRun({pos:t.pos,connectorKey:t.key},n.nativeEvent.shiftKey);else{let t=oS(e,f,Bw);r.setSnapTargetKey(null),r.extendPipeRun(t?{pos:t.pos,tapPipeId:t.partId,tapRotationY:t.rotationY,tapDiameter:t.diameter}:{pos:e},n.nativeEvent.shiftKey)}n.nativeEvent.shiftKey||r.setSnapTargetKey(null);return}n.intersections[0]?.eventObject===n.eventObject&&(n.nativeEvent.shiftKey||r.setSelected(null))},_=(0,v.useMemo)(()=>!e||!c?null:{id:`__ghost__`,type:e,position:c,rotation:[0,0,0],params:{...Yx[e].defaults}},[e,c]);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`mesh`,{rotation:[-Ow,0,0],position:[0,-.02,0],onPointerMove:h,onClick:g,children:[(0,Z.jsx)(`planeGeometry`,{args:[600,600]}),(0,Z.jsx)(`meshBasicMaterial`,{visible:!1,side:2})]}),(0,Z.jsxs)(`mesh`,{rotation:[-Ow,0,0],position:[0,-.01,0],receiveShadow:!0,children:[(0,Z.jsx)(`planeGeometry`,{args:[300,300]}),(0,Z.jsx)(`shadowMaterial`,{opacity:.35})]}),_&&(0,Z.jsx)(dw,{part:_,ghost:!0}),i.length>0&&(0,Z.jsx)(Rw,{points:i}),t===`pipeRun`&&a.length>0&&u&&(0,Z.jsx)(Lw,{points:a,hover:u})]})}function Lw({points:e,hover:t}){let n=e[e.length-1].pos,r=t,i=[n[0],.28,n[2]],a=[r[0],.28,r[2]],o=[(i[0]+a[0])/2,.55,(i[2]+a[2])/2],s=Uw(Math.hypot(r[0]-n[0],r[2]-n[2]));return(0,Z.jsxs)(`group`,{children:[e.length>1&&(0,Z.jsx)(mb,{points:e.map(e=>[e.pos[0],.26,e.pos[2]]),color:`#0ea5e9`,lineWidth:2,dashed:!0,dashScale:3}),(0,Z.jsx)(mb,{points:[i,a],color:`#38bdf8`,lineWidth:2,dashed:!0,dashScale:4}),(0,Z.jsx)(_y,{position:o,center:!0,distanceFactor:12,children:(0,Z.jsxs)(`div`,{className:`rounded bg-sky-400 px-1.5 py-0.5 font-mono text-[11px] font-bold text-sky-950 whitespace-nowrap`,children:[s.toFixed(2),` ft · Shift-click continues`]})})]})}function Rw({points:e}){let[t,n]=e,r=n?[(t[0]+n[0])/2,(t[1]+n[1])/2+.3,(t[2]+n[2])/2]:null,i=n?Math.hypot(n[0]-t[0],n[1]-t[1],n[2]-t[2]):0;return(0,Z.jsxs)(`group`,{children:[e.map((e,t)=>(0,Z.jsxs)(`mesh`,{position:e,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.09,12,12]}),(0,Z.jsx)(`meshBasicMaterial`,{color:`#fbbf24`,toneMapped:!1})]},t)),n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(mb,{points:[t,n],color:`#fbbf24`,lineWidth:2,dashed:!0,dashScale:3}),(0,Z.jsx)(_y,{position:r,center:!0,distanceFactor:12,children:(0,Z.jsxs)(`div`,{className:`rounded bg-amber-400 px-1.5 py-0.5 font-mono text-[11px] font-bold text-black whitespace-nowrap`,children:[i.toFixed(2),` ft`]})})]})]})}var zw=.45,Bw=.9,Vw=Yx.pipe.params.length.min,Hw=Yx.pipe.params.length.max;function Uw(e){return Math.min(Hw,Math.max(Vw,e))}function Ww(e){let t=rC.pipeStretch;if(!t)return null;let n=[e[0]-t.anchorPos[0],e[1]-t.anchorPos[1],e[2]-t.anchorPos[2]],r=Uw(n[0]*t.axis[0]+n[1]*t.axis[1]+n[2]*t.axis[2]),i=[t.anchorPos[0]+t.axis[0]*r,t.anchorPos[1]+t.axis[1]*r,t.anchorPos[2]+t.axis[2]*r];return{end:i,position:[(t.anchorPos[0]+i[0])/2,(t.anchorPos[1]+i[1])/2,(t.anchorPos[2]+i[2])/2],length:r}}function Gw(){let e=Q(e=>e.draggingId),t=Q(e=>e.viewMode),n=Q(e=>e.draggingId?e.parts[e.draggingId]:void 0),r=A_(e=>e.camera),[i,a]=(0,v.useState)(!1);if((0,v.useEffect)(()=>{let e=e=>e.key===`Shift`&&a(!0),t=e=>e.key===`Shift`&&a(!1);return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]),(0,v.useEffect)(()=>{if(!e)return;let t=()=>Kw(e);return window.addEventListener(`pointerup`,t),()=>window.removeEventListener(`pointerup`,t)},[e]),!e||!n)return null;let o=t===`orbit`&&i,s=`${t}:${o?`free`:`flat`}`,c=rC.groupIds.length?rC.groupIds:[e],l=n=>{let r=Q.getState(),i=r.parts[e];if(!i)return;rC.pushed||=(r.pushHistory(`drag:${e}`),!0),rC.planeKey&&rC.planeKey!==s&&(rC.grabOffset=[n.point.x-i.position[0],n.point.y-i.position[1],n.point.z-i.position[2]],rC.planeAnchor=[n.point.x,n.point.y,n.point.z]),rC.planeKey=s;let a=e=>r.snapToGrid?NS(e,r.gridSize):e;if(rC.pipeStretch&&rC.connectorKey){let i;i=o?[a(n.point.x),a(n.point.y),a(n.point.z)]:t===`front`?[a(n.point.x),a(n.point.y),rC.planeAnchor[2]]:t===`side`?[rC.planeAnchor[0],a(n.point.y),a(n.point.z)]:[a(n.point.x),rC.planeAnchor[1],a(n.point.z)];let s=Ww(i);if(!s)return;let c=aS(s.end,Object.values(r.parts).filter(e=>e.roomId===r.activeRoomId),new Set([e]));r.setSnapTargetKey(c?c.key:null),c&&c.dt.connectorId===e);if(t){let e=aS(t.pos,Object.values(r.parts).filter(e=>e.roomId===r.activeRoomId),new Set(c));r.setSnapTargetKey(e?e.key:null),e&&e.dKw(e)},f=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`planeGeometry`,{args:[600,600]}),(0,Z.jsx)(`meshBasicMaterial`,{visible:!1,side:2})]});if(o)return(0,Z.jsx)(`mesh`,{position:u,quaternion:r.quaternion,...d,children:f});let p=t===`front`||t===`side`;return(0,Z.jsx)(`mesh`,{position:p?t===`front`?[0,0,u[2]]:[u[0],0,0]:[0,u[1],0],rotation:p?t===`side`?[0,Ow,0]:[0,0,0]:[-Ow,0,0],...d,children:f})}function Kw(e){let t=Q.getState();if(t.draggingId!==e)return;let n=rC.groupIds.length?rC.groupIds:[e],r=rC.startPositions[e],i=t.parts[e],a=!r||!i?!1:Math.hypot(i.position[0]-r[0],i.position[1]-r[1],i.position[2]-r[2])>1e-6;if(rC.mode===`body`&&!a&&n.length>1){t.setSelected(e),t.setSnapTargetKey(null),t.setDraggingId(null);return}if(rC.mode===`handle`&&rC.connectorKey&&t.snapTargetKey){let r=t.parts[e],i=t.parts[t.snapTargetKey.split(`:`)[0]];if(r&&i){let a=rC.connectorKey.split(`:`)[1],o=nS(r).find(e=>e.connectorId===a),s=nS(i).find(e=>e.key===t.snapTargetKey);if(o&&s)if(rC.pipeStretch){let n=Ww(s.pos);n&&t.setPipeStretch(e,n.position,n.length)}else t.translateParts(n,[s.pos[0]-o.pos[0],s.pos[1]-o.pos[1],s.pos[2]-o.pos[2]])}}else rC.mode===`body`&&t.snapGroupToConnectors(n,e);t.setSnapTargetKey(null),t.setDraggingId(null)}function qw(){let e=Q(e=>e.parts),t=Q(e=>e.activeRoomId),n=Q(e=>e.selectedIds),r=YS();return(0,Z.jsx)(Z.Fragment,{children:(0,v.useMemo)(()=>Object.values(e).filter(e=>e.roomId===t),[e,t]).map(e=>(0,Z.jsx)(dw,{part:e,flow:r.flows[e.id]??0,selected:n.includes(e.id),connectedKeys:r.connectedKeys},e.id))})}var Jw=.05,Yw=20,Xw=.03;function Zw(){let e=Q(e=>e.draggingId),t=Q(e=>e.parts),n=Q(e=>e.activeRoomId),r=(0,v.useMemo)(()=>{if(!e)return[];let r=t[e];if(!r)return[];let[i,,a]=r.position,o=Object.values(t).filter(t=>t.id!==e&&t.roomId===n).map(e=>({p:e,d:Math.hypot(e.position[0]-i,e.position[2]-a)})).sort((e,t)=>e.d-t.d).slice(0,Yw).map(e=>e.p),s=[];for(let e of o){let[t,,n]=e.position;if(Math.abs(t-i)(0,Z.jsx)(mb,{points:e.points,color:`#22d3ee`,lineWidth:1.5,dashed:!0,dashScale:6},e.key))})}function Qw(){let e=Q(e=>e.focusTarget),t=A_(e=>e.controls),n=A_(e=>e.camera),r=(0,v.useRef)(0),i=(0,v.useRef)(new q),a=(0,v.useRef)(new q),o=(0,v.useRef)(null);return(0,v.useEffect)(()=>{!e||!t||(i.current.copy(t.target),a.current.copy(n.position),o.current=e,r.current=0)},[e,t,n]),j_((e,s)=>{let c=o.current;if(!c||!t)return;r.current=Math.min(1,r.current+s/.5);let l=r.current,u=l*l*(3-2*l);t.target.lerpVectors(i.current,new q(...c),u);let d=n.position.clone().sub(a.current),f=new q(...c).sub(i.current).multiplyScalar(u);n.position.copy(a.current).add(d).add(f),t.update(),l>=1&&(o.current=null,Q.getState().setFocusTarget(null))}),null}function $w(){let e=A_(e=>e.camera),t=A_(e=>e.controls),n=(0,v.useRef)({});return(0,v.useEffect)(()=>{let e=e=>{let t=e.target;t&&/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)||[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`].includes(e.key)&&(e.preventDefault(),n.current[e.key]=!0)},t=e=>{[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`].includes(e.key)&&(n.current[e.key]=!1)};return window.addEventListener(`keydown`,e,{passive:!1}),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]),j_((r,i)=>{let a=Math.min(.1,i),o=new q(1,0,0).applyQuaternion(e.quaternion),s=new q(0,1,0).applyQuaternion(e.quaternion),c=new q;n.current.ArrowUp&&c.add(s),n.current.ArrowDown&&c.add(s.clone().negate()),n.current.ArrowLeft&&c.add(o.clone().negate()),n.current.ArrowRight&&c.add(o),c.lengthSq()>0&&(c.normalize(),c.multiplyScalar(15*a),e.position.add(c),t&&t.target.add(c)),e.position.x=Math.max(-120,Math.min(120,e.position.x)),e.position.y=Math.max(-120,Math.min(120,e.position.y)),e.position.z=Math.max(-120,Math.min(120,e.position.z)),t&&(t.target.x=Math.max(-120,Math.min(120,t.target.x)),t.target.y=Math.max(-120,Math.min(120,t.target.y)),t.target.z=Math.max(-120,Math.min(120,t.target.z)),t.update())}),null}function eT({remoteCursors:e}){let t=Q(e=>e.activeRoomId);return(0,Z.jsx)(Z.Fragment,{children:Object.entries(e).map(([e,n])=>n.activeRoomId===t?(0,Z.jsxs)(`mesh`,{position:n.position,children:[(0,Z.jsx)(`sphereGeometry`,{args:[.15,16,16]}),(0,Z.jsx)(`meshBasicMaterial`,{color:n.color,toneMapped:!1}),(0,Z.jsx)(_y,{distanceFactor:15,center:!0,position:[0,.4,0],children:(0,Z.jsx)(`div`,{className:`px-1.5 py-0.5 rounded text-[10px] font-bold text-white whitespace-nowrap shadow-lg select-none pointer-events-none`,style:{backgroundColor:n.color},children:n.userName.split(`@`)[0]})})]},e):null)})}function tT(){let{raycaster:e}=A_();return j_(()=>{let t=new mo(new q(0,1,0),-.25),n=new q;e.ray.intersectPlane(t,n)&&window.dispatchEvent(new CustomEvent(`collab:cursor`,{detail:{x:n.x,y:n.y,z:n.z}}))}),null}function nT({remoteCursors:e={}}){let t=Q(e=>e.viewMode),n=Q(e=>e.renderMode),r=Q(e=>e.draggingId),i=Q(e=>e.gizmoDragging),a=(0,v.useRef)(null),o=Pw(n);return(0,Z.jsxs)(ty,{shadows:!0,dpr:[1,2],className:`touch-none`,children:[(0,Z.jsx)(`color`,{attach:`background`,args:[o.background]}),(0,Z.jsx)(`fog`,{attach:`fog`,args:[o.background,50,o.fogFar]}),t===`orbit`?(0,Z.jsx)(xb,{makeDefault:!0,fov:50,position:Nw.orbit.pos,near:.1,far:400}):(0,Z.jsx)(yb,{makeDefault:!0,zoom:48,position:Nw[t].pos,near:.1,far:400}),(0,Z.jsx)(Sb,{ref:a,makeDefault:!0,enabled:!r&&!i,enableRotate:t===`orbit`,enableDamping:!0,dampingFactor:.12,maxPolarAngle:Math.PI/2-.02,minDistance:2,maxDistance:120}),(0,Z.jsx)(Fw,{}),(0,Z.jsx)(Mw,{}),(0,Z.jsx)($w,{}),(0,Z.jsx)(`ambientLight`,{intensity:o.ambient}),(0,Z.jsx)(`hemisphereLight`,{args:[`#bcd6ff`,`#1a2230`,o.hemi]}),(0,Z.jsx)(`directionalLight`,{position:[12,18,8],intensity:o.dir,castShadow:!0,"shadow-mapSize":[2048,2048],"shadow-camera-left":-25,"shadow-camera-right":25,"shadow-camera-top":25,"shadow-camera-bottom":-25}),(0,Z.jsx)(Vb,{position:[0,0,0],args:[200,200],cellSize:.5,cellColor:o.gridCell,sectionSize:2.5,sectionColor:o.gridSection,fadeDistance:90,fadeStrength:1.5,infiniteGrid:!0}),(0,Z.jsx)(Iw,{}),(0,Z.jsx)(Gw,{}),(0,Z.jsx)(qw,{}),(0,Z.jsx)(xw,{}),(0,Z.jsx)(Dw,{}),(0,Z.jsx)(fw,{}),(0,Z.jsx)(UC,{}),(0,Z.jsx)(Zw,{}),(0,Z.jsx)(Qw,{}),(0,Z.jsx)(eT,{remoteCursors:e}),(0,Z.jsx)(tT,{}),(0,Z.jsx)(Ib,{alignment:`top-right`,margin:[80,80],children:(0,Z.jsx)(zb,{axisColors:[`#ef4444`,`#22c55e`,`#3b82f6`],labelColor:`white`})})]})}var rT=[`pipe`,`elbow`,`tee`,`valve`,`pump`,`reservoir`,`tower`,`tray`,`emitter`];function iT(e){let t=Number(e)-1;return Number.isInteger(t)&&t>=0&&t`quick-${e}-${t}-${crypto.randomUUID().slice(0,8)}`,sT=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],cT=(e,t,n,r)=>({...n,id:oT(e,t),position:sT(n.position,r),rotation:[...n.rotation],params:{...n.params}});function lT(e){if(!e.length)return[0,0,0];let t=Math.max(...e.map(e=>e.position[0]));return[Math.ceil(t/2)*2+4,0,0]}function uT(e,t=[0,0,0]){let n=Math.PI/2;return e===`dwcSystem`?[cT(e,`dwc-res`,{type:`reservoir`,position:[0,0,0],rotation:[0,0,0],params:{width:1.6,depth:1.6,height:1.5,level:75,ph:6,ec:1.2},label:`DWC Bucket`},t),cT(e,`dwc-pot-a`,{type:`netPot`,position:[-.3,1.5,0],rotation:[0,0,0],params:{size:1}},t),cT(e,`dwc-pot-b`,{type:`netPot`,position:[.3,1.5,0],rotation:[0,0,0],params:{size:1}},t),cT(e,`dwc-comp`,{type:`airCompressor`,position:[-1.6,0,0],rotation:[0,0,0],params:{gph:60,frequency:5,on:1},label:`DWC Aerator`},t),cT(e,`dwc-chiller`,{type:`waterChiller`,position:[0,0,-1.6],rotation:[0,0,0],params:{targetTemp:68,on:1,diameter:1},label:`Water Chiller`},t)]:e===`finiteDrainTest`?[cT(e,`res`,{type:`reservoir`,position:[-2,0,0],rotation:[0,0,0],params:{width:1,depth:1,height:1,level:10,ph:6,ec:1.2},label:`Finite test reservoir`},t),cT(e,`pump`,{type:`pump`,position:[-1.05,0,0],rotation:[0,0,0],params:{gph:400,maxHeadFt:8,on:1},label:`Drain test pump`},t),cT(e,`pipe`,{type:`pipe`,position:[.4,.25,0],rotation:[0,0,0],params:{length:2,diameter:1}},t),cT(e,`drain`,{type:`drain`,position:[1.75,0,0],rotation:[0,0,0],params:{capacityGph:1e3},label:`Open drain`},t)]:e===`dripManifold`?[cT(e,`res`,{type:`reservoir`,position:[-2,0,0],rotation:[0,0,0],params:{width:2,depth:1.4,height:1,level:70},label:`Drip reservoir`},t),cT(e,`pump`,{type:`pump`,position:[-.55,0,0],rotation:[0,0,0],params:{gph:240,maxHeadFt:8,on:1},label:`Drip pump`},t),cT(e,`pipe-feed`,{type:`pipe`,position:[.4,.25,0],rotation:[0,0,0],params:{length:1,diameter:.75}},t),cT(e,`tee-a`,{type:`tee`,position:[1.5,.25,0],rotation:[0,0,0],params:{diameter:.75},label:`Manifold split`},t),cT(e,`header`,{type:`pipe`,position:[2.35,.25,0],rotation:[0,0,0],params:{length:.5,diameter:.75}},t),cT(e,`tee-b`,{type:`tee`,position:[3.2,.25,0],rotation:[0,0,0],params:{diameter:.75}},t),cT(e,`valve-a`,{type:`valve`,position:[1.5,.25,.95],rotation:[0,-n,0],params:{diameter:.5,open:75}},t),cT(e,`branch-a`,{type:`pipe`,position:[1.5,.25,1.65],rotation:[0,-n,0],params:{length:.7,diameter:.5}},t),cT(e,`emit-a`,{type:`emitter`,position:[1.5,.25,2.2],rotation:[0,n,0],params:{},label:`Dripper A`},t),cT(e,`valve-b`,{type:`valve`,position:[3.2,.25,.95],rotation:[0,-n,0],params:{diameter:.5,open:75}},t),cT(e,`branch-b`,{type:`pipe`,position:[3.2,.25,1.65],rotation:[0,-n,0],params:{length:.7,diameter:.5}},t),cT(e,`emit-b`,{type:`emitter`,position:[3.2,.25,2.2],rotation:[0,n,0],params:{},label:`Dripper B`},t)]:[cT(e,`res`,{type:`reservoir`,position:[-2.5,0,0],rotation:[0,0,0],params:{width:2,depth:1.4,height:1,level:70},label:`NFT reservoir`},t),cT(e,`pump`,{type:`pump`,position:[-1.05,0,0],rotation:[0,0,0],params:{gph:300,maxHeadFt:8,on:1},label:`NFT pump`},t),cT(e,`feed`,{type:`pipe`,position:[.2,.25,0],rotation:[0,0,0],params:{length:1.6,diameter:1}},t),cT(e,`tray`,{type:`tray`,position:[2.5,0,0],rotation:[0,0,0],params:{length:3,width:1.2},label:`NFT channel`},t),cT(e,`return`,{type:`pipe`,position:[4.35,.15,0],rotation:[0,0,0],params:{length:.7,diameter:1}},t),cT(e,`drain`,{type:`drain`,position:[5.05,-.1,0],rotation:[0,0,0],params:{capacityGph:350},label:`NFT return drain`},t),cT(e,`pot-a`,{type:`netPot`,position:[1.8,.25,-.2],rotation:[0,0,0],params:{size:.8}},t),cT(e,`pot-b`,{type:`netPot`,position:[2.5,.25,-.2],rotation:[0,0,0],params:{size:.8}},t),cT(e,`pot-c`,{type:`netPot`,position:[3.2,.25,-.2],rotation:[0,0,0],params:{size:.8}},t)]}function dT(){let e=Math.PI/2;return[{id:`demo-res`,type:`reservoir`,position:[-4,0,0],rotation:[0,0,0],params:{width:2,depth:1.4,height:1,level:70},label:`Main reservoir`},{id:`demo-pump`,type:`pump`,position:[-2.55,0,0],rotation:[0,0,0],params:{gph:550,maxHeadFt:8,on:1},label:`Main pump`},{id:`demo-tee`,type:`tee`,position:[-1.5,.25,0],rotation:[0,0,0],params:{diameter:1}},{id:`demo-pipe1`,type:`pipe`,position:[-.4,.25,0],rotation:[0,0,0],params:{length:1,diameter:1}},{id:`demo-elbow1`,type:`elbow`,position:[.1,.25,0],rotation:[0,0,0],params:{angle:90,diameter:1}},{id:`demo-pipe2`,type:`pipe`,position:[.6,1.75,0],rotation:[0,0,e],params:{length:2,diameter:1}},{id:`demo-elbow2`,type:`elbow`,position:[.6,2.75,0],rotation:[0,0,e],params:{angle:90,diameter:1}},{id:`demo-pipe3`,type:`pipe`,position:[-1.4,3.25,0],rotation:[0,0,0],params:{length:3,diameter:1}},{id:`demo-emitter`,type:`emitter`,position:[-3.1,3.25,0],rotation:[0,0,0],params:{},label:`Return emitter`},{id:`demo-pipe4`,type:`pipe`,position:[-1.5,.25,1.1],rotation:[0,-e,0],params:{length:1,diameter:.5}},{id:`demo-drain`,type:`drain`,position:[-1.5,0,1.95],rotation:[0,-e,0],params:{capacityGph:100},label:`Floor drain`},{id:`demo-res2`,type:`reservoir`,position:[7.5,0,1.5],rotation:[0,0,0],params:{width:2,depth:1.4,height:1,level:60},label:`Tower reservoir`},{id:`demo-pump2`,type:`pump`,position:[6.05,0,1.5],rotation:[0,Math.PI,0],params:{gph:240,maxHeadFt:8,on:1},label:`Tower pump`},{id:`demo-elbow-t1`,type:`elbow`,position:[5.6,.25,1.5],rotation:[0,Math.PI,0],params:{angle:90,diameter:1}},{id:`demo-riser2`,type:`pipe`,position:[5.1,2.375,1.5],rotation:[0,0,e],params:{length:3.25,diameter:1}},{id:`demo-elbow-t2`,type:`elbow`,position:[5.1,4,1.5],rotation:[0,0,e],params:{angle:90,diameter:1}},{id:`demo-pipe-t1`,type:`pipe`,position:[4.05,4.5,1.5],rotation:[0,0,0],params:{length:1.1,diameter:1}},{id:`demo-elbow-t3`,type:`elbow`,position:[3.5,4.5,1.5],rotation:[0,0,Math.PI],params:{angle:90,diameter:1}},{id:`demo-elbow-t4`,type:`elbow`,position:[3.45,.15,1.5],rotation:[e,0,0],params:{angle:90,diameter:1}},{id:`demo-pipe-t2`,type:`pipe`,position:[3.95,.15,2.75],rotation:[0,e,0],params:{length:1.5,diameter:1}},{id:`demo-drain2`,type:`drain`,position:[3.95,-.1,3.85],rotation:[0,-e,0],params:{capacityGph:100},label:`Tower drain`},{id:`demo-tower`,type:`tower`,position:[3,0,1.5],rotation:[0,0,0],params:{height:4,sites:6},label:`Tower A`},{id:`demo-tray`,type:`tray`,position:[3,0,-1.5],rotation:[0,0,0],params:{length:3,width:1.2}},{id:`demo-pot1`,type:`netPot`,position:[2.4,.25,-1.5],rotation:[0,0,0],params:{size:1}},{id:`demo-pot2`,type:`netPot`,position:[3.4,.25,-1.5],rotation:[0,0,0],params:{size:1}},{id:`demo-lattice`,type:`lattice`,position:[5.5,0,0],rotation:[0,-e,0],params:{width:2.5,height:3}}]}var fT=`#cbd5e1`,pT=`#4ade80`;function mT({children:e,className:t}){return(0,Z.jsx)(`svg`,{viewBox:`0 0 40 40`,fill:`none`,stroke:fT,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,"aria-hidden":`true`,children:e})}function hT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`8`,y:`15`,width:`24`,height:`10`,rx:`2`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`rect`,{x:`4`,y:`12.5`,width:`5`,height:`15`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`rect`,{x:`31`,y:`12.5`,width:`5`,height:`15`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`path`,{d:`M12 18.5 H28`,strokeOpacity:.45,strokeWidth:1.5})]})}function gT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M5 10 H22 A8 8 0 0 1 30 18 V35 H20 V20 H5 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`rect`,{x:`3`,y:`8`,width:`4`,height:`14`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`rect`,{x:`18`,y:`33`,width:`14`,height:`4`,rx:`1.5`,fill:e,fillOpacity:.55})]})}function _T({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M5 13 H35 V23 H25 V35 H15 V23 H5 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`rect`,{x:`3`,y:`11`,width:`4`,height:`14`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`rect`,{x:`33`,y:`11`,width:`4`,height:`14`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`rect`,{x:`13`,y:`33`,width:`14`,height:`4`,rx:`1.5`,fill:e,fillOpacity:.55})]})}function vT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M6 15 L20 21.5 L6 28 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`path`,{d:`M34 15 L20 21.5 L34 28 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`path`,{d:`M20 21.5 V11`}),(0,Z.jsx)(`ellipse`,{cx:`20`,cy:`9`,rx:`8`,ry:`3`,stroke:e,fill:e,fillOpacity:.3})]})}function yT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`23`,y:`11`,width:`13`,height:`7`,rx:`1.5`,fill:e,fillOpacity:.45}),(0,Z.jsx)(`circle`,{cx:`18`,cy:`23`,r:`10`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`path`,{d:`M18 23 L18 16`,strokeWidth:1.8}),(0,Z.jsx)(`path`,{d:`M18 23 L12 26.5`,strokeWidth:1.8}),(0,Z.jsx)(`path`,{d:`M18 23 L24 26.5`,strokeWidth:1.8}),(0,Z.jsx)(`circle`,{cx:`18`,cy:`23`,r:`1.8`,fill:fT,stroke:`none`}),(0,Z.jsx)(`path`,{d:`M10 36 H26`})]})}function bT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`7`,y:`9`,width:`26`,height:`25`,rx:`3`}),(0,Z.jsx)(`path`,{d:`M8.5 21 Q12 18.5 15.5 21 T22.5 21 T29.5 21 L31.5 21 V29.5 Q31.5 32.5 28.5 32.5 H11.5 Q8.5 32.5 8.5 29.5 Z`,fill:e,fillOpacity:.6,stroke:`none`}),(0,Z.jsx)(`path`,{d:`M8.5 21 Q12 18.5 15.5 21 T22.5 21 T29.5 21 L31.5 21`,stroke:e,strokeWidth:1.8})]})}function xT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`16`,y:`5`,width:`8`,height:`28`,rx:`2`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`path`,{d:`M16 12 L10 9.5 V15 L16 16 Z`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`path`,{d:`M24 19 L30 16.5 V22 L24 23 Z`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`path`,{d:`M16 26 L10 23.5 V29 L16 30 Z`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`path`,{d:`M10 9.5 Q7 7 7.5 4.5 Q11 5 11.5 8.5`,fill:pT,stroke:pT,strokeWidth:1.2}),(0,Z.jsx)(`path`,{d:`M30 16.5 Q33 14 32.5 11.5 Q29 12 28.5 15.5`,fill:pT,stroke:pT,strokeWidth:1.2}),(0,Z.jsx)(`path`,{d:`M10 23.5 Q7 21 7.5 18.5 Q11 19 11.5 22.5`,fill:pT,stroke:pT,strokeWidth:1.2}),(0,Z.jsx)(`rect`,{x:`12`,y:`33`,width:`16`,height:`3.5`,rx:`1.5`,fill:e,fillOpacity:.4})]})}function ST({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M6 21 L14 14 H34 L26 21 Z`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`path`,{d:`M6 21 H26 V28 H6 Z`,fill:e,fillOpacity:.45}),(0,Z.jsx)(`path`,{d:`M26 21 L34 14 V21 L26 28 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`path`,{d:`M12 18.5 Q14 17 16 18.5`,strokeWidth:1.4,strokeOpacity:.8}),(0,Z.jsx)(`path`,{d:`M20 17.5 Q22 16 24 17.5`,strokeWidth:1.4,strokeOpacity:.8})]})}function CT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`8`,y:`6`,width:`24`,height:`28`,rx:`2`,fill:e,fillOpacity:.2}),[12.5,20.5,28.5].map(t=>[13,23].map(n=>(0,Z.jsx)(`path`,{d:`M${n} ${t} q2 2.5 4 0`,stroke:e,strokeWidth:1.8,fill:`none`},`${n}-${t}`))),(0,Z.jsx)(`path`,{d:`M14 11 q1 -2.5 3 -3`,stroke:pT,strokeWidth:1.4}),(0,Z.jsx)(`path`,{d:`M24 19 q1 -2.5 3 -3`,stroke:pT,strokeWidth:1.4}),(0,Z.jsx)(`path`,{d:`M14 27 q1 -2.5 3 -3`,stroke:pT,strokeWidth:1.4})]})}function wT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`7`,y:`7`,width:`26`,height:`26`,rx:`2`}),(0,Z.jsxs)(`g`,{stroke:e,strokeWidth:1.6,children:[(0,Z.jsx)(`path`,{d:`M7 21 L21 7`}),(0,Z.jsx)(`path`,{d:`M7 33 L33 7`}),(0,Z.jsx)(`path`,{d:`M19 33 L33 19`}),(0,Z.jsx)(`path`,{d:`M19 7 L33 21`}),(0,Z.jsx)(`path`,{d:`M7 7 L33 33`}),(0,Z.jsx)(`path`,{d:`M7 19 L21 33`})]})]})}function TT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M11 19 H29 L25.5 33 H14.5 Z`,fill:e,fillOpacity:.35}),(0,Z.jsx)(`path`,{d:`M14 22 L17 30 M19 22 L20 30 M24 22 L22 30`,strokeWidth:1.3,strokeOpacity:.7}),(0,Z.jsx)(`rect`,{x:`8.5`,y:`15.5`,width:`23`,height:`4`,rx:`1.5`,fill:e,fillOpacity:.55}),(0,Z.jsx)(`path`,{d:`M20 15 V8`,stroke:pT}),(0,Z.jsx)(`path`,{d:`M20 10 C16.5 10 14.5 7.5 14.5 4.5 C18 4.5 20 7 20 10 Z`,fill:pT,stroke:pT,strokeWidth:1}),(0,Z.jsx)(`path`,{d:`M20 10 C23.5 10 25.5 7.5 25.5 4.5 C22 4.5 20 7 20 10 Z`,fill:pT,stroke:pT,strokeWidth:1})]})}function ET({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M20 17 V10`,stroke:e,strokeWidth:1.8}),(0,Z.jsx)(`path`,{d:`M15.5 18.5 L10.5 12.5`,stroke:e,strokeWidth:1.8}),(0,Z.jsx)(`path`,{d:`M24.5 18.5 L29.5 12.5`,stroke:e,strokeWidth:1.8}),(0,Z.jsx)(`circle`,{cx:`20`,cy:`7.5`,r:`1.6`,fill:e,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`9`,cy:`10.5`,r:`1.6`,fill:e,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`31`,cy:`10.5`,r:`1.6`,fill:e,stroke:`none`}),(0,Z.jsx)(`rect`,{x:`17.5`,y:`20`,width:`5`,height:`5`,rx:`1`,fill:e,fillOpacity:.5}),(0,Z.jsx)(`path`,{d:`M14 25 H26 L24 32 H16 Z`,fill:e,fillOpacity:.3}),(0,Z.jsx)(`path`,{d:`M12 35 H28`})]})}function DT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M7 9 H33 L24 21 V29 L16 26 V21 Z`,fill:e,fillOpacity:.3}),(0,Z.jsx)(`path`,{d:`M14 12.5 V16`,strokeWidth:1.5,strokeOpacity:.8}),(0,Z.jsx)(`path`,{d:`M20 12.5 V19.5`,strokeWidth:1.5,strokeOpacity:.8}),(0,Z.jsx)(`path`,{d:`M26 12.5 V16`,strokeWidth:1.5,strokeOpacity:.8}),(0,Z.jsx)(`path`,{d:`M20 31.5 C18 34.5 18.4 36.8 20 36.8 C21.6 36.8 22 34.5 20 31.5 Z`,fill:e,stroke:`none`})]})}function OT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M7 33 V10 L12 6 H28 L33 10 V33`,fill:e,fillOpacity:.18}),(0,Z.jsx)(`path`,{d:`M12 6 V33 M28 6 V33 M7 15 H33`,stroke:e,strokeWidth:1.6}),(0,Z.jsx)(`path`,{d:`M20 15 V33`,strokeWidth:1.4,strokeOpacity:.7})]})}function kT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`circle`,{cx:`20`,cy:`20`,r:`11`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`circle`,{cx:`20`,cy:`20`,r:`4`,fill:e,fillOpacity:.6}),(0,Z.jsx)(`path`,{d:`M20 9 C25 11 27 15 25 20`,stroke:e}),(0,Z.jsx)(`path`,{d:`M31 20 C29 25 25 27 20 25`,stroke:e}),(0,Z.jsx)(`path`,{d:`M20 31 C15 29 13 25 15 20`,stroke:e}),(0,Z.jsx)(`path`,{d:`M9 20 C11 15 15 13 20 15`,stroke:e})]})}function AT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`circle`,{cx:`20`,cy:`15`,r:`8`,fill:e,fillOpacity:.18}),(0,Z.jsx)(`path`,{d:`M20 10 C23 11 24.5 13 23.5 16`,stroke:e}),(0,Z.jsx)(`path`,{d:`M25 15 C24 18 22 19.5 19 18.5`,stroke:e}),(0,Z.jsx)(`path`,{d:`M20 20 C17 19 15.5 17 16.5 14`,stroke:e}),(0,Z.jsx)(`path`,{d:`M20 23 V34`,stroke:e}),(0,Z.jsx)(`path`,{d:`M14 34 H26`,stroke:e})]})}function jT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`8`,y:`9`,width:`24`,height:`8`,rx:`2`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`path`,{d:`M12 9 L15 5 M28 9 L25 5`}),(0,Z.jsx)(`path`,{d:`M12 21 L10 27 M18 21 L18 29 M24 21 L26 27 M30 21 L32 27`,stroke:e})]})}function MT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`14`,y:`8`,width:`12`,height:`24`,rx:`4`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`rect`,{x:`17`,y:`5`,width:`6`,height:`4`,rx:`1.5`,fill:e,fillOpacity:.5}),(0,Z.jsx)(`path`,{d:`M23 7 H28`}),(0,Z.jsx)(`text`,{x:`20`,y:`23`,textAnchor:`middle`,fontSize:`7`,fill:fT,stroke:`none`,children:`CO2`})]})}function NT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`9`,y:`9`,width:`22`,height:`22`,rx:`5`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`circle`,{cx:`20`,cy:`20`,r:`3`,fill:e,stroke:`none`})]})}function PT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`8`,y:`14`,width:`24`,height:`16`,rx:`3`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`32`,r:`2`,fill:e,fillOpacity:.6}),(0,Z.jsx)(`circle`,{cx:`28`,cy:`32`,r:`2`,fill:e,fillOpacity:.6}),(0,Z.jsx)(`rect`,{x:`30`,y:`19`,width:`4`,height:`4`,fill:fT}),(0,Z.jsx)(`circle`,{cx:`16`,cy:`22`,r:`3`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`line`,{x1:`16`,y1:`22`,x2:`18`,y2:`20`,stroke:fT,strokeWidth:1.5})]})}var FT={pipe:hT,elbow:gT,tee:_T,valve:vT,pump:yT,reservoir:bT,tower:xT,tray:ST,wallPanel:CT,lattice:wT,netPot:TT,emitter:ET,drain:DT,growTent:OT,inlineFan:kT,circulationFan:AT,growLight:jT,co2Tank:MT,airCompressor:PT,reducingTee:IT,reducingElbow:LT,bulkhead:RT,waterChiller:zT,reverseOsmosis:BT};function IT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M 6,18 L 34,18`,stroke:e,strokeWidth:8,strokeLinecap:`round`}),(0,Z.jsx)(`path`,{d:`M 6,18 L 34,18`,stroke:fT,strokeWidth:1.5}),(0,Z.jsx)(`path`,{d:`M 20,18 L 20,30`,stroke:e,strokeWidth:4.5,strokeLinecap:`round`}),(0,Z.jsx)(`path`,{d:`M 20,18 L 20,30`,stroke:fT,strokeWidth:1.2})]})}function LT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`path`,{d:`M 8,28 A 12,12 0 0,1 28,8`,fill:`none`,stroke:e,strokeWidth:7,strokeLinecap:`round`}),(0,Z.jsx)(`path`,{d:`M 8,28 A 12,12 0 0,1 28,8`,fill:`none`,stroke:fT,strokeWidth:1.5}),(0,Z.jsx)(`line`,{x1:`8`,y1:`28`,x2:`12`,y2:`28`,stroke:fT,strokeWidth:1.5}),(0,Z.jsx)(`line`,{x1:`28`,y1:`8`,x2:`28`,y2:`12`,stroke:fT,strokeWidth:1.5})]})}function RT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`18`,y:`6`,width:`4`,height:`28`,fill:e,fillOpacity:.4,stroke:e,strokeWidth:1.2}),(0,Z.jsx)(`rect`,{x:`10`,y:`14`,width:`20`,height:`12`,fill:e,fillOpacity:.25,rx:`1`}),(0,Z.jsx)(`rect`,{x:`12`,y:`16`,width:`16`,height:`8`,fill:`none`,stroke:fT,strokeWidth:1.5})]})}function zT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`8`,y:`12`,width:`24`,height:`22`,rx:`2`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`rect`,{x:`12`,y:`7`,width:`3`,height:`5`,fill:e}),(0,Z.jsx)(`rect`,{x:`25`,y:`7`,width:`3`,height:`5`,fill:e}),(0,Z.jsx)(`rect`,{x:`14`,y:`17`,width:`12`,height:`6`,fill:`#09090b`,rx:`1`}),(0,Z.jsx)(`circle`,{cx:`20`,cy:`20`,r:`1.5`,fill:`#22c55e`}),(0,Z.jsx)(`line`,{x1:`12`,y1:`27`,x2:`28`,y2:`27`,stroke:fT,strokeWidth:1.2}),(0,Z.jsx)(`line`,{x1:`12`,y1:`30`,x2:`28`,y2:`30`,stroke:fT,strokeWidth:1.2})]})}function BT({color:e,className:t}){return(0,Z.jsxs)(mT,{className:t,children:[(0,Z.jsx)(`rect`,{x:`4`,y:`18`,width:`32`,height:`4`,rx:`1`,fill:e,fillOpacity:.4}),(0,Z.jsx)(`rect`,{x:`11`,y:`10`,width:`18`,height:`20`,rx:`3`,fill:e,fillOpacity:.25}),(0,Z.jsx)(`line`,{x1:`11`,y1:`15`,x2:`29`,y2:`15`,stroke:fT,strokeWidth:1.5}),(0,Z.jsx)(`line`,{x1:`11`,y1:`20`,x2:`29`,y2:`20`,stroke:fT,strokeWidth:1.5}),(0,Z.jsx)(`line`,{x1:`11`,y1:`25`,x2:`29`,y2:`25`,stroke:fT,strokeWidth:1.5})]})}function VT({type:e,color:t,className:n}){return(0,Z.jsx)(FT[e]??NT,{color:t??Yx[e]?.color??`#71717a`,className:n})}function HT(){let e=Q(e=>e.parts),t=Q(e=>e.placingType),n=Q(e=>e.setPlacingType),r=Q(e=>e.addPart),i=Q(e=>e.updatePart),a=Q(e=>e.setSelected),o=Q(e=>e.toggleSelected),[s,c]=(0,v.useState)(``),l=s.toLowerCase(),u=e=>Yx[e].label.toLowerCase().includes(l),d=l?rT.filter(u):rT,f=l?aT.filter(e=>e.label.toLowerCase().includes(l)):aT,p=Xx.map(e=>({...e,types:l?e.types.filter(u):e.types})).filter(e=>e.types.length>0),m=t=>{n(null);let s=uT(t,lT(Object.values(e))).map(e=>{let t=r(e.type,e.position,{snap:!1});return i(t,{rotation:e.rotation,params:e.params,label:e.label,color:e.color}),t});a(s[0]??null),s.slice(1).forEach(o)};return(0,Z.jsxs)(`aside`,{className:`flex w-56 shrink-0 flex-col border-r border-zinc-800 bg-zinc-950/80 backdrop-blur`,children:[(0,Z.jsxs)(`div`,{className:`border-b border-zinc-800 px-4 py-3`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-semibold tracking-widest text-zinc-400 uppercase`,children:`Parts Library`}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] leading-snug text-zinc-600`,children:`Click then place in scene, or drag onto the canvas. Shift-click to stamp copies.`})]}),(0,Z.jsx)(`div`,{className:`px-3 pt-2`,children:(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Search parts…`,className:`w-full rounded-md border border-zinc-800 bg-zinc-900 px-2.5 py-1.5 text-xs text-zinc-200 placeholder:text-zinc-600 outline-none focus:border-zinc-600 focus:ring-1 focus:ring-zinc-700`}),s&&(0,Z.jsx)(`button`,{onClick:()=>c(``),className:`absolute right-1.5 top-1/2 -translate-y-1/2 rounded px-1 text-xs text-zinc-500 hover:text-zinc-300`,children:`×`})]})}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:[d.length>0&&(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`h3`,{className:`px-1 py-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Tool Belt`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-3 gap-1.5`,children:d.map((e,r)=>(0,Z.jsx)(WT,{type:e,active:t===e,badge:l?void 0:`${r+1}`,compact:!0,onClick:()=>n(t===e?null:e)},`hotbar-${e}`))})]}),f.length>0&&(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`h3`,{className:`px-1 py-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Quick Builds`}),(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:f.map(e=>(0,Z.jsx)(UT,{label:e.label,description:e.description,onClick:()=>m(e.id)},e.id))})]}),p.map(e=>(0,Z.jsxs)(`div`,{className:`mb-3`,children:[(0,Z.jsx)(`h3`,{className:`px-1 py-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:e.name}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:e.types.map(e=>(0,Z.jsx)(WT,{type:e,active:t===e,onClick:()=>n(t===e?null:e)},e))})]},e.name))]})]})}function UT({label:e,description:t,onClick:n}){return(0,Z.jsxs)(`button`,{onClick:n,title:t,className:`flex items-center justify-between gap-2 rounded-lg border border-zinc-800 bg-zinc-900/60 px-3 py-2 text-left text-zinc-200 transition hover:border-emerald-500/60 hover:bg-emerald-500/10 hover:text-emerald-100`,children:[(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`block text-[12px] leading-tight font-semibold`,children:e}),(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[10px] leading-snug text-zinc-500`,children:t})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-sm text-emerald-400`,children:`+`})]})}function WT({type:e,active:t,badge:n,compact:r,onClick:i}){let a=Yx[e];return(0,Z.jsxs)(`button`,{draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/x-hydro-part`,e),t.dataTransfer.effectAllowed=`copy`},onClick:i,title:t?`${a.description} — click again to cancel${n?` (${n})`:``}`:`${a.description}${n?` (${n})`:``}`,className:`group relative flex flex-col items-center gap-1 rounded-lg border px-1.5 text-center transition ${t?`border-sky-400 bg-sky-500/15 text-sky-300 shadow-[0_0_10px_-2px_rgba(56,189,248,0.6)] ring-1 ring-sky-400/40`:`border-zinc-800 bg-zinc-900/60 text-zinc-300 hover:border-zinc-600 hover:bg-zinc-800/80`} ${r?`py-1.5`:`py-2`}`,children:[n&&(0,Z.jsx)(`span`,{className:`absolute top-1 left-1 rounded bg-zinc-950/90 px-1 py-0.5 text-[9px] font-bold leading-none text-zinc-400 ring-1 ring-zinc-800`,children:n}),(0,Z.jsx)(VT,{type:e,className:`${r?`h-7 w-7`:`h-9 w-9`} transition-transform duration-150 group-hover:scale-110 ${t?`scale-110 drop-shadow-[0_0_4px_rgba(56,189,248,0.5)]`:``}`}),(0,Z.jsx)(`span`,{className:`w-full font-medium break-words ${r?`text-[10px]`:`text-[11px] leading-tight`}`,children:a.label}),t&&(0,Z.jsx)(`span`,{className:`text-[9px] font-semibold tracking-wider text-sky-400 uppercase`,children:`Placing…`})]})}function GT(e,t){let n=e.params.width??0,r=e.params.depth??0,i=e.params.height??0,[a,o,s]=e.position,[c,l,u]=t.position;return c>=a-n/2&&c<=a+n/2&&u>=s-r/2&&u<=s+r/2&&l>=o&&l<=o+i}function KT(e){let t=Object.values(e);return t.filter(e=>e.type===`growTent`).map(e=>{let n=t.filter(t=>t.id!==e.id&>(e,t)),r=n.filter(e=>e.type===`inlineFan`&&(e.params.exhaust??1)>0).reduce((e,t)=>e+(t.params.cfm??0),0),i=n.filter(e=>e.type===`circulationFan`).reduce((e,t)=>e+(t.params.cfm??0),0),a=n.filter(e=>e.type===`growLight`).reduce((e,t)=>e+(t.params.watts??0),0),o=n.filter(e=>e.type===`co2Tank`),s=o.reduce((e,t)=>e+(t.params.regulatorCfh??0),0),c=(e.params.width??0)*(e.params.depth??0)*(e.params.height??0),l=c>0?r/c:0,u=(e.params.width??0)*(e.params.depth??0),d=u>0?a*2/u:0,f=n.filter(e=>e.type===`growLight`),p=u>0&&f.length>0?f.reduce((e,t)=>{let n=t.params.watts??0,r=t.params.photoperiod??18;return e+n*2/u*r*.0036},0):0,m=f.reduce((e,t)=>{let n=t.params.photoperiod??18,r=t.params.watts??0;return e+(n>0?r:0)},0),h=75+.01*m,g=e.params.humidity??60,_=(h-32)*5/9,v=.61078*Math.exp(17.27*_/(_+237.3)),y=v*(1-g/100),b=(e.params.sealed??0)>0,x=m>0,S=400;b&&x?S=o.length===0?150:1200:o.length>0&&(S=1200);let C=m*3.412,w=Math.max(.1,Math.min(1,y/1.2)),T=m*.032*w,E=T/24*1060,D=.01352*(g/100*v)/(_+273.15),O=.01352*(.61078*Math.exp(215/9*17.27/261.1888888888889)*.5)/297.0388888888889,k=0;!b&&r>0&&(k=Math.max(0,r*1381*(D-O)));let A=Math.max(0,T-k),j=0;!b&&r>0&&(j=r*1.08*(h-75));let M=A/24*1200,N=C-E-j+M,P=Math.max(0,N*1.15);return{roomId:e.id,label:e.label??`Grow room`,sealed:b,volumeFt3:c,exhaustCfm:r,circulationCfm:i,lightWatts:a,co2TankCount:o.length,co2Cfh:s,airChangesPerMinute:l,airChangesPerHour:l*60,roomPPFD:d,roomDLI:p,roomTempF:h,roomRH:g,roomVPD:y,roomCo2:S,sensibleHeatGainsBtuHr:C,latentCoolingBtuHr:E,acSizingBtuHr:P,dehumidifierPintsDay:A}})}var qT=[`#b8bfc9`,`#64748b`,`#38bdf8`,`#3d7bfa`,`#34d399`,`#3b7a57`,`#fbbf24`,`#f97316`,`#e0564f`,`#a78bfa`];function JT({ids:e}){let t=Q(e=>e.applyColor),n=Q(t=>{let n=e.length?t.parts[e[0]]:void 0;return n?n.color??Yx[n.type].color:`#888888`});return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`grid grid-cols-5 gap-1.5`,children:qT.map(r=>(0,Z.jsx)(`button`,{title:r,onClick:()=>t(e,r),className:`h-6 w-full rounded-md ring-1 transition hover:scale-110 ${n.toLowerCase()===r?`ring-2 ring-white`:`ring-black/40`}`,style:{backgroundColor:r}},r))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsxs)(`label`,{className:`relative flex h-6 flex-1 cursor-pointer items-center justify-center gap-1 overflow-hidden rounded-md border border-zinc-700 bg-zinc-800 text-[10px] font-medium text-zinc-300 hover:bg-zinc-700`,title:`Pick a custom color`,children:[(0,Z.jsx)(`span`,{className:`h-3 w-3 rounded-sm ring-1 ring-black/40`,style:{backgroundColor:n}}),`Custom`,(0,Z.jsx)(`input`,{type:`color`,value:n,onChange:n=>t(e,n.target.value),className:`absolute inset-0 cursor-pointer opacity-0`})]}),(0,Z.jsx)(`button`,{onClick:()=>t(e,void 0),title:`Reset to the catalog color`,className:`h-6 rounded-md border border-zinc-700 bg-zinc-800 px-2 text-[10px] font-medium text-zinc-300 hover:bg-zinc-700`,children:`Reset`})]})]})}function YT(){let e=Q(e=>e.colorPopover),t=Q(e=>e.selectedIds),n=Q(e=>e.closeColorPopover),r=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(!e)return;let t=e=>{r.current&&!r.current.contains(e.target)&&n()};return window.addEventListener(`pointerdown`,t,!0),()=>window.removeEventListener(`pointerdown`,t,!0)},[e,n]),!e||!t.length?null:(0,Z.jsxs)(`div`,{ref:r,className:`fixed z-50 w-[188px] rounded-xl border border-zinc-700 bg-zinc-900/95 p-2.5 shadow-2xl backdrop-blur`,style:{left:Math.max(8,Math.min(e.x,window.innerWidth-196)),top:Math.max(8,Math.min(e.y+10,window.innerHeight-150))},children:[(0,Z.jsxs)(`div`,{className:`mb-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:[`Color · `,t.length,` part`,t.length>1?`s`:``]}),(0,Z.jsx)(JT,{ids:t})]})}var XT=e=>Math.round(e*180/Math.PI),ZT=e=>e*Math.PI/180;function QT(){let e=Q(e=>e.selectedIds);return(0,Z.jsxs)(`aside`,{className:`flex w-64 shrink-0 flex-col border-l border-zinc-800 bg-zinc-950/80 backdrop-blur`,children:[(0,Z.jsx)(`div`,{className:`border-b border-zinc-800 px-4 py-3`,children:(0,Z.jsxs)(`h2`,{className:`text-xs font-semibold tracking-widest text-zinc-400 uppercase`,children:[`Inspector`,e.length>1&&(0,Z.jsxs)(`span`,{className:`ml-2 rounded-full bg-sky-500/15 px-2 py-0.5 text-[10px] font-bold text-sky-300`,children:[e.length,` selected`]})]})}),e.length===0?(0,Z.jsx)($T,{}):e.length===1?(0,Z.jsx)(uE,{partId:e[0]}):(0,Z.jsx)(tE,{ids:e})]})}function $T(){let e=Q(e=>e.growthStage),t=Q(e=>e.setGrowthStage);return(0,Z.jsxs)(`div`,{className:`px-4 py-6 text-xs leading-relaxed text-zinc-600 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`rounded-lg border border-zinc-800 bg-zinc-900/30 p-3`,children:[(0,Z.jsx)(`h3`,{className:`mb-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Crop Growth Stage`}),(0,Z.jsxs)(`select`,{value:e,onChange:e=>t(e.target.value),className:`w-full rounded-md border border-zinc-800 bg-zinc-900 px-2 py-1.5 text-xs text-zinc-200 outline-none focus:border-sky-600 cursor-pointer`,children:[(0,Z.jsx)(`option`,{value:`seedling`,children:`Seedling`}),(0,Z.jsx)(`option`,{value:`vegetative`,children:`Vegetative`}),(0,Z.jsx)(`option`,{value:`flowering`,children:`Flowering`})]})]}),(0,Z.jsxs)(`div`,{children:[`Select a part to edit its properties.`,(0,Z.jsxs)(`ul`,{className:`mt-4 space-y-1.5 text-[11px] text-zinc-700`,children:[(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`Click`}),` select · drag to move`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`⇧Click`}),` add/remove from selection`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`⌘Click`}),` change color`]}),(0,Z.jsxs)(`li`,{children:[`Drag `,(0,Z.jsx)(`span`,{className:`text-sky-600`,children:`connector dots`}),` to snap pipes`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`⇧Drag`}),` move vertically (3D view)`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`⌥Drag`}),` clone while dragging`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`Space`}),` play / pause water`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`R`}),` rotate 90° \xA0 `,(0,Z.jsx)(eE,{children:`Q`}),`/`,(0,Z.jsx)(eE,{children:`E`}),` lower / raise`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`D`}),` duplicate \xA0 `,(0,Z.jsx)(eE,{children:`⌫`}),` delete`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`⌘Z`}),` undo \xA0 `,(0,Z.jsx)(eE,{children:`⇧⌘Z`}),` redo`]}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(eE,{children:`Esc`}),` deselect / cancel`]})]})]})]})}function eE({children:e}){return(0,Z.jsx)(`kbd`,{className:`rounded border border-zinc-700 bg-zinc-800 px-1.5 py-0.5 font-mono text-[10px] text-zinc-300`,children:e})}function tE({ids:e}){let t=Q(e=>e.parts),n=Q(e=>e.removeParts),r=Q(e=>e.duplicateParts),i=new Map;for(let n of e){let e=t[n];if(!e)continue;let r=Yx[e.type].label;i.set(r,(i.get(r)??0)+1)}return(0,Z.jsxs)(`div`,{className:`flex-1 space-y-4 overflow-y-auto px-4 py-3`,children:[(0,Z.jsxs)(dE,{title:`Selection`,children:[(0,Z.jsx)(`ul`,{className:`space-y-1`,children:[...i.entries()].map(([e,t])=>(0,Z.jsxs)(`li`,{className:`flex justify-between text-xs text-zinc-300`,children:[(0,Z.jsx)(`span`,{children:e}),(0,Z.jsxs)(`span`,{className:`font-mono text-zinc-500`,children:[`× `,t]})]},e))}),(0,Z.jsx)(`p`,{className:`mt-2 text-[10px] leading-relaxed text-zinc-600`,children:`Drag any selected part (or the gizmo) to move the whole group.`})]}),(0,Z.jsx)(dE,{title:`Color`,children:(0,Z.jsx)(JT,{ids:e})}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,Z.jsx)(`button`,{onClick:()=>r(e),title:`Duplicate the whole selection (D)`,className:`flex-1 rounded-md border border-zinc-700 bg-zinc-800 px-2 py-1.5 text-xs font-medium text-zinc-200 hover:bg-zinc-700`,children:`Duplicate`}),(0,Z.jsx)(`button`,{onClick:()=>n(e),title:`Delete every selected part (⌫)`,className:`flex-1 rounded-md border border-rose-900 bg-rose-950 px-2 py-1.5 text-xs font-medium text-rose-300 hover:bg-rose-900`,children:`Delete`})]})]})}var nE=new Set([`gph`,`maxHeadFt`]),rE=new Set([`gph`,`frequency`]),iE=new Set([`ph`,`ec`]);function aE({part:e}){let t=Q(e=>e.setParam),n=YS(),r=(0,v.useRef)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=t=>{t.detail===e.id&&(r.current?.scrollIntoView({behavior:`smooth`,block:`nearest`}),a(!0),setTimeout(()=>a(!1),1e3))};return window.addEventListener(`hydro:flash-pump`,t),()=>window.removeEventListener(`hydro:flash-pump`,t)},[e.id]);let o=Yx.pump,s=(e.params.on??1)>0,c=n.pumps.find(t=>t.pumpId===e.id),l=e.params.gph??o.defaults.gph,u=e.params.maxHeadFt??o.defaults.maxHeadFt;return(0,Z.jsxs)(`div`,{ref:r,className:`rounded-lg border p-3 transition-all duration-300 ${i?`border-sky-400 bg-sky-950/60 ring-2 ring-sky-400/60`:`border-sky-900/70 bg-sky-950/30`}`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold tracking-wider text-sky-400 uppercase`,children:`Pump`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.id,`on`,+!s),title:s?`Turn pump off`:`Turn pump on`,className:`relative h-6 w-12 rounded-full transition-colors ${s?`bg-emerald-500`:`bg-zinc-700`}`,children:(0,Z.jsx)(`span`,{className:`absolute top-0.5 grid h-5 w-5 place-items-center rounded-full bg-white text-[8px] font-black text-zinc-700 shadow transition-all ${s?`left-6`:`left-0.5`}`,children:s?`I`:`O`})})]}),(0,Z.jsxs)(`div`,{className:`mb-2 rounded-md bg-zinc-900/70 px-2.5 py-1.5`,children:[(0,Z.jsxs)(`div`,{className:`text-lg font-bold tabular-nums text-sky-300`,children:[c&&s?c.gph.toFixed(0):`0`,(0,Z.jsx)(`span`,{className:`ml-1 text-[10px] font-medium text-zinc-500`,children:`GPH delivered`})]}),(0,Z.jsx)(`div`,{className:`text-[10px] text-zinc-500 tabular-nums`,children:c?`head ${c.headFt.toFixed(1)} / ${c.maxHeadFt} ft`:`not connected to a reservoir`})]}),(0,Z.jsx)(lE,{label:`Rated flow`,unit:`GPH`,value:l,meta:o.params.gph,onChange:n=>t(e.id,`gph`,n)}),(0,Z.jsx)(lE,{label:`Max head`,unit:`ft`,value:u,meta:o.params.maxHeadFt,onChange:n=>t(e.id,`maxHeadFt`,n)})]})}function oE({part:e}){let t=Q(e=>e.setParam),n=Q(e=>e.parts),r=(0,v.useRef)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=t=>{t.detail===e.id&&(r.current?.scrollIntoView({behavior:`smooth`,block:`nearest`}),a(!0),setTimeout(()=>a(!1),1e3))};return window.addEventListener(`hydro:flash-airCompressor`,t),()=>window.removeEventListener(`hydro:flash-airCompressor`,t)},[e.id]);let o=Yx.airCompressor,s=(e.params.on??1)>0,c=e.params.gph??o.defaults.gph,l=e.params.frequency??o.defaults.frequency,u=(0,v.useMemo)(()=>{let t=null,r=1/0,i=e.position;for(let e of Object.values(n))if(e.type===`reservoir`){let n=Math.hypot(e.position[0]-i[0],e.position[1]-i[1],e.position[2]-i[2]);n{if(!u)return null;let e=0;for(let t of Object.values(n))if(t.type===`airCompressor`&&(t.params.on??1)>0){let r=null,i=1/0;for(let e of Object.values(n))if(e.type===`reservoir`){let n=Math.hypot(e.position[0]-t.position[0],e.position[1]-t.position[1],e.position[2]-t.position[2]);n0&&o>0){let t=e/o;s=5.5+3.7*(1-Math.exp(-t*2))}return{volGal:o,totalAerationGph:e,tdo:s}},[n,u]);return(0,Z.jsxs)(`div`,{ref:r,className:`rounded-lg border p-3 transition-all duration-300 ${i?`border-sky-400 bg-sky-950/60 ring-2 ring-sky-400/60`:`border-sky-900/70 bg-sky-950/30`}`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold tracking-wider text-sky-400 uppercase`,children:`Air Compressor`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.id,`on`,+!s),title:s?`Turn compressor off`:`Turn compressor on`,className:`relative h-6 w-12 rounded-full transition-colors ${s?`bg-emerald-500`:`bg-zinc-700`}`,children:(0,Z.jsx)(`span`,{className:`absolute top-0.5 grid h-5 w-5 place-items-center rounded-full bg-white text-[8px] font-black text-zinc-700 shadow transition-all ${s?`left-6`:`left-0.5`}`,children:s?`I`:`O`})})]}),(0,Z.jsxs)(`div`,{className:`mb-3 rounded-md bg-zinc-900/70 px-2.5 py-1.5 space-y-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-semibold text-zinc-400`,children:`Target Reservoir:`}),u?(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center text-xs text-zinc-200`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:u.label||`Reservoir #${u.id}`}),(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500`,children:[Math.hypot(u.position[0]-e.position[0],u.position[2]-e.position[2]).toFixed(1),` ft away`]})]}),d&&(0,Z.jsxs)(`div`,{className:`mt-1.5 pt-1.5 border-t border-zinc-800/60 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] text-zinc-500`,children:`Dissolved O₂:`}),(0,Z.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] font-bold ${d.tdo>=8?`bg-emerald-500/10 text-emerald-400 border border-emerald-500/20`:d.tdo>=7?`bg-sky-500/10 text-sky-400 border border-sky-500/20`:`bg-amber-500/10 text-amber-400 border border-amber-500/20`}`,children:[d.tdo.toFixed(1),` mg/L`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between text-[9px] text-zinc-500`,children:[(0,Z.jsx)(`span`,{children:`Tank Volume:`}),(0,Z.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[d.volGal.toFixed(1),` Gal`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between text-[9px] text-zinc-500`,children:[(0,Z.jsx)(`span`,{children:`Total Aeration:`}),(0,Z.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[d.totalAerationGph,` GPH`]})]})]})]}):(0,Z.jsx)(`div`,{className:`text-xs text-amber-400/80 font-medium`,children:`No reservoir in scene!`})]}),(0,Z.jsx)(lE,{label:`Air Flow`,unit:`GPH`,value:c,meta:o.params.gph,onChange:n=>t(e.id,`gph`,n)}),(0,Z.jsx)(lE,{label:`Bubble Frequency`,unit:`Hz`,value:l,meta:o.params.frequency,onChange:n=>t(e.id,`frequency`,n)})]})}function sE({part:e}){let t=Q(e=>e.parts),n=(0,v.useMemo)(()=>KT(t).find(t=>t.roomId===e.id),[t,e.id]);return n?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-sky-900/50 bg-sky-950/20 p-3 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold tracking-wider text-sky-400 uppercase`,children:`Room Simulation`}),(0,Z.jsxs)(`span`,{className:`font-mono text-xs text-sky-300`,children:[n.volumeFt3.toFixed(0),` ft³`]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`VPD`}),(0,Z.jsxs)(`div`,{className:`mt-0.5 text-xs font-bold text-emerald-400`,children:[n.roomVPD.toFixed(2),(0,Z.jsx)(`span`,{className:`text-[8px] font-normal text-zinc-500 ml-0.5`,children:`kPa`})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`DLI`}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs font-bold text-amber-400`,children:n.roomDLI.toFixed(1)})]}),(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`CO₂`}),(0,Z.jsxs)(`div`,{className:`mt-0.5 text-xs font-bold text-sky-400`,children:[n.roomCo2,(0,Z.jsx)(`span`,{className:`text-[8px] font-normal text-zinc-500 ml-0.5`,children:`PPM`})]})]})]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-zinc-400 space-y-1 pt-1.5 border-t border-zinc-800/60 font-mono`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Est. Temp:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-200`,children:[n.roomTempF.toFixed(1),`°F`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Est. RH:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-200`,children:[n.roomRH,`%`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Room PPFD:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-200`,children:[n.roomPPFD.toFixed(0),` μmol/m²/s`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`AC Sizing:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-300 font-semibold`,children:[Math.round(n.acSizingBtuHr),` BTU/hr`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Dehumidifier:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-300 font-semibold`,children:[n.dehumidifierPintsDay.toFixed(1),` Pints/day`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Sensible Heat:`}),(0,Z.jsxs)(`span`,{className:`text-zinc-500`,children:[Math.round(n.sensibleHeatGainsBtuHr),` BTU/hr`]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Latent Cooling:`}),(0,Z.jsxs)(`span`,{className:`text-emerald-500/80`,children:[Math.round(n.latentCoolingBtuHr),` BTU/hr`]})]})]})]}):null}function cE({part:e}){let t=Q(e=>e.setParam),n=Q(e=>e.parts),r=Q(e=>e.growthStage),i=YS(),a=(0,v.useMemo)(()=>nC(e,n),[e,n]),o=i.reservoirRuntime[e.id],{ecLow:s,ecHigh:c}=(0,v.useMemo)(()=>r===`seedling`?{ecLow:.4,ecHigh:.8}:r===`flowering`?{ecLow:1.5,ecHigh:2.2}:{ecLow:1,ecHigh:1.6},[r]),l=a.ecc;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-sky-900/50 bg-sky-950/20 p-3 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold tracking-wider text-sky-400 uppercase`,children:`Reservoir Health`}),(0,Z.jsxs)(`span`,{className:`font-mono text-xs ${o?.empty?`text-rose-300`:`text-sky-300`}`,children:[(o?.gallonsCurrent??a.volGal).toFixed(1),` Gal`]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`Runtime`}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs font-bold ${o?.empty?`text-rose-400`:o?.minutesRemaining===null?`text-emerald-400`:`text-amber-400`}`,children:o?o.minutesRemaining===null?`Stable`:o.empty?`Dry`:`${o.minutesRemaining.toFixed(1)} min`:`Stable`}),(0,Z.jsx)(`div`,{className:`text-[8px] text-zinc-600`,children:o?.minutesRemaining===null?`No net draw`:o?.empty?`Source exhausted`:`${o.netOutflowGph.toFixed(1)} GPH net draw`})]}),(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`Volume`}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs font-bold text-sky-300`,children:o?`${o.gallonsCurrent.toFixed(1)} / ${o.gallonsCapacity.toFixed(1)}`:`${a.volGal.toFixed(1)} / ${a.volGal.toFixed(1)}`}),(0,Z.jsx)(`div`,{className:`text-[8px] text-zinc-600`,children:`Gallons`})]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`Temp`}),(0,Z.jsxs)(`div`,{className:`mt-0.5 text-xs font-bold ${a.tempF>73?`text-amber-400`:`text-emerald-400`}`,children:[a.tempF.toFixed(1),`°F`]}),(0,Z.jsx)(`div`,{className:`text-[8px] text-zinc-600`,children:a.tempF>73?`Too Warm`:`Optimal`})]}),(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`pH`}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs font-bold ${a.ph<5.5||a.ph>6.5?`text-amber-400`:`text-emerald-400`}`,children:a.ph.toFixed(1)}),(0,Z.jsx)(`div`,{className:`text-[8px] text-zinc-600`,children:a.ph<5.5||a.ph>6.5?`Lockout`:`Optimal`})]}),(0,Z.jsxs)(`div`,{className:`rounded-md bg-zinc-900/80 p-2 text-center`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-zinc-500 font-bold uppercase`,children:`EC`}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs font-bold ${l?`text-amber-400`:`text-emerald-400`}`,children:a.ec.toFixed(1)}),(0,Z.jsx)(`div`,{className:`text-[8px] text-zinc-600`,children:l?`Alert`:`Optimal`})]})]}),(0,Z.jsx)(lE,{label:`Adjust pH`,unit:``,value:e.params.ph??6,meta:Yx.reservoir.params.ph,onChange:n=>t(e.id,`ph`,n)}),(0,Z.jsx)(lE,{label:`Adjust EC`,unit:`mS/cm`,value:e.params.ec??1.2,meta:Yx.reservoir.params.ec,onChange:n=>t(e.id,`ec`,n)})]})}function lE({label:e,unit:t,value:n,meta:r,onChange:i}){return(0,Z.jsxs)(`div`,{className:`mt-1.5`,children:[(0,Z.jsxs)(`div`,{className:`mb-0.5 flex justify-between text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`text-zinc-400`,children:e}),(0,Z.jsxs)(`span`,{className:`font-mono text-sky-400`,children:[n,` `,t]})]}),(0,Z.jsx)(`input`,{type:`range`,min:r.min,max:r.max,step:r.step,value:n,onChange:e=>i(parseFloat(e.target.value)),className:`w-full accent-sky-500`})]})}function uE({partId:e}){let t=Q(t=>t.parts[e]),n=Q(e=>e.parts),r=Q(e=>e.updatePart),i=Q(e=>e.setParam),a=Q(e=>e.removeParts),o=Q(e=>e.duplicateParts),s=Q(e=>e.rotateParts),c=Q(e=>e.pushHistory),l=YS();if(!t)return null;let u=Yx[t.type],d=t.type===`netPot`?l.netPots.find(t=>t.partId===e):void 0,f=d?n[d.sourcePartId]:void 0,p=(n,i)=>{c(`pos:${e}:${n}`);let a=[...t.position];a[n]=n===1?Math.max(0,i):i,r(e,{position:a})},m=(n,i)=>{c(`rot:${e}:${n}`);let a=[...t.rotation];a[n]=ZT(i),r(e,{rotation:a})},h=Object.entries(u.params).filter(([e])=>(t.type!==`pump`||!nE.has(e))&&(t.type!==`airCompressor`||!rE.has(e))&&(t.type!==`reservoir`||!iE.has(e)));return(0,Z.jsxs)(`div`,{className:`flex-1 space-y-4 overflow-y-auto px-4 py-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`h-3 w-3 rounded`,style:{backgroundColor:t.color??u.color}}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-zinc-200`,children:u.label}),(0,Z.jsxs)(`span`,{className:`ml-auto font-mono text-[10px] text-zinc-600`,children:[`#`,t.id]})]}),(0,Z.jsx)(`input`,{value:t.label??``,placeholder:`Name this part…`,onChange:t=>r(e,{label:t.target.value}),className:`w-full rounded-md border border-zinc-800 bg-zinc-900 px-2 py-1.5 text-xs text-zinc-200 placeholder-zinc-600 outline-none focus:border-sky-600`})]}),t.type===`pump`&&(0,Z.jsx)(aE,{part:t}),t.type===`airCompressor`&&(0,Z.jsx)(oE,{part:t}),t.type===`reservoir`&&(0,Z.jsx)(cE,{part:t}),t.type===`growTent`&&(0,Z.jsx)(sE,{part:t}),t.type===`netPot`&&d&&(0,Z.jsx)(dE,{title:`Hydraulics`,children:(0,Z.jsxs)(`div`,{className:`rounded-lg border px-3 py-2.5 ${d.overflowing?`border-rose-900/70 bg-rose-950/40`:`border-amber-900/60 bg-amber-950/30`}`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold ${d.overflowing?`text-rose-300`:`text-amber-300`}`,children:d.overflowing?`Pot overflow active`:`Pot near overflow`}),(0,Z.jsxs)(`p`,{className:`mt-1 text-[11px] leading-snug text-zinc-400`,children:[`Water under this pot is coming from `,f?Yx[f.type].label:`the flooded line`,` at`,` `,d.inflowGph.toFixed(0),` GPH. Water height is `,d.waterHeightFt.toFixed(2),` ft and the rim is `,d.rimHeightFt.toFixed(2),` ft.`]}),(0,Z.jsxs)(`p`,{className:`mt-1.5 rounded-md bg-zinc-900/80 px-2 py-1 text-[11px] leading-snug text-zinc-300`,children:[(0,Z.jsx)(`span`,{className:`font-semibold text-sky-400`,children:`Fix: `}),`Add drainage or move the pot off the backed-up run.`]})]})}),(0,Z.jsx)(dE,{title:`Position (ft)`,children:(0,Z.jsx)(`div`,{className:`grid grid-cols-3 gap-1.5`,children:[`X`,`Y`,`Z`].map((e,n)=>(0,Z.jsx)(fE,{label:e,value:t.position[n],step:.25,onChange:e=>p(n,e)},e))})}),(0,Z.jsxs)(dE,{title:`Rotation (°)`,children:[(0,Z.jsx)(`div`,{className:`grid grid-cols-3 gap-1.5`,children:[`X`,`Y`,`Z`].map((e,n)=>(0,Z.jsx)(fE,{label:e,value:XT(t.rotation[n]),step:15,onChange:e=>m(n,e)},e))}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex gap-1.5`,children:[(0,Z.jsx)(pE,{onClick:()=>s([e],1,Math.PI/2),children:`⟳ 90° Y`}),(0,Z.jsx)(pE,{onClick:()=>s([e],2,Math.PI/2),children:`⟳ 90° Z`}),(0,Z.jsx)(pE,{onClick:()=>r(e,{rotation:[0,0,0]}),children:`Reset`})]})]}),h.length>0&&(0,Z.jsx)(dE,{title:`Parameters`,children:(0,Z.jsx)(`div`,{className:`space-y-2.5`,children:h.map(([n,r])=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-0.5 flex justify-between text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`text-zinc-400`,children:r.label}),(0,Z.jsxs)(`span`,{className:`font-mono text-sky-400`,children:[t.params[n]??u.defaults[n],r.unit?` ${r.unit}`:``]})]}),n===`diameter`||n===`diameterA`||n===`diameterB`?(0,Z.jsx)(`select`,{value:String(Jx(t.params[n]??u.defaults[n])),onChange:t=>i(e,n,parseFloat(t.target.value)),className:`w-full rounded-md border border-zinc-800 bg-zinc-900 px-2 py-1.5 text-[11px] text-zinc-200 outline-none focus:border-sky-600`,children:Wx.map(e=>(0,Z.jsxs)(`option`,{value:e,children:[e,` in`]},e))}):(0,Z.jsx)(`input`,{type:`range`,min:r.min,max:r.max,step:r.step,value:t.params[n]??u.defaults[n],onChange:t=>i(e,n,parseFloat(t.target.value)),className:`w-full accent-sky-500`})]},n))})}),(0,Z.jsx)(dE,{title:`Color`,children:(0,Z.jsx)(JT,{ids:[e]})}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,Z.jsx)(`button`,{onClick:()=>o([e]),title:`Duplicate this part (D)`,className:`flex-1 rounded-md border border-zinc-700 bg-zinc-800 px-2 py-1.5 text-xs font-medium text-zinc-200 hover:bg-zinc-700`,children:`Duplicate`}),(0,Z.jsx)(`button`,{onClick:()=>a([e]),title:`Delete this part (⌫)`,className:`flex-1 rounded-md border border-rose-900 bg-rose-950 px-2 py-1.5 text-xs font-medium text-rose-300 hover:bg-rose-900`,children:`Delete`})]})]})}function dE({title:e,children:t}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`mb-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:e}),t]})}function fE({label:e,value:t,step:n,onChange:r}){return(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 rounded-md border border-zinc-800 bg-zinc-900 px-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold text-zinc-600`,children:e}),(0,Z.jsx)(`input`,{type:`number`,value:Number(t.toFixed(2)),step:n,onChange:e=>{let t=parseFloat(e.target.value);Number.isNaN(t)||r(t)},className:`w-full bg-transparent py-1.5 text-right font-mono text-[11px] text-zinc-200 outline-none`})]})}function pE({children:e,onClick:t}){return(0,Z.jsx)(`button`,{onClick:t,className:`flex-1 rounded border border-zinc-800 bg-zinc-900 px-1.5 py-1 text-[10px] text-zinc-300 hover:bg-zinc-800`,children:e})}var mE=`hydro-builder:autosave`;function hE(e,t){return{app:`hydro-builder`,version:1,name:e,savedAt:new Date().toISOString(),parts:t}}function gE(e){let t=e;if(!t||t.app!==`hydro-builder`||!Array.isArray(t.parts))throw Error(`Not a valid Hydro Builder project file.`);let n=new Set([`Plumbing`,`Flow Control`,`Growing`,`Structure`,`Environment`]);for(let e of t.parts){if(!e||typeof e!=`object`)throw Error(`Project contains invalid or null part data.`);if(typeof e.id!=`string`||!e.id)throw Error(`Part is missing a valid ID.`);if(typeof e.type!=`string`||!(e.type in Yx))throw Error(`Part ${e.id} has an invalid or unrecognized type: ${e.type}.`);let t=Yx[e.type].category;if(!n.has(t))throw Error(`Part ${e.id} has an invalid category: ${t}.`);if(!Array.isArray(e.position)||e.position.length!==3||!e.position.every(e=>typeof e==`number`&&Number.isFinite(e)))throw Error(`Part ${e.id} must have a position with an array of 3 numbers.`);if(!Array.isArray(e.rotation)||e.rotation.length!==3||!e.rotation.every(e=>typeof e==`number`&&Number.isFinite(e)))throw Error(`Part ${e.id} must have a rotation with an array of 3 numbers.`)}let r=t.parts;return _E(t.name??`Imported project`,r,t.savedAt)}function _E(e,t,n){return{app:`hydro-builder`,version:1,name:e,savedAt:n??new Date().toISOString(),parts:t}}function vE(e,t,n){try{let r=n?`hydro-builder:autosave:${n}`:mE;localStorage.setItem(r,JSON.stringify(hE(e,t)))}catch{}}function yE(e){try{let t=e?`hydro-builder:autosave:${e}`:mE,n=localStorage.getItem(t);return n?gE(JSON.parse(n)):null}catch{return null}}function bE(e,t){let n=new Blob([JSON.stringify(hE(e,t),null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.replace(/[^a-z0-9-_ ]/gi,``).trim()||`hydro-system`}.json`,i.click(),URL.revokeObjectURL(r)}async function xE(e){let t=await e.text();return gE(JSON.parse(t))}var SE=(0,v.createContext)(void 0),CE=({children:e})=>{let[t,n]=(0,v.useState)(localStorage.getItem(`hydro-token`)),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!0),[s,c]=(0,v.useState)(null),l=async e=>{try{let t=await fetch(`/api/auth/me`,{headers:{Authorization:`Bearer ${e}`}});t.ok?i((await t.json()).user):f()}catch(e){console.error(`Error fetching user info:`,e)}finally{o(!1)}};(0,v.useEffect)(()=>{t?l(t):(i(null),o(!1));let e=new URLSearchParams(window.location.search);if(e.get(`checkout_success`)===`true`){let e=new URL(window.location.href);e.searchParams.delete(`checkout_success`),window.history.replaceState({},document.title,e.pathname),bS(`Payment successful! Your Premium Upgrade has been unlocked.`,`success`),t&&l(t)}else if(e.get(`checkout_cancel`)===`true`){let e=new URL(window.location.href);e.searchParams.delete(`checkout_cancel`),window.history.replaceState({},document.title,e.pathname),bS(`Payment cancelled.`,`info`)}},[t]);let u=async(e,t)=>{c(null);try{let r=await fetch(`/api/auth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({email:e,password:t})}),a=await r.json();if(!r.ok)throw Error(a.error||`Login failed`);localStorage.setItem(`hydro-token`,a.token),n(a.token),i(a.user)}catch(e){throw c(e instanceof Error?e.message:`Unknown login error`),e}},d=async(e,t)=>{c(null);try{let r=await fetch(`/api/auth/signup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({email:e,password:t})}),a=await r.json();if(!r.ok)throw Error(a.error||`Signup failed`);localStorage.setItem(`hydro-token`,a.token),n(a.token),i(a.user)}catch(e){throw c(e instanceof Error?e.message:`Unknown signup error`),e}},f=()=>{localStorage.removeItem(`hydro-token`),n(null),i(null)};return(0,Z.jsx)(SE.Provider,{value:{token:t,user:r,loading:a,error:s,login:u,signup:d,logout:f,refreshProfile:async()=>{t&&await l(t)},clearError:()=>{c(null)}},children:e})},wE=()=>{let e=(0,v.useContext)(SE);if(e===void 0)throw Error(`useAuth must be used within an AuthProvider`);return e},TE=({onClose:e})=>{let{token:t,user:n}=wE(),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(null);return(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center bg-zinc-950/80 backdrop-blur-sm`,children:(0,Z.jsxs)(`div`,{className:`w-full max-w-md overflow-hidden rounded-2xl border border-zinc-850 bg-zinc-900 shadow-2xl`,children:[(0,Z.jsx)(`div`,{className:`h-2 bg-gradient-to-r from-sky-400 via-blue-500 to-indigo-600`}),(0,Z.jsxs)(`div`,{className:`p-8`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,Z.jsx)(`div`,{className:`mb-4 grid h-14 w-14 place-items-center rounded-full bg-sky-500/10 text-2xl text-sky-400`,children:`💎`}),(0,Z.jsx)(`h3`,{className:`text-xl font-bold text-zinc-100`,children:`Unlock Premium Features`}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-zinc-400 leading-relaxed px-2`,children:`Free profiles do not have auto-saves or cloud build spaces. Upgrade to Premium permanently to enable browser auto-saves and unlock 10 cloud project slots.`})]}),(0,Z.jsxs)(`div`,{className:`my-6 rounded-xl border border-zinc-800 bg-zinc-950/50 p-5 text-center`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-sky-400 uppercase tracking-wider`,children:`Premium Lifetime Upgrade`}),(0,Z.jsxs)(`div`,{className:`mt-2 flex items-baseline justify-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-3xl font-black text-zinc-100`,children:`$5`}),(0,Z.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`one-time purchase`})]}),(0,Z.jsxs)(`div`,{className:`mt-4 flex flex-col gap-1.5 text-left text-xs text-zinc-400 border-t border-zinc-850 pt-4`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Slots Owned:`}),(0,Z.jsx)(`span`,{className:`font-semibold text-zinc-200`,children:n&&n.purchased_slots>0?10:0})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{children:`Active Projects:`}),(0,Z.jsx)(`span`,{className:`font-semibold text-zinc-200`,children:n?.project_count??0})]})]})]}),a&&(0,Z.jsx)(`div`,{className:`mb-4 rounded-lg border border-red-500/15 bg-red-500/5 p-3 text-xs text-red-400`,children:a}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n&&(0,Z.jsx)(`div`,{className:`w-full flex justify-center py-1`,children:(0,Z.jsx)(`stripe-buy-button`,{"buy-button-id":`buy_btn_1ThubIDPQ7Y9c4bKgoRwZuIm`,"publishable-key":`pk_live_51ThuN5DPQ7Y9c4bKvvcy6bl6FuoQufKFWNYdkaXwINzWiEqyPlrU2WwO2mlCpKtuGXkBfKfozBVfT0aTBTU0TdLm00LIvAP3si`,"client-reference-id":String(n.id)})}),(0,Z.jsx)(`button`,{onClick:e,className:`w-full rounded-lg bg-zinc-800/60 py-2.5 text-xs font-medium text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200 transition cursor-pointer`,children:`Cancel`})]})]})]})})},EE=Sy(e=>({status:`saved`,setStatus:t=>e({status:t})}));function DE(){let e=EE(e=>e.status);return e===`saved`?(0,Z.jsx)(`span`,{title:`All changes saved to browser`,className:`h-2 w-2 rounded-full bg-emerald-500 transition-colors duration-300 shrink-0`}):e===`saving`?(0,Z.jsx)(`span`,{title:`Saving changes...`,className:`h-2 w-2 rounded-full bg-amber-500 animate-pulse shrink-0`}):(0,Z.jsx)(`span`,{title:`Unsaved changes`,className:`h-2 w-2 rounded-full bg-amber-500 shrink-0`})}function OE({onOpenBom:e,onCheckBuild:t}){let{token:n,user:r,logout:i,refreshProfile:a}=wE(),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)(!1),f=Q(e=>e.projectName),p=Q(e=>e.setProjectName),m=Q(e=>e.growthStage),h=Q(e=>e.setGrowthStage),g=Q(e=>e.viewMode),_=Q(e=>e.setViewMode),y=Q(e=>e.renderMode),b=Q(e=>e.setRenderMode),x=Q(e=>e.tool),S=Q(e=>e.setTool),C=Q(e=>e.showFlow),w=Q(e=>e.toggleFlow),T=Q(e=>e.simRunning),E=Q(e=>e.toggleSimRunning),D=Q(e=>e.snapToGrid),O=Q(e=>e.toggleSnap),k=Q(e=>e.undo),A=Q(e=>e.redo),j=Q(e=>e.past.length>0),M=Q(e=>e.future.length>0),N=Q(e=>e.autoCapOpenEnds),P=Q(e=>e.rooms),F=Q(e=>e.activeRoomId),I=Q(e=>e.addRoom),L=Q(e=>e.removeRoom),ee=Q(e=>e.setActiveRoomId),R=(0,v.useRef)(null),[te,z]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!1),ne=async()=>{if(n){d(!0);try{let e=await fetch(`/api/projects`,{headers:{Authorization:`Bearer ${n}`}});e.ok&&l(await e.json())}catch(e){console.error(`Failed to fetch projects`,e)}finally{d(!1)}}};(0,v.useEffect)(()=>{te&&ne()},[te]);let re=async()=>{if(!n)return;let e=Q.getState(),t=Object.values(e.parts);try{let r=await fetch(`/api/projects`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${n}`},body:JSON.stringify({name:e.projectName,parts:t})}),i=await r.json();if(!r.ok){r.status===402?s(!0):bS(i.error||`Failed to save project`,`error`);return}await a(),bS(`Project saved successfully!`,`success`)}catch(e){bS(`Save failed: `+e,`error`)}},ie=e=>{let t=c.find(t=>t.name===e);t&&Q.getState().loadParts(t.parts,t.name),z(!1)},ae=async(e,t)=>{if(e.stopPropagation(),!(!n||!confirm(`Delete project "${t}" permanently?`)))try{let e=await fetch(`/api/projects/${encodeURIComponent(t)}`,{method:`DELETE`,headers:{Authorization:`Bearer ${n}`}});e.ok?(await ne(),await a(),bS(`Project deleted successfully`,`success`)):bS((await e.json()).error||`Failed to delete project`,`error`)}catch(e){bS(`Delete failed: `+e,`error`)}},oe=()=>{let e=Q.getState();bE(e.projectName,Object.values(e.parts))},se=async e=>{try{let t=await xE(e);Q.getState().loadParts(t.parts,t.name),bS(`Project imported successfully`,`success`)}catch(e){bS(e instanceof Error?e.message:`Import failed`,`error`)}};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center gap-2 border-b border-zinc-800 bg-zinc-950 px-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pr-2`,children:[(0,Z.jsx)(`span`,{className:`grid h-7 w-7 place-items-center rounded-lg bg-gradient-to-br from-sky-500 to-blue-700 text-sm font-black text-white`,children:`H`}),(0,Z.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),className:`w-44 rounded-md border border-transparent bg-transparent px-1.5 py-1 text-sm font-semibold text-zinc-100 outline-none hover:border-zinc-800 focus:border-sky-700 focus:bg-zinc-900`}),(0,Z.jsx)(DE,{})]}),(0,Z.jsx)(kE,{}),(0,Z.jsx)(AE,{onClick:()=>{confirm(`Start a new empty project? Unsaved changes are kept in undo history.`)&&(Q.getState().clearAll(),p(`Untitled system`))},title:`New empty project`,children:`New`}),(0,Z.jsx)(AE,{onClick:re,title:`Save to cloud storage`,children:`Save`}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(AE,{onClick:()=>z(e=>!e),title:`Load a saved project`,children:`Load ▾`}),te&&(0,Z.jsxs)(`div`,{className:`absolute top-9 left-0 z-50 max-h-72 w-64 overflow-y-auto rounded-lg border border-zinc-700 bg-zinc-900 p-1 shadow-2xl`,children:[u&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`Loading...`}),!u&&c.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`No saved projects yet.`}),!u&&c.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-md px-3 py-1.5 hover:bg-zinc-800 group`,children:[(0,Z.jsxs)(`button`,{onClick:()=>ie(e.name),className:`flex-1 text-left text-xs text-zinc-200 outline-none`,children:[e.name,(0,Z.jsx)(`span`,{className:`block text-[10px] text-zinc-500`,children:new Date(e.savedAt).toLocaleString()})]}),(0,Z.jsx)(`button`,{onClick:t=>ae(t,e.name),className:`hidden group-hover:block text-[10px] text-red-400 hover:text-red-300 px-2 py-0.5 rounded bg-zinc-950/40`,title:`Delete project`,children:`✕`})]},e.name))]})]}),(0,Z.jsx)(AE,{onClick:oe,title:`Download design as JSON`,children:`Export`}),(0,Z.jsx)(AE,{onClick:()=>R.current?.click(),title:`Import a design JSON`,children:`Import`}),(0,Z.jsx)(AE,{onClick:()=>V(!0),title:`Show Keyboard Shortcuts`,children:`⌨️ Shortcuts`}),(0,Z.jsx)(`input`,{ref:R,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&se(t),e.target.value=``}}),(0,Z.jsx)(kE,{}),(0,Z.jsx)(AE,{onClick:e,title:`Open bill of materials`,children:`BOM`}),(0,Z.jsx)(AE,{onClick:t,title:`Run design validation`,children:`Check Build`}),(0,Z.jsx)(AE,{onClick:()=>N(),title:`Add caps to every loose plumbing end`,children:`Auto Cap`}),(0,Z.jsx)(kE,{}),(0,Z.jsx)(AE,{onClick:k,disabled:!j,title:`Undo (⌘Z)`,children:`↶`}),(0,Z.jsx)(AE,{onClick:A,disabled:!M,title:`Redo (⇧⌘Z)`,children:`↷`}),(0,Z.jsx)(kE,{}),(0,Z.jsx)(AE,{active:x===`measure`,onClick:()=>S(x===`measure`?`select`:`measure`),title:`Measure: click two points in the scene`,children:`📏 Measure`}),(0,Z.jsx)(AE,{active:x===`pipeRun`,onClick:()=>S(x===`pipeRun`?`select`:`pipeRun`),title:`Pipe Run: click two ground points`,children:`Pipe Run`}),(0,Z.jsx)(AE,{active:D,onClick:O,title:`Snap to grid (0.25 ft)`,children:`⌗ Snap`}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{onClick:E,title:T?`Pause water simulation (Space)`:`Run water simulation (Space)`,className:`grid h-8 w-8 shrink-0 place-items-center rounded-full text-white shadow-lg transition-all hover:scale-110 active:scale-95 ${T?`bg-emerald-500 shadow-emerald-500/40 hover:bg-emerald-400`:`bg-sky-600 shadow-sky-600/40 hover:bg-sky-500`}`,children:T?(0,Z.jsxs)(`svg`,{viewBox:`0 0 16 16`,className:`h-3.5 w-3.5`,fill:`currentColor`,children:[(0,Z.jsx)(`rect`,{x:`3`,y:`2.5`,width:`3.4`,height:`11`,rx:`1`}),(0,Z.jsx)(`rect`,{x:`9.6`,y:`2.5`,width:`3.4`,height:`11`,rx:`1`})]}):(0,Z.jsx)(`svg`,{viewBox:`0 0 16 16`,className:`ml-0.5 h-3.5 w-3.5`,fill:`currentColor`,children:(0,Z.jsx)(`path`,{d:`M4 2.8a1 1 0 0 1 1.52-.86l8.2 5.2a1 1 0 0 1 0 1.7l-8.2 5.2A1 1 0 0 1 4 13.2V2.8Z`})})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 bg-zinc-900 border border-zinc-800 rounded-lg px-2.5 py-1`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] uppercase font-bold text-zinc-400`,children:`Stage`}),(0,Z.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`bg-transparent text-xs text-zinc-200 outline-none border-none cursor-pointer pr-1`,children:[(0,Z.jsx)(`option`,{value:`seedling`,className:`bg-zinc-900 text-zinc-200`,children:`Seedling`}),(0,Z.jsx)(`option`,{value:`vegetative`,className:`bg-zinc-900 text-zinc-200`,children:`Vegetative`}),(0,Z.jsx)(`option`,{value:`flowering`,className:`bg-zinc-900 text-zinc-200`,children:`Flowering`})]})]}),(0,Z.jsx)(AE,{active:C,onClick:w,title:`Toggle water flow animation`,children:`💧 Flow`}),(0,Z.jsx)(`div`,{className:`flex overflow-hidden rounded-lg border border-zinc-800`,children:[{id:`builder`,label:`Builder`,title:`Standard building mode`},{id:`xray`,label:`X-Ray`,title:`Transparent shell with internal water visibility`},{id:`water`,label:`Water`,title:`Water-first view with solids faded back`}].map(e=>(0,Z.jsx)(`button`,{onClick:()=>b(e.id),title:e.title,className:`px-3 py-1.5 text-xs font-medium transition ${y===e.id?`bg-cyan-600 text-white`:`bg-zinc-900 text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200`}`,children:e.label},e.id))}),(0,Z.jsx)(`div`,{className:`flex overflow-hidden rounded-lg border border-zinc-800`,children:[{id:`orbit`,label:`3D`,title:`Free 3D orbit view`},{id:`top`,label:`Top`,title:`Top-down plan view`},{id:`front`,label:`Front`,title:`Front elevation view`},{id:`side`,label:`Side`,title:`Side elevation view`}].map(e=>(0,Z.jsx)(`button`,{onClick:()=>_(e.id),title:e.title,className:`px-3 py-1.5 text-xs font-medium transition ${g===e.id?`bg-sky-600 text-white`:`bg-zinc-900 text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200`}`,children:e.label},e.id))}),r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(kE,{}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-semibold text-zinc-300 max-w-24 truncate`,children:r.email}),(0,Z.jsxs)(`span`,{className:`text-[9px] font-bold uppercase ${r.total_slots===0||r.project_count>=r.total_slots?`text-amber-400`:`text-emerald-400`}`,children:[r.project_count,` / `,r.total_slots,` Slots`]})]}),r.total_slots===0?(0,Z.jsx)(`button`,{onClick:()=>s(!0),className:`rounded bg-gradient-to-r from-sky-500/20 to-blue-500/20 hover:from-sky-500/30 hover:to-blue-500/30 text-sky-300 border border-sky-700 px-2 py-1 text-[10px] font-bold transition cursor-pointer flex items-center gap-1 shadow-lg`,children:`💎 Upgrade`}):r.project_count>=r.total_slots&&(0,Z.jsx)(`button`,{onClick:()=>s(!0),className:`rounded bg-amber-500/20 hover:bg-amber-500/30 text-amber-300 border border-amber-600/30 px-2 py-1 text-[10px] font-semibold transition cursor-pointer`,children:`+ Add Slot`}),(0,Z.jsx)(`button`,{onClick:i,className:`rounded border border-zinc-800 bg-zinc-900 px-2 py-1 text-[10px] font-medium text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200 transition cursor-pointer`,children:`Logout`})]})]})]}),o&&(0,Z.jsx)(TE,{onClose:()=>s(!1)}),B&&(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center bg-zinc-950/80 backdrop-blur-sm`,children:(0,Z.jsxs)(`div`,{className:`w-full max-w-sm rounded-xl border border-zinc-800 bg-zinc-900 p-6 shadow-2xl text-left`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-bold text-zinc-100 mb-4 flex items-center gap-1.5 border-b border-zinc-800 pb-2`,children:`⌨️ Keyboard Shortcuts`}),(0,Z.jsxs)(`div`,{className:`space-y-2.5 text-xs text-zinc-400`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Undo / Redo`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`⌘Z / ⌘Y`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Rotate Selected`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`R`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Duplicate Selected`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`D`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Delete Selected`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`⌫ / Del`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Run / Pause Sim`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`Spacebar`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Pan Camera View`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`Arrow Keys`})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between border-b border-zinc-800/40 pb-1.5`,children:[(0,Z.jsx)(`span`,{children:`Clear Selection & Tool`}),(0,Z.jsx)(`span`,{className:`font-mono bg-zinc-950 px-1.5 py-0.5 rounded text-zinc-300`,children:`Esc`})]})]}),(0,Z.jsx)(`button`,{onClick:()=>V(!1),className:`mt-6 w-full rounded bg-zinc-800 py-2 text-xs font-semibold text-zinc-200 hover:bg-zinc-700 transition cursor-pointer`,children:`Close`})]})})]}),(0,Z.jsxs)(`div`,{className:`flex h-10 shrink-0 items-center justify-between border-b border-zinc-850 bg-zinc-900/60 px-3`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto`,children:P.map(e=>(0,Z.jsxs)(`div`,{className:`group flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-semibold transition cursor-pointer select-none ${e.id===F?`bg-sky-500/15 text-sky-400 border border-sky-500/30`:`text-zinc-400 hover:text-zinc-200 border border-transparent`}`,onClick:()=>ee(e.id),children:[(0,Z.jsx)(`span`,{children:e.name}),P.length>1&&(0,Z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),confirm(`Delete room "${e.name}" and all its parts permanently?`)&&L(e.id)},className:`opacity-0 group-hover:opacity-100 hover:text-red-400 text-[10px] ml-1 transition`,children:`✕`})]},e.id))}),(0,Z.jsx)(`button`,{onClick:()=>{let e=prompt(`Enter room name:`,`Room ${P.length+1}`);e&&I(e.trim())},className:`rounded border border-zinc-700 bg-zinc-850 hover:bg-zinc-800 text-zinc-300 px-2.5 py-1 text-[11px] font-semibold transition flex items-center gap-1 cursor-pointer`,children:`+ Add Room`})]})]})}function kE(){return(0,Z.jsx)(`div`,{className:`mx-1 h-6 w-px bg-zinc-800`})}function AE({children:e,onClick:t,title:n,active:r,disabled:i}){return(0,Z.jsx)(`button`,{onClick:t,title:n,disabled:i,className:`rounded-md px-2.5 py-1.5 text-xs font-medium transition disabled:cursor-default disabled:opacity-30 ${r?`bg-sky-500/15 text-sky-300 ring-1 ring-sky-700`:`text-zinc-300 hover:bg-zinc-800`}`,children:e})}var jE={error:`border-rose-900/60 bg-rose-950/60 text-rose-300`,warning:`border-amber-900/60 bg-amber-950/50 text-amber-300`,info:`border-sky-900/60 bg-sky-950/50 text-sky-300`},ME={error:`⛔`,warning:`⚠️`,info:`ℹ️`};function NE(){let e=YS(),t=Q(e=>Object.keys(e.parts).length),n=Q(e=>e.parts),r=Q(e=>e.setSelected),i=Q(e=>e.simRunning),a=Q(e=>e.toggleSimRunning),o=Q(e=>e.heatmapMode),s=Q(e=>e.toggleHeatmapMode),c=(0,v.useMemo)(()=>KT(n),[n]),l=(0,v.useMemo)(()=>Object.values(n).filter(e=>e.type===`reservoir`),[n]),u=(0,v.useMemo)(()=>l.map(e=>nC(e,n)),[l,n]),d=e.totalGph*3.785,f=e.pumps.some(e=>e.running),p=Math.max(0,...Object.values(e.velocities)),m=Math.max(0,...Object.values(e.pressures));return(0,Z.jsxs)(`footer`,{className:`flex h-36 shrink-0 border-t border-zinc-800 bg-zinc-950/90 backdrop-blur`,children:[(0,Z.jsxs)(`div`,{className:`flex w-56 shrink-0 flex-col justify-center gap-1 border-r border-zinc-800 px-4`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Simulation`}),(0,Z.jsxs)(`div`,{className:`text-2xl font-bold text-sky-400 tabular-nums`,children:[e.totalGph.toFixed(0),(0,Z.jsx)(`span`,{className:`ml-1 text-xs font-medium text-zinc-500`,children:`GPH`})]}),(0,Z.jsxs)(`div`,{className:`text-[11px] text-zinc-500 tabular-nums`,children:[`≈ `,d.toFixed(0),` L/h · `,t,` parts · `,e.connectionCount,` connections`]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-zinc-600 tabular-nums`,children:[`peak `,p.toFixed(1),` ft/s · `,m.toFixed(1),` psi`]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1`,children:[(0,Z.jsxs)(`button`,{onClick:a,title:i?`Pause simulation (Space)`:`Resume simulation (Space)`,className:`inline-flex w-fit cursor-pointer items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-semibold transition hover:brightness-125 ${i?f?`bg-emerald-950 text-emerald-400 ring-1 ring-emerald-800`:`bg-zinc-900 text-zinc-500 ring-1 ring-zinc-800`:`bg-amber-950 text-amber-400 ring-1 ring-amber-800`}`,children:[(0,Z.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5`,children:[i&&f&&(0,Z.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-60`}),(0,Z.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-current`})]}),i?f?`Water flowing`:`System idle`:`⏸ Paused`]}),(0,Z.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-[10px] font-semibold text-zinc-400 hover:text-zinc-200`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:o,onChange:s,className:`accent-sky-500 cursor-pointer h-3 w-3 rounded border-zinc-700 bg-zinc-850`}),(0,Z.jsx)(`span`,{children:`Heatmap`})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col gap-1.5 overflow-y-auto border-r border-zinc-800 px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Pumps`}),e.pumps.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-zinc-600`,children:`No pumps in the system.`}),e.pumps.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>r(e.pumpId),className:`rounded-md border border-zinc-800 bg-zinc-900/70 px-2.5 py-1.5 text-left hover:border-zinc-600`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsxs)(`span`,{className:`text-xs font-semibold text-zinc-200`,children:[e.gph>0?`${e.gph.toFixed(0)} GPH`:`No flow`,(0,Z.jsxs)(`span`,{className:`ml-1 text-[10px] font-normal text-zinc-500`,children:[`/ `,e.ratedGph,` rated`]})]}),(0,Z.jsxs)(`span`,{className:`font-mono text-[10px] text-zinc-500`,children:[`head `,e.headFt.toFixed(1),`/`,e.maxHeadFt,` ft`]})]}),(0,Z.jsx)(`div`,{className:`mt-1 h-1 overflow-hidden rounded-full bg-zinc-800`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full ${e.gph/e.ratedGph>.5?`bg-emerald-500`:e.gph>0?`bg-amber-500`:`bg-rose-600`}`,style:{width:`${Math.max(2,e.gph/e.ratedGph*100)}%`}})})]},e.pumpId))]}),(0,Z.jsxs)(`div`,{className:`flex w-80 shrink-0 flex-col gap-1 overflow-y-auto border-r border-zinc-800 px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Environment`}),c.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-zinc-600`,children:`Add a grow tent/room to track air exchange.`}):c.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>r(e.roomId),className:`rounded-md border border-zinc-800 bg-zinc-900/70 px-2.5 py-1.5 text-left hover:border-zinc-600`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-zinc-200`,children:e.label}),(0,Z.jsx)(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-semibold ${e.sealed?`bg-emerald-950 text-emerald-300 ring-1 ring-emerald-800`:`bg-sky-950 text-sky-300 ring-1 ring-sky-800`}`,children:e.sealed?`Sealed`:`Open air`})]}),(0,Z.jsxs)(`div`,{className:`mt-1 text-[11px] text-zinc-400 tabular-nums`,children:[e.volumeFt3.toFixed(0),` ft3 · `,e.exhaustCfm.toFixed(0),` exhaust CFM`]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-zinc-500 tabular-nums`,children:[e.airChangesPerMinute.toFixed(2),` exchanges/min · `,e.airChangesPerHour.toFixed(1),` ACH`]}),(0,Z.jsxs)(`div`,{className:`mt-1 text-[10px] text-zinc-600 tabular-nums`,children:[`circ `,e.circulationCfm.toFixed(0),` CFM · light `,e.lightWatts.toFixed(0),` W · CO2 `,e.co2TankCount,` tank`,e.co2TankCount===1?``:`s`]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex gap-1.5 text-[9px] font-mono`,children:[(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1 py-0.5 text-emerald-400 border border-zinc-800`,children:[`VPD `,e.roomVPD.toFixed(2),` kPa`]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1 py-0.5 text-amber-400 border border-zinc-800`,children:[`DLI `,e.roomDLI.toFixed(1)]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1 py-0.5 text-sky-400 border border-zinc-800`,children:[`CO₂ `,e.roomCo2,` ppm`]})]})]},e.roomId))]}),(0,Z.jsxs)(`div`,{className:`flex w-56 shrink-0 flex-col justify-center gap-1.5 border-r border-zinc-800 px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Room Readout`}),c.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-zinc-600`,children:`No room placed`}):(()=>{let e=c[0];return(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1 text-[10px] font-mono tabular-nums`,children:[(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1.5 py-0.5 border border-zinc-800 text-rose-400`,children:[`🌡️ `,e.roomTempF.toFixed(0),`°F`]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1.5 py-0.5 border border-zinc-800 text-sky-400`,children:[`💧 `,e.roomRH.toFixed(0),`%`]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1.5 py-0.5 border border-zinc-800 text-emerald-400`,children:[`VPD `,e.roomVPD.toFixed(2)]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1.5 py-0.5 border border-zinc-800 text-sky-400`,children:[`CO₂ `,e.roomCo2]}),(0,Z.jsxs)(`span`,{className:`rounded bg-zinc-900 px-1.5 py-0.5 border border-zinc-800 text-amber-400`,children:[`☀️ `,e.roomPPFD.toFixed(0)]})]})})()]}),(0,Z.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col gap-1.5 overflow-y-auto border-r border-zinc-800 px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Aeration & Water`}),u.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-zinc-600`,children:`No reservoirs in the system.`}),u.map(t=>(0,Z.jsxs)(`button`,{onClick:()=>r(t.id),className:`rounded-md border border-zinc-800 bg-zinc-900/70 px-2.5 py-1.5 text-left hover:border-zinc-600`,children:[(()=>{let n=e.reservoirRuntime[t.id];return n?(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[9px] font-mono`,children:[(0,Z.jsxs)(`span`,{className:`${n.empty?`text-rose-400`:`text-sky-400`}`,children:[n.gallonsCurrent.toFixed(1),` / `,n.gallonsCapacity.toFixed(1),` gal`]}),(0,Z.jsx)(`span`,{className:`text-zinc-500`,children:n.minutesRemaining===null?`steady`:`${n.minutesRemaining.toFixed(1)} min left`})]}):null})(),(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-zinc-200`,children:t.label}),(0,Z.jsxs)(`span`,{className:`font-mono text-[10px] text-zinc-500`,children:[t.volGal.toFixed(1),` Gal`]})]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center justify-between text-[10px] text-zinc-400`,children:[(0,Z.jsxs)(`span`,{children:[`Aeration: `,t.activeAerationGph,` GPH`]}),(0,Z.jsxs)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] font-bold ${t.tdo>=8?`bg-emerald-950 text-emerald-400 border border-emerald-800/30`:t.tdo>=7?`bg-sky-950 text-sky-300 border border-sky-800/30`:`bg-amber-950 text-amber-400 border border-amber-800/30 animate-pulse`}`,children:[t.tdo.toFixed(1),` mg/L`]})]}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex justify-between text-[9px] text-zinc-500 font-mono`,children:[(0,Z.jsxs)(`span`,{className:t.tempF>73?`text-amber-400 font-semibold`:`text-zinc-500`,children:[`Temp: `,t.tempF.toFixed(1),`°F`]}),(0,Z.jsxs)(`span`,{className:t.ph<5.5||t.ph>6.5?`text-amber-400 font-semibold`:`text-zinc-500`,children:[`pH: `,t.ph.toFixed(1)]}),(0,Z.jsxs)(`span`,{className:t.ec<.8||t.ec>2?`text-amber-400 font-semibold`:`text-zinc-500`,children:[`EC: `,t.ec.toFixed(1)]})]})]},t.id))]}),(0,Z.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 overflow-y-auto px-4 py-2.5`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Diagnostics`}),e.warnings.length===0?(0,Z.jsx)(`p`,{className:`flex items-center gap-1.5 text-xs text-emerald-400`,children:`✓ System healthy — no issues detected.`}):e.warnings.map((e,t)=>(0,Z.jsxs)(`button`,{onClick:()=>e.partId&&r(e.partId),className:`rounded-md border px-2.5 py-1 text-left text-[11px] leading-snug ${jE[e.level]} ${e.partId?`cursor-pointer hover:brightness-125`:`cursor-default`}`,children:[ME[e.level],` `,e.message]},t))]})]})}var PE=[[.5,.45],[.75,.55],[1,.75],[1.25,.95],[1.5,1.1],[2,1.55],[3,2.9],[4,3.8]];function FE(e){for(let[t,n]of PE)if(e<=t)return n;return 3.8+(e-4)*1}function IE(e){return UE(FE(e)*(120/12))}var LE={elbow:[.6,1.4,3.6],tee:[.85,1.9,4.6],cross:[1.6,3.2,7.5],yJoint:[1.4,2.8,6.5],wye:[1.4,2.8,6.5],reducer:[.9,1.8,4.2],coupling:[.45,.95,2.4],valve:[6,11,24],emitter:[1.25,1.25,1.25],reverseOsmosis:[15,30,65],generic:[1,2,5]};function RE(e,t){let n=LE[e];return n?n[t<=1?0:t<=2?1:2]:null}function zE(e){return e<=200?18:e<=400?28:e<=800?45:e<=1200?70:110}function BE(e){return e<=10?15:e<=20?25:e<=40?45:e<=75?80:130}var VE=e=>e*7.48052;function HE(e,t){switch(e){case`pump`:return zE(t.gph??400);case`reservoir`:return BE(VE((t.width??2)*(t.depth??1.4)*(t.height??1)));case`tower`:return UE(18+(t.height??4)*5+(t.sites??6)*1);case`tray`:return UE(12+(t.length??3)*(t.width??1.2)*6);case`wallPanel`:return UE(20+(t.rows??4)*(t.cols??5)*3);case`lattice`:return UE(10+(t.width??2.5)*(t.height??3)*4);case`netPot`:return UE(.75*(t.size??1));case`drain`:return(t.capacityGph??250)<=250?8:14;case`growTent`:case`tent`:return UE(90+(t.width??4)*(t.depth??4)*(t.height??6.5)*1.2);case`light`:case`growLight`:return UE(40+(t.watts??100)*.6);default:return null}}var UE=e=>Math.round(e*100)/100;function WE(e){let t=[],n=new Map,r=new Map;for(let t of e)t.type===`pipe`?lD(n,t.params.diameter??1,t):lD(r,KE(t),t);let i=[];for(let[e,r]of[...n.entries()].sort((e,t)=>e[0]-t[0])){let n=XE(e,r);i.push(n);let a=IE(e);if(t.push({key:`pipe:${e}`,partType:`pipe`,category:eD(`pipe`),description:`${iD(e)} PVC Pipe — 10 ft stick`,spec:`${aD(n.totalCutIn)} total run, ${n.cuts.length} cuts across ${r.length} pipe${r.length===1?``:`s`}`,qty:n.sticksToBuy,unit:`stick`,unitCost:a,totalCost:UE(a*n.sticksToBuy),estimated:!1,partIds:r.map(e=>e.id)}),n.spliceCount>0){let r=RE(`coupling`,e)??1;t.push({key:`coupling:${e}`,partType:`coupling`,category:eD(`pipe`),description:`${iD(e)} PVC Coupling`,spec:`splices for runs longer than 10 ft`,qty:n.spliceCount,unit:`each`,unitCost:r,totalCost:UE(r*n.spliceCount),estimated:!1,partIds:[]})}}for(let e of r.values())t.push(JE(e));tD(t);let a=new Map;for(let e of t)a.set(e.category,(a.get(e.category)??0)+e.totalCost);return{lines:t,cutLists:i,categories:[...a.entries()].map(([e,t])=>({name:e,subtotal:UE(t)})).sort((e,t)=>$E(e.name)-$E(t.name)),totalCost:UE(t.reduce((e,t)=>e+t.totalCost,0)),partCount:e.length}}var GE={pump:e=>`${e.gph??400} GPH, ${e.maxHeadFt??8} ft max head`,reservoir:e=>{let t=e.width??2,n=e.depth??1.4,r=e.height??1;return`${t} × ${n} × ${r} ft, ${VE(t*n*r).toFixed(1)} gal`},tower:e=>`${e.height??4} ft tall, ${e.sites??6} plant sites`,tray:e=>`${e.length??3} × ${e.width??1.2} ft`,wallPanel:e=>`${e.width??3} × ${e.height??4} ft, ${(e.rows??4)*(e.cols??5)} pockets`,lattice:e=>`${e.width??2.5} × ${e.height??3} ft`,netPot:e=>`size ${e.size??1}`,drain:e=>`${e.capacityGph??250} GPH capacity`};function KE(e){let t=e.params;if(e.type===`reducer`)return`${e.type}:${t.diameterA??1.5}:${t.diameterB??1}`;if(cD(t,`diameter`)&&qE(e.type)){let n=cD(t,`angle`)?`:${t.angle}`:``;return`${e.type}:${t.diameter}${n}`}let n=Object.keys(t).filter(e=>e!==`level`&&e!==`open`).sort().map(e=>`${e}=${t[e]}`).join(`,`);return`${e.type}:${n}`}function qE(e){return e in GE?!1:RE(e,1)!==null||!(e in Yx)}function JE(e){let t=e[0],{type:n,params:r}=t,i=Yx[n]?.label??nD(n),a=eD(n),o=e.length,s,c=!1,l=i,u,d=HE(n,r),f=RE(n,YE(n,r));return d===null?f!==null&&n in Yx?(s=f,cD(r,`diameter`)&&(l=`${iD(r.diameter)} ${i}`),n===`reducer`&&(l=`${iD(r.diameterA??1.5)} × ${iD(r.diameterB??1)} ${i}`),cD(r,`angle`)&&r.angle!==90&&(l+=` (${r.angle}°)`)):n in Yx&&cD(r,`diameter`)?(s=RE(`generic`,r.diameter)??5,c=!0,l=`${iD(r.diameter)} ${i}`):(s=5,c=!0,u=Object.entries(r).map(([e,t])=>`${e} ${t}`).join(`, `)||void 0):(s=d,u=GE[n]?.(r)),{key:KE(t),partType:n,category:a,description:l,spec:u,qty:o,unit:`each`,unitCost:UE(s),totalCost:UE(s*o),estimated:c,partIds:e.map(e=>e.id)}}function YE(e,t){return e===`reducer`?Math.max(t.diameterA??1.5,t.diameterB??1):t.diameter??1}function XE(e,t){let n=[],r=0;for(let e of t){let t=UE((e.params.length??2)*12);if(t<=0)continue;let i=[];for(;t>120;)i.push(120),t=UE(t-120);t>0&&i.push(t),r+=i.length-1,n.push(...i)}let i=ZE(n,120),a=UE(n.reduce((e,t)=>e+t,0));return{diameterIn:e,stickLengthIn:120,cuts:[...n].sort((e,t)=>t-e),sticks:i,sticksToBuy:i.length,totalCutIn:a,totalLeftoverIn:UE(i.reduce((e,t)=>e+t.leftoverIn,0)),spliceCount:r}}function ZE(e,t){let n=[...e].sort((e,t)=>t-e),r=[];for(let e of n){let n=!1;for(let i of r)if(i.usedIn+e<=t+1e-9){i.cuts.push(e),i.usedIn=UE(i.usedIn+e),n=!0;break}n||r.push({index:r.length+1,cuts:[e],usedIn:e,leftoverIn:0})}for(let e of r)e.leftoverIn=UE(t-e.usedIn);return r}var QE=[`Plumbing`,`Flow Control`,`Growing`,`Structure`,`Other`];function $E(e){let t=QE.indexOf(e);return t===-1?QE.length:t}function eD(e){return Yx[e]?.category??`Other`}function tD(e){e.sort((e,t)=>$E(e.category)-$E(t.category)||e.description.localeCompare(t.description))}function nD(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}var rD={"0.25":`1/4`,"0.5":`1/2`,"0.75":`3/4`,"1.25":`1-1/4`,"1.5":`1-1/2`,"1.75":`1-3/4`,"2.5":`2-1/2`,"3.5":`3-1/2`};function iD(e){return Number.isInteger(e)?`${e} in`:`${rD[String(e)]??String(e)} in`}function aD(e){let t=Math.floor(e/12),n=UE(e-t*12);return t===0?`${sD(n)}"`:n===0?`${t}'`:`${t}' ${sD(n)}"`}function oD(e){return`$${e.toFixed(2)}`}var sD=e=>String(UE(e));function cD(e,t){return typeof e[t]==`number`}function lD(e,t,n){let r=e.get(t);r?r.push(n):e.set(t,[n])}function uD(e){let t=String(e);return/[",\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var dD=(...e)=>e.map(uD).join(`,`);function fD(e){let t=[];t.push(dD(`LINE ITEMS`)),t.push(dD(`Category`,`Item`,`Spec`,`Qty`,`Unit`,`Unit Cost`,`Total`,`Pricing`));for(let n of e.lines)t.push(dD(n.category,n.description,n.spec??``,n.qty,n.unit,n.unitCost.toFixed(2),n.totalCost.toFixed(2),n.estimated?`est.`:`listed`));if(e.cutLists.length>0){t.push(``),t.push(dD(`CUT LIST`)),t.push(dD(`Diameter`,`Stick`,`Cuts (in)`,`Used (in)`,`Leftover (in)`));for(let n of e.cutLists)for(let e of n.sticks)t.push(dD(iD(n.diameterIn),`Stick ${e.index}`,e.cuts.join(` | `),e.usedIn,e.leftoverIn))}t.push(``),t.push(dD(`TOTALS`));for(let n of e.categories)t.push(dD(n.name,n.subtotal.toFixed(2)));return t.push(dD(`Grand total`,e.totalCost.toFixed(2))),t.push(dD(`Part count`,e.partCount)),t.join(` `)}function pD(e){let t=[],n=`─`.repeat(58);t.push(`HYDRO BUILDER — SHOPPING LIST`),t.push(`${e.partCount} parts · estimated total ${oD(e.totalCost)}`),t.push(n);let r=``;for(let n of e.lines){n.category!==r&&(r=n.category,t.push(``),t.push(`${r.toUpperCase()}`));let e=n.qty>1||n.unit===`stick`?`${n.description} ×${n.qty}`:n.description,i=`${oD(n.totalCost)}${n.estimated?` est.`:``}`;t.push(` ${e.padEnd(44)} ${i}`),n.spec&&t.push(` ${n.spec}`)}if(e.cutLists.length>0){t.push(``),t.push(n),t.push(`CUT LIST (10 ft sticks)`);for(let n of e.cutLists){t.push(``),t.push(`${iD(n.diameterIn)} PVC — buy ${n.sticksToBuy} stick${n.sticksToBuy===1?``:`s`}, ${aD(n.totalCutIn)} of cuts, ${aD(n.totalLeftoverIn)} scrap`);for(let e of n.sticks){let n=e.cuts.map(e=>aD(e)).join(`, `);t.push(` Stick ${e.index}: ${n} — ${aD(e.leftoverIn)} left`)}n.spliceCount>0&&t.push(` (${n.spliceCount} coupling${n.spliceCount===1?``:`s`} needed for runs over 10 ft)`)}}t.push(``),t.push(n);for(let n of e.categories)t.push(`${n.name.padEnd(46)} ${oD(n.subtotal)}`);return t.push(`${`TOTAL (estimated)`.padEnd(46)} ${oD(e.totalCost)}`),t.join(` `)}function mD(e,t){let n=new Blob([fD(e)],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.replace(/[^a-z0-9-_ ]/gi,``).trim()||`hydro-system`}-bom.csv`,i.click(),URL.revokeObjectURL(r)}function hD(e){"@babel/helpers - typeof";return hD=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},hD(e)}var gD=Uint8Array,_D=Uint16Array,vD=Int32Array,yD=new gD([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),bD=new gD([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),xD=new gD([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),SD=function(e,t){for(var n=new _D(31),r=0;r<31;++r)n[r]=t+=1<>1|(kD&21845)<<1;AD=(AD&52428)>>2|(AD&13107)<<2,AD=(AD&61680)>>4|(AD&3855)<<4,OD[kD]=((AD&65280)>>8|(AD&255)<<8)>>1}for(var jD=(function(e,t,n){for(var r=e.length,i=0,a=new _D(t);i>c]=l}else for(s=new _D(r),i=0;i>15-e[i]);return s}),MD=new gD(288),kD=0;kD<144;++kD)MD[kD]=8;for(var kD=144;kD<256;++kD)MD[kD]=9;for(var kD=256;kD<280;++kD)MD[kD]=7;for(var kD=280;kD<288;++kD)MD[kD]=8;for(var ND=new gD(32),kD=0;kD<32;++kD)ND[kD]=5;var PD=jD(MD,9,0),FD=jD(ND,5,0),ID=function(e){return(e+7)/8|0},LD=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new gD(e.subarray(t,n))},RD=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},zD=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},BD=function(e,t){for(var n=[],r=0;rf&&(f=a[r].s);var p=new _D(f+1),m=VD(n[u-1],p,0);if(m>t){var r=0,h=0,g=m-t,_=1<t)h+=_-(1<>=g;h>0;){var y=a[r].s;p[y]=0&&h;--r){var b=a[r].s;p[b]==t&&(--p[b],++h)}m=t}return{t:new gD(p),l:m}},VD=function(e,t,n){return e.s==-1?Math.max(VD(e.l,t,n+1),VD(e.r,t,n+1)):t[e.s]=n},HD=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new _D(++t),r=0,i=e[0],a=1,o=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++a;else{if(!i&&a>2){for(;a>138;a-=138)o(32754);a>2&&(o(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(o(i),--a;a>6;a-=6)o(8304);a>2&&(o(a-3<<5|8208),a=0)}for(;a--;)o(i);a=1,i=e[s]}return{c:n.subarray(0,r),n:t}},UD=function(e,t){for(var n=0,r=0;r>8,e[i+2]=e[i]^255,e[i+3]=e[i+1]^255;for(var a=0;a4&&!E[xD[O-1]];--O);var k=l+5<<3,A=UD(i,MD)+UD(a,ND)+o,j=UD(i,f)+UD(a,h)+o+14+3*O+UD(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&k<=A&&k<=j)return WD(t,u,e.subarray(c,c+l));var M,N,P,F;if(RD(t,u,1+(j15&&(RD(t,u,R[w]>>5&127),u+=R[w]>>12)}}else M=PD,N=MD,P=FD,F=ND;for(var w=0;w255){var te=z>>18&31;zD(t,u,M[te+257]),u+=N[te+257],te>7&&(RD(t,u,z>>23&31),u+=yD[te]);var B=z&31;zD(t,u,P[B]),u+=F[B],B>3&&(zD(t,u,z>>5&8191),u+=bD[B])}else zD(t,u,M[z]),u+=N[z]}return zD(t,u,M[256]),u+N[256]},KD=new vD([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),qD=new gD(0),JD=function(e,t,n,r,i,a){var o=a.z||e.length,s=new gD(r+o+5*(1+Math.ceil(o/7e3))+i),c=s.subarray(r,s.length-i),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=KD[t-1],f=d>>13,p=d&8191,m=(1<7e3||E>24576)&&(M>423||!l)){u=GD(e,c,0,b,x,S,w,E,O,T-O,u),E=C=w=0,O=T;for(var N=0;N<286;++N)x[N]=0;for(var N=0;N<30;++N)S[N]=0}var P=2,F=0,I=p,L=A-j&32767;if(M>2&&k==y(T-L))for(var ee=Math.min(f,M)-1,R=Math.min(32767,T),te=Math.min(258,M);L<=R&&--I&&A!=j;){if(e[T+P]==e[T+P-L]){for(var z=0;zP){if(P=z,F=L,z>ee)break;for(var B=Math.min(L,z-2),V=0,N=0;NV&&(V=re,j=ne)}}}A=j,j=h[A],L+=A-j&32767}if(F){b[E++]=268435456|TD[P]<<18|DD[F];var ie=TD[P]&31,ae=DD[F]&31;w+=yD[ie]+bD[ae],++x[257+ie],++S[ae],D=T+P,++C}else b[E++]=e[T],++x[e[T]]}}for(T=Math.max(T,D);T=o&&(c[u/8|0]=l,oe=o),u=WD(c,u+1,e.subarray(T,oe))}a.i=o}return LD(s,0,r+ID(u)+i)},YD=function(){var e=1,t=0;return{p:function(n){for(var r=e,i=t,a=n.length|0,o=0;o!=a;){for(var s=Math.min(o+2655,a);o>16),i=(i&65535)+15*(i>>16)}e=r,t=i},d:function(){return e%=65521,t%=65521,(e&255)<<24|(e&65280)<<8|(t&255)<<8|t>>8}}},XD=function(e,t,n,r,i){if(!i&&(i={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),o=new gD(a.length+e.length);o.set(a),o.set(e,a.length),e=o,i.w=a.length}return JD(e,t.level==null?6:t.level,t.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,i)},ZD=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},QD=function(e,t){var n=t.level,r=n==0?0:n<6?1:n==9?3:2;if(e[0]=120,e[1]=r<<6|(t.dictionary&&32),e[1]|=31-(e[0]<<8|e[1])%31,t.dictionary){var i=YD();i.p(t.dictionary),ZD(e,2,i.d())}};function $D(e,t){t||={};var n=YD();n.p(e);var r=XD(e,t,t.dictionary?6:2,4);return QD(r,t),ZD(r,r.length-4,n.d()),r}var eO=typeof TextDecoder<`u`&&new TextDecoder;try{eO.decode(qD,{stream:!0})}catch{}function tO(e){if(Array.isArray(e))return e}function nO(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function rO(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),fO={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array},pO=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=uO,n={}){let r=!1;typeof t==`number`?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);let i=n.offset?n.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),r?this.lastWrittenByte=a:this.lastWrittenByte=0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}available(e=1){return this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e=1){return this.offset+=e,this}back(e=1){return this.offset-=e,this}seek(e){return this.offset=e,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let e=this._marks.pop();if(e===void 0)throw Error(`Mark stack empty`);return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e=1){if(!this.available(e)){let t=(this.offset+e)*2,n=new Uint8Array(t);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=t,this.byteLength=t,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(e=1){return this.readArray(e,`uint8`)}readArray(e,t){let n=fO[t].BYTES_PER_ELEMENT*e,r=this.byteOffset+this.offset,i=this.buffer.slice(r,r+n);if(this.littleEndian===dO&&t!==`uint8`&&t!==`int8`){let e=new Uint8Array(this.buffer.slice(r,r+n));e.reverse();let i=new fO[t](e.buffer);return this.offset+=n,i.reverse(),i}let a=new fO[t](i);return this.offset+=n,a}readInt16(){let e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){let e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){let e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){let e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){let e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){let e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readBigInt64(){let e=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}readBigUint64(){let e=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return String.fromCharCode(this.readInt8())}readChars(e=1){let t=``;for(let n=0;nthis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}},mO=4,hO=0,gO=1,_O=2;function vO(e){let t=e.length;for(;--t>=0;)e[t]=0}var yO=0,bO=1,xO=2,SO=29,CO=256,wO=286,TO=30,EO=19,DO=573,OO=15,kO=16,AO=7,jO=256,MO=16,NO=17,PO=18,FO=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),IO=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),LO=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),RO=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zO=512,BO=Array(288*2);vO(BO);var VO=Array(TO*2);vO(VO);var HO=Array(zO);vO(HO);var UO=Array(256);vO(UO);var WO=Array(SO);vO(WO);var GO=Array(TO);vO(GO);function KO(e,t,n,r,i){this.static_tree=e,this.extra_bits=t,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=e&&e.length}var qO,JO,YO;function XO(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}var ZO=e=>e<256?HO[e]:HO[256+(e>>>7)],QO=(e,t)=>{e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255},$O=(e,t,n)=>{e.bi_valid>kO-n?(e.bi_buf|=t<>kO-e.bi_valid,e.bi_valid+=n-kO):(e.bi_buf|=t<{$O(e,n[t*2],n[t*2+1])},tk=(e,t)=>{let n=0;do n|=e&1,e>>>=1,n<<=1;while(--t>0);return n>>>1},nk=e=>{e.bi_valid===16?(QO(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)},rk=(e,t)=>{let n=t.dyn_tree,r=t.max_code,i=t.stat_desc.static_tree,a=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,s=t.stat_desc.extra_base,c=t.stat_desc.max_length,l,u,d,f,p,m,h=0;for(f=0;f<=OO;f++)e.bl_count[f]=0;for(n[e.heap[e.heap_max]*2+1]=0,l=e.heap_max+1;lc&&(f=c,h++),n[u*2+1]=f,!(u>r)&&(e.bl_count[f]++,p=0,u>=s&&(p=o[u-s]),m=n[u*2],e.opt_len+=m*(f+p),a&&(e.static_len+=m*(i[u*2+1]+p)));if(h!==0){do{for(f=c-1;e.bl_count[f]===0;)f--;e.bl_count[f]--,e.bl_count[f+1]+=2,e.bl_count[c]--,h-=2}while(h>0);for(f=c;f!==0;f--)for(u=e.bl_count[f];u!==0;)d=e.heap[--l],!(d>r)&&(n[d*2+1]!==f&&(e.opt_len+=(f-n[d*2+1])*n[d*2],n[d*2+1]=f),u--)}},ik=(e,t,n)=>{let r=Array(16),i=0,a,o;for(a=1;a<=OO;a++)i=i+n[a-1]<<1,r[a]=i;for(o=0;o<=t;o++){let t=e[o*2+1];t!==0&&(e[o*2]=tk(r[t]++,t))}},ak=()=>{let e,t,n,r,i,a=Array(16);for(n=0,r=0;r>=7;r{let t;for(t=0;t{e.bi_valid>8?QO(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},ck=(e,t,n,r)=>{let i=t*2,a=n*2;return e[i]{let r=e.heap[n],i=n<<1;for(;i<=e.heap_len&&(i{let r,i,a=0,o,s;if(e.sym_next!==0)do r=e.pending_buf[e.sym_buf+ a++]&255,r+=(e.pending_buf[e.sym_buf+ a++]&255)<<8,i=e.pending_buf[e.sym_buf+ a++],r===0?ek(e,i,t):(o=UO[i],ek(e,o+CO+1,t),s=FO[o],s!==0&&(i-=WO[o],$O(e,i,s)),r--,o=ZO(r),ek(e,o,n),s=IO[o],s!==0&&(r-=GO[o],$O(e,r,s)));while(a{let n=t.dyn_tree,r=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.elems,o,s,c=-1,l;for(e.heap_len=0,e.heap_max=DO,o=0;o>1;o>=1;o--)lk(e,n,o);l=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],lk(e,n,1),s=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=s,n[l*2]=n[o*2]+n[s*2],e.depth[l]=(e.depth[o]>=e.depth[s]?e.depth[o]:e.depth[s])+1,n[o*2+1]=n[s*2+1]=l,e.heap[1]=l++,lk(e,n,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],rk(e,t),ik(n,c,e.bl_count)},fk=(e,t,n)=>{let r,i=-1,a,o=t[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),t[(n+1)*2+1]=65535,r=0;r<=n;r++)a=o,o=t[(r+1)*2+1],!(++s{let r,i=-1,a,o=t[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),r=0;r<=n;r++)if(a=o,o=t[(r+1)*2+1],!(++s{let t;for(fk(e,e.dyn_ltree,e.l_desc.max_code),fk(e,e.dyn_dtree,e.d_desc.max_code),dk(e,e.bl_desc),t=EO-1;t>=3&&e.bl_tree[RO[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t},hk=(e,t,n,r)=>{let i;for($O(e,t-257,5),$O(e,n-1,5),$O(e,r-4,4),i=0;i{let t=4093624447,n;for(n=0;n<=31;n++,t>>>=1)if(t&1&&e.dyn_ltree[n*2]!==0)return hO;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return gO;for(n=32;n{_k||=(ak(),!0),e.l_desc=new XO(e.dyn_ltree,qO),e.d_desc=new XO(e.dyn_dtree,JO),e.bl_desc=new XO(e.bl_tree,YO),e.bi_buf=0,e.bi_valid=0,ok(e)},yk=(e,t,n,r)=>{$O(e,(yO<<1)+ +!!r,3),sk(e),QO(e,n),QO(e,~n),n&&e.pending_buf.set(e.window.subarray(t,t+n),e.pending),e.pending+=n},bk={_tr_init:vk,_tr_stored_block:yk,_tr_flush_block:(e,t,n,r)=>{let i,a,o=0;e.level>0?(e.strm.data_type===_O&&(e.strm.data_type=gk(e)),dk(e,e.l_desc),dk(e,e.d_desc),o=mk(e),i=e.opt_len+3+7>>>3,a=e.static_len+3+7>>>3,a<=i&&(i=a)):i=a=n+5,n+4<=i&&t!==-1?yk(e,t,n,r):e.strategy===mO||a===i?($O(e,(bO<<1)+ +!!r,3),uk(e,BO,VO)):($O(e,(xO<<1)+ +!!r,3),hk(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),uk(e,e.dyn_ltree,e.dyn_dtree)),ok(e),r&&sk(e)},_tr_tally:(e,t,n)=>(e.pending_buf[e.sym_buf+ e.sym_next++]=t,e.pending_buf[e.sym_buf+ e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+ e.sym_next++]=n,t===0?e.dyn_ltree[n*2]++:(e.matches++,t--,e.dyn_ltree[(UO[n]+CO+1)*2]++,e.dyn_dtree[ZO(t)*2]++),e.sym_next===e.sym_end),_tr_align:e=>{$O(e,bO<<1,3),ek(e,jO,BO),nk(e)}},xk=(e,t,n,r)=>{let i=e&65535|0,a=e>>>16&65535|0,o=0;for(;n!==0;){o=n>2e3?2e3:n,n-=o;do i=i+t[r++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0},Sk=new Uint32Array((()=>{let e,t=[];for(var n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=e&1?3988292384^e>>>1:e>>>1;t[n]=e}return t})()),Ck=(e,t,n,r)=>{let i=Sk,a=r+n;e^=-1;for(let n=r;n>>8^i[(e^t[n])&255];return e^-1},wk={2:`need dictionary`,1:`stream end`,0:``,"-1":`file error`,"-2":`stream error`,"-3":`data error`,"-4":`insufficient memory`,"-5":`buffer error`,"-6":`incompatible version`},Tk={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:Ek,_tr_stored_block:Dk,_tr_flush_block:Ok,_tr_tally:kk,_tr_align:Ak}=bk,{Z_NO_FLUSH:jk,Z_PARTIAL_FLUSH:Mk,Z_FULL_FLUSH:Nk,Z_FINISH:Pk,Z_BLOCK:Fk,Z_OK:Ik,Z_STREAM_END:Lk,Z_STREAM_ERROR:Rk,Z_DATA_ERROR:zk,Z_BUF_ERROR:Bk,Z_DEFAULT_COMPRESSION:Vk,Z_FILTERED:Hk,Z_HUFFMAN_ONLY:Uk,Z_RLE:Wk,Z_FIXED:Gk,Z_DEFAULT_STRATEGY:Kk,Z_UNKNOWN:qk,Z_DEFLATED:Jk}=Tk,Yk=9,Xk=15,Zk=8,Qk=573,$k=3,eA=258,tA=262,nA=32,rA=42,iA=57,aA=69,oA=73,sA=91,cA=103,lA=113,uA=666,dA=1,fA=2,pA=3,mA=4,hA=3,gA=(e,t)=>(e.msg=wk[t],t),_A=e=>e*2-(e>4?9:0),vA=e=>{let t=e.length;for(;--t>=0;)e[t]=0},yA=e=>{let t,n,r,i=e.w_size;t=e.hash_size,r=t;do n=e.head[--r],e.head[r]=n>=i?n-i:0;while(--t);t=i,r=t;do n=e.prev[--r],e.prev[r]=n>=i?n-i:0;while(--t)},bA=(e,t,n)=>(t<{let t=e.state,n=t.pending;n>e.avail_out&&(n=e.avail_out),n!==0&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+n),e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,t.pending===0&&(t.pending_out=0))},SA=(e,t)=>{Ok(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,xA(e.strm)},CA=(e,t)=>{e.pending_buf[e.pending++]=t},wA=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255},TA=(e,t,n,r)=>{let i=e.avail_in;return i>r&&(i=r),i===0?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),n),e.state.wrap===1?e.adler=xk(e.adler,t,i,n):e.state.wrap===2&&(e.adler=Ck(e.adler,t,i,n)),e.next_in+=i,e.total_in+=i,i)},EA=(e,t)=>{let n=e.max_chain_length,r=e.strstart,i,a,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-tA?e.strstart-(e.w_size-tA):0,l=e.window,u=e.w_mask,d=e.prev,f=e.strstart+eA,p=l[r+o-1],m=l[r+o];e.prev_length>=e.good_match&&(n>>=2),s>e.lookahead&&(s=e.lookahead);do{if(i=t,l[i+o]!==m||l[i+o-1]!==p||l[i]!==l[r]||l[++i]!==l[r+1])continue;r+=2,i++;do;while(l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&ro){if(e.match_start=t,o=a,a>=s)break;p=l[r+o-1],m=l[r+o]}}while((t=d[t&u])>c&&--n!==0);return o<=e.lookahead?o:e.lookahead},DA=e=>{let t=e.w_size,n,r,i;do{if(r=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-tA)&&(e.window.set(e.window.subarray(t,t+t-r),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),yA(e),r+=t),e.strm.avail_in===0)break;if(n=TA(e.strm,e.window,e.strstart+e.lookahead,r),e.lookahead+=n,e.lookahead+e.insert>=$k)for(i=e.strstart-e.insert,e.ins_h=e.window[i],e.ins_h=bA(e,e.ins_h,e.window[i+1]);e.insert&&(e.ins_h=bA(e,e.ins_h,e.window[i+$k-1]),e.prev[i&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=i,i++,e.insert--,!(e.lookahead+e.insert<$k)););}while(e.lookahead{let n=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,r,i,a,o=0,s=e.strm.avail_in;do{if(r=65535,a=e.bi_valid+42>>3,e.strm.avail_outi+e.strm.avail_in&&(r=i+e.strm.avail_in),r>a&&(r=a),r>8,e.pending_buf[e.pending-2]=~r,e.pending_buf[e.pending-1]=~r>>8,xA(e.strm),i&&(i>r&&(i=r),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+i),e.strm.next_out),e.strm.next_out+=i,e.strm.avail_out-=i,e.strm.total_out+=i,e.block_start+=i,r-=i),r&&(TA(e.strm,e.strm.output,e.strm.next_out,r),e.strm.next_out+=r,e.strm.avail_out-=r,e.strm.total_out+=r)}while(o===0);return s-=e.strm.avail_in,s&&(s>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=s&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-s,e.strm.next_in),e.strstart),e.strstart+=s,e.insert+=s>e.w_size-e.insert?e.w_size-e.insert:s),e.block_start=e.strstart),e.high_watera&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,a+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),a>e.strm.avail_in&&(a=e.strm.avail_in),a&&(TA(e.strm,e.window,e.strstart,a),e.strstart+=a,e.insert+=a>e.w_size-e.insert?e.w_size-e.insert:a),e.high_water>3,a=e.pending_buf_size-a>65535?65535:e.pending_buf_size-a,n=a>e.w_size?e.w_size:a,i=e.strstart-e.block_start,(i>=n||(i||t===Pk)&&t!==jk&&e.strm.avail_in===0&&i<=a)&&(r=i>a?a:i,o=+(t===Pk&&e.strm.avail_in===0&&r===i),Dk(e,e.block_start,r,o),e.block_start+=r,xA(e.strm)),o?pA:dA)},kA=(e,t)=>{let n,r;for(;;){if(e.lookahead=$k&&(e.ins_h=bA(e,e.ins_h,e.window[e.strstart+$k-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),n!==0&&e.strstart-n<=e.w_size-tA&&(e.match_length=EA(e,n)),e.match_length>=$k)if(r=kk(e,e.strstart-e.match_start,e.match_length-$k),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=$k){e.match_length--;do e.strstart++,e.ins_h=bA(e,e.ins_h,e.window[e.strstart+$k-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=bA(e,e.ins_h,e.window[e.strstart+1]);else r=kk(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&(SA(e,!1),e.strm.avail_out===0))return dA}return e.insert=e.strstart<$k-1?e.strstart:$k-1,t===Pk?(SA(e,!0),e.strm.avail_out===0?pA:mA):e.sym_next&&(SA(e,!1),e.strm.avail_out===0)?dA:fA},AA=(e,t)=>{let n,r,i;for(;;){if(e.lookahead=$k&&(e.ins_h=bA(e,e.ins_h,e.window[e.strstart+$k-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=$k-1,n!==0&&e.prev_length4096)&&(e.match_length=$k-1)),e.prev_length>=$k&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-$k,r=kk(e,e.strstart-1-e.prev_match,e.prev_length-$k),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=bA(e,e.ins_h,e.window[e.strstart+$k-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=$k-1,e.strstart++,r&&(SA(e,!1),e.strm.avail_out===0))return dA}else if(e.match_available){if(r=kk(e,0,e.window[e.strstart-1]),r&&SA(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return dA}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&=(r=kk(e,0,e.window[e.strstart-1]),0),e.insert=e.strstart<$k-1?e.strstart:$k-1,t===Pk?(SA(e,!0),e.strm.avail_out===0?pA:mA):e.sym_next&&(SA(e,!1),e.strm.avail_out===0)?dA:fA},jA=(e,t)=>{let n,r,i,a,o=e.window;for(;;){if(e.lookahead<=eA){if(DA(e),e.lookahead<=eA&&t===jk)return dA;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=$k&&e.strstart>0&&(i=e.strstart-1,r=o[i],r===o[++i]&&r===o[++i]&&r===o[++i])){a=e.strstart+eA;do;while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&ie.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=$k?(n=kk(e,1,e.match_length-$k),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=kk(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(SA(e,!1),e.strm.avail_out===0))return dA}return e.insert=0,t===Pk?(SA(e,!0),e.strm.avail_out===0?pA:mA):e.sym_next&&(SA(e,!1),e.strm.avail_out===0)?dA:fA},MA=(e,t)=>{let n;for(;;){if(e.lookahead===0&&(DA(e),e.lookahead===0)){if(t===jk)return dA;break}if(e.match_length=0,n=kk(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(SA(e,!1),e.strm.avail_out===0))return dA}return e.insert=0,t===Pk?(SA(e,!0),e.strm.avail_out===0?pA:mA):e.sym_next&&(SA(e,!1),e.strm.avail_out===0)?dA:fA};function NA(e,t,n,r,i){this.good_length=e,this.max_lazy=t,this.nice_length=n,this.max_chain=r,this.func=i}var PA=[new NA(0,0,0,0,OA),new NA(4,4,8,4,kA),new NA(4,5,16,8,kA),new NA(4,6,32,32,kA),new NA(4,4,16,16,AA),new NA(8,16,32,32,AA),new NA(8,16,128,128,AA),new NA(8,32,128,256,AA),new NA(32,128,258,1024,AA),new NA(32,258,258,4096,AA)],FA=e=>{e.window_size=2*e.w_size,vA(e.head),e.max_lazy_match=PA[e.level].max_lazy,e.good_match=PA[e.level].good_length,e.nice_match=PA[e.level].nice_length,e.max_chain_length=PA[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=$k-1,e.match_available=0,e.ins_h=0};function IA(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Jk,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(Qk*2),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),vA(this.dyn_ltree),vA(this.dyn_dtree),vA(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),vA(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),vA(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var LA=e=>{if(!e)return 1;let t=e.state;return+(!t||t.strm!==e||t.status!==rA&&t.status!==iA&&t.status!==aA&&t.status!==oA&&t.status!==sA&&t.status!==cA&&t.status!==lA&&t.status!==uA)},RA=e=>{if(LA(e))return gA(e,Rk);e.total_in=e.total_out=0,e.data_type=qk;let t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap===2?iA:t.wrap?rA:lA,e.adler=t.wrap===2?0:1,t.last_flush=-2,Ek(t),Ik},zA=e=>{let t=RA(e);return t===Ik&&FA(e.state),t},BA=(e,t)=>LA(e)||e.state.wrap!==2?Rk:(e.state.gzhead=t,Ik),VA=(e,t,n,r,i,a)=>{if(!e)return Rk;let o=1;if(t===Vk&&(t=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>Yk||n!==Jk||r<8||r>15||t<0||t>9||a<0||a>Gk||r===8&&o!==1)return gA(e,Rk);r===8&&(r=9);let s=new IA;return e.state=s,s.strm=e,s.status=rA,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<VA(e,t,Jk,Xk,Zk,Kk),deflateInit2:VA,deflateReset:zA,deflateResetKeep:RA,deflateSetHeader:BA,deflate:(e,t)=>{if(LA(e)||t>Fk||t<0)return e?gA(e,Rk):Rk;let n=e.state;if(!e.output||e.avail_in!==0&&!e.input||n.status===uA&&t!==Pk)return gA(e,e.avail_out===0?Bk:Rk);let r=n.last_flush;if(n.last_flush=t,n.pending!==0){if(xA(e),e.avail_out===0)return n.last_flush=-1,Ik}else if(e.avail_in===0&&_A(t)<=_A(r)&&t!==Pk)return gA(e,Bk);if(n.status===uA&&e.avail_in!==0)return gA(e,Bk);if(n.status===rA&&n.wrap===0&&(n.status=lA),n.status===rA){let t=Jk+(n.w_bits-8<<4)<<8,r=-1;if(r=n.strategy>=Uk||n.level<2?0:n.level<6?1:n.level===6?2:3,t|=r<<6,n.strstart!==0&&(t|=nA),t+=31-t%31,wA(n,t),n.strstart!==0&&(wA(n,e.adler>>>16),wA(n,e.adler&65535)),e.adler=1,n.status=lA,xA(e),n.pending!==0)return n.last_flush=-1,Ik}if(n.status===iA){if(e.adler=0,CA(n,31),CA(n,139),CA(n,8),n.gzhead)CA(n,+!!n.gzhead.text+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),CA(n,n.gzhead.time&255),CA(n,n.gzhead.time>>8&255),CA(n,n.gzhead.time>>16&255),CA(n,n.gzhead.time>>24&255),CA(n,n.level===9?2:n.strategy>=Uk||n.level<2?4:0),CA(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(CA(n,n.gzhead.extra.length&255),CA(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=Ck(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=aA;else if(CA(n,0),CA(n,0),CA(n,0),CA(n,0),CA(n,0),CA(n,n.level===9?2:n.strategy>=Uk||n.level<2?4:0),CA(n,hA),n.status=lA,xA(e),n.pending!==0)return n.last_flush=-1,Ik}if(n.status===aA){if(n.gzhead.extra){let t=n.pending,r=(n.gzhead.extra.length&65535)-n.gzindex;for(;n.pending+r>n.pending_buf_size;){let i=n.pending_buf_size-n.pending;if(n.pending_buf.set(n.gzhead.extra.subarray(n.gzindex,n.gzindex+i),n.pending),n.pending=n.pending_buf_size,n.gzhead.hcrc&&n.pending>t&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t)),n.gzindex+=i,xA(e),n.pending!==0)return n.last_flush=-1,Ik;t=0,r-=i}let i=new Uint8Array(n.gzhead.extra);n.pending_buf.set(i.subarray(n.gzindex,n.gzindex+r),n.pending),n.pending+=r,n.gzhead.hcrc&&n.pending>t&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t)),n.gzindex=0}n.status=oA}if(n.status===oA){if(n.gzhead.name){let t=n.pending,r;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>t&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t)),xA(e),n.pending!==0)return n.last_flush=-1,Ik;t=0}r=n.gzindext&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t)),n.gzindex=0}n.status=sA}if(n.status===sA){if(n.gzhead.comment){let t=n.pending,r;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>t&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t)),xA(e),n.pending!==0)return n.last_flush=-1,Ik;t=0}r=n.gzindext&&(e.adler=Ck(e.adler,n.pending_buf,n.pending-t,t))}n.status=cA}if(n.status===cA){if(n.gzhead.hcrc){if(n.pending+2>n.pending_buf_size&&(xA(e),n.pending!==0))return n.last_flush=-1,Ik;CA(n,e.adler&255),CA(n,e.adler>>8&255),e.adler=0}if(n.status=lA,xA(e),n.pending!==0)return n.last_flush=-1,Ik}if(e.avail_in!==0||n.lookahead!==0||t!==jk&&n.status!==uA){let r=n.level===0?OA(n,t):n.strategy===Uk?MA(n,t):n.strategy===Wk?jA(n,t):PA[n.level].func(n,t);if((r===pA||r===mA)&&(n.status=uA),r===dA||r===pA)return e.avail_out===0&&(n.last_flush=-1),Ik;if(r===fA&&(t===Mk?Ak(n):t!==Fk&&(Dk(n,0,0,!1),t===Nk&&(vA(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),xA(e),e.avail_out===0))return n.last_flush=-1,Ik}return t===Pk?n.wrap<=0?Lk:(n.wrap===2?(CA(n,e.adler&255),CA(n,e.adler>>8&255),CA(n,e.adler>>16&255),CA(n,e.adler>>24&255),CA(n,e.total_in&255),CA(n,e.total_in>>8&255),CA(n,e.total_in>>16&255),CA(n,e.total_in>>24&255)):(wA(n,e.adler>>>16),wA(n,e.adler&65535)),xA(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending===0?Lk:Ik):Ik},deflateEnd:e=>{if(LA(e))return Rk;let t=e.state.status;return e.state=null,t===lA?gA(e,zk):Ik},deflateSetDictionary:(e,t)=>{let n=t.length;if(LA(e))return Rk;let r=e.state,i=r.wrap;if(i===2||i===1&&r.status!==rA||r.lookahead)return Rk;if(i===1&&(e.adler=xk(e.adler,t,n,0)),r.wrap=0,n>=r.w_size){i===0&&(vA(r.head),r.strstart=0,r.block_start=0,r.insert=0);let e=new Uint8Array(r.w_size);e.set(t.subarray(n-r.w_size,n),0),t=e,n=r.w_size}let a=e.avail_in,o=e.next_in,s=e.input;for(e.avail_in=n,e.next_in=0,e.input=t,DA(r);r.lookahead>=$k;){let e=r.strstart,t=r.lookahead-($k-1);do r.ins_h=bA(r,r.ins_h,r.window[e+$k-1]),r.prev[e&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=e,e++;while(--t);r.strstart=e,r.lookahead=$k-1,DA(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=$k-1,r.match_available=0,e.next_in=o,e.input=s,e.avail_in=a,r.wrap=i,Ik},deflateInfo:`pako deflate (from Nodeca project)`},UA=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),WA={assign:function(e){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let n=t.shift();if(n){if(typeof n!=`object`)throw TypeError(n+`must be non-object`);for(let t in n)UA(n,t)&&(e[t]=n[t])}}return e},flattenChunks:e=>{let t=0;for(let n=0,r=e.length;n=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;KA[254]=KA[254]=1;var qA=e=>{if(typeof TextEncoder==`function`&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let t,n,r,i,a,o=e.length,s=0;for(i=0;i>>6,t[a++]=128|n&63):n<65536?(t[a++]=224|n>>>12,t[a++]=128|n>>>6&63,t[a++]=128|n&63):(t[a++]=240|n>>>18,t[a++]=128|n>>>12&63,t[a++]=128|n>>>6&63,t[a++]=128|n&63);return t},JA=(e,t)=>{if(t<65534&&e.subarray&&GA)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let n=``;for(let r=0;r{let n=t||e.length;if(typeof TextDecoder==`function`&&TextDecoder.prototype.decode)return new TextDecoder().decode(e.subarray(0,t));let r,i,a=Array(n*2);for(i=0,r=0;r4){a[i++]=65533,r+=o-1;continue}for(t&=o===2?31:o===3?15:7;o>1&&r1){a[i++]=65533;continue}t<65536?a[i++]=t:(t-=65536,a[i++]=55296|t>>10&1023,a[i++]=56320|t&1023)}return JA(a,i)},utf8border:(e,t)=>{t||=e.length,t>e.length&&(t=e.length);let n=t-1;for(;n>=0&&(e[n]&192)==128;)n--;return n<0||n===0?t:n+KA[e[n]]>t?n:t}};function XA(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg=``,this.state=null,this.data_type=2,this.adler=0}var ZA=XA,QA=Object.prototype.toString,{Z_NO_FLUSH:$A,Z_SYNC_FLUSH:ej,Z_FULL_FLUSH:tj,Z_FINISH:nj,Z_OK:rj,Z_STREAM_END:ij,Z_DEFAULT_COMPRESSION:aj,Z_DEFAULT_STRATEGY:oj,Z_DEFLATED:sj}=Tk;function cj(e){this.options=WA.assign({level:aj,method:sj,chunkSize:16384,windowBits:15,memLevel:8,strategy:oj},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg=``,this.ended=!1,this.chunks=[],this.strm=new ZA,this.strm.avail_out=0;let n=HA.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(n!==rj)throw Error(wk[n]);if(t.header&&HA.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e=typeof t.dictionary==`string`?YA.string2buf(t.dictionary):QA.call(t.dictionary)===`[object ArrayBuffer]`?new Uint8Array(t.dictionary):t.dictionary,n=HA.deflateSetDictionary(this.strm,e),n!==rj)throw Error(wk[n]);this._dict_set=!0}}cj.prototype.push=function(e,t){let n=this.strm,r=this.options.chunkSize,i,a;if(this.ended)return!1;for(a=t===~~t?t:t===!0?nj:$A,typeof e==`string`?n.input=YA.string2buf(e):QA.call(e)===`[object ArrayBuffer]`?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){if(n.avail_out===0&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),(a===ej||a===tj)&&n.avail_out<=6){this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;continue}if(i=HA.deflate(n,a),i===ij)return n.next_out>0&&this.onData(n.output.subarray(0,n.next_out)),i=HA.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===rj;if(n.avail_out===0){this.onData(n.output);continue}if(a>0&&n.next_out>0){this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;continue}if(n.avail_in===0)break}return!0},cj.prototype.onData=function(e){this.chunks.push(e)},cj.prototype.onEnd=function(e){e===rj&&(this.result=WA.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function lj(e,t){let n=new cj(t);if(n.push(e,!0),n.err)throw n.msg||wk[n.err];return n.result}function uj(e,t){return t||={},t.raw=!0,lj(e,t)}function dj(e,t){return t||={},t.gzip=!0,lj(e,t)}var fj={Deflate:cj,deflate:lj,deflateRaw:uj,gzip:dj,constants:Tk},pj=16209,mj=16191,hj=function(e,t){let n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E=e.state;n=e.next_in,w=e.input,r=n+(e.avail_in-5),i=e.next_out,T=e.output,a=i-(t-e.avail_out),o=i+(e.avail_out-257),s=E.dmax,c=E.wsize,l=E.whave,u=E.wnext,d=E.window,f=E.hold,p=E.bits,m=E.lencode,h=E.distcode,g=(1<>>24,f>>>=y,p-=y,y=v>>>16&255,y===0)T[i++]=v&65535;else if(y&16){b=v&65535,y&=15,y&&(p>>=y,p-=y),p<15&&(f+=w[n++]<>>24,f>>>=y,p-=y,y=v>>>16&255,y&16){if(x=v&65535,y&=15,ps){e.msg=`invalid distance too far back`,E.mode=pj;break top}if(f>>>=y,p-=y,y=i-a,x>y){if(y=x-y,y>l&&E.sane){e.msg=`invalid distance too far back`,E.mode=pj;break top}if(S=0,C=d,u===0){if(S+=c-y,y2;)T[i++]=C[S++],T[i++]=C[S++],T[i++]=C[S++],b-=3;b&&(T[i++]=C[S++],b>1&&(T[i++]=C[S++]))}else{S=i-x;do T[i++]=T[S++],T[i++]=T[S++],T[i++]=T[S++],b-=3;while(b>2);b&&(T[i++]=T[S++],b>1&&(T[i++]=T[S++]))}}else if(y&64){e.msg=`invalid distance code`,E.mode=pj;break top}else{v=h[(v&65535)+(f&(1<>3,n-=b,p-=b<<3,f&=(1<{let c=s.bits,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y,b,x,S,C,w=null,T,E=new Uint16Array(16),D=new Uint16Array(16),O=null,k,A,j;for(l=0;l<=gj;l++)E[l]=0;for(u=0;u=1&&E[f]===0;f--);if(p>f&&(p=f),f===0)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(d=1;d0&&(e===yj||f!==1))return-1;for(D[1]=0,l=1;l_j||e===xj&&_>vj)return 1;for(;;){k=l-h,o[u]+1=T?(A=O[o[u]-T],j=w[o[u]-T]):(A=96,j=0),y=1<>h)+b]=k<<24|A<<16|j|0;while(b!==0);for(y=1<>=1;if(y===0?v=0:(v&=y-1,v+=y),u++,--E[l]===0){if(l===f)break;l=t[n+o[u]]}if(l>p&&(v&S)!==x){for(h===0&&(h=p),C+=d,m=l-h,g=1<_j||e===xj&&_>vj)return 1;x=v&S,i[x]=p<<24|m<<16|C-a|0}}return v!==0&&(i[C+v]=l-h<<24|4194304),s.bits=p,0},Dj=0,Oj=1,kj=2,{Z_FINISH:Aj,Z_BLOCK:jj,Z_TREES:Mj,Z_OK:Nj,Z_STREAM_END:Pj,Z_NEED_DICT:Fj,Z_STREAM_ERROR:Ij,Z_DATA_ERROR:Lj,Z_MEM_ERROR:Rj,Z_BUF_ERROR:zj,Z_DEFLATED:Bj}=Tk,Vj=16180,Hj=16181,Uj=16182,Wj=16183,Gj=16184,Kj=16185,qj=16186,Jj=16187,Yj=16188,Xj=16189,Zj=16190,Qj=16191,$j=16192,eM=16193,tM=16194,nM=16195,rM=16196,iM=16197,aM=16198,oM=16199,sM=16200,cM=16201,lM=16202,uM=16203,dM=16204,fM=16205,pM=16206,mM=16207,hM=16208,gM=16209,_M=16210,vM=16211,yM=852,bM=592,xM=15,SM=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function CM(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var wM=e=>{if(!e)return 1;let t=e.state;return+(!t||t.strm!==e||t.modevM)},TM=e=>{if(wM(e))return Ij;let t=e.state;return e.total_in=e.total_out=t.total=0,e.msg=``,t.wrap&&(e.adler=t.wrap&1),t.mode=Vj,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(yM),t.distcode=t.distdyn=new Int32Array(bM),t.sane=1,t.back=-1,Nj},EM=e=>{if(wM(e))return Ij;let t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,TM(e)},DM=(e,t)=>{let n;if(wM(e))return Ij;let r=e.state;return t<0?(n=0,t=-t):(n=(t>>4)+5,t<48&&(t&=15)),t&&(t<8||t>15)?Ij:(r.window!==null&&r.wbits!==t&&(r.window=null),r.wrap=n,r.wbits=t,EM(e))},OM=(e,t)=>{if(!e)return Ij;let n=new CM;e.state=n,n.strm=e,n.window=null,n.mode=Vj;let r=DM(e,t);return r!==Nj&&(e.state=null),r},kM=e=>OM(e,xM),AM=!0,jM,MM,NM=e=>{if(AM){jM=new Int32Array(512),MM=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Ej(Oj,e.lens,0,288,jM,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Ej(kj,e.lens,0,32,MM,0,e.work,{bits:5}),AM=!1}e.lencode=jM,e.lenbits=9,e.distcode=MM,e.distbits=5},PM=(e,t,n,r)=>{let i,a=e.state;return a.window===null&&(a.wsize=1<=a.wsize?(a.window.set(t.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>r&&(i=r),a.window.set(t.subarray(n-r,n-r+i),a.wnext),r-=i,r?(a.window.set(t.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave{let n,r,i,a,o,s,c,l,u,d,f,p,m,h,g=0,_,v,y,b,x,S,C,w,T=new Uint8Array(4),E,D,O=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(wM(e)||!e.output||!e.input&&e.avail_in!==0)return Ij;n=e.state,n.mode===Qj&&(n.mode=$j),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,r=e.input,s=e.avail_in,l=n.hold,u=n.bits,d=s,f=c,w=Nj;inf_leave:for(;;)switch(n.mode){case Vj:if(n.wrap===0){n.mode=$j;break}for(;u<16;){if(s===0)break inf_leave;s--,l+=r[a++]<>>8&255,n.check=Ck(n.check,T,2,0),l=0,u=0,n.mode=Hj;break}if(n.head&&(n.head.done=!1),!(n.wrap&1)||(((l&255)<<8)+(l>>8))%31){e.msg=`incorrect header check`,n.mode=gM;break}if((l&15)!==Bj){e.msg=`unknown compression method`,n.mode=gM;break}if(l>>>=4,u-=4,C=(l&15)+8,n.wbits===0&&(n.wbits=C),C>15||C>n.wbits){e.msg=`invalid window size`,n.mode=gM;break}n.dmax=1<>8&1),n.flags&512&&n.wrap&4&&(T[0]=l&255,T[1]=l>>>8&255,n.check=Ck(n.check,T,2,0)),l=0,u=0,n.mode=Uj;case Uj:for(;u<32;){if(s===0)break inf_leave;s--,l+=r[a++]<>>8&255,T[2]=l>>>16&255,T[3]=l>>>24&255,n.check=Ck(n.check,T,4,0)),l=0,u=0,n.mode=Wj;case Wj:for(;u<16;){if(s===0)break inf_leave;s--,l+=r[a++]<>8),n.flags&512&&n.wrap&4&&(T[0]=l&255,T[1]=l>>>8&255,n.check=Ck(n.check,T,2,0)),l=0,u=0,n.mode=Gj;case Gj:if(n.flags&1024){for(;u<16;){if(s===0)break inf_leave;s--,l+=r[a++]<>>8&255,n.check=Ck(n.check,T,2,0)),l=0,u=0}else n.head&&(n.head.extra=null);n.mode=Kj;case Kj:if(n.flags&1024&&(p=n.length,p>s&&(p=s),p&&(n.head&&(C=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+p),C)),n.flags&512&&n.wrap&4&&(n.check=Ck(n.check,r,p,a)),s-=p,a+=p,n.length-=p),n.length))break inf_leave;n.length=0,n.mode=qj;case qj:if(n.flags&2048){if(s===0)break inf_leave;p=0;do C=r[a+ p++],n.head&&C&&n.length<65536&&(n.head.name+=String.fromCharCode(C));while(C&&p>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=Qj;break;case Xj:for(;u<32;){if(s===0)break inf_leave;s--,l+=r[a++]<>>=u&7,u-=u&7,n.mode=pM;break}for(;u<3;){if(s===0)break inf_leave;s--,l+=r[a++]<>>=1,--u,l&3){case 0:n.mode=eM;break;case 1:if(NM(n),n.mode=oM,t===Mj){l>>>=2,u-=2;break inf_leave}break;case 2:n.mode=rM;break;case 3:e.msg=`invalid block type`,n.mode=gM}l>>>=2,u-=2;break;case eM:for(l>>>=u&7,u-=u&7;u<32;){if(s===0)break inf_leave;s--,l+=r[a++]<>>16^65535)){e.msg=`invalid stored block lengths`,n.mode=gM;break}if(n.length=l&65535,l=0,u=0,n.mode=tM,t===Mj)break inf_leave;case tM:n.mode=nM;case nM:if(p=n.length,p){if(p>s&&(p=s),p>c&&(p=c),p===0)break inf_leave;i.set(r.subarray(a,a+p),o),s-=p,a+=p,c-=p,o+=p,n.length-=p;break}n.mode=Qj;break;case rM:for(;u<14;){if(s===0)break inf_leave;s--,l+=r[a++]<>>=5,u-=5,n.ndist=(l&31)+1,l>>>=5,u-=5,n.ncode=(l&15)+4,l>>>=4,u-=4,n.nlen>286||n.ndist>30){e.msg=`too many length or distance symbols`,n.mode=gM;break}n.have=0,n.mode=iM;case iM:for(;n.have>>=3,u-=3}for(;n.have<19;)n.lens[O[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},w=Ej(Dj,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,w){e.msg=`invalid code lengths set`,n.mode=gM;break}n.have=0,n.mode=aM;case aM:for(;n.have>>24,v=g>>>16&255,y=g&65535,!(_<=u);){if(s===0)break inf_leave;s--,l+=r[a++]<>>=_,u-=_,n.lens[n.have++]=y;else{if(y===16){for(D=_+2;u>>=_,u-=_,n.have===0){e.msg=`invalid bit length repeat`,n.mode=gM;break}C=n.lens[n.have-1],p=3+(l&3),l>>>=2,u-=2}else if(y===17){for(D=_+3;u>>=_,u-=_,C=0,p=3+(l&7),l>>>=3,u-=3}else{for(D=_+7;u>>=_,u-=_,C=0,p=11+(l&127),l>>>=7,u-=7}if(n.have+p>n.nlen+n.ndist){e.msg=`invalid bit length repeat`,n.mode=gM;break}for(;p--;)n.lens[n.have++]=C}}if(n.mode===gM)break;if(n.lens[256]===0){e.msg=`invalid code -- missing end-of-block`,n.mode=gM;break}if(n.lenbits=9,E={bits:n.lenbits},w=Ej(Oj,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,w){e.msg=`invalid literal/lengths set`,n.mode=gM;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},w=Ej(kj,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,w){e.msg=`invalid distances set`,n.mode=gM;break}if(n.mode=oM,t===Mj)break inf_leave;case oM:n.mode=sM;case sM:if(s>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,n.hold=l,n.bits=u,hj(e,f),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,r=e.input,s=e.avail_in,l=n.hold,u=n.bits,n.mode===Qj&&(n.back=-1);break}for(n.back=0;g=n.lencode[l&(1<>>24,v=g>>>16&255,y=g&65535,!(_<=u);){if(s===0)break inf_leave;s--,l+=r[a++]<>b)],_=g>>>24,v=g>>>16&255,y=g&65535,!(b+_<=u);){if(s===0)break inf_leave;s--,l+=r[a++]<>>=b,u-=b,n.back+=b}if(l>>>=_,u-=_,n.back+=_,n.length=y,v===0){n.mode=fM;break}if(v&32){n.back=-1,n.mode=Qj;break}if(v&64){e.msg=`invalid literal/length code`,n.mode=gM;break}n.extra=v&15,n.mode=cM;case cM:if(n.extra){for(D=n.extra;u>>=n.extra,u-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=lM;case lM:for(;g=n.distcode[l&(1<>>24,v=g>>>16&255,y=g&65535,!(_<=u);){if(s===0)break inf_leave;s--,l+=r[a++]<>b)],_=g>>>24,v=g>>>16&255,y=g&65535,!(b+_<=u);){if(s===0)break inf_leave;s--,l+=r[a++]<>>=b,u-=b,n.back+=b}if(l>>>=_,u-=_,n.back+=_,v&64){e.msg=`invalid distance code`,n.mode=gM;break}n.offset=y,n.extra=v&15,n.mode=uM;case uM:if(n.extra){for(D=n.extra;u>>=n.extra,u-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg=`invalid distance too far back`,n.mode=gM;break}n.mode=dM;case dM:if(c===0)break inf_leave;if(p=f-c,n.offset>p){if(p=n.offset-p,p>n.whave&&n.sane){e.msg=`invalid distance too far back`,n.mode=gM;break}p>n.wnext?(p-=n.wnext,m=n.wsize-p):m=n.wnext-p,p>n.length&&(p=n.length),h=n.window}else h=i,m=o-n.offset,p=n.length;p>c&&(p=c),c-=p,n.length-=p;do i[o++]=h[m++];while(--p);n.length===0&&(n.mode=sM);break;case fM:if(c===0)break inf_leave;i[o++]=n.length,c--,n.mode=sM;break;case pM:if(n.wrap){for(;u<32;){if(s===0)break inf_leave;s--,l|=r[a++]<{if(wM(e))return Ij;let t=e.state;return t.window&&=null,e.state=null,Nj},inflateGetHeader:(e,t)=>{if(wM(e))return Ij;let n=e.state;return n.wrap&2?(n.head=t,t.done=!1,Nj):Ij},inflateSetDictionary:(e,t)=>{let n=t.length,r,i,a;return wM(e)||(r=e.state,r.wrap!==0&&r.mode!==Zj)?Ij:r.mode===Zj&&(i=1,i=xk(i,t,n,0),i!==r.check)?Lj:(a=PM(e,t,n,n),a?(r.mode=_M,Rj):(r.havedict=1,Nj))},inflateInfo:`pako inflate (from Nodeca project)`};function IM(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name=``,this.comment=``,this.hcrc=0,this.done=!1}var LM=IM,RM=Object.prototype.toString,{Z_NO_FLUSH:zM,Z_FINISH:BM,Z_OK:VM,Z_STREAM_END:HM,Z_NEED_DICT:UM,Z_STREAM_ERROR:WM,Z_DATA_ERROR:GM,Z_MEM_ERROR:KM}=Tk;function qM(e){this.options=WA.assign({chunkSize:1024*64,windowBits:15,to:``},e||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,t.windowBits===0&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(t.windowBits&15||(t.windowBits|=15)),this.err=0,this.msg=``,this.ended=!1,this.chunks=[],this.strm=new ZA,this.strm.avail_out=0;let n=FM.inflateInit2(this.strm,t.windowBits);if(n!==VM||(this.header=new LM,FM.inflateGetHeader(this.strm,this.header),t.dictionary&&(typeof t.dictionary==`string`?t.dictionary=YA.string2buf(t.dictionary):RM.call(t.dictionary)===`[object ArrayBuffer]`&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(n=FM.inflateSetDictionary(this.strm,t.dictionary),n!==VM))))throw Error(wk[n])}qM.prototype.push=function(e,t){let n=this.strm,r=this.options.chunkSize,i=this.options.dictionary,a,o,s;if(this.ended)return!1;for(o=t===~~t?t:t===!0?BM:zM,RM.call(e)===`[object ArrayBuffer]`?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){for(n.avail_out===0&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),a=FM.inflate(n,o),a===UM&&i&&(a=FM.inflateSetDictionary(n,i),a===VM?a=FM.inflate(n,o):a===GM&&(a=UM));n.avail_in>0&&a===HM&&n.state.wrap>0&&e[n.next_in]!==0;)FM.inflateReset(n),a=FM.inflate(n,o);switch(a){case WM:case GM:case UM:case KM:return this.onEnd(a),this.ended=!0,!1}if(s=n.avail_out,n.next_out&&(n.avail_out===0||a===HM))if(this.options.to===`string`){let e=YA.utf8border(n.output,n.next_out),t=n.next_out-e,i=YA.buf2string(n.output,e);n.next_out=t,n.avail_out=r-t,t&&n.output.set(n.output.subarray(e,e+t),0),this.onData(i)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(!(a===VM&&s===0)){if(a===HM)return a=FM.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,!0;if(n.avail_in===0)break}}return!0},qM.prototype.onData=function(e){this.chunks.push(e)},qM.prototype.onEnd=function(e){e===VM&&(this.options.to===`string`?this.result=this.chunks.join(``):this.result=WA.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function JM(e,t){let n=new qM(t);if(n.push(e),n.err)throw n.msg||wk[n.err];return n.result}function YM(e,t){return t||={},t.raw=!0,JM(e,t)}var XM={Inflate:qM,inflate:JM,inflateRaw:YM,ungzip:JM,constants:Tk},{Deflate:ZM,deflate:QM,deflateRaw:$M,gzip:eN}=fj,{Inflate:tN,inflate:nN,inflateRaw:rN,ungzip:iN}=XM,aN=tN,oN=nN,sN=[];for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;sN[e]=t}var cN=4294967295;function lN(e,t,n){let r=e;for(let e=0;e>>8;return r}function uN(e,t){return(lN(cN,e,t)^cN)>>>0}function dN(e,t,n){let r=e.readUint32(),i=uN(new Uint8Array(e.buffer,e.byteOffset+e.offset-t-4,t),t);if(i!==r)throw Error(`CRC mismatch for chunk ${n}. Expected ${r}, found ${i}`)}function fN(e,t,n){for(let r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gN(e,t,n,r,i){let a=0;if(n.length===0){for(;a=n||o>=r))for(let e=0;e>8&255}var CN=new Uint16Array([255]),wN=new Uint8Array(CN.buffer)[0]===255,TN=new Uint8Array;function EN(e){let{data:t,width:n,height:r,channels:i,depth:a}=e,o=Math.ceil(a/8)*i,s=Math.ceil(a/8*i*n),c=new Uint8Array(r*s),l=TN,u=0,d,f;for(let e=0;e>8&255}var ON=Uint8Array.of(137,80,78,71,13,10,26,10);function kN(e){if(!AN(e.readBytes(ON.length)))throw Error(`wrong PNG signature`)}function AN(e){if(e.length79)throw Error(`keyword length must be between 1 and 79`)}var FN=/^[\u0000-\u00FF]*$/;function IN(e){if(!FN.test(e))throw Error(`invalid latin1 text`)}function LN(e,t,n){let r=RN(t);e[r]=zN(t,n-r.length-1)}function RN(e){for(e.mark();e.readByte()!==MN;);let t=e.offset;e.reset();let n=NN.decode(e.readBytes(t-e.offset-1));return e.skip(1),PN(n),n}function zN(e,t){return NN.decode(e.readBytes(t))}var BN={UNKNOWN:-1,GREYSCALE:0,TRUECOLOUR:2,INDEXED_COLOUR:3,GREYSCALE_ALPHA:4,TRUECOLOUR_ALPHA:6},VN={UNKNOWN:-1,DEFLATE:0},HN={UNKNOWN:-1,ADAPTIVE:0},UN={UNKNOWN:-1,NO_INTERLACE:0,ADAM7:1},WN={NONE:0,BACKGROUND:1,PREVIOUS:2},GN={SOURCE:0,OVER:1},KN=class extends pO{_checkCrc;_inflator;_png;_apng;_end;_hasPalette;_palette;_hasTransparency;_transparency;_compressionMethod;_filterMethod;_interlaceMethod;_colorType;_isAnimated;_numberOfFrames;_numberOfPlays;_frames;_writingDataChunks;constructor(e,t={}){super(e);let{checkCrc:n=!1}=t;this._checkCrc=n,this._inflator=new aN,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array,depth:1,text:{}},this._apng={width:-1,height:-1,channels:-1,depth:1,numberOfFrames:1,numberOfPlays:0,text:{},frames:[]},this._end=!1,this._hasPalette=!1,this._palette=[],this._hasTransparency=!1,this._transparency=new Uint16Array,this._compressionMethod=VN.UNKNOWN,this._filterMethod=HN.UNKNOWN,this._interlaceMethod=UN.UNKNOWN,this._colorType=BN.UNKNOWN,this._isAnimated=!1,this._numberOfFrames=1,this._numberOfPlays=0,this._frames=[],this._writingDataChunks=!1,this.setBigEndian()}decode(){for(kN(this);!this._end;){let e=this.readUint32(),t=this.readChars(4);this.decodeChunk(e,t)}return this.decodeImage(),this._png}decodeApng(){for(kN(this);!this._end;){let e=this.readUint32(),t=this.readChars(4);this.decodeApngChunk(e,t)}return this.decodeApngImage(),this._apng}decodeChunk(e,t){let n=this.offset;switch(t){case`IHDR`:this.decodeIHDR();break;case`PLTE`:this.decodePLTE(e);break;case`IDAT`:this.decodeIDAT(e);break;case`IEND`:this._end=!0;break;case`tRNS`:this.decodetRNS(e);break;case`iCCP`:this.decodeiCCP(e);break;case jN:LN(this._png.text,this,e);break;case`pHYs`:this.decodepHYs();break;default:this.skip(e);break}if(this.offset-n!==e)throw Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?dN(this,e+4,t):this.skip(4)}decodeApngChunk(e,t){let n=this.offset;switch(t!==`fdAT`&&t!==`IDAT`&&this._writingDataChunks&&this.pushDataToFrame(),t){case`acTL`:this.decodeACTL();break;case`fcTL`:this.decodeFCTL();break;case`fdAT`:this.decodeFDAT(e);break;default:this.decodeChunk(e,t),this.offset=n+e;break}if(this.offset-n!==e)throw Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?dN(this,e+4,t):this.skip(4)}decodeIHDR(){let e=this._png;e.width=this.readUint32(),e.height=this.readUint32(),e.depth=qN(this.readUint8());let t=this.readUint8();this._colorType=t;let n;switch(t){case BN.GREYSCALE:n=1;break;case BN.TRUECOLOUR:n=3;break;case BN.INDEXED_COLOUR:n=1;break;case BN.GREYSCALE_ALPHA:n=2;break;case BN.TRUECOLOUR_ALPHA:n=4;break;case BN.UNKNOWN:default:throw Error(`Unknown color type: ${t}`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==VN.DEFLATE)throw Error(`Unsupported compression method: ${this._compressionMethod}`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodeACTL(){this._numberOfFrames=this.readUint32(),this._numberOfPlays=this.readUint32(),this._isAnimated=!0}decodeFCTL(){let e={sequenceNumber:this.readUint32(),width:this.readUint32(),height:this.readUint32(),xOffset:this.readUint32(),yOffset:this.readUint32(),delayNumber:this.readUint16(),delayDenominator:this.readUint16(),disposeOp:this.readUint8(),blendOp:this.readUint8(),data:new Uint8Array};this._frames.push(e)}decodePLTE(e){if(e%3!=0)throw RangeError(`PLTE field length must be a multiple of 3. Got ${e}`);let t=e/3;this._hasPalette=!0;let n=[];this._palette=n;for(let e=0;ethis._png.width*this._png.height)throw Error(`tRNS chunk contains more alpha values than there are pixels (${e/2} vs ${this._png.width*this._png.height})`);this._hasTransparency=!0,this._transparency=new Uint16Array(e/2);for(let t=0;tthis._palette.length)throw Error(`tRNS chunk contains more alpha values than there are palette colors (${e} vs ${this._palette.length})`);let t=0;for(;t({index:((e+t.yOffset)*this._png.width+t.xOffset+n)*this._png.channels,frameIndex:(e*t.width+n)*this._png.channels});switch(t.blendOp){case GN.SOURCE:for(let n=0;n=200&&t.status<=299}function tP(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{var t=document.createEvent(`MouseEvents`);t.initMouseEvent(`click`,!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var nP=XN.saveAs||((typeof window>`u`?`undefined`:hD(window))!==`object`||window!==XN?function(){}:typeof HTMLAnchorElement<`u`&&`download`in HTMLAnchorElement.prototype?function(e,t,n){var r=XN.URL||XN.webkitURL,i=document.createElement(`a`);t=t||e.name||`download`,i.download=t,i.rel=`noopener`,typeof e==`string`?(i.href=e,i.origin===location.origin?tP(i):eP(i.href)?$N(e,t,n):tP(i,i.target=`_blank`)):(i.href=r.createObjectURL(e),setTimeout(function(){r.revokeObjectURL(i.href)},4e4),setTimeout(function(){tP(i)},0))}:`msSaveOrOpenBlob`in navigator?function(e,t,n){if(t=t||e.name||`download`,typeof e==`string`)if(eP(e))$N(e,t,n);else{var r=document.createElement(`a`);r.href=e,r.target=`_blank`,setTimeout(function(){tP(r)})}else navigator.msSaveOrOpenBlob(function(e,t){return t===void 0?t={autoBom:!1}:hD(t)!==`object`&&(QN.warn(`Deprecated: Expected third argument to be a object`),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}(e,n),t)}:function(e,t,n,r){if((r||=open(``,`_blank`))&&(r.document.title=r.document.body.innerText=`downloading...`),typeof e==`string`)return $N(e,t,n);var i=e.type===`application/octet-stream`,a=/constructor/i.test(XN.HTMLElement)||XN.safari,o=/CriOS\/[\d]+/.test(navigator.userAgent);if((o||i&&a)&&(typeof FileReader>`u`?`undefined`:hD(FileReader))===`object`){var s=new FileReader;s.onloadend=function(){var e=s.result;e=o?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),r?r.location.href=e:location=e,r=null},s.readAsDataURL(e)}else{var c=XN.URL||XN.webkitURL,l=c.createObjectURL(e);r?r.location=l:location.href=l,r=null,setTimeout(function(){c.revokeObjectURL(l)},4e4)}});function rP(e){var t;e||=``,this.ok=!1,e.charAt(0)==`#`&&(e=e.substr(1,6)),e={aliceblue:`f0f8ff`,antiquewhite:`faebd7`,aqua:`00ffff`,aquamarine:`7fffd4`,azure:`f0ffff`,beige:`f5f5dc`,bisque:`ffe4c4`,black:`000000`,blanchedalmond:`ffebcd`,blue:`0000ff`,blueviolet:`8a2be2`,brown:`a52a2a`,burlywood:`deb887`,cadetblue:`5f9ea0`,chartreuse:`7fff00`,chocolate:`d2691e`,coral:`ff7f50`,cornflowerblue:`6495ed`,cornsilk:`fff8dc`,crimson:`dc143c`,cyan:`00ffff`,darkblue:`00008b`,darkcyan:`008b8b`,darkgoldenrod:`b8860b`,darkgray:`a9a9a9`,darkgreen:`006400`,darkkhaki:`bdb76b`,darkmagenta:`8b008b`,darkolivegreen:`556b2f`,darkorange:`ff8c00`,darkorchid:`9932cc`,darkred:`8b0000`,darksalmon:`e9967a`,darkseagreen:`8fbc8f`,darkslateblue:`483d8b`,darkslategray:`2f4f4f`,darkturquoise:`00ced1`,darkviolet:`9400d3`,deeppink:`ff1493`,deepskyblue:`00bfff`,dimgray:`696969`,dodgerblue:`1e90ff`,feldspar:`d19275`,firebrick:`b22222`,floralwhite:`fffaf0`,forestgreen:`228b22`,fuchsia:`ff00ff`,gainsboro:`dcdcdc`,ghostwhite:`f8f8ff`,gold:`ffd700`,goldenrod:`daa520`,gray:`808080`,green:`008000`,greenyellow:`adff2f`,honeydew:`f0fff0`,hotpink:`ff69b4`,indianred:`cd5c5c`,indigo:`4b0082`,ivory:`fffff0`,khaki:`f0e68c`,lavender:`e6e6fa`,lavenderblush:`fff0f5`,lawngreen:`7cfc00`,lemonchiffon:`fffacd`,lightblue:`add8e6`,lightcoral:`f08080`,lightcyan:`e0ffff`,lightgoldenrodyellow:`fafad2`,lightgrey:`d3d3d3`,lightgreen:`90ee90`,lightpink:`ffb6c1`,lightsalmon:`ffa07a`,lightseagreen:`20b2aa`,lightskyblue:`87cefa`,lightslateblue:`8470ff`,lightslategray:`778899`,lightsteelblue:`b0c4de`,lightyellow:`ffffe0`,lime:`00ff00`,limegreen:`32cd32`,linen:`faf0e6`,magenta:`ff00ff`,maroon:`800000`,mediumaquamarine:`66cdaa`,mediumblue:`0000cd`,mediumorchid:`ba55d3`,mediumpurple:`9370d8`,mediumseagreen:`3cb371`,mediumslateblue:`7b68ee`,mediumspringgreen:`00fa9a`,mediumturquoise:`48d1cc`,mediumvioletred:`c71585`,midnightblue:`191970`,mintcream:`f5fffa`,mistyrose:`ffe4e1`,moccasin:`ffe4b5`,navajowhite:`ffdead`,navy:`000080`,oldlace:`fdf5e6`,olive:`808000`,olivedrab:`6b8e23`,orange:`ffa500`,orangered:`ff4500`,orchid:`da70d6`,palegoldenrod:`eee8aa`,palegreen:`98fb98`,paleturquoise:`afeeee`,palevioletred:`d87093`,papayawhip:`ffefd5`,peachpuff:`ffdab9`,peru:`cd853f`,pink:`ffc0cb`,plum:`dda0dd`,powderblue:`b0e0e6`,purple:`800080`,red:`ff0000`,rosybrown:`bc8f8f`,royalblue:`4169e1`,saddlebrown:`8b4513`,salmon:`fa8072`,sandybrown:`f4a460`,seagreen:`2e8b57`,seashell:`fff5ee`,sienna:`a0522d`,silver:`c0c0c0`,skyblue:`87ceeb`,slateblue:`6a5acd`,slategray:`708090`,snow:`fffafa`,springgreen:`00ff7f`,steelblue:`4682b4`,tan:`d2b48c`,teal:`008080`,thistle:`d8bfd8`,tomato:`ff6347`,turquoise:`40e0d0`,violet:`ee82ee`,violetred:`d02090`,wheat:`f5deb3`,white:`ffffff`,whitesmoke:`f5f5f5`,yellow:`ffff00`,yellowgreen:`9acd32`}[e=(e=e.replace(/ /g,``)).toLowerCase()]||e;for(var n=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:[`rgb(123, 234, 45)`,`rgb(255,234,245)`],process:function(e){return[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]}},{re:/^(\w{2})(\w{2})(\w{2})$/,example:[`#00ff00`,`336699`],process:function(e){return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:[`#fb0`,`f0f`],process:function(e){return[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)]}}],r=0;r255?255:this.r,this.g=this.g<0||isNaN(this.g)?0:this.g>255?255:this.g,this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b,this.toRGB=function(){return`rgb(`+this.r+`, `+this.g+`, `+this.b+`)`},this.toHex=function(){var e=this.r.toString(16),t=this.g.toString(16),n=this.b.toString(16);return e.length==1&&(e=`0`+e),t.length==1&&(t=`0`+t),n.length==1&&(n=`0`+n),`#`+e+t+n}}var iP=XN.atob.bind(XN),aP=XN.btoa.bind(XN);function oP(e,t){var n=e[0],r=e[1],i=e[2],a=e[3];n=cP(n,r,i,a,t[0],7,-680876936),a=cP(a,n,r,i,t[1],12,-389564586),i=cP(i,a,n,r,t[2],17,606105819),r=cP(r,i,a,n,t[3],22,-1044525330),n=cP(n,r,i,a,t[4],7,-176418897),a=cP(a,n,r,i,t[5],12,1200080426),i=cP(i,a,n,r,t[6],17,-1473231341),r=cP(r,i,a,n,t[7],22,-45705983),n=cP(n,r,i,a,t[8],7,1770035416),a=cP(a,n,r,i,t[9],12,-1958414417),i=cP(i,a,n,r,t[10],17,-42063),r=cP(r,i,a,n,t[11],22,-1990404162),n=cP(n,r,i,a,t[12],7,1804603682),a=cP(a,n,r,i,t[13],12,-40341101),i=cP(i,a,n,r,t[14],17,-1502002290),n=lP(n,r=cP(r,i,a,n,t[15],22,1236535329),i,a,t[1],5,-165796510),a=lP(a,n,r,i,t[6],9,-1069501632),i=lP(i,a,n,r,t[11],14,643717713),r=lP(r,i,a,n,t[0],20,-373897302),n=lP(n,r,i,a,t[5],5,-701558691),a=lP(a,n,r,i,t[10],9,38016083),i=lP(i,a,n,r,t[15],14,-660478335),r=lP(r,i,a,n,t[4],20,-405537848),n=lP(n,r,i,a,t[9],5,568446438),a=lP(a,n,r,i,t[14],9,-1019803690),i=lP(i,a,n,r,t[3],14,-187363961),r=lP(r,i,a,n,t[8],20,1163531501),n=lP(n,r,i,a,t[13],5,-1444681467),a=lP(a,n,r,i,t[2],9,-51403784),i=lP(i,a,n,r,t[7],14,1735328473),n=uP(n,r=lP(r,i,a,n,t[12],20,-1926607734),i,a,t[5],4,-378558),a=uP(a,n,r,i,t[8],11,-2022574463),i=uP(i,a,n,r,t[11],16,1839030562),r=uP(r,i,a,n,t[14],23,-35309556),n=uP(n,r,i,a,t[1],4,-1530992060),a=uP(a,n,r,i,t[4],11,1272893353),i=uP(i,a,n,r,t[7],16,-155497632),r=uP(r,i,a,n,t[10],23,-1094730640),n=uP(n,r,i,a,t[13],4,681279174),a=uP(a,n,r,i,t[0],11,-358537222),i=uP(i,a,n,r,t[3],16,-722521979),r=uP(r,i,a,n,t[6],23,76029189),n=uP(n,r,i,a,t[9],4,-640364487),a=uP(a,n,r,i,t[12],11,-421815835),i=uP(i,a,n,r,t[15],16,530742520),n=dP(n,r=uP(r,i,a,n,t[2],23,-995338651),i,a,t[0],6,-198630844),a=dP(a,n,r,i,t[7],10,1126891415),i=dP(i,a,n,r,t[14],15,-1416354905),r=dP(r,i,a,n,t[5],21,-57434055),n=dP(n,r,i,a,t[12],6,1700485571),a=dP(a,n,r,i,t[3],10,-1894986606),i=dP(i,a,n,r,t[10],15,-1051523),r=dP(r,i,a,n,t[1],21,-2054922799),n=dP(n,r,i,a,t[8],6,1873313359),a=dP(a,n,r,i,t[15],10,-30611744),i=dP(i,a,n,r,t[6],15,-1560198380),r=dP(r,i,a,n,t[13],21,1309151649),n=dP(n,r,i,a,t[4],6,-145523070),a=dP(a,n,r,i,t[11],10,-1120210379),i=dP(i,a,n,r,t[2],15,718787259),r=dP(r,i,a,n,t[9],21,-343485551),e[0]=yP(n,e[0]),e[1]=yP(r,e[1]),e[2]=yP(i,e[2]),e[3]=yP(a,e[3])}function sP(e,t,n,r,i,a){return t=yP(yP(t,e),yP(r,a)),yP(t<>>32-i,n)}function cP(e,t,n,r,i,a,o){return sP(t&n|~t&r,e,t,i,a,o)}function lP(e,t,n,r,i,a,o){return sP(t&r|n&~r,e,t,i,a,o)}function uP(e,t,n,r,i,a,o){return sP(t^n^r,e,t,i,a,o)}function dP(e,t,n,r,i,a,o){return sP(n^(t|~r),e,t,i,a,o)}function fP(e){var t,n=e.length,r=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=e.length;t+=64)oP(r,pP(e.substring(t-64,t)));e=e.substring(t-64);var i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t>2]|=e.charCodeAt(t)<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(oP(r,i),t=0;t<16;t++)i[t]=0;return i[14]=8*n,oP(r,i),r}function pP(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}var mP=`0123456789abcdef`.split(``);function hP(e){for(var t=``,n=0;n<4;n++)t+=mP[e>>8*n+4&15]+mP[e>>8*n&15];return t}function gP(e){return String.fromCharCode(255&e,(65280&e)>>8,(16711680&e)>>16,(4278190080&e)>>24)}function _P(e){return fP(e).map(gP).join(``)}var vP=function(e){for(var t=0;t>16)+(t>>16)+(n>>16)<<16|65535&n}return e+t&4294967295}function bP(e,t){var n,r,i,a;if(e!==n){for(var o=(i=e,a=1+(256/e.length|0),Array(a+1).join(i)),s=[],c=0;c<256;c++)s[c]=c;var l=0;for(c=0;c<256;c++){var u=s[c];l=(l+u+o.charCodeAt(c))%256,s[c]=s[l],s[l]=u}n=e,r=s}else s=r;var d=t.length,f=0,p=0,m=``;for(c=0;c€/\f©þdSiz`;var a=(t+this.padding).substr(0,32),o=(n+this.padding).substr(0,32);this.O=this.processOwnerPassword(a,o),this.P=-(1+(255^i)),this.encryptionKey=_P(a+this.O+this.lsbFirstWord(this.P)+this.hexToBytes(r)).substr(0,5),this.U=bP(this.encryptionKey,this.padding)}function CP(e){if(/[^\u0000-\u00ff]/.test(e))throw Error(`Invalid PDF Name Object: `+e+`, Only accept ASCII characters.`);for(var t=``,n=e.length,r=0;r126?`#`+(`0`+i.toString(16)).slice(-2):e[r]}return t}function wP(e){if(hD(e)!==`object`)throw Error(`Invalid Context passed to initialize PubSub (jsPDF-module)`);var t={};this.subscribe=function(e,n,r){if(r||=!1,typeof e!=`string`||typeof n!=`function`||typeof r!=`boolean`)throw Error(`Invalid arguments passed to PubSub.subscribe (jsPDF-module)`);t.hasOwnProperty(e)||(t[e]={});var i=Math.random().toString(35);return t[e][i]=[n,!!r],i},this.unsubscribe=function(e){for(var n in t)if(t[n][e])return delete t[n][e],Object.keys(t[n]).length===0&&delete t[n],!0;return!1},this.publish=function(n){if(t.hasOwnProperty(n)){var r=Array.prototype.slice.call(arguments,1),i=[];for(var a in t[n]){var o=t[n][a];try{o[0].apply(e,r)}catch(e){XN.console&&QN.error(`jsPDF PubSub Error`,e.message,e)}o[1]&&i.push(a)}i.length&&i.forEach(this.unsubscribe)}},this.getTopics=function(){return t}}function TP(e){if(!(this instanceof TP))return new TP(e);var t=`opacity,stroke-opacity`.split(`,`);for(var n in e)e.hasOwnProperty(n)&&t.indexOf(n)>=0&&(this[n]=e[n]);this.id=``,this.objectNumber=-1}function EP(e,t){this.gState=e,this.matrix=t,this.id=``,this.objectNumber=-1}function DP(e,t,n,r,i){if(!(this instanceof DP))return new DP(e,t,n,r,i);this.type=e===`axial`?2:3,this.coords=t,this.colors=n,EP.call(this,r,i)}function OP(e,t,n,r,i){if(!(this instanceof OP))return new OP(e,t,n,r,i);this.boundingBox=e,this.xStep=t,this.yStep=n,this.stream=``,this.cloneIndex=0,EP.call(this,r,i)}function kP(e){var t,n=typeof arguments[0]==`string`?arguments[0]:`p`,r=arguments[1],i=arguments[2],a=arguments[3],o=[],s=1,c=16,l=`S`,u=null;hD(e||={})===`object`&&(n=e.orientation,r=e.unit||r,i=e.format||i,a=e.compress||e.compressPdf||a,(u=e.encryption||null)!==null&&(u.userPassword=u.userPassword||``,u.ownerPassword=u.ownerPassword||``,u.userPermissions=u.userPermissions||[]),s=typeof e.userUnit==`number`?Math.abs(e.userUnit):1,e.precision!==void 0&&(t=e.precision),e.floatPrecision!==void 0&&(c=e.floatPrecision),l=e.defaultPathOperation||`S`),o=e.filters||(!0===a?[`FlateEncode`]:o),r||=`mm`,n=(``+(n||`P`)).toLowerCase();var d=e.putOnlyUsedFonts||!1,f={},p={internal:{},__private__:{}};p.__private__.PubSub=wP;var m=`1.3`,h=p.__private__.getPdfVersion=function(){return m};p.__private__.setPdfVersion=function(e){m=e};var g={a0:[2383.94,3370.39],a1:[1683.78,2383.94],a2:[1190.55,1683.78],a3:[841.89,1190.55],a4:[595.28,841.89],a5:[419.53,595.28],a6:[297.64,419.53],a7:[209.76,297.64],a8:[147.4,209.76],a9:[104.88,147.4],a10:[73.7,104.88],b0:[2834.65,4008.19],b1:[2004.09,2834.65],b2:[1417.32,2004.09],b3:[1000.63,1417.32],b4:[708.66,1000.63],b5:[498.9,708.66],b6:[354.33,498.9],b7:[249.45,354.33],b8:[175.75,249.45],b9:[124.72,175.75],b10:[87.87,124.72],c0:[2599.37,3676.54],c1:[1836.85,2599.37],c2:[1298.27,1836.85],c3:[918.43,1298.27],c4:[649.13,918.43],c5:[459.21,649.13],c6:[323.15,459.21],c7:[229.61,323.15],c8:[161.57,229.61],c9:[113.39,161.57],c10:[79.37,113.39],dl:[311.81,623.62],letter:[612,792],"government-letter":[576,756],legal:[612,1008],"junior-legal":[576,360],ledger:[1224,792],tabloid:[792,1224],"credit-card":[153,243]};p.__private__.getPageFormats=function(){return g};var _=p.__private__.getPageFormat=function(e){return g[e]};i||=`a4`;var v=`compat`,y=`advanced`,b=v;function x(){this.saveGraphicsState(),H(new Be(U,0,0,-U,0,Cn()*U).toString()+` cm`),this.setFontSize(this.getFontSize()/U),l=`n`,b=y}function S(){this.restoreGraphicsState(),l=`S`,b=v}var C=p.__private__.combineFontStyleAndFontWeight=function(e,t){if(e==`bold`&&t==`normal`||e==`bold`&&t==400||e==`normal`&&t==`italic`||e==`bold`&&t==`italic`)throw Error(`Invalid Combination of fontweight and fontstyle`);return t&&(e=t==400||t===`normal`?e===`italic`?`italic`:`normal`:t!=700&&t!==`bold`||e!==`normal`?(t==700?`bold`:t)+``+e:`bold`),e};p.advancedAPI=function(e){var t=b===v;return t&&x.call(this),typeof e!=`function`||(e(this),t&&S.call(this)),this},p.compatAPI=function(e){var t=b===y;return t&&S.call(this),typeof e!=`function`||(e(this),t&&x.call(this)),this},p.isAdvancedAPI=function(){return b===y};var w,T=function(e){if(b!==y)throw Error(e+` is only available in 'advanced' API mode. You need to call advancedAPI() first.`)},E=p.roundToPrecision=p.__private__.roundToPrecision=function(e,n){var r=t||n;if(isNaN(e)||isNaN(r))throw Error(`Invalid argument passed to jsPDF.roundToPrecision`);return e.toFixed(r).replace(/0+$/,``)};w=p.hpf=p.__private__.hpf=typeof c==`number`?function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.hpf`);return E(e,c)}:c===`smart`?function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.hpf`);return E(e,e>-1&&e<1?16:5)}:function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.hpf`);return E(e,16)};var D=p.f2=p.__private__.f2=function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.f2`);return E(e,2)},O=p.__private__.f3=function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.f3`);return E(e,3)},k=p.scale=p.__private__.scale=function(e){if(isNaN(e))throw Error(`Invalid argument passed to jsPDF.scale`);return b===v?e*U:b===y?e:void 0},A=function(e){return k(function(e){return b===v?Cn()-e:b===y?e:void 0}(e))};p.__private__.setPrecision=p.setPrecision=function(e){typeof parseInt(e,10)==`number`&&(t=parseInt(e,10))};var j,M=`00000000000000000000000000000000`,N=p.__private__.getFileId=function(){return M},P=p.__private__.setFileId=function(e){return M=e!==void 0&&/^[a-fA-F0-9]{32}$/.test(e)?e.toUpperCase():M.split(``).map(function(){return`ABCDEF0123456789`.charAt(Math.floor(16*Math.random()))}).join(``),u!==null&&(kt=new SP(u.userPermissions,u.userPassword,u.ownerPassword,M)),M};p.setFileId=function(e){return P(e),this},p.getFileId=function(){return N()};var F=p.__private__.convertDateToPDFDate=function(e){var t=e.getTimezoneOffset(),n=t<0?`+`:`-`,r=Math.floor(Math.abs(t/60)),i=Math.abs(t%60),a=[n,te(r),`'`,te(i),`'`].join(``);return[`D:`,e.getFullYear(),te(e.getMonth()+1),te(e.getDate()),te(e.getHours()),te(e.getMinutes()),te(e.getSeconds()),a].join(``)},I=p.__private__.convertPDFDateToDate=function(e){var t=parseInt(e.substr(2,4),10),n=parseInt(e.substr(6,2),10)-1,r=parseInt(e.substr(8,2),10),i=parseInt(e.substr(10,2),10),a=parseInt(e.substr(12,2),10),o=parseInt(e.substr(14,2),10);return new Date(t,n,r,i,a,o,0)},L=p.__private__.setCreationDate=function(e){var t;if(e===void 0&&(e=new Date),e instanceof Date)t=F(e);else{if(!/^D:(20[0-2][0-9]|203[0-7]|19[7-9][0-9])(0[0-9]|1[0-2])([0-2][0-9]|3[0-1])(0[0-9]|1[0-9]|2[0-3])(0[0-9]|[1-5][0-9])(0[0-9]|[1-5][0-9])(\+0[0-9]|\+1[0-4]|-0[0-9]|-1[0-1])'(0[0-9]|[1-5][0-9])'?$/.test(e))throw Error(`Invalid argument passed to jsPDF.setCreationDate`);t=e}return j=t},ee=p.__private__.getCreationDate=function(e){var t=j;return e===`jsDate`&&(t=I(j)),t};p.setCreationDate=function(e){return L(e),this},p.getCreationDate=function(e){return ee(e)};var R,te=p.__private__.padd2=function(e){return(`0`+parseInt(e)).slice(-2)},z=p.__private__.padd2Hex=function(e){return(`00`+(e=e.toString())).substr(e.length)},B=0,V=[],ne=[],re=0,ie=[],ae=[],oe=!1,se=ne;p.__private__.setCustomOutputDestination=function(e){oe=!0,se=e};var ce=function(e){oe||(se=e)};p.__private__.resetCustomOutputDestination=function(){oe=!1,se=ne};var H=p.__private__.out=function(e){return e=e.toString(),re+=e.length+1,se.push(e),se},le=p.__private__.write=function(e){return H(arguments.length===1?e.toString():Array.prototype.join.call(arguments,` `))},ue=p.__private__.getArrayBuffer=function(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n);t--;)r[t]=e.charCodeAt(t);return n},de=[[`Helvetica`,`helvetica`,`normal`,`WinAnsiEncoding`],[`Helvetica-Bold`,`helvetica`,`bold`,`WinAnsiEncoding`],[`Helvetica-Oblique`,`helvetica`,`italic`,`WinAnsiEncoding`],[`Helvetica-BoldOblique`,`helvetica`,`bolditalic`,`WinAnsiEncoding`],[`Courier`,`courier`,`normal`,`WinAnsiEncoding`],[`Courier-Bold`,`courier`,`bold`,`WinAnsiEncoding`],[`Courier-Oblique`,`courier`,`italic`,`WinAnsiEncoding`],[`Courier-BoldOblique`,`courier`,`bolditalic`,`WinAnsiEncoding`],[`Times-Roman`,`times`,`normal`,`WinAnsiEncoding`],[`Times-Bold`,`times`,`bold`,`WinAnsiEncoding`],[`Times-Italic`,`times`,`italic`,`WinAnsiEncoding`],[`Times-BoldItalic`,`times`,`bolditalic`,`WinAnsiEncoding`],[`ZapfDingbats`,`zapfdingbats`,`normal`,null],[`Symbol`,`symbol`,`normal`,null]];p.__private__.getStandardFonts=function(){return de};var fe=e.fontSize||16;p.__private__.setFontSize=p.setFontSize=function(e){return fe=b===y?e/U:e,this};var pe,me=p.__private__.getFontSize=p.getFontSize=function(){return b===v?fe:fe*U},he=e.R2L||!1;p.__private__.setR2L=p.setR2L=function(e){return he=e,this},p.__private__.getR2L=p.getR2L=function(){return he};var ge,_e=p.__private__.setZoomMode=function(e){if(/^(?:\d+\.\d*|\d*\.\d+|\d+)%$/.test(e))pe=e;else if(isNaN(e)){if([void 0,null,`fullwidth`,`fullheight`,`fullpage`,`original`].indexOf(e)===-1)throw Error(`zoom must be Integer (e.g. 2), a percentage Value (e.g. 300%) or fullwidth, fullheight, fullpage, original. "`+e+`" is not recognized.`);pe=e}else pe=parseInt(e,10)};p.__private__.getZoomMode=function(){return pe};var ve,ye=p.__private__.setPageMode=function(e){if([void 0,null,`UseNone`,`UseOutlines`,`UseThumbs`,`FullScreen`].indexOf(e)==-1)throw Error(`Page mode must be one of UseNone, UseOutlines, UseThumbs, or FullScreen. "`+e+`" is not recognized.`);ge=e};p.__private__.getPageMode=function(){return ge};var be=p.__private__.setLayoutMode=function(e){if([void 0,null,`continuous`,`single`,`twoleft`,`tworight`,`two`].indexOf(e)==-1)throw Error(`Layout mode must be one of continuous, single, twoleft, tworight. "`+e+`" is not recognized.`);ve=e};p.__private__.getLayoutMode=function(){return ve},p.__private__.setDisplayMode=p.setDisplayMode=function(e,t,n){return _e(e),be(t),ye(n),this};var xe={title:``,subject:``,author:``,keywords:``,creator:``};p.__private__.getDocumentProperty=function(e){if(Object.keys(xe).indexOf(e)===-1)throw Error(`Invalid argument passed to jsPDF.getDocumentProperty`);return xe[e]},p.__private__.getDocumentProperties=function(){return xe},p.__private__.setDocumentProperties=p.setProperties=p.setDocumentProperties=function(e){for(var t in xe)xe.hasOwnProperty(t)&&e[t]&&(xe[t]=e[t]);return this},p.__private__.setDocumentProperty=function(e,t){if(Object.keys(xe).indexOf(e)===-1)throw Error(`Invalid arguments passed to jsPDF.setDocumentProperty`);return xe[e]=t};var Se,U,Ce,we,Te,W={},Ee={},De=[],Oe={},ke={},Ae={},je={},Me=null,Ne=0,Pe=[],Fe=new wP(p),Ie=e.hotfixes||[],Le={},Re={},ze=[],Be=function e(t,n,r,i,a,o){if(!(this instanceof e))return new e(t,n,r,i,a,o);isNaN(t)&&(t=1),isNaN(n)&&(n=0),isNaN(r)&&(r=0),isNaN(i)&&(i=1),isNaN(a)&&(a=0),isNaN(o)&&(o=0),this._matrix=[t,n,r,i,a,o]};Object.defineProperty(Be.prototype,"sx",{get:function(){return this._matrix[0]},set:function(e){this._matrix[0]=e}}),Object.defineProperty(Be.prototype,"shy",{get:function(){return this._matrix[1]},set:function(e){this._matrix[1]=e}}),Object.defineProperty(Be.prototype,"shx",{get:function(){return this._matrix[2]},set:function(e){this._matrix[2]=e}}),Object.defineProperty(Be.prototype,"sy",{get:function(){return this._matrix[3]},set:function(e){this._matrix[3]=e}}),Object.defineProperty(Be.prototype,"tx",{get:function(){return this._matrix[4]},set:function(e){this._matrix[4]=e}}),Object.defineProperty(Be.prototype,"ty",{get:function(){return this._matrix[5]},set:function(e){this._matrix[5]=e}}),Object.defineProperty(Be.prototype,"a",{get:function(){return this._matrix[0]},set:function(e){this._matrix[0]=e}}),Object.defineProperty(Be.prototype,"b",{get:function(){return this._matrix[1]},set:function(e){this._matrix[1]=e}}),Object.defineProperty(Be.prototype,"c",{get:function(){return this._matrix[2]},set:function(e){this._matrix[2]=e}}),Object.defineProperty(Be.prototype,"d",{get:function(){return this._matrix[3]},set:function(e){this._matrix[3]=e}}),Object.defineProperty(Be.prototype,"e",{get:function(){return this._matrix[4]},set:function(e){this._matrix[4]=e}}),Object.defineProperty(Be.prototype,"f",{get:function(){return this._matrix[5]},set:function(e){this._matrix[5]=e}}),Object.defineProperty(Be.prototype,"rotation",{get:function(){return Math.atan2(this.shx,this.sx)}}),Object.defineProperty(Be.prototype,"scaleX",{get:function(){return this.decompose().scale.sx}}),Object.defineProperty(Be.prototype,"scaleY",{get:function(){return this.decompose().scale.sy}}),Object.defineProperty(Be.prototype,"isIdentity",{get:function(){return this.sx===1&&this.shy===0&&this.shx===0&&this.sy===1&&this.tx===0&&this.ty===0}}),Be.prototype.join=function(e){return[this.sx,this.shy,this.shx,this.sy,this.tx,this.ty].map(w).join(e)},Be.prototype.multiply=function(e){return new Be(e.sx*this.sx+e.shy*this.shx,e.sx*this.shy+e.shy*this.sy,e.shx*this.sx+e.sy*this.shx,e.shx*this.shy+e.sy*this.sy,e.tx*this.sx+e.ty*this.shx+this.tx,e.tx*this.shy+e.ty*this.sy+this.ty)},Be.prototype.decompose=function(){var e=this.sx,t=this.shy,n=this.shx,r=this.sy,i=this.tx,a=this.ty,o=Math.sqrt(e*e+t*t),s=(e/=o)*n+(t/=o)*r;n-=e*s,r-=t*s;var c=Math.sqrt(n*n+r*r);return s/=c,e*(r/=c)>16&255,r=c>>8&255,i=255&c}if(r===void 0||a===void 0&&n===r&&r===i)t=typeof n==`string`?n+` `+o[0]:e.precision===2?D(n/255)+` `+o[0]:O(n/255)+` `+o[0];else if(a===void 0||hD(a)===`object`){if(a&&!isNaN(a.a)&&a.a===0)return[`1.`,`1.`,`1.`,o[1]].join(` `);t=typeof n==`string`?[n,r,i,o[1]].join(` `):e.precision===2?[D(n/255),D(r/255),D(i/255),o[1]].join(` `):[O(n/255),O(r/255),O(i/255),o[1]].join(` `)}else t=typeof n==`string`?[n,r,i,a,o[2]].join(` `):e.precision===2?[D(n),D(r),D(i),D(a),o[2]].join(` `):[O(n),O(r),O(i),O(a),o[2]].join(` `);return t},$e=p.__private__.getFilters=function(){return o},et=p.__private__.putStream=function(e){var t=(e||={}).data||``,n=e.filters||$e(),r=e.alreadyAppliedFilters||[],i=e.addLength1||!1,a=t.length,o=e.objectId,s=function(e){return e};if(u!==null&&o===void 0)throw Error(`ObjectId must be passed to putStream for file encryption`);u!==null&&(s=kt.encryptor(o,0));var c={};!0===n&&(n=[`FlateEncode`]);var l=e.additionalKeyValues||[],d=(c=kP.API.processDataByFilters===void 0?{data:t,reverseChain:[]}:kP.API.processDataByFilters(t,n)).reverseChain+(Array.isArray(r)?r.join(` `):r.toString());if(c.data.length!==0&&(l.push({key:`Length`,value:c.data.length}),!0===i&&l.push({key:`Length1`,value:a})),d.length!=0)if(d.split(`/`).length-1==1)l.push({key:`Filter`,value:d});else{l.push({key:`Filter`,value:`[`+d+`]`});for(var f=0;f>`),c.data.length!==0&&(H(`stream`),H(s(c.data)),H(`endstream`))},tt=p.__private__.putPage=function(e){var t=e.number,n=e.data,r=e.objId,i=e.contentsObjId;qe(r,!0),H(`<>`),H(`endobj`);var a=n.join(` `);return b===y&&(a+=` Q`),qe(i,!0),et({data:a,filters:$e(),objectId:i}),H(`endobj`),r},nt=p.__private__.putPages=function(){var e,t,n=[];for(e=1;e<=Ne;e++)Pe[e].objId=Ke(),Pe[e].contentsObjId=Ke();for(e=1;e<=Ne;e++)n.push(tt({number:e,data:ae[e],objId:Pe[e].objId,contentsObjId:Pe[e].contentsObjId,mediaBox:Pe[e].mediaBox,cropBox:Pe[e].cropBox,bleedBox:Pe[e].bleedBox,trimBox:Pe[e].trimBox,artBox:Pe[e].artBox,userUnit:Pe[e].userUnit,rootDictionaryObjId:Ye,resourceDictionaryObjId:Xe}));qe(Ye,!0),H(`<>`),H(`endobj`),Fe.publish(`postPutPages`)},rt=function(e){Fe.publish(`putFont`,{font:e,out:H,newObject:Ge,putStream:et}),!0!==e.isAlreadyPutted&&(e.objectNumber=Ge(),H(`<<`),H(`/Type /Font`),H(`/BaseFont /`+CP(e.postScriptName)),H(`/Subtype /Type1`),typeof e.encoding==`string`&&H(`/Encoding /`+e.encoding),H(`/FirstChar 32`),H(`/LastChar 255`),H(`>>`),H(`endobj`))},it=function(e){e.objectNumber=Ge();var t=[];t.push({key:`Type`,value:`/XObject`}),t.push({key:`Subtype`,value:`/Form`}),t.push({key:`BBox`,value:`[`+[w(e.x),w(e.y),w(e.x+e.width),w(e.y+e.height)].join(` `)+`]`}),t.push({key:`Matrix`,value:`[`+e.matrix.toString()+`]`}),et({data:e.pages[1].join(` `),additionalKeyValues:t,objectId:e.objectNumber}),H(`endobj`)},at=function(e,t){t||=21;var n=Ge(),r=function(e,t){var n,r=[],i=1/(t-1);for(n=0;n<1;n+=i)r.push(n);if(r.push(1),e[0].offset!=0){var a={offset:0,color:e[0].color};e.unshift(a)}if(e[e.length-1].offset!=1){var o={offset:1,color:e[e.length-1].color};e.push(o)}for(var s=``,c=0,l=0;le[c+1].offset;)c++;var u=e[c].offset,d=(n-u)/(e[c+1].offset-u),f=e[c].color,p=e[c+1].color;s+=z(Math.round((1-d)*f[0]+d*p[0]).toString(16))+z(Math.round((1-d)*f[1]+d*p[1]).toString(16))+z(Math.round((1-d)*f[2]+d*p[2]).toString(16))}return s.trim()}(e.colors,t),i=[];i.push({key:`FunctionType`,value:`0`}),i.push({key:`Domain`,value:`[0.0 1.0]`}),i.push({key:`Size`,value:`[`+t+`]`}),i.push({key:`BitsPerSample`,value:`8`}),i.push({key:`Range`,value:`[0.0 1.0 0.0 1.0 0.0 1.0]`}),i.push({key:`Decode`,value:`[0.0 1.0 0.0 1.0 0.0 1.0]`}),et({data:r,additionalKeyValues:i,alreadyAppliedFilters:[`/ASCIIHexDecode`],objectId:n}),H(`endobj`),e.objectNumber=Ge(),H(`<< /ShadingType `+e.type),H(`/ColorSpace /DeviceRGB`);var a=`/Coords [`+w(parseFloat(e.coords[0]))+` `+w(parseFloat(e.coords[1]))+` `;e.type===2?a+=w(parseFloat(e.coords[2]))+` `+w(parseFloat(e.coords[3])):a+=w(parseFloat(e.coords[2]))+` `+w(parseFloat(e.coords[3]))+` `+w(parseFloat(e.coords[4]))+` `+w(parseFloat(e.coords[5])),H(a+=`]`),e.matrix&&H(`/Matrix [`+e.matrix.toString()+`]`),H(`/Function `+n+` 0 R`),H(`/Extend [true true]`),H(`>>`),H(`endobj`)},ot=function(e,t){var n=Ke(),r=Ge();t.push({resourcesOid:n,objectOid:r}),e.objectNumber=r;var i=[];i.push({key:`Type`,value:`/Pattern`}),i.push({key:`PatternType`,value:`1`}),i.push({key:`PaintType`,value:`1`}),i.push({key:`TilingType`,value:`1`}),i.push({key:`BBox`,value:`[`+e.boundingBox.map(w).join(` `)+`]`}),i.push({key:`XStep`,value:w(e.xStep)}),i.push({key:`YStep`,value:w(e.yStep)}),i.push({key:`Resources`,value:n+` 0 R`}),e.matrix&&i.push({key:`Matrix`,value:`[`+e.matrix.toString()+`]`}),et({data:e.stream,additionalKeyValues:i,objectId:e.objectNumber}),H(`endobj`)},st=function(e){for(var t in e.objectNumber=Ge(),H(`<<`),e)switch(t){case`opacity`:H(`/ca `+D(e[t]));break;case`stroke-opacity`:H(`/CA `+D(e[t]))}H(`>>`),H(`endobj`)},ct=function(e){qe(e.resourcesOid,!0),H(`<<`),H(`/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]`),function(){for(var e in H(`/Font <<`),W)W.hasOwnProperty(e)&&(!1===d||!0===d&&f.hasOwnProperty(e))&&H(`/`+e+` `+W[e].objectNumber+` 0 R`);H(`>>`)}(),function(){if(Object.keys(Oe).length>0){for(var e in H(`/Shading <<`),Oe)Oe.hasOwnProperty(e)&&Oe[e]instanceof DP&&Oe[e].objectNumber>=0&&H(`/`+e+` `+Oe[e].objectNumber+` 0 R`);Fe.publish(`putShadingPatternDict`),H(`>>`)}}(),function(e){if(Object.keys(Oe).length>0){for(var t in H(`/Pattern <<`),Oe)Oe.hasOwnProperty(t)&&Oe[t]instanceof p.TilingPattern&&Oe[t].objectNumber>=0&&Oe[t].objectNumber>`)}}(e.objectOid),function(){if(Object.keys(Ae).length>0){for(var e in H(`/ExtGState <<`),Ae)Ae.hasOwnProperty(e)&&Ae[e].objectNumber>=0&&H(`/`+e+` `+Ae[e].objectNumber+` 0 R`);Fe.publish(`putGStateDict`),H(`>>`)}}(),function(){for(var e in H(`/XObject <<`),Le)Le.hasOwnProperty(e)&&Le[e].objectNumber>=0&&H(`/`+e+` `+Le[e].objectNumber+` 0 R`);Fe.publish(`putXobjectDict`),H(`>>`)}(),H(`>>`),H(`endobj`)},lt=function(e){Ee[e.fontName]=Ee[e.fontName]||{},Ee[e.fontName][e.fontStyle]=e.id},ut=function(e,t,n,r,i){var a={id:`F`+(Object.keys(W).length+1).toString(10),postScriptName:e,fontName:t,fontStyle:n,encoding:r,isStandardFont:i||!1,metadata:{}};return Fe.publish(`addFont`,{font:a,instance:this}),W[a.id]=a,lt(a),a.id},dt=p.__private__.pdfEscape=p.pdfEscape=function(e,t){return function(e,t){var n,r,i,a,o,s,c,l,u;if(i=(t||={}).sourceEncoding||`Unicode`,o=t.outputEncoding,(t.autoencode||o)&&W[Se].metadata&&W[Se].metadata[i]&&W[Se].metadata[i].encoding&&(a=W[Se].metadata[i].encoding,!o&&W[Se].encoding&&(o=W[Se].encoding),!o&&a.codePages&&(o=a.codePages[0]),typeof o==`string`&&(o=a[o]),o)){for(c=!1,s=[],n=0,r=e.length;n>8&&(c=!0);e=s.join(``)}for(n=e.length;c===void 0&&n!==0;)e.charCodeAt(n-1)>>8&&(c=!0),n--;if(!c)return e;for(s=t.noBOM?[]:[254,255],n=0,r=e.length;n>8)>>8)throw Error(`Character at position `+n+` of string '`+e+`' exceeds 16bits. Cannot be encoded into UCS-2 BE`);s.push(u),s.push(l-(u<<8))}return String.fromCharCode.apply(void 0,s)}(e,t).replace(/\\/g,`\\\\`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)},ft=p.__private__.beginPage=function(e){ae[++Ne]=[],Pe[Ne]={objId:0,contentsObjId:0,userUnit:Number(s),artBox:null,bleedBox:null,cropBox:null,trimBox:null,mediaBox:{bottomLeftX:0,bottomLeftY:0,topRightX:Number(e[0]),topRightY:Number(e[1])}},ht(Ne),ce(ae[R])},pt=function(e,t){var r,a,o;switch(n=t||n,typeof e==`string`&&(r=_(e.toLowerCase()),Array.isArray(r)&&(a=r[0],o=r[1])),Array.isArray(e)&&(a=e[0]*U,o=e[1]*U),isNaN(a)&&(a=i[0],o=i[1]),(a>14400||o>14400)&&(QN.warn(`A page in a PDF can not be wider or taller than 14400 userUnit. jsPDF limits the width/height to 14400`),a=Math.min(14400,a),o=Math.min(14400,o)),i=[a,o],n.substr(0,1)){case`l`:o>a&&(i=[o,a]);break;case`p`:a>o&&(i=[o,a])}ft(i),Yt(qt),H(nn),ln!==0&&H(ln+` J`),un!==0&&H(un+` j`),Fe.publish(`addPage`,{pageNumber:Ne})},mt=function(e){e>0&&e<=Ne&&(ae.splice(e,1),Pe.splice(e,1),Ne--,R>Ne&&(R=Ne),this.setPage(R))},ht=function(e){e>0&&e<=Ne&&(R=e)},gt=p.__private__.getNumberOfPages=p.getNumberOfPages=function(){return ae.length-1},_t=function(e,t,n){var r,i=void 0;return n||={},e=e===void 0?W[Se].fontName:e,t=t===void 0?W[Se].fontStyle:t,r=e.toLowerCase(),Ee[r]!==void 0&&Ee[r][t]!==void 0?i=Ee[r][t]:Ee[e]!==void 0&&Ee[e][t]!==void 0?i=Ee[e][t]:!1===n.disableWarning&&QN.warn(`Unable to look up font label for font '`+e+`', '`+t+`'. Refer to getFontList() for available fonts.`),i||n.noFallback||((i=Ee.times[t])??(i=Ee.times.normal)),i},vt=p.__private__.putInfo=function(){var e=Ge(),t=function(e){return e};for(var n in u!==null&&(t=kt.encryptor(e,0)),H(`<<`),H(`/Producer (`+dt(t(`jsPDF `+kP.version))+`)`),xe)xe.hasOwnProperty(n)&&xe[n]&&H(`/`+n.substr(0,1).toUpperCase()+n.substr(1)+` (`+dt(t(xe[n]))+`)`);H(`/CreationDate (`+dt(t(j))+`)`),H(`>>`),H(`endobj`)},yt=p.__private__.putCatalog=function(e){var t=(e||={}).rootDictionaryObjId||Ye;switch(Ge(),H(`<<`),H(`/Type /Catalog`),H(`/Pages `+t+` 0 R`),pe||=`fullwidth`,pe){case`fullwidth`:H(`/OpenAction [3 0 R /FitH null]`);break;case`fullheight`:H(`/OpenAction [3 0 R /FitV null]`);break;case`fullpage`:H(`/OpenAction [3 0 R /Fit]`);break;case`original`:H(`/OpenAction [3 0 R /XYZ null null 1]`);break;default:var n=``+pe;n.substr(n.length-1)===`%`&&(pe=parseInt(pe)/100),typeof pe==`number`&&H(`/OpenAction [3 0 R /XYZ null null `+D(pe)+`]`)}switch(ve||=`continuous`,ve){case`continuous`:H(`/PageLayout /OneColumn`);break;case`single`:H(`/PageLayout /SinglePage`);break;case`two`:case`twoleft`:H(`/PageLayout /TwoColumnLeft`);break;case`tworight`:H(`/PageLayout /TwoColumnRight`)}ge&&H(`/PageMode /`+ge),Fe.publish(`putCatalog`),H(`>>`),H(`endobj`)},bt=p.__private__.putTrailer=function(){H(`trailer`),H(`<<`),H(`/Size `+(B+1)),H(`/Root `+B+` 0 R`),H(`/Info `+(B-1)+` 0 R`),u!==null&&H(`/Encrypt `+kt.oid+` 0 R`),H(`/ID [ <`+M+`> <`+M+`> ]`),H(`>>`)},xt=p.__private__.putHeader=function(){H(`%PDF-`+m),H(`%ºß¬à`)},St=p.__private__.putXRef=function(){var e=`0000000000`;H(`xref`),H(`0 `+(B+1)),H(`0000000000 65535 f `);for(var t=1;t<=B;t++)typeof V[t]==`function`?H((e+V[t]()).slice(-10)+` 00000 n `):V[t]===void 0?H(`0000000000 00000 n `):H((e+V[t]).slice(-10)+` 00000 n `)},Ct=p.__private__.buildDocument=function(){var e;B=0,re=0,ne=[],V=[],ie=[],Ye=Ke(),Xe=Ke(),ce(ne),Fe.publish(`buildDocument`),xt(),nt(),function(){Fe.publish(`putAdditionalObjects`);for(var e=0;e`),H(`/O <`+kt.toHexString(kt.O)+`>`),H(`/P `+kt.P),H(`>>`),H(`endobj`)),vt(),yt();var t=re;return St(),bt(),H(`startxref`),H(``+t),H(`%%EOF`),ce(ae[R]),ne.join(` `)},wt=p.__private__.getBlob=function(e){return new Blob([ue(e)],{type:`application/pdf`})},Tt=function(e){for(;e.firstChild;)e.removeChild(e.firstChild)},Et=function(e){var t,n=e.document,r=n.documentElement,i=n.head,a=n.body;return i||(i=n.createElement(`head`),r.appendChild(i)),a||(a=n.createElement(`body`),r.appendChild(a)),Tt(i),Tt(a),(t=n.createElement(`style`)).appendChild(n.createTextNode(`html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}`)),i.appendChild(t),{document:n,body:a}},Dt=p.output=p.__private__.output=(We=function(e,t){switch(typeof(t||={})==`string`?t={filename:t}:t.filename=t.filename||`generated.pdf`,e){case void 0:return Ct();case`save`:p.save(t.filename);break;case`arraybuffer`:return ue(Ct());case`blob`:return wt(Ct());case`bloburi`:case`bloburl`:if(XN.URL!==void 0&&typeof XN.URL.createObjectURL==`function`)return XN.URL&&XN.URL.createObjectURL(wt(Ct()))||void 0;QN.warn(`bloburl is not supported by your system, because URL.createObjectURL is not supported by your browser.`);break;case`datauristring`:case`dataurlstring`:var n=``,r=Ct();try{n=aP(r)}catch{n=aP(unescape(encodeURIComponent(r)))}return`data:application/pdf;filename=`+encodeURIComponent(t.filename)+`;base64,`+n;case`pdfobjectnewwindow`:if(Object.prototype.toString.call(XN)===`[object Window]`){var i=`https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js`,a=!t.pdfObjectUrl;a||(i=t.pdfObjectUrl);var o=XN.open();if(o!==null){var s=Et(o),c=s.document.createElement(`script`),l=this;c.src=i,a&&(c.integrity=`sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==`,c.crossOrigin=`anonymous`),c.onload=function(){o.PDFObject.embed(l.output(`dataurlstring`),t)},s.body.appendChild(c)}return o}throw Error(`The option pdfobjectnewwindow just works in a browser-environment.`);case`pdfjsnewwindow`:if(Object.prototype.toString.call(XN)===`[object Window]`){var u=t.pdfJsUrl||`examples/PDF.js/web/viewer.html`,d=XN.open();if(d!==null){var f=Et(d),m=f.document.createElement(`iframe`),h=u.indexOf(`?`)===-1?`?`:`&`;l=this,m.id=`pdfViewer`,m.width=`500px`,m.height=`400px`,m.src=u+h+`file=&downloadName=`+encodeURIComponent(t.filename),m.onload=function(){d.document.title=t.filename,m.contentWindow.PDFViewerApplication.open(l.output(`bloburl`))},f.body.appendChild(m)}return d}throw Error(`The option pdfjsnewwindow just works in a browser-environment.`);case`dataurlnewwindow`:if(Object.prototype.toString.call(XN)!==`[object Window]`)throw Error(`The option dataurlnewwindow just works in a browser-environment.`);var g=XN.open();if(g!==null){var _=Et(g),v=_.document.createElement(`iframe`);v.src=this.output(`datauristring`,t),_.body.appendChild(v),g.document.title=t.filename}if(g||typeof safari>`u`)return g;break;case`datauri`:case`dataurl`:return XN.document.location.href=this.output(`datauristring`,t);default:return null}},We.foo=function(){try{return We.apply(this,arguments)}catch(n){var e=n.stack||``;~e.indexOf(` at `)&&(e=e.split(` at `)[1]);var t=`Error in function `+e.split(` `)[0].split(`<`)[0]+`: `+n.message;if(!XN.console)throw Error(t);XN.console.error(t,n),XN.alert&&alert(t)}},We.foo.bar=We,We.foo),Ot=function(e){return!0===Array.isArray(Ie)&&Ie.indexOf(e)>-1};switch(r){case`pt`:U=1;break;case`mm`:U=72/25.4;break;case`cm`:U=72/2.54;break;case`in`:U=72;break;case`px`:U=Ot(`px_scaling`)==1?.75:96/72;break;case`pc`:case`em`:U=12;break;case`ex`:U=6;break;default:if(typeof r!=`number`)throw Error(`Invalid unit: `+r);U=r}var kt=null;L(),P();var At=p.__private__.getPageInfo=p.getPageInfo=function(e){if(isNaN(e)||e%1!=0)throw Error(`Invalid argument passed to jsPDF.getPageInfo`);return{objId:Pe[e].objId,pageNumber:e,pageContext:Pe[e]}},jt=p.__private__.getPageInfoByObjId=function(e){if(isNaN(e)||e%1!=0)throw Error(`Invalid argument passed to jsPDF.getPageInfoByObjId`);for(var t in Pe)if(Pe[t].objId===e)break;return At(t)},Mt=p.__private__.getCurrentPageInfo=p.getCurrentPageInfo=function(){return{objId:Pe[R].objId,pageNumber:R,pageContext:Pe[R]}};p.addPage=function(){return pt.apply(this,arguments),this},p.setPage=function(){return ht.apply(this,arguments),ce.call(this,ae[R]),this},p.insertPage=function(e){return this.addPage(),this.movePage(R,e),this},p.movePage=function(e,t){var n,r;if(e>t){n=ae[e],r=Pe[e];for(var i=e;i>t;i--)ae[i]=ae[i-1],Pe[i]=Pe[i-1];ae[t]=n,Pe[t]=r,this.setPage(t)}else if(e0&&(typeof e==`string`?e=h.splitTextToSize(e,u):Object.prototype.toString.call(e)===`[object Array]`&&(e=e.reduce(function(e,t){return e.concat(h.splitTextToSize(t,u))},[]))),a={text:e,x:t,y:n,options:r,mutex:{pdfEscape:dt,activeFontKey:Se,fonts:W,activeFontSize:fe}},Fe.publish(`preProcessText`,a),e=a.text,s=(r=a.options).angle,m instanceof Be==0&&s&&typeof s==`number`){s*=Math.PI/180,r.rotationDirection===0&&(s=-s),b===y&&(s=-s);var I=Math.cos(s),L=Math.sin(s);m=new Be(I,L,-L,I,0,0)}else s&&s instanceof Be&&(m=s);b!==y||m||(m=He),(l=r.charSpace||sn)!==void 0&&(v+=w(k(l))+` Tc `,this.setCharSpace(this.getCharSpace()||0)),(p=r.horizontalScale)!==void 0&&(v+=w(100*p)+` Tz `),r.lang;var ee=-1,R=r.renderingMode===void 0?r.stroke:r.renderingMode,te=h.internal.getCurrentPageInfo().pageContext;switch(R){case 0:case!1:case`fill`:ee=0;break;case 1:case!0:case`stroke`:ee=1;break;case 2:case`fillThenStroke`:ee=2;break;case 3:case`invisible`:ee=3;break;case 4:case`fillAndAddForClipping`:ee=4;break;case 5:case`strokeAndAddPathForClipping`:ee=5;break;case 6:case`fillThenStrokeAndAddToPathForClipping`:ee=6;break;case 7:case`addToPathForClipping`:ee=7}var z=te.usedRenderingMode===void 0?-1:te.usedRenderingMode;ee===-1?z!==-1&&(v+=`0 Tr `):v+=ee+` Tr `,ee!==-1&&(te.usedRenderingMode=ee),c=r.align||`left`;var B,V=fe*x,ne=h.internal.pageSize.getWidth(),re=W[Se];l=r.charSpace||sn,u=r.maxWidth||0,d=Object.assign({autoencode:!0,noBOM:!0},r.flags);var ie=[],ae=function(e){return h.getStringUnitWidth(e,{font:re,charSpace:l,fontSize:fe,doKerning:!1})*fe/S};if(Object.prototype.toString.call(e)===`[object Array]`){var oe;o=E(e),c!==`left`&&(B=o.map(ae));var se,ce=0;if(c===`right`){t-=B[0],e=[],N=o.length;for(var le=0;le0?(u-B[me])/be:0;me`:`)`),Ce=parseFloat(o[ke][1]),we=parseFloat(o[ke][2]);break;case 0:Te=(_?`<`:`(`)+o[ke]+(_?`>`:`)`),Ce=G(t),we=$t(n)}ie!==void 0&&ie[ke]!==void 0&&(De=ie[ke]+` Tw `),ke===0?e.push(De+Oe(Ce,we,m)+Te):Ee===0?e.push(De+Te):Ee===1&&e.push(De+Oe(Ce,we,m)+Te)}e=Ee===0?e.join(` Tj T* `):e.join(` Tj `),e+=` Tj `;var Ae=`BT /`;return Ae+=Se+` `+fe+` Tf `,Ae+=w(fe*x)+` TL `,Ae+=an+` `,Ae+=v,Ae+=e,H(Ae+=`ET`),f[Se]=!0,h};var Nt=p.__private__.clip=p.clip=function(e){return H(e===`evenodd`?`W*`:`W`),this};p.clipEvenOdd=function(){return Nt(`evenodd`)},p.__private__.discardPath=p.discardPath=function(){return H(`n`),this};var Pt=p.__private__.isValidStyle=function(e){var t=!1;return[void 0,null,`S`,`D`,`F`,`DF`,`FD`,`f`,`f*`,`B`,`B*`,`n`].indexOf(e)!==-1&&(t=!0),t};p.__private__.setDefaultPathOperation=p.setDefaultPathOperation=function(e){return Pt(e)&&(l=e),this};var Ft=p.__private__.getStyle=p.getStyle=function(e){var t=l;switch(e){case`D`:case`S`:t=`S`;break;case`F`:t=`f`;break;case`FD`:case`DF`:t=`B`;break;case`f`:case`f*`:case`B`:case`B*`:t=e}return t},It=p.close=function(){return H(`h`),this};p.stroke=function(){return H(`S`),this},p.fill=function(e){return Lt(`f`,e),this},p.fillEvenOdd=function(e){return Lt(`f*`,e),this},p.fillStroke=function(e){return Lt(`B`,e),this},p.fillStrokeEvenOdd=function(e){return Lt(`B*`,e),this};var Lt=function(e,t){hD(t)===`object`?Bt(t,e):H(e)},Rt=function(e){e===null||b===y&&e===void 0||(e=Ft(e),H(e))};function zt(e,t,n,r,i){var a=new OP(t||this.boundingBox,n||this.xStep,r||this.yStep,this.gState,i||this.matrix);return a.stream=this.stream,Ue(e+`$$`+ this.cloneIndex+++`$$`,a),a}var Bt=function(e,t){var n=ke[e.key],r=Oe[n];if(r instanceof DP)H(`q`),H(Vt(t)),r.gState&&p.setGState(r.gState),H(e.matrix.toString()+` cm`),H(`/`+n+` sh`),H(`Q`);else if(r instanceof OP){var i=new Be(1,0,0,-1,0,Cn());e.matrix&&(i=i.multiply(e.matrix||He),n=zt.call(r,e.key,e.boundingBox,e.xStep,e.yStep,i).id),H(`q`),H(`/Pattern cs`),H(`/`+n+` scn`),r.gState&&p.setGState(r.gState),H(t),H(`Q`)}},Vt=function(e){switch(e){case`f`:case`F`:case`n`:return`W n`;case`f*`:return`W* n`;case`B`:case`S`:return`W S`;case`B*`:return`W* S`}},Ht=p.moveTo=function(e,t){return H(w(k(e))+` `+w(A(t))+` m`),this},Ut=p.lineTo=function(e,t){return H(w(k(e))+` `+w(A(t))+` l`),this},Wt=p.curveTo=function(e,t,n,r,i,a){return H([w(k(e)),w(A(t)),w(k(n)),w(A(r)),w(k(i)),w(A(a)),`c`].join(` `)),this};p.__private__.line=p.line=function(e,t,n,r,i){if(isNaN(e)||isNaN(t)||isNaN(n)||isNaN(r)||!Pt(i))throw Error(`Invalid arguments passed to jsPDF.line`);return b===v?this.lines([[n-e,r-t]],e,t,[1,1],i||`S`):this.lines([[n-e,r-t]],e,t,[1,1]).stroke()},p.__private__.lines=p.lines=function(e,t,n,r,i,a){var o,s,c,l,u,d,f,p,m,h,g,_;if(typeof e==`number`&&(_=n,n=t,t=e,e=_),r||=[1,1],a||=!1,isNaN(t)||isNaN(n)||!Array.isArray(e)||!Array.isArray(r)||!Pt(i)||typeof a!=`boolean`)throw Error(`Invalid arguments passed to jsPDF.lines`);for(Ht(t,n),o=r[0],s=r[1],l=e.length,h=t,g=n,c=0;c>8&255,e>>16&255,e>>24&255)},SP.prototype.toHexString=function(e){return e.split(``).map(function(e){return(`0`+(255&e.charCodeAt(0)).toString(16)).slice(-2)}).join(``)},SP.prototype.hexToBytes=function(e){for(var t=[],n=0;n>8&255,e>>16&255,255&t,t>>8&255)).substr(0,10);return function(e){return bP(n,e)}},TP.prototype.equals=function(e){var t,n=`id,objectNumber,equals`;if(!e||hD(e)!==hD(this))return!1;var r=0;for(t in this)if(!(n.indexOf(t)>=0)){if(this.hasOwnProperty(t)&&!e.hasOwnProperty(t)||this[t]!==e[t])return!1;r++}for(t in e)e.hasOwnProperty(t)&&n.indexOf(t)<0&&r--;return r===0},kP.API={events:[]},kP.version=`4.2.1`;var AP=kP.API,jP=1,MP=function(e){return e.replace(/\\/g,`\\\\`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)},NP=function(e){return e.replace(/\\\\/g,`\\`).replace(/\\\(/g,`(`).replace(/\\\)/g,`)`)},PP=function(e){return e.toString().replace(/#/g,`#23`).replace(/[\s\n\r()<>[\]{}\/%]/g,function(e){var t=e.charCodeAt(0).toString(16).toUpperCase();return`#`+(t.length===1?`0`+t:t)})},FP=function(e){return e.toFixed(2)},IP=function(e){return e.toFixed(5)};AP.__acroform__={};var LP=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e},RP=function(e){return e*jP},zP=function(e){var t=new nF,n=gF.internal.getHeight(e)||0,r=gF.internal.getWidth(e)||0;return t.BBox=[0,0,Number(FP(r)),Number(FP(n))],t},BP=AP.__acroform__.setBit=function(e,t){if(e||=0,t||=0,isNaN(e)||isNaN(t))throw Error(`Invalid arguments passed to jsPDF.API.__acroform__.setBit`);return e|1<0;){t=``,a--;var l,u,d=YP(`3`,e,a).height,f=e.multiline?o-a:(o-d)/2,p=f+=2,m=0,h=0,g=0;if(a<=0){t=`(...) Tj `,t+=`% Width of Text: `+YP(t,e,a=12).width+`, FieldWidth:`+s+` `;break}for(var _=``,v=0,y=0;yo)continue t;_+=i[y][g],b=!0,h=y,y--}else{_=(_+=i[y][g]+` `).substr(_.length-1)==` `?_.substr(0,_.length-1):_;var x=parseInt(y),S=c(x,_,a),C=y>=i.length-1;if(S&&!C){_+=` `,g=0;continue}if(S||C){if(C)h=x;else if(e.multiline&&(d+2)*(v+2)+2>o)continue t}else{if(!e.multiline||(d+2)*(v+2)+2>o)continue t;h=x}}for(var w=``,T=m;T<=h;T++){var E=i[T];if(e.multiline){if(T===h){w+=E[g]+` `,g=(g+1)%E.length;continue}if(T===m){w+=E[E.length-1]+` `;continue}}w+=E[0]+` `}switch(w=w.substr(w.length-1)==` `?w.substr(0,w.length-1):w,u=YP(w,e,a).width,e.textAlign){case`right`:l=s-u-2;break;case`center`:l=(s-u)/2;break;default:l=2}t+=FP(l)+` `+FP(p)+` Td `,t+=`(`+MP(w)+`) Tj `,t+=-FP(l)+` 0 Td `,p=-(a+2),u=0,m=b?h:h+1,v++,_=``}break}return r.text=t,r.fontSize=a,r},YP=function(e,t,n){var r=t.scope.internal.getFont(t.fontName,t.fontStyle),i=t.scope.getStringUnitWidth(e,{font:r,fontSize:parseFloat(n),charSpace:0})*parseFloat(n);return{height:t.scope.getStringUnitWidth(`3`,{font:r,fontSize:parseFloat(n),charSpace:0})*parseFloat(n)*1.5,width:i}},XP={fields:[],xForms:[],acroFormDictionaryRoot:null,printedOut:!1,internal:null,isInitialized:!1},ZP=function(e,t){var n={type:`reference`,object:e};t.internal.getPageInfo(e.page).pageContext.annotations.find(function(e){return e.type===n.type&&e.object===n.object})===void 0&&t.internal.getPageInfo(e.page).pageContext.annotations.push(n)},QP=function(e,t){if(t.scope=e,e.internal!==void 0&&(e.internal.acroformPlugin===void 0||!1===e.internal.acroformPlugin.isInitialized)){if(iF.FieldNum=0,e.internal.acroformPlugin=JSON.parse(JSON.stringify(XP)),e.internal.acroformPlugin.acroFormDictionaryRoot)throw Error(`Exception while creating AcroformDictionary`);jP=e.internal.scaleFactor,e.internal.acroformPlugin.acroFormDictionaryRoot=new rF,e.internal.acroformPlugin.acroFormDictionaryRoot.scope=e,e.internal.acroformPlugin.acroFormDictionaryRoot._eventID=e.internal.events.subscribe(`postPutResources`,function(){(function(e){e.internal.events.unsubscribe(e.internal.acroformPlugin.acroFormDictionaryRoot._eventID),delete e.internal.acroformPlugin.acroFormDictionaryRoot._eventID,e.internal.acroformPlugin.printedOut=!0})(e)}),e.internal.events.subscribe(`buildDocument`,function(){(function(e){e.internal.acroformPlugin.acroFormDictionaryRoot.objId=void 0;var t=e.internal.acroformPlugin.acroFormDictionaryRoot.Fields;for(var n in t)if(t.hasOwnProperty(n)){var r=t[n];r.objId=void 0,r.hasAnnotation&&ZP(r,e)}})(e)}),e.internal.events.subscribe(`putCatalog`,function(){(function(e){if(e.internal.acroformPlugin.acroFormDictionaryRoot===void 0)throw Error(`putCatalogCallback: Root missing.`);e.internal.write(`/AcroForm `+e.internal.acroformPlugin.acroFormDictionaryRoot.objId+` 0 R`)})(e)}),e.internal.events.subscribe(`postPutPages`,function(t){(function(e,t){var n=!e;for(var r in e||(t.internal.newObjectDeferredBegin(t.internal.acroformPlugin.acroFormDictionaryRoot.objId,!0),t.internal.acroformPlugin.acroFormDictionaryRoot.putStream()),e||=t.internal.acroformPlugin.acroFormDictionaryRoot.Kids)if(e.hasOwnProperty(r)){var i=e[r],a=[],o=i.Rect;if(i.Rect&&=KP(i.Rect,t),t.internal.newObjectDeferredBegin(i.objId,!0),i.DA=gF.createDefaultAppearanceStream(i),hD(i)===`object`&&typeof i.getKeyValueListForStream==`function`&&(a=i.getKeyValueListForStream()),i.Rect=o,i.hasAppearanceStream&&!i.appearanceStreamContent){var s=qP(i);a.push({key:`AP`,value:`<>`}),t.internal.acroformPlugin.xForms.push(s)}if(i.appearanceStreamContent){var c=``;for(var l in i.appearanceStreamContent)if(i.appearanceStreamContent.hasOwnProperty(l)){var u=i.appearanceStreamContent[l];if(c+=`/`+l+` `,c+=`<<`,Object.keys(u).length>=1||Array.isArray(u)){for(var r in u)if(u.hasOwnProperty(r)){var d=u[r];typeof d==`function`&&(d=d.call(t,i)),c+=`/`+r+` `+d+` `,t.internal.acroformPlugin.xForms.indexOf(d)>=0||t.internal.acroformPlugin.xForms.push(d)}}else typeof(d=u)==`function`&&(d=d.call(t,i)),c+=`/`+r+` `+d,t.internal.acroformPlugin.xForms.indexOf(d)>=0||t.internal.acroformPlugin.xForms.push(d);c+=`>>`}a.push({key:`AP`,value:`<< `+c+`>>`})}t.internal.putStream({additionalKeyValues:a,objectId:i.objId}),t.internal.out(`endobj`)}n&&function(e,t){for(var n in e)if(e.hasOwnProperty(n)){var r=n,i=e[n];t.internal.newObjectDeferredBegin(i.objId,!0),hD(i)===`object`&&typeof i.putStream==`function`&&i.putStream(),delete e[r]}}(t.internal.acroformPlugin.xForms,t)})(t,e)}),e.internal.acroformPlugin.isInitialized=!0}},$P=AP.__acroform__.arrayToPdfArray=function(e,t,n){var r=function(e){return e};if(Array.isArray(e)){for(var i=`[`,a=0;a0?t:void 0}}),Object.defineProperty(this,"Fields",{enumerable:!1,configurable:!1,get:function(){return t}}),Object.defineProperty(this,"DA",{enumerable:!1,configurable:!1,get:function(){if(e){var t=function(e){return e};return this.scope&&(t=this.scope.internal.getEncryptor(this.objId)),`(`+MP(t(e))+`)`}},set:function(t){e=t}})};LP(rF,tF);var iF=function e(){tF.call(this);var t=4;Object.defineProperty(this,"F",{enumerable:!1,configurable:!1,get:function(){return t},set:function(e){if(isNaN(e))throw Error(`Invalid value "`+e+`" for attribute F supplied.`);t=e}}),Object.defineProperty(this,"showWhenPrinted",{enumerable:!0,configurable:!0,get:function(){return!!UP(t,3)},set:function(e){!!e==1?this.F=WP(t,3):this.F=GP(t,3)}});var n=0;Object.defineProperty(this,"Ff",{enumerable:!1,configurable:!1,get:function(){return n},set:function(e){if(isNaN(e))throw Error(`Invalid value "`+e+`" for attribute Ff supplied.`);n=e}});var r=[];Object.defineProperty(this,"Rect",{enumerable:!1,configurable:!1,get:function(){if(r.length!==0)return r},set:function(e){r=e===void 0?[]:e}}),Object.defineProperty(this,"x",{enumerable:!0,configurable:!0,get:function(){return!r||isNaN(r[0])?0:r[0]},set:function(e){r[0]=e}}),Object.defineProperty(this,"y",{enumerable:!0,configurable:!0,get:function(){return!r||isNaN(r[1])?0:r[1]},set:function(e){r[1]=e}}),Object.defineProperty(this,"width",{enumerable:!0,configurable:!0,get:function(){return!r||isNaN(r[2])?0:r[2]},set:function(e){r[2]=e}}),Object.defineProperty(this,"height",{enumerable:!0,configurable:!0,get:function(){return!r||isNaN(r[3])?0:r[3]},set:function(e){r[3]=e}});var i=``;Object.defineProperty(this,"FT",{enumerable:!0,configurable:!1,get:function(){return i},set:function(e){switch(e){case`/Btn`:case`/Tx`:case`/Ch`:case`/Sig`:i=e;break;default:throw Error(`Invalid value "`+e+`" for attribute FT supplied.`)}}});var a=null;Object.defineProperty(this,"T",{enumerable:!0,configurable:!1,get:function(){if(!a||a.length<1){if(this instanceof fF)return;a=`FieldObject`+ e.FieldNum++}var t=function(e){return e};return this.scope&&(t=this.scope.internal.getEncryptor(this.objId)),`(`+MP(t(a))+`)`},set:function(e){a=e.toString()}}),Object.defineProperty(this,"fieldName",{configurable:!0,enumerable:!0,get:function(){return a},set:function(e){a=e}});var o=`helvetica`;Object.defineProperty(this,"fontName",{enumerable:!0,configurable:!0,get:function(){return o},set:function(e){o=e}});var s=`normal`;Object.defineProperty(this,"fontStyle",{enumerable:!0,configurable:!0,get:function(){return s},set:function(e){s=e}});var c=0;Object.defineProperty(this,"fontSize",{enumerable:!0,configurable:!0,get:function(){return c},set:function(e){c=e}});var l=void 0;Object.defineProperty(this,"maxFontSize",{enumerable:!0,configurable:!0,get:function(){return l===void 0?50/jP:l},set:function(e){l=e}});var u=`black`;Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,get:function(){return u},set:function(e){u=e}});var d=`/F1 0 Tf 0 g`;Object.defineProperty(this,"DA",{enumerable:!0,configurable:!1,get:function(){if(!(!d||this instanceof fF||this instanceof mF))return eF(d,this.objId,this.scope)},set:function(e){e=e.toString(),d=e}});var f=null;Object.defineProperty(this,"DV",{enumerable:!1,configurable:!1,get:function(){if(f)return this instanceof lF==0?eF(f,this.objId,this.scope):f},set:function(e){e=e.toString(),f=this instanceof lF==0?e.substr(0,1)===`(`?NP(e.substr(1,e.length-2)):NP(e):e}}),Object.defineProperty(this,"defaultValue",{enumerable:!0,configurable:!0,get:function(){return this instanceof lF==1?NP(f.substr(1,f.length-1)):f},set:function(e){e=e.toString(),f=this instanceof lF==1?`/`+PP(e):e}});var p=null;Object.defineProperty(this,"_V",{enumerable:!1,configurable:!1,get:function(){if(p)return p},set:function(e){this.V=e}}),Object.defineProperty(this,"V",{enumerable:!1,configurable:!1,get:function(){if(p)return this instanceof lF==0?eF(p,this.objId,this.scope):p},set:function(e){e=e.toString(),p=this instanceof lF==0?e.substr(0,1)===`(`?NP(e.substr(1,e.length-2)):NP(e):e}}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,get:function(){return this instanceof lF==1?NP(p.substr(1,p.length-1)):p},set:function(e){e=e.toString(),p=this instanceof lF==1?`/`+PP(e):e}}),Object.defineProperty(this,"hasAnnotation",{enumerable:!0,configurable:!0,get:function(){return this.Rect}}),Object.defineProperty(this,"Type",{enumerable:!0,configurable:!1,get:function(){return this.hasAnnotation?`/Annot`:null}}),Object.defineProperty(this,"Subtype",{enumerable:!0,configurable:!1,get:function(){return this.hasAnnotation?`/Widget`:null}});var m,h=!1;Object.defineProperty(this,"hasAppearanceStream",{enumerable:!0,configurable:!0,get:function(){return h},set:function(e){e=!!e,h=e}}),Object.defineProperty(this,"page",{enumerable:!0,configurable:!0,get:function(){if(m)return m},set:function(e){m=e}}),Object.defineProperty(this,"readOnly",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,1)},set:function(e){!!e==1?this.Ff=WP(this.Ff,1):this.Ff=GP(this.Ff,1)}}),Object.defineProperty(this,"required",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,2)},set:function(e){!!e==1?this.Ff=WP(this.Ff,2):this.Ff=GP(this.Ff,2)}}),Object.defineProperty(this,"noExport",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,3)},set:function(e){!!e==1?this.Ff=WP(this.Ff,3):this.Ff=GP(this.Ff,3)}});var g=null;Object.defineProperty(this,"Q",{enumerable:!0,configurable:!1,get:function(){if(g!==null)return g},set:function(e){if([0,1,2].indexOf(e)===-1)throw Error(`Invalid value "`+e+`" for attribute Q supplied.`);g=e}}),Object.defineProperty(this,"textAlign",{get:function(){var e;switch(g){case 0:default:e=`left`;break;case 1:e=`center`;break;case 2:e=`right`}return e},configurable:!0,enumerable:!0,set:function(e){switch(e){case`right`:case 2:g=2;break;case`center`:case 1:g=1;break;default:g=0}}})};LP(iF,tF);var aF=function(){iF.call(this),this.FT=`/Ch`,this.V=`()`,this.fontName=`zapfdingbats`;var e=0;Object.defineProperty(this,"TI",{enumerable:!0,configurable:!1,get:function(){return e},set:function(t){e=t}}),Object.defineProperty(this,"topIndex",{enumerable:!0,configurable:!0,get:function(){return e},set:function(t){e=t}});var t=[];Object.defineProperty(this,"Opt",{enumerable:!0,configurable:!1,get:function(){return $P(t,this.objId,this.scope)},set:function(e){var n,r=[];typeof(n=e)==`string`&&(r=function(e,t,n){n||=1;for(var r,i=[];r=t.exec(e);)i.push(r[n]);return i}(n,/\((.*?)\)/g)),t=r}}),this.getOptions=function(){return t},this.setOptions=function(e){t=e,this.sort&&t.sort()},this.addOption=function(e){e=(e||=``).toString(),t.push(e),this.sort&&t.sort()},this.removeOption=function(e,n){for(n||=!1,e=(e||=``).toString();t.indexOf(e)!==-1&&(t.splice(t.indexOf(e),1),!1!==n););},Object.defineProperty(this,"combo",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,18)},set:function(e){!!e==1?this.Ff=WP(this.Ff,18):this.Ff=GP(this.Ff,18)}}),Object.defineProperty(this,"edit",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,19)},set:function(e){!0===this.combo&&(!!e==1?this.Ff=WP(this.Ff,19):this.Ff=GP(this.Ff,19))}}),Object.defineProperty(this,"sort",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,20)},set:function(e){!!e==1?(this.Ff=WP(this.Ff,20),t.sort()):this.Ff=GP(this.Ff,20)}}),Object.defineProperty(this,"multiSelect",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,22)},set:function(e){!!e==1?this.Ff=WP(this.Ff,22):this.Ff=GP(this.Ff,22)}}),Object.defineProperty(this,"doNotSpellCheck",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,23)},set:function(e){!!e==1?this.Ff=WP(this.Ff,23):this.Ff=GP(this.Ff,23)}}),Object.defineProperty(this,"commitOnSelChange",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,27)},set:function(e){!!e==1?this.Ff=WP(this.Ff,27):this.Ff=GP(this.Ff,27)}}),this.hasAppearanceStream=!1};LP(aF,iF);var oF=function(){aF.call(this),this.fontName=`helvetica`,this.combo=!1};LP(oF,aF);var sF=function(){oF.call(this),this.combo=!0};LP(sF,oF);var cF=function(){sF.call(this),this.edit=!0};LP(cF,sF);var lF=function(){iF.call(this),this.FT=`/Btn`,Object.defineProperty(this,"noToggleToOff",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,15)},set:function(e){!!e==1?this.Ff=WP(this.Ff,15):this.Ff=GP(this.Ff,15)}}),Object.defineProperty(this,"radio",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,16)},set:function(e){!!e==1?this.Ff=WP(this.Ff,16):this.Ff=GP(this.Ff,16)}}),Object.defineProperty(this,"pushButton",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,17)},set:function(e){!!e==1?this.Ff=WP(this.Ff,17):this.Ff=GP(this.Ff,17)}}),Object.defineProperty(this,"radioIsUnison",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,26)},set:function(e){!!e==1?this.Ff=WP(this.Ff,26):this.Ff=GP(this.Ff,26)}});var e,t={};Object.defineProperty(this,"MK",{enumerable:!1,configurable:!1,get:function(){var e=function(e){return e};if(this.scope&&(e=this.scope.internal.getEncryptor(this.objId)),Object.keys(t).length!==0){var n,r=[];for(n in r.push(`<<`),t)r.push(`/`+n+` (`+MP(e(t[n]))+`)`);return r.push(`>>`),r.join(` `)}},set:function(e){hD(e)===`object`&&(t=e)}}),Object.defineProperty(this,"caption",{enumerable:!0,configurable:!0,get:function(){return t.CA||``},set:function(e){typeof e==`string`&&(t.CA=e)}}),Object.defineProperty(this,"AS",{enumerable:!1,configurable:!1,get:function(){return e},set:function(t){var n=t==null?``:t.toString();n.substr(0,1)===`/`&&(n=n.substr(1)),e=`/`+PP(n)}}),Object.defineProperty(this,"appearanceState",{enumerable:!0,configurable:!0,get:function(){return e.substr(1,e.length-1)},set:function(t){e=`/`+PP(t)}})};LP(lF,iF);var uF=function(){lF.call(this),this.pushButton=!0};LP(uF,lF);var dF=function(){lF.call(this),this.radio=!0,this.pushButton=!1;var e=[];Object.defineProperty(this,"Kids",{enumerable:!0,configurable:!1,get:function(){return e},set:function(t){e=t===void 0?[]:t}})};LP(dF,lF);var fF=function(){var e,t;iF.call(this),Object.defineProperty(this,"Parent",{enumerable:!1,configurable:!1,get:function(){return e},set:function(t){e=t}}),Object.defineProperty(this,"optionName",{enumerable:!1,configurable:!0,get:function(){return t},set:function(e){t=e}});var n,r={};Object.defineProperty(this,"MK",{enumerable:!1,configurable:!1,get:function(){var e=function(e){return e};this.scope&&(e=this.scope.internal.getEncryptor(this.objId));var t,n=[];for(t in n.push(`<<`),r)n.push(`/`+t+` (`+MP(e(r[t]))+`)`);return n.push(`>>`),n.join(` `)},set:function(e){hD(e)===`object`&&(r=e)}}),Object.defineProperty(this,"caption",{enumerable:!0,configurable:!0,get:function(){return r.CA||``},set:function(e){typeof e==`string`&&(r.CA=e)}}),Object.defineProperty(this,"AS",{enumerable:!1,configurable:!1,get:function(){return n},set:function(e){var t=e==null?``:e.toString();t.substr(0,1)===`/`&&(t=t.substr(1)),n=`/`+PP(t)}}),Object.defineProperty(this,"appearanceState",{enumerable:!0,configurable:!0,get:function(){return n.substr(1,n.length-1)},set:function(e){var t=e==null?``:e.toString();t.substr(0,1)===`/`&&(t=t.substr(1)),n=`/`+PP(t)}}),this.caption=`l`,this.appearanceState=`Off`,this._AppearanceType=gF.RadioButton.Circle,this.appearanceStreamContent=this._AppearanceType.createAppearanceStream(this.optionName)};LP(fF,iF),dF.prototype.setAppearance=function(e){if(!(`createAppearanceStream`in e)||!(`getCA`in e))throw Error(`Couldn't assign Appearance to RadioButton. Appearance was Invalid!`);for(var t in this.Kids)if(this.Kids.hasOwnProperty(t)){var n=this.Kids[t];n.appearanceStreamContent=e.createAppearanceStream(n.optionName),n.caption=e.getCA()}},dF.prototype.createOption=function(e){var t=new fF;return t.Parent=this,t.optionName=e,this.Kids.push(t),_F.call(this.scope,t),t};var pF=function(){lF.call(this),this.fontName=`zapfdingbats`,this.caption=`3`,this.appearanceState=`On`,this.value=`On`,this.textAlign=`center`,this.appearanceStreamContent=gF.CheckBox.createAppearanceStream()};LP(pF,lF);var mF=function(){iF.call(this),this.FT=`/Tx`,Object.defineProperty(this,"multiline",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,13)},set:function(e){!!e==1?this.Ff=WP(this.Ff,13):this.Ff=GP(this.Ff,13)}}),Object.defineProperty(this,"fileSelect",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,21)},set:function(e){!!e==1?this.Ff=WP(this.Ff,21):this.Ff=GP(this.Ff,21)}}),Object.defineProperty(this,"doNotSpellCheck",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,23)},set:function(e){!!e==1?this.Ff=WP(this.Ff,23):this.Ff=GP(this.Ff,23)}}),Object.defineProperty(this,"doNotScroll",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,24)},set:function(e){!!e==1?this.Ff=WP(this.Ff,24):this.Ff=GP(this.Ff,24)}}),Object.defineProperty(this,"comb",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,25)},set:function(e){!!e==1?this.Ff=WP(this.Ff,25):this.Ff=GP(this.Ff,25)}}),Object.defineProperty(this,"richText",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,26)},set:function(e){!!e==1?this.Ff=WP(this.Ff,26):this.Ff=GP(this.Ff,26)}});var e=null;Object.defineProperty(this,"MaxLen",{enumerable:!0,configurable:!1,get:function(){return e},set:function(t){e=t}}),Object.defineProperty(this,"maxLength",{enumerable:!0,configurable:!0,get:function(){return e},set:function(t){Number.isInteger(t)&&(e=t)}}),Object.defineProperty(this,"hasAppearanceStream",{enumerable:!0,configurable:!0,get:function(){return this.V||this.DV}})};LP(mF,iF);var hF=function(){mF.call(this),Object.defineProperty(this,"password",{enumerable:!0,configurable:!0,get:function(){return!!UP(this.Ff,14)},set:function(e){!!e==1?this.Ff=WP(this.Ff,14):this.Ff=GP(this.Ff,14)}}),this.password=!0};LP(hF,mF);var gF={CheckBox:{createAppearanceStream:function(){return{N:{On:gF.CheckBox.YesNormal},D:{On:gF.CheckBox.YesPushDown,Off:gF.CheckBox.OffPushDown}}},YesPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=[],r=e.scope.internal.getFont(e.fontName,e.fontStyle).id,i=e.scope.__private__.encodeColorString(e.color),a=JP(e,e.caption);return n.push(`0.749023 g`),n.push(`0 0 `+FP(gF.internal.getWidth(e))+` `+FP(gF.internal.getHeight(e))+` re`),n.push(`f`),n.push(`BMC`),n.push(`q`),n.push(`0 0 1 rg`),n.push(`/`+r+` `+FP(a.fontSize)+` Tf `+i),n.push(`BT`),n.push(a.text),n.push(`ET`),n.push(`Q`),n.push(`EMC`),t.stream=n.join(` `),t},YesNormal:function(e){var t=zP(e);t.scope=e.scope;var n=e.scope.internal.getFont(e.fontName,e.fontStyle).id,r=e.scope.__private__.encodeColorString(e.color),i=[],a=gF.internal.getHeight(e),o=gF.internal.getWidth(e),s=JP(e,e.caption);return i.push(`1 g`),i.push(`0 0 `+FP(o)+` `+FP(a)+` re`),i.push(`f`),i.push(`q`),i.push(`0 0 1 rg`),i.push(`0 0 `+FP(o-1)+` `+FP(a-1)+` re`),i.push(`W`),i.push(`n`),i.push(`0 g`),i.push(`BT`),i.push(`/`+n+` `+FP(s.fontSize)+` Tf `+r),i.push(s.text),i.push(`ET`),i.push(`Q`),t.stream=i.join(` `),t},OffPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=[];return n.push(`0.749023 g`),n.push(`0 0 `+FP(gF.internal.getWidth(e))+` `+FP(gF.internal.getHeight(e))+` re`),n.push(`f`),t.stream=n.join(` `),t}},RadioButton:{Circle:{createAppearanceStream:function(e){var t={D:{Off:gF.RadioButton.Circle.OffPushDown},N:{}};return t.N[e]=gF.RadioButton.Circle.YesNormal,t.D[e]=gF.RadioButton.Circle.YesPushDown,t},getCA:function(){return`l`},YesNormal:function(e){var t=zP(e);t.scope=e.scope;var n=[],r=gF.internal.getWidth(e)<=gF.internal.getHeight(e)?gF.internal.getWidth(e)/4:gF.internal.getHeight(e)/4;r=Number((.9*r).toFixed(5));var i=gF.internal.Bezier_C,a=Number((r*i).toFixed(5));return n.push(`q`),n.push(`1 0 0 1 `+IP(gF.internal.getWidth(e)/2)+` `+IP(gF.internal.getHeight(e)/2)+` cm`),n.push(r+` 0 m`),n.push(r+` `+a+` `+a+` `+r+` 0 `+r+` c`),n.push(`-`+a+` `+r+` -`+r+` `+a+` -`+r+` 0 c`),n.push(`-`+r+` -`+a+` -`+a+` -`+r+` 0 -`+r+` c`),n.push(a+` -`+r+` `+r+` -`+a+` `+r+` 0 c`),n.push(`f`),n.push(`Q`),t.stream=n.join(` `),t},YesPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=[],r=gF.internal.getWidth(e)<=gF.internal.getHeight(e)?gF.internal.getWidth(e)/4:gF.internal.getHeight(e)/4;r=Number((.9*r).toFixed(5));var i=Number((2*r).toFixed(5)),a=Number((i*gF.internal.Bezier_C).toFixed(5)),o=Number((r*gF.internal.Bezier_C).toFixed(5));return n.push(`0.749023 g`),n.push(`q`),n.push(`1 0 0 1 `+IP(gF.internal.getWidth(e)/2)+` `+IP(gF.internal.getHeight(e)/2)+` cm`),n.push(i+` 0 m`),n.push(i+` `+a+` `+a+` `+i+` 0 `+i+` c`),n.push(`-`+a+` `+i+` -`+i+` `+a+` -`+i+` 0 c`),n.push(`-`+i+` -`+a+` -`+a+` -`+i+` 0 -`+i+` c`),n.push(a+` -`+i+` `+i+` -`+a+` `+i+` 0 c`),n.push(`f`),n.push(`Q`),n.push(`0 g`),n.push(`q`),n.push(`1 0 0 1 `+IP(gF.internal.getWidth(e)/2)+` `+IP(gF.internal.getHeight(e)/2)+` cm`),n.push(r+` 0 m`),n.push(r+` `+o+` `+o+` `+r+` 0 `+r+` c`),n.push(`-`+o+` `+r+` -`+r+` `+o+` -`+r+` 0 c`),n.push(`-`+r+` -`+o+` -`+o+` -`+r+` 0 -`+r+` c`),n.push(o+` -`+r+` `+r+` -`+o+` `+r+` 0 c`),n.push(`f`),n.push(`Q`),t.stream=n.join(` `),t},OffPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=[],r=gF.internal.getWidth(e)<=gF.internal.getHeight(e)?gF.internal.getWidth(e)/4:gF.internal.getHeight(e)/4;r=Number((.9*r).toFixed(5));var i=Number((2*r).toFixed(5)),a=Number((i*gF.internal.Bezier_C).toFixed(5));return n.push(`0.749023 g`),n.push(`q`),n.push(`1 0 0 1 `+IP(gF.internal.getWidth(e)/2)+` `+IP(gF.internal.getHeight(e)/2)+` cm`),n.push(i+` 0 m`),n.push(i+` `+a+` `+a+` `+i+` 0 `+i+` c`),n.push(`-`+a+` `+i+` -`+i+` `+a+` -`+i+` 0 c`),n.push(`-`+i+` -`+a+` -`+a+` -`+i+` 0 -`+i+` c`),n.push(a+` -`+i+` `+i+` -`+a+` `+i+` 0 c`),n.push(`f`),n.push(`Q`),t.stream=n.join(` `),t}},Cross:{createAppearanceStream:function(e){var t={D:{Off:gF.RadioButton.Cross.OffPushDown},N:{}};return t.N[e]=gF.RadioButton.Cross.YesNormal,t.D[e]=gF.RadioButton.Cross.YesPushDown,t},getCA:function(){return`8`},YesNormal:function(e){var t=zP(e);t.scope=e.scope;var n=[],r=gF.internal.calculateCross(e);return n.push(`q`),n.push(`1 1 `+FP(gF.internal.getWidth(e)-2)+` `+FP(gF.internal.getHeight(e)-2)+` re`),n.push(`W`),n.push(`n`),n.push(FP(r.x1.x)+` `+FP(r.x1.y)+` m`),n.push(FP(r.x2.x)+` `+FP(r.x2.y)+` l`),n.push(FP(r.x4.x)+` `+FP(r.x4.y)+` m`),n.push(FP(r.x3.x)+` `+FP(r.x3.y)+` l`),n.push(`s`),n.push(`Q`),t.stream=n.join(` `),t},YesPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=gF.internal.calculateCross(e),r=[];return r.push(`0.749023 g`),r.push(`0 0 `+FP(gF.internal.getWidth(e))+` `+FP(gF.internal.getHeight(e))+` re`),r.push(`f`),r.push(`q`),r.push(`1 1 `+FP(gF.internal.getWidth(e)-2)+` `+FP(gF.internal.getHeight(e)-2)+` re`),r.push(`W`),r.push(`n`),r.push(FP(n.x1.x)+` `+FP(n.x1.y)+` m`),r.push(FP(n.x2.x)+` `+FP(n.x2.y)+` l`),r.push(FP(n.x4.x)+` `+FP(n.x4.y)+` m`),r.push(FP(n.x3.x)+` `+FP(n.x3.y)+` l`),r.push(`s`),r.push(`Q`),t.stream=r.join(` `),t},OffPushDown:function(e){var t=zP(e);t.scope=e.scope;var n=[];return n.push(`0.749023 g`),n.push(`0 0 `+FP(gF.internal.getWidth(e))+` `+FP(gF.internal.getHeight(e))+` re`),n.push(`f`),t.stream=n.join(` `),t}}},createDefaultAppearanceStream:function(e){var t=e.scope.internal.getFont(e.fontName,e.fontStyle).id,n=e.scope.__private__.encodeColorString(e.color);return`/`+t+` `+e.fontSize+` Tf `+n}};gF.internal={Bezier_C:.551915024494,calculateCross:function(e){var t=gF.internal.getWidth(e),n=gF.internal.getHeight(e),r=Math.min(t,n);return{x1:{x:(t-r)/2,y:(n-r)/2+r},x2:{x:(t-r)/2+r,y:(n-r)/2},x3:{x:(t-r)/2,y:(n-r)/2},x4:{x:(t-r)/2+r,y:(n-r)/2+r}}}},gF.internal.getWidth=function(e){var t=0;return hD(e)===`object`&&(t=RP(e.Rect[2])),t},gF.internal.getHeight=function(e){var t=0;return hD(e)===`object`&&(t=RP(e.Rect[3])),t};var _F=AP.addField=function(e){if(QP(this,e),!(e instanceof iF))throw Error(`Invalid argument passed to jsPDF.addField.`);var t;return(t=e).scope.internal.acroformPlugin.printedOut&&(t.scope.internal.acroformPlugin.printedOut=!1,t.scope.internal.acroformPlugin.acroFormDictionaryRoot=null),t.scope.internal.acroformPlugin.acroFormDictionaryRoot.Fields.push(t),e.page=e.scope.internal.getCurrentPageInfo().pageNumber,this};AP.AcroFormChoiceField=aF,AP.AcroFormListBox=oF,AP.AcroFormComboBox=sF,AP.AcroFormEditBox=cF,AP.AcroFormButton=lF,AP.AcroFormPushButton=uF,AP.AcroFormRadioButton=dF,AP.AcroFormCheckBox=pF,AP.AcroFormTextField=mF,AP.AcroFormPasswordField=hF,AP.AcroFormAppearance=gF,AP.AcroForm={ChoiceField:aF,ListBox:oF,ComboBox:sF,EditBox:cF,Button:lF,PushButton:uF,RadioButton:dF,CheckBox:pF,TextField:mF,PasswordField:hF,Appearance:gF},kP.AcroForm={ChoiceField:aF,ListBox:oF,ComboBox:sF,EditBox:cF,Button:lF,PushButton:uF,RadioButton:dF,CheckBox:pF,TextField:mF,PasswordField:hF,Appearance:gF},kP.AcroForm;function vF(e){return e.reduce(function(e,t,n){return e[t]=n,e},{})}(function(e){var t=`addImage_`;e.__addimage__={};var n=`UNKNOWN`,r={PNG:[[137,80,78,71]],TIFF:[[77,77,0,42],[73,73,42,0]],JPEG:[[255,216,255,224,void 0,void 0,74,70,73,70,0],[255,216,255,225,void 0,void 0,69,120,105,102,0,0],[255,216,255,219],[255,216,255,238]],JPEG2000:[[0,0,0,12,106,80,32,32]],GIF87a:[[71,73,70,56,55,97]],GIF89a:[[71,73,70,56,57,97]],WEBP:[[82,73,70,70,void 0,void 0,void 0,void 0,87,69,66,80]],BMP:[[66,77],[66,65],[67,73],[67,80],[73,67],[80,84]]},i=e.__addimage__.getImageFileTypeByImageData=function(e,t){var i,a,o,s,c,l=n;if((t||=n)===`RGBA`||e.data!==void 0&&e.data instanceof Uint8ClampedArray&&`height`in e&&`width`in e)return`RGBA`;if(S(e))for(c in r)for(o=r[c],i=0;i>`}),`transparency`in t&&Array.isArray(t.transparency)&&t.transparency.length>0){for(var o=``,s=0,c=t.transparency.length;s>`,m.content=i;var v=m.objId+` 0 R`;i=`<>`,h.content=i,this.internal.write(m.objId,`0 R`,h.objId,`0 R`);break;case`freetext`:r=`/Rect [`+a(n.bounds.x)+` `+o(n.bounds.y)+` `+a(n.bounds.x+n.bounds.w)+` `+o(n.bounds.y+n.bounds.h)+`] `;var y=`font: Helvetica,sans-serif 12.0pt; text-align:left; color:#`+(n.color||`#000000`);i=`<>`,this.internal.write(i);break;case`link`:if(n.options.name){var b=this.annotations._nameMap[n.options.name];n.options.pageNumber=b.page,n.options.top=b.y}else n.options.top||(n.options.top=0);if(r=`/Rect [`+n.finalBounds.x+` `+n.finalBounds.y+` `+n.finalBounds.w+` `+n.finalBounds.h+`] `,i=``,n.options.url)i=`<>`;else if(n.options.pageNumber)switch(i=`<>`,this.internal.write(i))}}this.internal.write(`]`)}}]),e.createAnnotation=function(e){var t=this.internal.getCurrentPageInfo();switch(e.type){case`link`:this.link(e.bounds.x,e.bounds.y,e.bounds.w,e.bounds.h,e);break;case`text`:case`freetext`:t.pageContext.annotations.push(e)}},e.link=function(e,t,n,r,i){var a=this.internal.getCurrentPageInfo(),o=this.internal.getCoordinateString,s=this.internal.getVerticalCoordinateString;a.pageContext.annotations.push({finalBounds:{x:o(e),y:s(t),w:o(e+n),h:s(t+r)},options:i,type:`link`})},e.textWithLink=function(e,t,n,r){var i,a,o=this.getTextWidth(e),s=this.internal.getLineHeight()/this.internal.scaleFactor;if(r.maxWidth!==void 0){a=r.maxWidth;var c=this.splitTextToSize(e,a).length;i=Math.ceil(s*c)}else a=o,i=s;return this.text(e,t,n,r),n+=.2*s,r.align===`center`&&(t-=o/2),r.align===`right`&&(t-=o),this.link(t,n-s,a,i,r),o},e.getTextWidth=function(e){var t=this.internal.getFontSize();return this.getStringUnitWidth(e)*t/this.internal.scaleFactor}}(kP.API),function(e){var t={1569:[65152],1570:[65153,65154],1571:[65155,65156],1572:[65157,65158],1573:[65159,65160],1574:[65161,65162,65163,65164],1575:[65165,65166],1576:[65167,65168,65169,65170],1577:[65171,65172],1578:[65173,65174,65175,65176],1579:[65177,65178,65179,65180],1580:[65181,65182,65183,65184],1581:[65185,65186,65187,65188],1582:[65189,65190,65191,65192],1583:[65193,65194],1584:[65195,65196],1585:[65197,65198],1586:[65199,65200],1587:[65201,65202,65203,65204],1588:[65205,65206,65207,65208],1589:[65209,65210,65211,65212],1590:[65213,65214,65215,65216],1591:[65217,65218,65219,65220],1592:[65221,65222,65223,65224],1593:[65225,65226,65227,65228],1594:[65229,65230,65231,65232],1601:[65233,65234,65235,65236],1602:[65237,65238,65239,65240],1603:[65241,65242,65243,65244],1604:[65245,65246,65247,65248],1605:[65249,65250,65251,65252],1606:[65253,65254,65255,65256],1607:[65257,65258,65259,65260],1608:[65261,65262],1609:[65263,65264,64488,64489],1610:[65265,65266,65267,65268],1649:[64336,64337],1655:[64477],1657:[64358,64359,64360,64361],1658:[64350,64351,64352,64353],1659:[64338,64339,64340,64341],1662:[64342,64343,64344,64345],1663:[64354,64355,64356,64357],1664:[64346,64347,64348,64349],1667:[64374,64375,64376,64377],1668:[64370,64371,64372,64373],1670:[64378,64379,64380,64381],1671:[64382,64383,64384,64385],1672:[64392,64393],1676:[64388,64389],1677:[64386,64387],1678:[64390,64391],1681:[64396,64397],1688:[64394,64395],1700:[64362,64363,64364,64365],1702:[64366,64367,64368,64369],1705:[64398,64399,64400,64401],1709:[64467,64468,64469,64470],1711:[64402,64403,64404,64405],1713:[64410,64411,64412,64413],1715:[64406,64407,64408,64409],1722:[64414,64415],1723:[64416,64417,64418,64419],1726:[64426,64427,64428,64429],1728:[64420,64421],1729:[64422,64423,64424,64425],1733:[64480,64481],1734:[64473,64474],1735:[64471,64472],1736:[64475,64476],1737:[64482,64483],1739:[64478,64479],1740:[64508,64509,64510,64511],1744:[64484,64485,64486,64487],1746:[64430,64431],1747:[64432,64433]},n={65247:{65154:65269,65156:65271,65160:65273,65166:65275},65248:{65154:65270,65156:65272,65160:65274,65166:65276},65165:{65247:{65248:{65258:65010}}},1617:{1612:64606,1613:64607,1614:64608,1615:64609,1616:64610}},r={1612:64606,1613:64607,1614:64608,1615:64609,1616:64610},i=[1570,1571,1573,1575];e.__arabicParser__={};var a=e.__arabicParser__.isInArabicSubstitutionA=function(e){return t[e.charCodeAt(0)]!==void 0},o=e.__arabicParser__.isArabicLetter=function(e){return typeof e==`string`&&/^[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]+$/.test(e)},s=e.__arabicParser__.isArabicEndLetter=function(e){return o(e)&&a(e)&&t[e.charCodeAt(0)].length<=2},c=e.__arabicParser__.isArabicAlfLetter=function(e){return o(e)&&i.indexOf(e.charCodeAt(0))>=0};e.__arabicParser__.arabicLetterHasIsolatedForm=function(e){return o(e)&&a(e)&&t[e.charCodeAt(0)].length>=1};var l=e.__arabicParser__.arabicLetterHasFinalForm=function(e){return o(e)&&a(e)&&t[e.charCodeAt(0)].length>=2};e.__arabicParser__.arabicLetterHasInitialForm=function(e){return o(e)&&a(e)&&t[e.charCodeAt(0)].length>=3};var u=e.__arabicParser__.arabicLetterHasMedialForm=function(e){return o(e)&&a(e)&&t[e.charCodeAt(0)].length==4},d=e.__arabicParser__.resolveLigatures=function(e){var t=0,r=n,i=``,a=0;for(t=0;t>`),this.internal.out(`endobj`)}),this.internal.events.subscribe(`putCatalog`,function(){this.internal.out(`/OpenAction `+t+` 0 R`)})),this},function(e){var t=function(){var e=void 0;Object.defineProperty(this,"pdf",{get:function(){return e},set:function(t){e=t}});var t=150;Object.defineProperty(this,"width",{get:function(){return t},set:function(e){t=isNaN(e)||!1===Number.isInteger(e)||e<0?150:e,this.getContext(`2d`).pageWrapXEnabled&&(this.getContext(`2d`).pageWrapX=t+1)}});var n=300;Object.defineProperty(this,"height",{get:function(){return n},set:function(e){n=isNaN(e)||!1===Number.isInteger(e)||e<0?300:e,this.getContext(`2d`).pageWrapYEnabled&&(this.getContext(`2d`).pageWrapY=n+1)}});var r=[];Object.defineProperty(this,"childNodes",{get:function(){return r},set:function(e){r=e}});var i={};Object.defineProperty(this,"style",{get:function(){return i},set:function(e){i=e}}),Object.defineProperty(this,"parentNode",{})};t.prototype.getContext=function(e,t){var n;if((e||=`2d`)!==`2d`)return null;for(n in t)this.pdf.context2d.hasOwnProperty(n)&&(this.pdf.context2d[n]=t[n]);return this.pdf.context2d._canvas=this,this.pdf.context2d},t.prototype.toDataURL=function(){throw Error(`toDataURL is not implemented.`)},e.events.push([`initialized`,function(){this.canvas=new t,this.canvas.pdf=this}])}(kP.API),function(e){var t={left:0,top:0,bottom:0,right:0},n=!1,r=function(){this.internal.__cell__===void 0&&(this.internal.__cell__={},this.internal.__cell__.padding=3,this.internal.__cell__.headerFunction=void 0,this.internal.__cell__.margins=Object.assign({},t),this.internal.__cell__.margins.width=this.getPageWidth(),i.call(this))},i=function(){this.internal.__cell__.lastCell=new a,this.internal.__cell__.pages=1},a=function(){var e=arguments[0];Object.defineProperty(this,"x",{enumerable:!0,get:function(){return e},set:function(t){e=t}});var t=arguments[1];Object.defineProperty(this,"y",{enumerable:!0,get:function(){return t},set:function(e){t=e}});var n=arguments[2];Object.defineProperty(this,"width",{enumerable:!0,get:function(){return n},set:function(e){n=e}});var r=arguments[3];Object.defineProperty(this,"height",{enumerable:!0,get:function(){return r},set:function(e){r=e}});var i=arguments[4];Object.defineProperty(this,"text",{enumerable:!0,get:function(){return i},set:function(e){i=e}});var a=arguments[5];Object.defineProperty(this,"lineNumber",{enumerable:!0,get:function(){return a},set:function(e){a=e}});var o=arguments[6];return Object.defineProperty(this,"align",{enumerable:!0,get:function(){return o},set:function(e){o=e}}),this};a.prototype.clone=function(){return new a(this.x,this.y,this.width,this.height,this.text,this.lineNumber,this.align)},a.prototype.toArray=function(){return[this.x,this.y,this.width,this.height,this.text,this.lineNumber,this.align]},e.setHeaderFunction=function(e){return r.call(this),this.internal.__cell__.headerFunction=typeof e==`function`?e:void 0,this},e.getTextDimensions=function(e,t){r.call(this);var n=(t||={}).fontSize||this.getFontSize(),i=t.font||this.getFont(),a=t.scaleFactor||this.internal.scaleFactor,o=0,s=0,c=0,l=this;if(!Array.isArray(e)&&typeof e!=`string`){if(typeof e!=`number`)throw Error(`getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings.`);e=String(e)}var u=t.maxWidth;u>0?typeof e==`string`?e=this.splitTextToSize(e,u):Object.prototype.toString.call(e)===`[object Array]`&&(e=e.reduce(function(e,t){return e.concat(l.splitTextToSize(t,u))},[])):e=Array.isArray(e)?e:[e];for(var d=0;dthis.getPageHeight()?(this.cellAddPage(),e.y=s.top,l&&c&&(this.printHeaderRow(e.lineNumber,!0),e.y+=c[0].height)):e.y=i.y+i.height||e.y),e.text[0]!==void 0&&(this.rect(e.x,e.y,e.width,e.height,!0===n?`FD`:void 0),e.align===`right`?this.text(e.text,e.x+e.width-o,e.y+o,{align:`right`,baseline:`top`}):e.align===`center`?this.text(e.text,e.x+e.width/2,e.y+o,{align:`center`,baseline:`top`,maxWidth:e.width-o-o}):this.text(e.text,e.x+o,e.y+o,{align:`left`,baseline:`top`,maxWidth:e.width-o-o})),this.internal.__cell__.lastCell=e,this};e.table=function(e,n,c,l,u){if(r.call(this),!c)throw Error(`No data for PDF table.`);var d,f,p,m,h=[],g=[],_=[],v={},y={},b=[],x=[],S=(u||={}).autoSize||!1,C=!1!==u.printHeaders,w=u.css&&u.css[`font-size`]!==void 0?16*u.css[`font-size`]:u.fontSize||12,T=u.margins||Object.assign({width:this.getPageWidth()},t),E=typeof u.padding==`number`?u.padding:3,D=u.headerBackgroundColor||`#c8c8c8`,O=u.headerTextColor||`#000`;if(i.call(this),this.internal.__cell__.printHeaders=C,this.internal.__cell__.margins=T,this.internal.__cell__.table_font_size=w,this.internal.__cell__.padding=E,this.internal.__cell__.headerBackgroundColor=D,this.internal.__cell__.headerTextColor=O,this.setFontSize(w),l==null)g=h=Object.keys(c[0]),_=h.map(function(){return`left`});else if(Array.isArray(l)&&hD(l[0])===`object`)for(h=l.map(function(e){return e.name}),g=l.map(function(e){return e.prompt||e.name||``}),_=l.map(function(e){return e.align||`left`}),d=0;d0&&this.setTableHeaderRow(c),this.setFont(void 0,`normal`),n=!1}}(kP.API);var yF={italic:[`italic`,`oblique`,`normal`],oblique:[`oblique`,`italic`,`normal`],normal:[`normal`,`oblique`,`italic`]},bF=[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`],xF=vF(bF),SF=[100,200,300,400,500,600,700,800,900],CF=vF(SF);function wF(e){var t=e.family.replace(/"|'/g,``).toLowerCase(),n=function(e){return yF[e||=`normal`]?e:`normal`}(e.style),r=function(e){return e?typeof e==`number`?e>=100&&e<=900&&e%100==0?e:400:/^\d00$/.test(e)?parseInt(e):e===`bold`?700:400:400}(e.weight),i=function(e){return typeof xF[e||=`normal`]==`number`?e:`normal`}(e.stretch);return{family:t,style:n,weight:r,stretch:i,src:e.src||[],ref:e.ref||{name:t,style:[i,n,r].join(` `)}}}function TF(e,t,n,r){var i;for(i=n;i>=0&&i=0&&i>>1)&255}return i}function UF(e,t,n){var r=e.length,i=[];i[0]=4;for(var a=0;a>a&o}function qF(e,t,n,r){var i=n*r,a=Math.floor(i/8),o=16-(i-8*a+r),s=(1<>8&255;e.setUint8(t,r)}})(e,a,JF(e,a)&~(s<>7,o=1<<1+(7&i);e[t++],e[t++];var s=null,c=null;a&&(s=t,c=o,t+=3*o);var l=!0,u=[],d=0,f=null,p=0,m=null;for(this.width=n,this.height=r;l&&t=0))throw Error(`Invalid block size`);if(D===0)break;t+=D}break;case 249:if(e[t++]!==4||e[t+4]!==0)throw Error(`Invalid graphics extension block.`);var h=e[t++];d=e[t++]|e[t++]<<8,f=e[t++],1&h||(f=null),p=h>>2&7,t++;break;case 254:for(;;){if(!((D=e[t++])>=0))throw Error(`Invalid block size`);if(D===0)break;t+=D}break;default:throw Error(`Unknown graphic control label: 0x`+e[t-1].toString(16))}break;case 44:var g=e[t++]|e[t++]<<8,_=e[t++]|e[t++]<<8,v=e[t++]|e[t++]<<8,y=e[t++]|e[t++]<<8,b=e[t++],x=b>>6&1,S=1<<1+(7&b),C=s,w=c,T=!1;b>>7&&(T=!0,C=t,w=S,t+=3*S);var E=t;for(t++;;){var D;if(!((D=e[t++])>=0))throw Error(`Invalid block size`);if(D===0)break;t+=D}u.push({x:g,y:_,width:v,height:y,has_local_palette:T,palette_offset:C,palette_size:w,data_offset:E,data_length:t-E,transparent_index:f,interlaced:!!x,delay:d,disposal:p});break;case 59:l=!1;break;default:throw Error(`Unknown gif block: 0x`+e[t-1].toString(16))}this.numFrames=function(){return u.length},this.loopCount=function(){return m},this.frameInfo=function(e){if(e<0||e>=u.length)throw Error(`Frame index out of range.`);return u[e]},this.decodeAndBlitFrameBGRA=function(t,r){var i=this.frameInfo(t),a=i.width*i.height;if(a>536870912)throw Error(`Image dimensions exceed 512MB, which is too large.`);var o=new Uint8Array(a);XF(e,i.data_offset,o,a);var s=i.palette_offset,c=i.transparent_index;c===null&&(c=256);var l=i.width,u=n-l,d=l,f=4*(i.y*n+i.x),p=4*((i.y+i.height)*n+i.x),m=f,h=4*u;!0===i.interlaced&&(h+=4*n*7);for(var g=8,_=0,v=o.length;_=p&&(h=4*u+4*n*(g-1),m=f+(l+u)*(g<<1),g>>=1)),y===c)m+=4;else{var b=e[s+3*y],x=e[s+3*y+1],S=e[s+3*y+2];r[m++]=S,r[m++]=x,r[m++]=b,r[m++]=255}--d}},this.decodeAndBlitFrameRGBA=function(t,r){var i=this.frameInfo(t),a=i.width*i.height;if(a>536870912)throw Error(`Image dimensions exceed 512MB, which is too large.`);var o=new Uint8Array(a);XF(e,i.data_offset,o,a);var s=i.palette_offset,c=i.transparent_index;c===null&&(c=256);var l=i.width,u=n-l,d=l,f=4*(i.y*n+i.x),p=4*((i.y+i.height)*n+i.x),m=f,h=4*u;!0===i.interlaced&&(h+=4*n*7);for(var g=8,_=0,v=o.length;_=p&&(h=4*u+4*n*(g-1),m=f+(l+u)*(g<<1),g>>=1)),y===c)m+=4;else{var b=e[s+3*y],x=e[s+3*y+1],S=e[s+3*y+2];r[m++]=b,r[m++]=x,r[m++]=S,r[m++]=255}--d}}}function XF(e,t,n,r){for(var i=e[t++],a=1<>=c,u-=c,g!==a){if(g===o)break;for(var _=ga;)y=m[y]>>8,++v;var b=y;if(f+v+(_===g?0:1)>r)return void QN.log(`Warning, gif stream longer than expected.`);n[f++]=b;var x=f+=v;for(_!==g&&(n[f++]=b),y=_;v--;)y=m[y],n[--x]=255&y,y>>=8;h!==null&&s<4096&&(m[s++]=h<<8|b,s>=l+1&&c<12&&(++c,l=l<<1|1)),h=g}else s=o+1,l=(1<<(c=i+1))-1,h=null}return f!==r&&QN.log(`Warning, gif stream shorter than expected.`),n}function ZF(e){var t,n,r,i,a,o=Math.floor,s=Array(64),c=Array(64),l=Array(64),u=Array(64),d=Array(65535),f=Array(65535),p=Array(64),m=Array(64),h=[],g=0,_=7,v=Array(64),y=Array(64),b=Array(64),x=Array(256),S=Array(2048),C=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],w=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],T=[0,1,2,3,4,5,6,7,8,9,10,11],E=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],D=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],O=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],k=[0,1,2,3,4,5,6,7,8,9,10,11],A=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],j=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function M(e,t){for(var n=0,r=0,i=[],a=1;a<=16;a++){for(var o=1;o<=e[a];o++)i[t[r]]=[],i[t[r]][0]=n,i[t[r]][1]=a,r++,n++;n*=2}return i}function N(e){for(var t=e[0],n=e[1]-1;n>=0;)t&1<>8&255),P(255&e)}function I(e,t,n,r,i){for(var a,o=i[0],s=i[240],c=function(e,t){var n,r,i,a,o,s,c,l,u,d,f=0;for(u=0;u<8;++u){n=e[f],r=e[f+1],i=e[f+2],a=e[f+3],o=e[f+4],s=e[f+5],c=e[f+6];var m=n+(l=e[f+7]),h=n-l,g=r+c,_=r-c,v=i+s,y=i-s,b=a+o,x=a-o,S=m+b,C=m-b,w=g+v,T=g-v;e[f]=S+w,e[f+4]=S-w;var E=.707106781*(T+C);e[f+2]=C+E,e[f+6]=C-E;var D=.382683433*((S=x+y)-(T=_+h)),O=.5411961*S+D,k=1.306562965*T+D,A=.707106781*(w=y+_),j=h+A,M=h-A;e[f+5]=M+O,e[f+3]=M-O,e[f+1]=j+k,e[f+7]=j-k,f+=8}for(f=0,u=0;u<8;++u){n=e[f],r=e[f+8],i=e[f+16],a=e[f+24],o=e[f+32],s=e[f+40],c=e[f+48];var N=n+(l=e[f+56]),P=n-l,F=r+c,I=r-c,L=i+s,ee=i-s,R=a+o,te=a-o,z=N+R,B=N-R,V=F+L,ne=F-L;e[f]=z+V,e[f+32]=z-V;var re=.707106781*(ne+B);e[f+16]=B+re,e[f+48]=B-re;var ie=.382683433*((z=te+ee)-(ne=I+P)),ae=.5411961*z+ie,oe=1.306562965*ne+ie,se=.707106781*(V=ee+I),ce=P+se,H=P-se;e[f+40]=H+ae,e[f+24]=H-ae,e[f+8]=ce+oe,e[f+56]=ce-oe,f++}for(u=0;u<64;++u)d=e[u]*t[u],p[u]=d>0?d+.5|0:d-.5|0;return p}(e,t),l=0;l<64;++l)m[C[l]]=c[l];var u=m[0]-n;n=m[0],u==0?N(r[0]):(N(r[f[a=32767+u]]),N(d[a]));for(var h=63;h>0&&m[h]==0;)h--;if(h==0)return N(o),n;for(var g,_=1;_<=h;){for(var v=_;m[_]==0&&_<=h;)++_;var y=_-v;if(y>=16){g=y>>4;for(var b=1;b<=g;++b)N(s);y&=15}a=32767+m[_],N(i[(y<<4)+f[a]]),N(d[a]),_++}return h!=63&&N(o),n}function L(e){e=Math.min(Math.max(e,1),100),a!=e&&(function(e){for(var t=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],n=0;n<64;n++){var r=o((t[n]*e+50)/100);r=Math.min(Math.max(r,1),255),s[C[n]]=r}for(var i=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],a=0;a<64;a++){var d=o((i[a]*e+50)/100);d=Math.min(Math.max(d,1),255),c[C[a]]=d}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],p=0,m=0;m<8;m++)for(var h=0;h<8;h++)l[p]=1/(s[C[p]]*f[m]*f[h]*8),u[p]=1/(c[C[p]]*f[m]*f[h]*8),p++}(Math.floor(e<50?5e3/e:200-2*e)),a=e)}this.encode=function(e,a){a&&L(a),h=[],g=0,_=7,F(65496),F(65504),F(16),P(74),P(70),P(73),P(70),P(0),P(1),P(1),P(0),F(1),F(1),P(0),P(0),function(){F(65499),F(132),P(0);for(var e=0;e<64;e++)P(s[e]);P(1);for(var t=0;t<64;t++)P(c[t])}(),function(e,t){F(65472),F(17),P(8),F(t),F(e),P(3),P(1),P(17),P(0),P(2),P(17),P(1),P(3),P(17),P(1)}(e.width,e.height),function(){F(65476),F(418),P(0);for(var e=0;e<16;e++)P(w[e+1]);for(var t=0;t<=11;t++)P(T[t]);P(16);for(var n=0;n<16;n++)P(E[n+1]);for(var r=0;r<=161;r++)P(D[r]);P(1);for(var i=0;i<16;i++)P(O[i+1]);for(var a=0;a<=11;a++)P(k[a]);P(17);for(var o=0;o<16;o++)P(A[o+1]);for(var s=0;s<=161;s++)P(j[s])}(),F(65498),F(12),P(3),P(1),P(0),P(2),P(17),P(3),P(17),P(0),P(63),P(0);var o=0,d=0,f=0;g=0,_=7,this.encode.displayName=`_encode_`;for(var p,m,x,C,M,ee,R,te,z,B=e.data,V=e.width,ne=e.height,re=4*V,ie=0;ie>3)*re+(R=4*(7&z)),ie+te>=ne&&(ee-=re*(ie+1+te-ne)),p+R>=re&&(ee-=p+R-re+4),m=B[ee++],x=B[ee++],C=B[ee++],v[z]=(S[m]+S[x+256|0]+S[C+512|0]>>16)-128,y[z]=(S[m+768|0]+S[x+1024|0]+S[C+1280|0]>>16)-128,b[z]=(S[m+1280|0]+S[x+1536|0]+S[C+1792|0]>>16)-128;o=I(v,l,o,t,r),d=I(y,u,d,n,i),f=I(b,u,f,n,i),p+=32}ie+=8}if(_>=0){var ae=[];ae[1]=_+1,ae[0]=(1<<_+1)-1,N(ae)}return F(65497),new Uint8Array(h)},e||=50,function(){for(var e=String.fromCharCode,t=0;t<256;t++)x[t]=e(t)}(),t=M(w,T),n=M(O,k),r=M(E,D),i=M(A,j),function(){for(var e=1,t=2,n=1;n<=15;n++){for(var r=e;rr;r++)if(e[t+r]!=n.charCodeAt(r))return!0;return!1}function r(e,t,n,r,i){for(var a=0;ar+1?[]:new t),!(i.length>>0;e&n;)n>>>=1;return n?(e&n-1)+n:e}function l(e,n,r,i,a){t(!(i%r));do e[n+(i-=r)]=a;while(0=o),512>=o)var s=a(512);else if((s=a(o))==null)return 0;return function(e,n,r,i,o,s){var u,f,p=n,m=1<u;++u){if(h[u]>1<(S-=h[u]))return 0;for(;0=u;++u,o<<=1){if(x+=S<<=1,0>(S-=h[u]))return 0;for(;0v&&!(0>=(_-=h[v]));)++v,_<<=1;m+=C=1<<(_=v-r),e[n+(v=b&y)].g=_+r,e[n+v].value=p-n-v}i.g=u-r,i.value=s[f++],l(e,p+(b>>r),o,C,i),b=c(b,u)}}return x==2*g[15]-1?m:0}(e,n,r,i,o,s)}function d(){this.value=this.g=0}function f(){this.value=this.g=0}function p(){this.G=o(5,d),this.H=a(5),this.jc=this.Qb=this.qb=this.nd=0,this.pd=o(Wn,f)}function m(e,n,r,i){t(e!=null),t(n!=null),t(2147483648>i),e.Ca=254,e.I=0,e.b=-8,e.Ka=0,e.oa=n,e.pa=r,e.Jd=n,e.Yc=r+i,e.Zc=4<=i?r+i-4+1:r,E(e)}function h(e,t){for(var n=0;0i),e.Sb=i,e.Ra=0,e.u=0,e.h=0,4>>=8,e.Ra+=e.oa[e.pa+e.bb]<>>0,++e.bb,e.u-=8;C(e)&&(e.h=1,e.u=0)}function y(e,n){if(t(0<=n),!e.h&&n<=Kn){var r=S(e)&Gn[n];return e.u+=n,v(e),r}return e.h=1,e.u=0}function b(){this.b=this.Ca=this.I=0,this.oa=[],this.pa=0,this.Jd=[],this.Yc=0,this.Zc=[],this.Ka=0}function x(){this.Ra=0,this.oa=[],this.h=this.u=this.bb=this.Sb=this.pa=0}function S(e){return e.Ra>>>(e.u&qn-1)>>>0}function C(e){return t(e.bb<=e.Sb),e.h||e.bb==e.Sb&&e.u>qn}function w(e,t){e.u=t,e.h=C(e)}function T(e){e.u>=Jn&&(t(e.u>=Jn),v(e))}function E(e){t(e!=null&&e.oa!=null),e.pa>>0,e.b+=8):(t(e!=null&&e.oa!=null),e.pae.b&&E(e);var r=e.b,i=n*t>>>8,a=(e.I>>>r>i)+0;for(a?(n-=i,e.I-=i+1<>>0):n=i+1,r=n,i=0;256<=r;)i+=8,r>>=8;return r=7^i+Yn[r],e.b-=r,e.Ca=(n<>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=255&n}function A(e,t){return e[t+0]|e[t+1]<<8}function j(e,t){return A(e,t)|e[t+2]<<16}function M(e,t){return A(e,t)|A(e,t+2)<<16}function N(e,n){var r=1<=a||0>=o?0:(r[0]=a,i[0]=o,1)}function L(e,t){return e+(1<>>t}function ee(e,t){return((4278255360&e)+(4278255360&t)>>>0&4278255360)+((16711935&e)+(16711935&t)>>>0&16711935)>>>0}function R(t,n){e[n]=function(n,r,i,a,o,s,c){var l;for(l=0;l>>1)+(e&t)>>>0}function B(e){return 0<=e&&256>e?e:0>e?0:255>1))}function ne(e,t,n){return Math.abs(t-n)-Math.abs(e-n)}function re(e,t,n,r,i,a,o){for(r=a[o-1],n=0;n>8&255,c=16711935&(c=(c=16711935&o)+((s<<16)+s));r[i+a]=(4278255360&o)+c>>>0}}function ae(e,t){t.jd=255&e,t.hd=e>>8&255,t.ud=e>>16&255}function oe(e,t,n,r,i,a){var o;for(o=0;o>>8,l=s,u=255&(u=(u=s>>>16)+((e.jd<<24>>24)*(c<<24>>24)>>>5));l=255&(l=(l+=(e.hd<<24>>24)*(c<<24>>24)>>>5)+((e.ud<<24>>24)*(u<<24>>24)>>>5)),i[a+o]=(4278255360&s)+(u<<16)+l}}function se(t,n,r,i,a){e[n]=function(e,t,n,r,o,s,c,l,u){for(r=c;r>t.b,f=t.Ea,p=t.K[0],m=t.w;if(8>d)for(t=(1<>=d}else e[`VP8LMapColor`+r](s,c,p,m,l,u,n,o,f)}}function ce(e,t,n,r,i){for(n=t+n;t>16&255,r[i++]=a>>8&255,r[i++]=255&a}}function H(e,t,n,r,i){for(n=t+n;t>16&255,r[i++]=a>>8&255,r[i++]=255&a,r[i++]=a>>24&255}}function le(e,t,n,r,i){for(n=t+n;t>16&240|o>>12&15,o=240&o|o>>28&15;r[i++]=a,r[i++]=o}}function ue(e,t,n,r,i){for(n=t+n;t>16&248|o>>13&7,o=o>>5&224|o>>3&31;r[i++]=a,r[i++]=o}}function de(e,t,n,r,i){for(n=t+n;t>8&255,r[i++]=a>>16&255}}function fe(e,t,n,i,a,o){if(o==0)for(n=t+n;t>24|o[1]>>8&65280|o[2]<<8&16711680|o[3]<<24)>>>0),a+=32;else r(i,a,e,t,n)}function pe(t,n){e[n][0]=e[t+`0`],e[n][1]=e[t+`1`],e[n][2]=e[t+`2`],e[n][3]=e[t+`3`],e[n][4]=e[t+`4`],e[n][5]=e[t+`5`],e[n][6]=e[t+`6`],e[n][7]=e[t+`7`],e[n][8]=e[t+`8`],e[n][9]=e[t+`9`],e[n][10]=e[t+`10`],e[n][11]=e[t+`11`],e[n][12]=e[t+`12`],e[n][13]=e[t+`13`],e[n][14]=e[t+`0`],e[n][15]=e[t+`0`]}function me(e){return e==Kr||e==qr||e==Jr||e==Yr}function he(){this.eb=[],this.size=this.A=this.fb=0}function ge(){this.y=[],this.f=[],this.ea=[],this.F=[],this.Tc=this.Ed=this.Cd=this.Fd=this.lb=this.Db=this.Ab=this.fa=this.J=this.W=this.N=this.O=0}function _e(){this.Rd=this.height=this.width=this.S=0,this.f={},this.f.RGBA=new he,this.f.kb=new ge,this.sd=null}function ve(){this.width=[0],this.height=[0],this.Pd=[0],this.Qd=[0],this.format=[0]}function ye(){this.Id=this.fd=this.Md=this.hb=this.ib=this.da=this.bd=this.cd=this.j=this.v=this.Da=this.Sd=this.ob=0}function be(e){return alert(`todo:WebPSamplerProcessPlane`),e.T}function xe(e,t){var n=e.T,i=t.ba.f.RGBA,a=i.eb,o=i.fb+e.ka*i.A,s=bi[t.ba.S],c=e.y,l=e.O,u=e.f,d=e.N,f=e.ea,p=e.W,m=t.cc,h=t.dc,g=t.Mc,_=t.Nc,v=e.ka,y=e.ka+e.T,b=e.U,x=b+1>>1;for(v==0?s(c,l,null,null,u,d,f,p,u,d,f,p,a,o,null,null,b):(s(t.ec,t.fc,c,l,m,h,g,_,u,d,f,p,a,o-i.A,a,o,b),++n);v+2n,i=n==Br||n==Hr||n==Ur||n==Wr||n==12||me(n);if(t.memory=null,t.Ib=null,t.Jb=null,t.Nd=null,!Vn(t.Oa,e,i?11:12))return 0;if(i&&me(n)&&En(),e.da)alert(`todo:use_scaling`);else{if(r){if(t.Ib=be,e.Kb){if(n=e.U+1>>1,t.memory=a(e.U+2*n),t.memory==null)return 0;t.ec=t.memory,t.fc=0,t.cc=t.ec,t.dc=t.fc+e.U,t.Mc=t.cc,t.Nc=t.dc+n,t.Ib=xe,En()}}else alert(`todo:EmitYUV`);i&&(t.Jb=Se,r&&wn())}if(r&&!Pi){for(e=0;256>e;++e)Fi[e]=89858*(e-128)+ki>>Oi,Ri[e]=-22014*(e-128)+ki,Li[e]=-45773*(e-128),Ii[e]=113618*(e-128)+ki>>Oi;for(e=Ai;e>Oi,zi[e-Ai]=et(t,255),Bi[e-Ai]=et(t+8>>4,15);Pi=1}return 1}function Ce(e){var n=e.ma,r=e.U,i=e.T;return t(!(1&e.ka)),0>=r||0>=i?0:(r=n.Ib(e,n),n.Jb!=null&&n.Jb(e,n,r),n.Dc+=r,1)}function we(e){e.ma.memory=null}function Te(e,t,n,r){return y(e,8)==47?(t[0]=y(e,14)+1,n[0]=y(e,14)+1,r[0]=y(e,1),y(e,3)==0?!e.h:0):0}function W(e,t){if(4>e)return e+1;var n=e-2>>1;return(2+(1&e)<>4)*e+(8-(15&n)))?n:1;var n}function De(e,t,n){var r=S(n),i=e[t+=255&r].g-8;return 0>>0,t(8>=r.g),e.g}function ke(e,n,r){var i=e.xc;return t((n=i==0?0:e.vc[e.md*(r>>i)+(n>>i)])>E.b)*w;_x&&(A=x),(0,rr[D[O++]>>8&15])(m,h+ +k,y,b+k-x,A-k,y,b+k),k=A}h+=x,b+=x,++_&C||(E+=w)}p!=d.nc&&r(u,l-g,u,l+(p-f-1)*g,g);break;case 1:for(g=m,v=h,x=(m=d.Ea)-(b=m&~(y=(h=1<>d.b)*_;f=a),0o.o&&(i=o.o),r=i?r=0:(a[0]+=4*o.v,o.ka=r-o.j,o.U=o.va-o.v,o.T=i-r,r=1),r){if(c=c[0],11>(r=e.ca).S){var d=r.f.RGBA,f=(i=r.S,a=o.U,o=o.T,u=d.eb,d.A),p=o;for(d=d.fb+e.Ma*d.A;0i){var a=e.l.width,o=r.ca,s=r.tb+a*i,c=e.V,l=e.Ba+e.c*i,u=e.gc;t(e.ab==1),t(u[0].hc==3),tr(u[0],i,n,c,l,o,s),Ne(r,i,n,o,s,a)}e.C=e.Ma=n}function Fe(e,n,r,i,a,o,s){var c=e.$/i,l=e.$%i,u=e.m,d=e.s,f=r+e.$,p=f;a=r+i*a;var m=r+i*o,h=280+d.ua,g=e.Pb?c:16777216,_=0=g){var E=f-r;t((g=e).Pb),g.wd=g.m,g.xd=E,0O.g?(w(x,x.u+O.g),E[D]=O.value,x=0):(w(x,x.u+O.g-256),t(256<=O.value),x=O.value),x==0&&(b=!0)}else x=De(y.G[0],y.H[0],u);if(u.h)break;if(b||256>x){if(!b)if(y.nd)n[f]=(y.qb|x<<8)>>>0;else{if(T(u),b=De(y.G[1],y.H[1],u),T(u),E=De(y.G[2],y.H[2],u),D=De(y.G[3],y.H[3],u),u.h)break;n[f]=(D<<24|b<<16|x<<8|E)>>>0}if(b=!1,++f,++l>=i&&(l=0,++c,s!=null&&c<=o&&!(c%16)&&s(e,c),_!=null))for(;p>>_.Mb]=x}else if(280>x){if(x=W(x-256,u),E=De(y.G[4],y.H[4],u),T(u),E=Ee(i,E=W(E,u)),u.h)break;if(f-r=i;)l-=i,++c,s!=null&&c<=o&&!(c%16)&&s(e,c);if(t(f<=a),l&v&&(y=ke(d,l,c)),_!=null)for(;p>>_.Mb]=x}else{if(!(x>>_.Mb]=x;x=f,t(!(b>>>(E=_).Xa)),n[x]=E.X[b],b=!0}b||t(u.h==C(u))}if(e.Pb&&u.h&&fo?o:c),e.a=0,e.$=f-r}return 1}return e.a=3,0}function Ie(e){t(e!=null),e.vc=null,e.yc=null,e.Ya=null;var n=e.Wa;n!=null&&(n.X=null),e.vb=null,t(e!=null)}function Le(){var t=new mn;return t==null?null:(t.a=0,t.xb=vi,pe(`Predictor`,`VP8LPredictors`),pe(`Predictor`,`VP8LPredictors_C`),pe(`PredictorAdd`,`VP8LPredictorsAdd`),pe(`PredictorAdd`,`VP8LPredictorsAdd_C`),Qn=ie,J=oe,ir=ce,ar=H,or=le,sr=ue,cr=de,e.VP8LMapColor32b=er,e.VP8LMapColor8b=nr,t)}function Re(e,n,r,s,c){var l=1,f=[e],m=[n],h=s.m,g=s.s,_=null,v=0;t:for(;;){if(r)for(;l&&y(h,1);){var b=f,x=m,C=s,E=1,D=C.m,O=C.gc[C.ab],k=y(D,2);if(C.Oc&1<=C.ab),k){case 0:case 1:O.b=y(D,3)+2,E=Re(L(O.Ea,O.b),L(O.nc,O.b),0,C,O.K),O.K=O.K[0];break;case 3:var A,j=y(D,8)+1,M=16>I.b),te=a(R);if(te==null)A=0;else{var z=I.K[0],B=I.w;for(te[0]=I.K[0][0],P=1;P<1*F;++P)te[P]=ee(z[B+P],te[P-1]);for(;P<4*R;++P)te[P]=0;I.K[0]=null,I.K[0]=te,A=1}}E=A;break;case 2:break;default:t(0)}l=E}}if(f=f[0],m=m[0],l&&y(h,1)&&!(l=1<=(v=y(h,4))&&11>=v)){s.a=3;break t}var V;if(V=l)e:{var ne,re,ie,ae=s,oe=f,se=m,ce=v,H=r,le=ae.m,ue=ae.s,de=[null],fe=1,pe=0,me=ni[ce];r:for(;;){if(H&&y(le,1)){var he=y(le,3)+2,ge=L(oe,he),_e=L(se,he),ve=ge*_e;if(!Re(ge,_e,0,ae,de))break r;for(de=de[0],ue.xc=he,ne=0;ne>8&65535;de[ne]=ye,ye>=fe&&(fe=ye+1)}}if(le.h)break r;for(re=0;5>re;++re){var be=Qr[re];!re&&0=Se),Ce=U;var we=a(pe);if(Ce==null||we==null||xe==null){ae.a=1;break r}var Te=xe;for(ne=ie=0;nere;++re){be=Qr[re],Ee[re]=Te,De[re]=ie,!re&&0et)break i}else Xe=et;for(Ze=0;Zest)tt[Ze++]=st,st!=0&&(it=st);else{var ct=st==16,lt=st-16,ut=Zr[lt],dt=y(rt,Xr[lt])+ut;if(Ze+dt>et)break i;for(var ft=ct?it:0;0=re){var pt,mt=we[0];for(pt=1;ptmt&&(mt=we[pt]);je+=mt}}if(W.nd=Ae,W.Qb=0,Ae&&(W.qb=(Ee[3][De[3]+0].value<<24|Ee[1][De[1]+0].value<<16|Ee[2][De[2]+0].value)>>>0,ke==0&&256>Ee[0][De[0]+0].value&&(W.Qb=1,W.qb+=Ee[0][De[0]+0].value<<8)),W.jc=!W.Qb&&6>je,W.jc){var ht,gt=W;for(ht=0;ht>=Oe(yt,8,vt),_t>>=Oe(gt.G[1][gt.H[1]+_t],16,vt),_t>>=Oe(gt.G[2][gt.H[2]+_t],0,vt),Oe(gt.G[3][gt.H[3]+_t],24,vt))}}}ue.vc=de,ue.Wb=fe,ue.Ya=Ce,ue.yc=xe,V=1;break e}V=0}if(!(l=V)){s.a=3;break t}if(0n+1?[]:0),!(r.lengthe?0:e>t?t:e}function tt(){this.T=this.U=this.ka=this.height=this.width=0,this.y=[],this.f=[],this.ea=[],this.Rc=this.fa=this.W=this.N=this.O=0,this.ma=`void`,this.put=`VP8IoPutHook`,this.ac=`VP8IoSetupHook`,this.bc=`VP8IoTeardownHook`,this.ha=this.Kb=0,this.data=[],this.hb=this.ib=this.da=this.o=this.j=this.va=this.v=this.Da=this.ob=this.w=0,this.F=[],this.J=0}function nt(){var e=new $e;return e!=null&&(e.a=0,e.sc=`OK`,e.cb=0,e.Xb=0,oi||=ot),e}function rt(e,t,n){return e.a==0&&(e.a=t,e.sc=n,e.cb=0),0}function it(e,t,n){return 3<=n&&e[t+0]==157&&e[t+1]==1&&e[t+2]==42}function at(e,n){if(e==null)return 0;if(e.a=0,e.sc=`OK`,n==null)return rt(e,2,`null VP8Io passed to VP8GetHeaders()`);var r=n.data,a=n.w,o=n.ha;if(4>o)return rt(e,7,`Truncated header.`);var s=r[a+0]|r[a+1]<<8|r[a+2]<<16,c=e.Od;if(c.Rb=!(1&s),c.td=s>>1&7,c.yd=s>>4&1,c.ub=s>>5,3o)return rt(e,7,`cannot parse picture header`);if(!it(r,a,o))return rt(e,3,`Bad code word`);l.c=16383&(r[a+4]<<8|r[a+3]),l.Td=r[a+4]>>6,l.i=16383&(r[a+6]<<8|r[a+5]),l.Ud=r[a+6]>>6,a+=7,o-=7,e.za=l.c+15>>4,e.Ub=l.i+15>>4,n.width=l.c,n.height=l.i,n.Da=0,n.j=0,n.v=0,n.va=n.width,n.o=n.height,n.da=0,n.ib=n.width,n.hb=n.height,n.U=n.width,n.T=n.height,i((s=e.Pa).jb,0,255,s.jb.length),t((s=e.Qa)!=null),s.Cb=0,s.Bb=0,s.Fb=1,i(s.Zb,0,0,s.Zb.length),i(s.Lb,0,0,s.Lb)}if(c.ub>o)return rt(e,7,`bad partition length`);m(s=e.m,r,a,c.ub),a+=c.ub,o-=c.ub,c.Rb&&(l.Ld=D(s),l.Kd=D(s)),l=e.Qa;var u,d=e.Pa;if(t(s!=null),t(l!=null),l.Cb=D(s),l.Cb){if(l.Bb=D(s),D(s)){for(l.Fb=D(s),u=0;4>u;++u)l.Zb[u]=D(s)?g(s,7):0;for(u=0;4>u;++u)l.Lb[u]=D(s)?g(s,6):0}if(l.Bb)for(u=0;3>u;++u)d.jb[u]=D(s)?h(s,8):255}else l.Bb=0;if(s.Ka)return rt(e,3,`cannot parse segment header`);if((l=e.ed).zd=D(s),l.Tb=h(s,6),l.wb=h(s,3),l.Pc=D(s),l.Pc&&D(s)){for(d=0;4>d;++d)D(s)&&(l.vd[d]=g(s,6));for(d=0;4>d;++d)D(s)&&(l.od[d]=g(s,6))}if(e.L=l.Tb==0?0:l.zd?1:2,s.Ka)return rt(e,3,`cannot parse filter header`);var f=o;if(o=u=a,a=u+f,l=f,e.Xb=(1<l&&(p=l),m(e.Jc[+f],r,u,p),u+=p,l-=p,o+=3}m(e.Jc[+d],r,u,l),r=up;++p){if(f.Cb){var _=f.Zb[p];f.Fb||(_+=r)}else{if(0>16,8>v.Eb[1]&&(v.Eb[1]=8),v.Qc[0]=ii[et(_+d,117)],v.Qc[1]=ai[et(_+u,127)],v.lc=_+u}if(!c.Rb)return rt(e,4,`Not a key frame.`);for(D(s),c=e.Pa,r=0;4>r;++r){for(o=0;8>o;++o)for(a=0;3>a;++a)for(l=0;11>l;++l)d=O(s,fi[r][o][a][l])?h(s,8):ui[r][o][a][l],c.Wc[r][o].Yb[a][l]=d;for(o=0;17>o;++o)c.Xc[r][o]=c.Wc[r][pi[o]]}return e.kc=D(s),e.kc&&(e.Bd=h(s,8)),e.cb=1}function ot(e,t,n,r,i,a,o){var s=t[i].Yb[n];for(n=0;16>i;++i){if(!O(e,s[n+0]))return i;for(;!O(e,s[n+1]);)if(s=t[++i].Yb[0],n=0,i==16)return 16;var c=t[i+1].Yb;if(O(e,s[n+2])){var l=e,u=0;if(O(l,(f=s)[(d=n)+3]))if(O(l,f[d+6])){for(s=0,d=2*(u=O(l,f[d+8]))+(f=O(l,f[d+9+u])),u=0,f=si[d];f[s];++s)u+=u+O(l,f[s]);u+=3+(8<(l=e).b&&E(l);var d,f=l.b,p=(d=l.Ca>>1)-(l.I>>f)>>31;--l.b,l.Ca+=p,l.Ca|=1,l.I-=(d+1&p)<>3),e[t+n+32*r]=-256&i?0>i?0:255:i}function lt(e,t,n,r,i,a){ct(e,t,0,n,r+i),ct(e,t,1,n,r+a),ct(e,t,2,n,r-a),ct(e,t,3,n,r-i)}function ut(e){return(20091*e>>16)+e}function dt(e,t,n,r){var i,o=0,s=a(16);for(i=0;4>i;++i){var c=e[t+0]+e[t+8],l=e[t+0]-e[t+8],u=(35468*e[t+4]>>16)-ut(e[t+12]),d=ut(e[t+4])+(35468*e[t+12]>>16);s[o+0]=c+d,s[o+1]=l+u,s[o+2]=l-u,s[o+3]=c-d,o+=4,t++}for(i=o=0;4>i;++i)c=(e=s[o+0]+4)+s[o+8],l=e-s[o+8],u=(35468*s[o+4]>>16)-ut(s[o+12]),ct(n,r,0,0,c+(d=ut(s[o+4])+(35468*s[o+12]>>16))),ct(n,r,1,0,l+u),ct(n,r,2,0,l-u),ct(n,r,3,0,c-d),o++,r+=32}function ft(e,t,n,r){var i=e[t+0]+4,a=35468*e[t+4]>>16,o=ut(e[t+4]),s=35468*e[t+1]>>16;lt(n,r,0,i+o,e=ut(e[t+1]),s),lt(n,r,1,i+a,e,s),lt(n,r,2,i-a,e,s),lt(n,r,3,i-o,e,s)}function pt(e,t,n,r,i){dt(e,t,n,r),i&&dt(e,t+16,n,r+4)}function mt(e,t,n,r){ur(e,t+0,n,r,1),ur(e,t+32,n,r+128,1)}function ht(e,t,n,r){var i;for(e=e[t+0]+4,i=0;4>i;++i)for(t=0;4>t;++t)ct(n,r,t,i,e)}function gt(e,t,n,r){e[t+0]&&pr(e,t+0,n,r),e[t+16]&&pr(e,t+16,n,r+4),e[t+32]&&pr(e,t+32,n,r+128),e[t+48]&&pr(e,t+48,n,r+128+4)}function _t(e,t,n,r){var i,o=a(16);for(i=0;4>i;++i){var s=e[t+0+i]+e[t+12+i],c=e[t+4+i]+e[t+8+i],l=e[t+4+i]-e[t+8+i],u=e[t+0+i]-e[t+12+i];o[0+i]=s+c,o[8+i]=s-c,o[4+i]=u+l,o[12+i]=u-l}for(i=0;4>i;++i)s=(e=o[0+4*i]+3)+o[3+4*i],c=o[1+4*i]+o[2+4*i],l=o[1+4*i]-o[2+4*i],u=e-o[3+4*i],n[r+0]=s+c>>3,n[r+16]=u+l>>3,n[r+32]=s-c>>3,n[r+48]=u-l>>3,r+=64}function vt(e,t,n){var r,i=t-32,a=Y,o=255-e[i-1];for(r=0;rn;++n)r(e,t+32*n,e,t-32,16)}function Ct(e,t){var n;for(n=16;0r;++r)i(t,n+32*r,e,16)}function Tt(e,t){var n,r=16;for(n=0;16>n;++n)r+=e[t-1+32*n]+e[t+n-32];wt(r>>5,e,t)}function Et(e,t){var n,r=8;for(n=0;16>n;++n)r+=e[t-1+32*n];wt(r>>4,e,t)}function Dt(e,t){var n,r=8;for(n=0;16>n;++n)r+=e[t+n-32];wt(r>>4,e,t)}function Ot(e,t){wt(128,e,t)}function kt(e,t,n){return e+2*t+n+2>>2}function At(e,t){var n,i=t-32;for(i=new Uint8Array([kt(e[i-1],e[i+0],e[i+1]),kt(e[i+0],e[i+1],e[i+2]),kt(e[i+1],e[i+2],e[i+3]),kt(e[i+2],e[i+3],e[i+4])]),n=0;4>n;++n)r(e,t+32*n,i,0,i.length)}function jt(e,t){var n=e[t-1],r=e[t-1+32],i=e[t-1+64],a=e[t-1+96];k(e,t+0,16843009*kt(e[t-1-32],n,r)),k(e,t+32,16843009*kt(n,r,i)),k(e,t+64,16843009*kt(r,i,a)),k(e,t+96,16843009*kt(i,a,a))}function Mt(e,t){var n,r=4;for(n=0;4>n;++n)r+=e[t+n-32]+e[t-1+32*n];for(r>>=3,n=0;4>n;++n)i(e,t+32*n,r,4)}function Nt(e,t){var n=e[t-1+0],r=e[t-1+32],i=e[t-1+64],a=e[t-1-32],o=e[t+0-32],s=e[t+1-32],c=e[t+2-32],l=e[t+3-32];e[t+0+96]=kt(r,i,e[t-1+96]),e[t+1+96]=e[t+0+64]=kt(n,r,i),e[t+2+96]=e[t+1+64]=e[t+0+32]=kt(a,n,r),e[t+3+96]=e[t+2+64]=e[t+1+32]=e[t+0+0]=kt(o,a,n),e[t+3+64]=e[t+2+32]=e[t+1+0]=kt(s,o,a),e[t+3+32]=e[t+2+0]=kt(c,s,o),e[t+3+0]=kt(l,c,s)}function Pt(e,t){var n=e[t+1-32],r=e[t+2-32],i=e[t+3-32],a=e[t+4-32],o=e[t+5-32],s=e[t+6-32],c=e[t+7-32];e[t+0+0]=kt(e[t+0-32],n,r),e[t+1+0]=e[t+0+32]=kt(n,r,i),e[t+2+0]=e[t+1+32]=e[t+0+64]=kt(r,i,a),e[t+3+0]=e[t+2+32]=e[t+1+64]=e[t+0+96]=kt(i,a,o),e[t+3+32]=e[t+2+64]=e[t+1+96]=kt(a,o,s),e[t+3+64]=e[t+2+96]=kt(o,s,c),e[t+3+96]=kt(s,c,c)}function Ft(e,t){var n=e[t-1+0],r=e[t-1+32],i=e[t-1+64],a=e[t-1-32],o=e[t+0-32],s=e[t+1-32],c=e[t+2-32],l=e[t+3-32];e[t+0+0]=e[t+1+64]=a+o+1>>1,e[t+1+0]=e[t+2+64]=o+s+1>>1,e[t+2+0]=e[t+3+64]=s+c+1>>1,e[t+3+0]=c+l+1>>1,e[t+0+96]=kt(i,r,n),e[t+0+64]=kt(r,n,a),e[t+0+32]=e[t+1+96]=kt(n,a,o),e[t+1+32]=e[t+2+96]=kt(a,o,s),e[t+2+32]=e[t+3+96]=kt(o,s,c),e[t+3+32]=kt(s,c,l)}function It(e,t){var n=e[t+0-32],r=e[t+1-32],i=e[t+2-32],a=e[t+3-32],o=e[t+4-32],s=e[t+5-32],c=e[t+6-32],l=e[t+7-32];e[t+0+0]=n+r+1>>1,e[t+1+0]=e[t+0+64]=r+i+1>>1,e[t+2+0]=e[t+1+64]=i+a+1>>1,e[t+3+0]=e[t+2+64]=a+o+1>>1,e[t+0+32]=kt(n,r,i),e[t+1+32]=e[t+0+96]=kt(r,i,a),e[t+2+32]=e[t+1+96]=kt(i,a,o),e[t+3+32]=e[t+2+96]=kt(a,o,s),e[t+3+64]=kt(o,s,c),e[t+3+96]=kt(s,c,l)}function Lt(e,t){var n=e[t-1+0],r=e[t-1+32],i=e[t-1+64],a=e[t-1+96];e[t+0+0]=n+r+1>>1,e[t+2+0]=e[t+0+32]=r+i+1>>1,e[t+2+32]=e[t+0+64]=i+a+1>>1,e[t+1+0]=kt(n,r,i),e[t+3+0]=e[t+1+32]=kt(r,i,a),e[t+3+32]=e[t+1+64]=kt(i,a,a),e[t+3+64]=e[t+2+64]=e[t+0+96]=e[t+1+96]=e[t+2+96]=e[t+3+96]=a}function Rt(e,t){var n=e[t-1+0],r=e[t-1+32],i=e[t-1+64],a=e[t-1+96],o=e[t-1-32],s=e[t+0-32],c=e[t+1-32],l=e[t+2-32];e[t+0+0]=e[t+2+32]=n+o+1>>1,e[t+0+32]=e[t+2+64]=r+n+1>>1,e[t+0+64]=e[t+2+96]=i+r+1>>1,e[t+0+96]=a+i+1>>1,e[t+3+0]=kt(s,c,l),e[t+2+0]=kt(o,s,c),e[t+1+0]=e[t+3+32]=kt(n,o,s),e[t+1+32]=e[t+3+64]=kt(r,n,o),e[t+1+64]=e[t+3+96]=kt(i,r,n),e[t+1+96]=kt(a,i,r)}function zt(e,t){var n;for(n=0;8>n;++n)r(e,t+32*n,e,t-32,8)}function Bt(e,t){var n;for(n=0;8>n;++n)i(e,t,e[t-1],8),t+=32}function Vt(e,t,n){var r;for(r=0;8>r;++r)i(t,n+32*r,e,8)}function Ht(e,t){var n,r=8;for(n=0;8>n;++n)r+=e[t+n-32]+e[t-1+32*n];Vt(r>>4,e,t)}function Ut(e,t){var n,r=4;for(n=0;8>n;++n)r+=e[t+n-32];Vt(r>>3,e,t)}function Wt(e,t){var n,r=4;for(n=0;8>n;++n)r+=e[t-1+32*n];Vt(r>>3,e,t)}function Gt(e,t){Vt(128,e,t)}function Kt(e,t,n){var r=e[t-n],i=e[t+0],a=3*(i-r)+Ir[1020+e[t-2*n]-e[t+n]],o=Lr[112+(a+4>>3)];e[t-n]=Y[255+r+Lr[112+(a+3>>3)]],e[t+0]=Y[255+i-o]}function qt(e,t,n,r){var i=e[t+0],a=e[t+n];return Rr[255+e[t-2*n]-e[t-n]]>r||Rr[255+a-i]>r}function Jt(e,t,n,r){return 4*Rr[255+e[t-n]-e[t+0]]+Rr[255+e[t-2*n]-e[t+n]]<=r}function Yt(e,t,n,r,i){var a=e[t-3*n],o=e[t-2*n],s=e[t-n],c=e[t+0],l=e[t+n],u=e[t+2*n],d=e[t+3*n];return 4*Rr[255+s-c]+Rr[255+o-l]>r?0:Rr[255+e[t-4*n]-a]<=i&&Rr[255+a-o]<=i&&Rr[255+o-s]<=i&&Rr[255+d-u]<=i&&Rr[255+u-l]<=i&&Rr[255+l-c]<=i}function Xt(e,t,n,r){var i=2*r+1;for(r=0;16>r;++r)Jt(e,t+r,n,i)&&Kt(e,t+r,n)}function Zt(e,t,n,r){var i=2*r+1;for(r=0;16>r;++r)Jt(e,t+r*n,1,i)&&Kt(e,t+r*n,1)}function Qt(e,t,n,r){var i;for(i=3;0>7,_=18*v+63>>7,v=9*v+63>>7;c[l-3*u]=Y[255+c[l-3*u]+v],c[l-2*u]=Y[255+d+_],c[l-u]=Y[255+f+g],c[l+0]=Y[255+p-g],c[l+u]=Y[255+m-_],c[l+2*u]=Y[255+h-v]}t+=r}}function en(e,t,n,r,i,a,o,s){for(a=2*a+1;0>3)],h=Lr[112+(h+3>>3)],g=m+1>>1;c[l-2*u]=Y[255+c[l-2*u]+g],c[l-u]=Y[255+d+h],c[l+0]=Y[255+f-m],c[l+u]=Y[255+p-g]}t+=r}}function tn(e,t,n,r,i,a){$t(e,t,n,1,16,r,i,a)}function nn(e,t,n,r,i,a){$t(e,t,1,n,16,r,i,a)}function rn(e,t,n,r,i,a){var o;for(o=3;0l?0:255:l)&255,l=c,i[a+s]=u}}function yn(e,n,i,o){var s=n.width,c=n.o;if(t(e!=null&&n!=null),0>i||0>=o||i+o>c)return null;if(!e.Cc){if(e.ga==null){var l;if(e.ga=new hn,(l=e.ga==null)||(l=n.width*n.o,t(e.Gb.length==0),e.Gb=a(l),e.Uc=0,e.Gb==null?l=0:(e.mb=e.Gb,e.nb=e.Uc,e.rc=null,l=1),l=!l),!l){l=e.ga;var u=e.Fa,d=e.P,f=e.qc,p=e.mb,m=e.nb,h=d+1,g=f-1,v=l.l;if(t(u!=null&&p!=null&&n!=null),yi[0]=null,yi[1]=gn,yi[2]=_n,yi[3]=vn,l.ca=p,l.tb=m,l.c=n.width,l.i=n.height,t(0=f)n=0;else if(l.$a=3&u[d+0],l.Z=u[d+0]>>2&3,l.Lc=u[d+0]>>4&3,d=u[d+0]>>6&3,0>l.$a||1=l.c*l.i;l=!n}if(l)return null;e.ga.Lc==1?o=c-i:e.Ga=0}t(e.ga!=null),t(i+o<=c);t:{if(n=(u=e.ga).c,c=u.l.o,u.$a==0){if(h=e.rc,g=e.Vc,v=e.Fa,d=e.P+1+i*n,f=e.mb,p=e.nb+i*n,t(d<=e.P+e.qc),u.Z!=0)for(t(yi[u.Z]!=null),l=0;l=n)n=1;else if(u.ic||wn(),u.ic){u=l.V,h=l.Ba,g=l.c;var y=l.i,b=(v=1,d=l.$/g,f=l.$%g,p=l.m,m=l.s,l.$),x=g*y,S=g*n,w=m.wc,E=b(y=De(E.G[0],E.H[0],p)))u[h+b]=y,++b,++f>=g&&(f=0,++d<=n&&!(d%16)&&Pe(l,d));else{if(!(280>y)){v=0;break e}y=W(y-256,p);var D,O=De(E.G[4],E.H[4],p);if(T(p),!(b>=(O=Ee(g,O=W(O,p)))&&x-b>=y)){v=0;break e}for(D=0;D=g;)f-=g,++d<=n&&!(d%16)&&Pe(l,d);bn?n:d);break e}!v||p.h&&b=c&&(e.Cc=1),o=1}if(!o)return null;if(e.Cc&&((o=e.ga)!=null&&(o.mc=null),e.ga=null,0>23,s[c+4*o+1]=s[c+4*o+1]*d>>23,s[c+4*o+2]=s[c+4*o+2]*d>>23)}t+=a}}function xn(e,t,n,r,i){for(;0>4)*c>>16;e[t+2*a+0]=(240&o|o>>4)*c>>16&240|(15&o|o<<4)*c>>16>>4&15,e[t+2*a+1]=240&l|s}t+=i}}function Sn(e,t,n,r,i,a,o,s){var c,l,u=255;for(l=0;l>8}function wn(){Dr=bn,Or=xn,kr=Sn,Ar=Cn}function Tn(n,r,i){e[n]=function(e,n,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y){var b,x=y-1>>1,S=s[c+0]|l[u+0]<<16,C=d[f+0]|p[m+0]<<16;t(e!=null);var w=3*S+C+131074>>2;for(r(e[n+0],255&w,w>>16,h,g),a!=null&&(w=3*C+S+131074>>2,r(a[o+0],255&w,w>>16,_,v)),b=1;b<=x;++b){var T=s[c+b]|l[u+b]<<16,E=d[f+b]|p[m+b]<<16,D=S+T+C+E+524296,O=D+2*(T+C)>>3;w=O+S>>1,S=(D=D+2*(S+E)>>3)+T>>1,r(e[n+2*b-1],255&w,w>>16,h,g+(2*b-1)*i),r(e[n+2*b-0],255&S,S>>16,h,g+(2*b-0)*i),a!=null&&(w=D+C>>1,S=O+E>>1,r(a[o+2*b-1],255&w,w>>16,_,v+(2*b-1)*i),r(a[o+2*b+0],255&S,S>>16,_,v+(2*b+0)*i)),S=T,C=E}1&y||(w=3*S+C+131074>>2,r(e[n+y-1],255&w,w>>16,h,g+(y-1)*i),a!=null&&(w=3*C+S+131074>>2,r(a[o+y-1],255&w,w>>16,_,v+(y-1)*i)))}}function En(){bi[zr]=xi,bi[Br]=Ci,bi[Vr]=Si,bi[Hr]=wi,bi[Ur]=Ti,bi[Wr]=Ei,bi[Gr]=Di,bi[Kr]=Ci,bi[qr]=wi,bi[Jr]=Ti,bi[Yr]=Ei}function Dn(e){return e&~Ni?0>e?0:255:e>>Mi}function On(e,t){return Dn((19077*e>>8)+(26149*t>>8)-14234)}function kn(e,t,n){return Dn((19077*e>>8)-(6419*t>>8)-(13320*n>>8)+8708)}function An(e,t){return Dn((19077*e>>8)+(33050*t>>8)-17685)}function jn(e,t,n,r,i){r[i+0]=On(e,n),r[i+1]=kn(e,t,n),r[i+2]=An(e,t)}function K(e,t,n,r,i){r[i+0]=An(e,t),r[i+1]=kn(e,t,n),r[i+2]=On(e,n)}function Mn(e,t,n,r,i){var a=kn(e,t,n);t=a<<3&224|An(e,t)>>3,r[i+0]=248&On(e,n)|a>>5,r[i+1]=t}function q(e,t,n,r,i){var a=240&An(e,t)|15;r[i+0]=240&On(e,n)|kn(e,t,n)>>4,r[i+1]=a}function Nn(e,t,n,r,i){r[i+0]=255,jn(e,t,n,r,i+1)}function Pn(e,t,n,r,i){K(e,t,n,r,i),r[i+3]=255}function Fn(e,t,n,r,i){jn(e,t,n,r,i),r[i+3]=255}function In(t,n,r){e[t]=function(e,t,i,a,o,s,c,l,u){for(var d=l+(-2&u)*r;l!=d;)n(e[t+0],i[a+0],o[s+0],c,l),n(e[t+1],i[a+0],o[s+0],c,l+r),t+=2,++a,++s,l+=2*r;1&u&&n(e[t+0],i[a+0],o[s+0],c,l)}}function Ln(e,t,n){return n==0?e==0?t==0?6:5:t==0?4:0:n}function Rn(e,t,n,r,i){switch(e>>>30){case 3:ur(t,n,r,i,0);break;case 2:dr(t,n,r,i);break;case 1:pr(t,n,r,i)}}function zn(e,t){var n,a,o=t.M,s=t.Nb,c=e.oc,l=e.pc+40,u=e.oc,d=e.pc+584,f=e.oc,p=e.pc+600;for(n=0;16>n;++n)c[l+32*n-1]=129;for(n=0;8>n;++n)u[d+32*n-1]=129,f[p+32*n-1]=129;for(0n;++n)r(c,l+32*n-4,c,l+32*n+12,4);for(n=-1;8>n;++n)r(u,d+32*n-4,u,d+32*n+4,4),r(f,p+32*n-4,f,p+32*n+4,4)}var h=e.Gd,g=e.Hd+a,_=m.ad,v=m.Hc;if(0=e.za-1?i(y,b,h[g].y[15],4):r(y,b,h[g+1].y,0,4)),n=0;4>n;n++)y[b+128+n]=y[b+256+n]=y[b+384+n]=y[b+0+n];for(n=0;16>n;++n,v<<=2)y=c,b=l+Vi[n],hi[m.Ob[n]](y,b),Rn(v,_,16*n,y,b)}else if(y=Ln(a,o,m.Ob[0]),mi[y](c,l),v!=0)for(n=0;16>n;++n,v<<=2)Rn(v,_,16*n,c,l+Vi[n]);for(n=m.Gc,y=Ln(a,o,m.Dd),gi[y](u,d),gi[y](f,p),v=_,y=u,b=d,255&(m=0|n)&&(170&m?fr(v,256,y,b):mr(v,256,y,b)),m=f,v=p,255&(n>>=8)&&(170&n?fr(_,320,m,v):mr(_,320,m,v)),on;++n)r(h,g+n*e.R,c,l+32*n,16);for(n=0;8>n;++n)r(_,m+n*e.B,u,d+32*n,8),r(v,y+n*e.B,f,p+32*n,8)}}function Bn(e,r,i,a,o,s,c,l,u){var d=[0],f=[0],p=0,m=u==null?0:u.kd,h=u??new dn;if(e==null||12>i)return 7;h.data=e,h.w=r,h.ha=i,r=[r],i=[i],h.gb=[h.gb];t:{var g=r,v=i,y=h.gb;if(t(e!=null),t(v!=null),t(y!=null),y[0]=0,12<=v[0]&&!n(e,g[0],`RIFF`)){if(n(e,g[0]+8,`WEBP`)){y=3;break t}var b=M(e,g[0]+4);if(12>b||4294967286v[0]-8){y=7;break t}y[0]=b,g[0]+=12,v[0]-=12}y=0}if(y!=0)return y;for(b=0y[0])y=7;else{if(!n(S,v[0],`VP8X`)){if(M(S,v[0]+4)!=10){y=3;break t}if(18>y[0]){y=7;break t}var E=M(S,v[0]+8),D=1+j(S,v[0]+12);if(2147483648<=D*(S=1+j(S,v[0]+15))){y=3;break t}T!=null&&(T[0]=E),C!=null&&(C[0]=D),w!=null&&(w[0]=S),v[0]+=18,y[0]-=18,O[0]=1}y=0}}if(p=p[0],g=g[0],y!=0)return y;if(v=!!(2&g),!b&&p)return 3;if(s!=null&&(s[0]=!!(16&g)),c!=null&&(c[0]=v),l!=null&&(l[0]=0),c=d[0],g=f[0],p&&v&&u==null){y=0;break}if(4>i){y=7;break}if(b&&p||!b&&!p&&!n(e,r[0],`ALPH`)){i=[i],h.na=[h.na],h.P=[h.P],h.Sa=[h.Sa];t:{E=e,y=r,b=i;var O=h.gb;C=h.na,w=h.P,T=h.Sa,D=22,t(E!=null),t(b!=null),S=y[0];var k=b[0];for(t(C!=null),t(T!=null),C[0]=null,w[0]=null,T[0]=0;;){if(y[0]=S,b[0]=k,8>k){y=7;break t}var A=M(E,S+4);if(4294967286O){y=3;break t}if(!n(E,S,`VP8 `)||!n(E,S,`VP8L`)){y=0;break t}if(k[0]b[0])y=7;else{if(S||D){if(O=M(O,E+4),12<=C&&O>C-12){y=3;break t}if(m&&O>b[0]-8){y=7;break t}w[0]=O,y[0]+=8,b[0]-=8,T[0]=D}else T[0]=5<=b[0]&&O[E+0]==47&&!(O[E+4]>>5),w[0]=b[0];y=0}if(i=i[0],h.Ja=h.Ja[0],h.xa=h.xa[0],r=r[0],y!=0)break;if(4294967286i){y=7;break}l=c,m=g,v=s,e==null||5>i?e=0:5<=i&&e[r+0]==47&&!(e[r+4]>>5)?(b=[0],O=[0],C=[0],_(w=new x,e,r,i),Te(w,b,O,C)?(l!=null&&(l[0]=b[0]),m!=null&&(m[0]=O[0]),v!=null&&(v[0]=C[0]),e=1):e=0):e=0}else{if(10>i){y=7;break}l=g,e==null||10>i||!it(e,r+3,i-3)?e=0:(m=e[r+0]|e[r+1]<<8|e[r+2]<<16,v=16383&(e[r+7]<<8|e[r+6]),e=16383&(e[r+9]<<8|e[r+8]),1&m||3<(m>>1&7)||!(m>>4&1)||m>>5>=h.Ja||!v||!e?e=0:(c&&(c[0]=v),l&&(l[0]=e),e=1))}if(!e||(c=c[0],g=g[0],p&&(d[0]!=c||f[0]!=g)))return 3;u!=null&&(u[0]=h,u.offset=r-u.w,t(4294967286>r-u.w),t(u.offset==u.ha-i));break}return y==0||y==7&&p&&u==null?(s!=null&&(s[0]|=h.na!=null&&0n||(a&=-2,o&=-2),0>a||0>o||0>=s||0>=c||a+s>r||o+c>i))return 0;if(t.v=a,t.j=o,t.va=a+s,t.o=o+c,t.U=s,t.T=c,t.da=e!=null&&0e.S){var t=e.f.RGBA;t.fb+=(e.height-1)*t.A,t.A=-t.A}else t=e.f.kb,e=e.height,t.O+=(e-1)*t.fa,t.fa=-t.fa,t.N+=(e-1>>1)*t.Ab,t.Ab=-t.Ab,t.W+=(e-1>>1)*t.Db,t.Db=-t.Db,t.F!=null&&(t.J+=(e-1)*t.lb,t.lb=-t.lb);return 0}function Un(e,t,n,r){if(r==null||0>=e||0>=t)return 2;if(n!=null){if(n.Da){var i=n.cd,o=n.bd,s=-2&n.v,c=-2&n.j;if(0>s||0>c||0>=i||0>=o||s+i>e||c+o>t)return 2;e=i,t=o}if(n.da){if(!I(e,t,i=[n.ib],o=[n.hb]))return 2;e=i[0],t=o[0]}}r.width=e,r.height=t;t:{var l=r.width,u=r.height;if(e=r.S,0>=l||0>=u||!(e>=zr&&13>e))e=2;else{if(0>=r.Rd&&r.sd==null){s=o=i=t=0;var d=(c=l*Gi[e])*u;if(11>e||(o=(u+1)/2*(t=(l+1)/2),e==12&&(s=(i=l)*u)),(u=a(d+2*o+s))==null){e=1;break t}r.sd=u,11>e?((l=r.f.RGBA).eb=u,l.fb=0,l.A=c,l.size=d):((l=r.f.kb).y=u,l.O=0,l.fa=c,l.Fd=d,l.f=u,l.N=0+d,l.Ab=t,l.Cd=o,l.ea=u,l.W=0+d+o,l.Db=t,l.Ed=o,e==12&&(l.F=u,l.J=0+d+2*o),l.Tc=s,l.lb=i)}if(t=1,i=r.S,o=r.width,s=r.height,i>=zr&&13>i)if(11>i)e=r.f.RGBA,t&=(c=Math.abs(e.A))*(s-1)+o<=e.size,t&=c>=o*Gi[i],t&=e.eb!=null;else{e=r.f.kb,c=(o+1)/2,d=(s+1)/2,l=Math.abs(e.fa),u=Math.abs(e.Ab);var f=Math.abs(e.Db),p=Math.abs(e.lb),m=p*(s-1)+o;t&=l*(s-1)+o<=e.Fd,t&=u*(d-1)+c<=e.Cd,t=(t&=f*(d-1)+c<=e.Ed)&l>=o&u>=c&f>=c,t&=e.y!=null,t&=e.f!=null,t&=e.ea!=null,i==12&&(t&=p>=o,t&=m<=e.Tc,t&=e.F!=null)}else t=0;e=t?0:2}}return e!=0||n!=null&&n.fd&&(e=Hn(r)),e}var Wn=64,Gn=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215],Kn=24,qn=32,Jn=8,Yn=[0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7];R(`Predictor0`,`PredictorAdd0`),e.Predictor0=function(){return 4278190080},e.Predictor1=function(e){return e},e.Predictor2=function(e,t,n){return t[n+0]},e.Predictor3=function(e,t,n){return t[n+1]},e.Predictor4=function(e,t,n){return t[n-1]},e.Predictor5=function(e,t,n){return z(z(e,t[n+1]),t[n+0])},e.Predictor6=function(e,t,n){return z(e,t[n-1])},e.Predictor7=function(e,t,n){return z(e,t[n+0])},e.Predictor8=function(e,t,n){return z(t[n-1],t[n+0])},e.Predictor9=function(e,t,n){return z(t[n+0],t[n+1])},e.Predictor10=function(e,t,n){return z(z(e,t[n-1]),z(t[n+0],t[n+1]))},e.Predictor11=function(e,t,n){var r=t[n+0];return 0>=ne(r>>24&255,e>>24&255,(t=t[n-1])>>24&255)+ne(r>>16&255,e>>16&255,t>>16&255)+ne(r>>8&255,e>>8&255,t>>8&255)+ne(255&r,255&e,255&t)?r:e},e.Predictor12=function(e,t,n){var r=t[n+0];return(B((e>>24&255)+(r>>24&255)-((t=t[n-1])>>24&255))<<24|B((e>>16&255)+(r>>16&255)-(t>>16&255))<<16|B((e>>8&255)+(r>>8&255)-(t>>8&255))<<8|B((255&e)+(255&r)-(255&t)))>>>0},e.Predictor13=function(e,t,n){var r=t[n-1];return(V((e=z(e,t[n+0]))>>24&255,r>>24&255)<<24|V(e>>16&255,r>>16&255)<<16|V(e>>8&255,r>>8&255)<<8|V(255&e,255&r))>>>0};var Xn=e.PredictorAdd0;e.PredictorAdd1=re,R(`Predictor2`,`PredictorAdd2`),R(`Predictor3`,`PredictorAdd3`),R(`Predictor4`,`PredictorAdd4`),R(`Predictor5`,`PredictorAdd5`),R(`Predictor6`,`PredictorAdd6`),R(`Predictor7`,`PredictorAdd7`),R(`Predictor8`,`PredictorAdd8`),R(`Predictor9`,`PredictorAdd9`),R(`Predictor10`,`PredictorAdd10`),R(`Predictor11`,`PredictorAdd11`),R(`Predictor12`,`PredictorAdd12`),R(`Predictor13`,`PredictorAdd13`);var Zn=e.PredictorAdd2;se(`ColorIndexInverseTransform`,`MapARGB`,`32b`,function(e){return e>>8&255},function(e){return e}),se(`VP8LColorIndexInverseTransformAlpha`,`MapAlpha`,`8b`,function(e){return e},function(e){return e>>8&255});var Qn,$n=e.ColorIndexInverseTransform,er=e.MapARGB,tr=e.VP8LColorIndexInverseTransformAlpha,nr=e.MapAlpha,rr=e.VP8LPredictorsAdd=[];rr.length=16,(e.VP8LPredictors=[]).length=16,(e.VP8LPredictorsAdd_C=[]).length=16,(e.VP8LPredictors_C=[]).length=16;var J,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr=a(511),Mr=a(2041),Nr=a(225),Pr=a(767),Fr=0,Ir=Mr,Lr=Nr,Y=Pr,Rr=jr,zr=0,Br=1,Vr=2,Hr=3,Ur=4,Wr=5,Gr=6,Kr=7,qr=8,Jr=9,Yr=10,Xr=[2,3,7],Zr=[3,3,11],Qr=[280,256,256,256,40],$r=[0,1,1,1,0],ei=[17,18,0,1,2,3,4,5,16,6,7,8,9,10,11,12,13,14,15],ti=[24,7,23,25,40,6,39,41,22,26,38,42,56,5,55,57,21,27,54,58,37,43,72,4,71,73,20,28,53,59,70,74,36,44,88,69,75,52,60,3,87,89,19,29,86,90,35,45,68,76,85,91,51,61,104,2,103,105,18,30,102,106,34,46,84,92,67,77,101,107,50,62,120,1,119,121,83,93,17,31,100,108,66,78,118,122,33,47,117,123,49,63,99,109,82,94,0,116,124,65,79,16,32,98,110,48,115,125,81,95,64,114,126,97,111,80,113,127,96,112],ni=[2954,2956,2958,2962,2970,2986,3018,3082,3212,3468,3980,5004],ri=8,ii=[4,5,6,7,8,9,10,10,11,12,13,14,15,16,17,17,18,19,20,20,21,21,22,22,23,23,24,25,25,26,27,28,29,30,31,32,33,34,35,36,37,37,38,39,40,41,42,43,44,45,46,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,76,77,78,79,80,81,82,83,84,85,86,87,88,89,91,93,95,96,98,100,101,102,104,106,108,110,112,114,116,118,122,124,126,128,130,132,134,136,138,140,143,145,148,151,154,157],ai=[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,167,170,173,177,181,185,189,193,197,201,205,209,213,217,221,225,229,234,239,245,249,254,259,264,269,274,279,284],oi=null,si=[[173,148,140,0],[176,155,140,135,0],[180,157,141,134,130,0],[254,254,243,230,196,177,153,140,133,130,129,0]],ci=[0,1,4,8,5,2,3,6,9,12,13,10,7,11,14,15],li=[-0,1,-1,2,-2,3,4,6,-3,5,-4,-5,-6,7,-7,8,-8,-9],ui=[[[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]],[[253,136,254,255,228,219,128,128,128,128,128],[189,129,242,255,227,213,255,219,128,128,128],[106,126,227,252,214,209,255,255,128,128,128]],[[1,98,248,255,236,226,255,255,128,128,128],[181,133,238,254,221,234,255,154,128,128,128],[78,134,202,247,198,180,255,219,128,128,128]],[[1,185,249,255,243,255,128,128,128,128,128],[184,150,247,255,236,224,128,128,128,128,128],[77,110,216,255,236,230,128,128,128,128,128]],[[1,101,251,255,241,255,128,128,128,128,128],[170,139,241,252,236,209,255,255,128,128,128],[37,116,196,243,228,255,255,255,128,128,128]],[[1,204,254,255,245,255,128,128,128,128,128],[207,160,250,255,238,128,128,128,128,128,128],[102,103,231,255,211,171,128,128,128,128,128]],[[1,152,252,255,240,255,128,128,128,128,128],[177,135,243,255,234,225,128,128,128,128,128],[80,129,211,255,194,224,128,128,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[246,1,255,128,128,128,128,128,128,128,128],[255,128,128,128,128,128,128,128,128,128,128]]],[[[198,35,237,223,193,187,162,160,145,155,62],[131,45,198,221,172,176,220,157,252,221,1],[68,47,146,208,149,167,221,162,255,223,128]],[[1,149,241,255,221,224,255,255,128,128,128],[184,141,234,253,222,220,255,199,128,128,128],[81,99,181,242,176,190,249,202,255,255,128]],[[1,129,232,253,214,197,242,196,255,255,128],[99,121,210,250,201,198,255,202,128,128,128],[23,91,163,242,170,187,247,210,255,255,128]],[[1,200,246,255,234,255,128,128,128,128,128],[109,178,241,255,231,245,255,255,128,128,128],[44,130,201,253,205,192,255,255,128,128,128]],[[1,132,239,251,219,209,255,165,128,128,128],[94,136,225,251,218,190,255,255,128,128,128],[22,100,174,245,186,161,255,199,128,128,128]],[[1,182,249,255,232,235,128,128,128,128,128],[124,143,241,255,227,234,128,128,128,128,128],[35,77,181,251,193,211,255,205,128,128,128]],[[1,157,247,255,236,231,255,255,128,128,128],[121,141,235,255,225,227,255,255,128,128,128],[45,99,188,251,195,217,255,224,128,128,128]],[[1,1,251,255,213,255,128,128,128,128,128],[203,1,248,255,255,128,128,128,128,128,128],[137,1,177,255,224,255,128,128,128,128,128]]],[[[253,9,248,251,207,208,255,192,128,128,128],[175,13,224,243,193,185,249,198,255,255,128],[73,17,171,221,161,179,236,167,255,234,128]],[[1,95,247,253,212,183,255,255,128,128,128],[239,90,244,250,211,209,255,255,128,128,128],[155,77,195,248,188,195,255,255,128,128,128]],[[1,24,239,251,218,219,255,205,128,128,128],[201,51,219,255,196,186,128,128,128,128,128],[69,46,190,239,201,218,255,228,128,128,128]],[[1,191,251,255,255,128,128,128,128,128,128],[223,165,249,255,213,255,128,128,128,128,128],[141,124,248,255,255,128,128,128,128,128,128]],[[1,16,248,255,255,128,128,128,128,128,128],[190,36,230,255,236,255,128,128,128,128,128],[149,1,255,128,128,128,128,128,128,128,128]],[[1,226,255,128,128,128,128,128,128,128,128],[247,192,255,128,128,128,128,128,128,128,128],[240,128,255,128,128,128,128,128,128,128,128]],[[1,134,252,255,255,128,128,128,128,128,128],[213,62,250,255,255,128,128,128,128,128,128],[55,93,255,128,128,128,128,128,128,128,128]],[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]]],[[[202,24,213,235,186,191,220,160,240,175,255],[126,38,182,232,169,184,228,174,255,187,128],[61,46,138,219,151,178,240,170,255,216,128]],[[1,112,230,250,199,191,247,159,255,255,128],[166,109,228,252,211,215,255,174,128,128,128],[39,77,162,232,172,180,245,178,255,255,128]],[[1,52,220,246,198,199,249,220,255,255,128],[124,74,191,243,183,193,250,221,255,255,128],[24,71,130,219,154,170,243,182,255,255,128]],[[1,182,225,249,219,240,255,224,128,128,128],[149,150,226,252,216,205,255,171,128,128,128],[28,108,170,242,183,194,254,223,255,255,128]],[[1,81,230,252,204,203,255,192,128,128,128],[123,102,209,247,188,196,255,233,128,128,128],[20,95,153,243,164,173,255,203,128,128,128]],[[1,222,248,255,216,213,128,128,128,128,128],[168,175,246,252,235,205,255,255,128,128,128],[47,116,215,255,211,212,255,255,128,128,128]],[[1,121,236,253,212,214,255,255,128,128,128],[141,84,213,252,201,202,255,219,128,128,128],[42,80,160,240,162,185,255,205,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[244,1,255,128,128,128,128,128,128,128,128],[238,1,255,128,128,128,128,128,128,128,128]]]],di=[[[231,120,48,89,115,113,120,152,112],[152,179,64,126,170,118,46,70,95],[175,69,143,80,85,82,72,155,103],[56,58,10,171,218,189,17,13,152],[114,26,17,163,44,195,21,10,173],[121,24,80,195,26,62,44,64,85],[144,71,10,38,171,213,144,34,26],[170,46,55,19,136,160,33,206,71],[63,20,8,114,114,208,12,9,226],[81,40,11,96,182,84,29,16,36]],[[134,183,89,137,98,101,106,165,148],[72,187,100,130,157,111,32,75,80],[66,102,167,99,74,62,40,234,128],[41,53,9,178,241,141,26,8,107],[74,43,26,146,73,166,49,23,157],[65,38,105,160,51,52,31,115,128],[104,79,12,27,217,255,87,17,7],[87,68,71,44,114,51,15,186,23],[47,41,14,110,182,183,21,17,194],[66,45,25,102,197,189,23,18,22]],[[88,88,147,150,42,46,45,196,205],[43,97,183,117,85,38,35,179,61],[39,53,200,87,26,21,43,232,171],[56,34,51,104,114,102,29,93,77],[39,28,85,171,58,165,90,98,64],[34,22,116,206,23,34,43,166,73],[107,54,32,26,51,1,81,43,31],[68,25,106,22,64,171,36,225,114],[34,19,21,102,132,188,16,76,124],[62,18,78,95,85,57,50,48,51]],[[193,101,35,159,215,111,89,46,111],[60,148,31,172,219,228,21,18,111],[112,113,77,85,179,255,38,120,114],[40,42,1,196,245,209,10,25,109],[88,43,29,140,166,213,37,43,154],[61,63,30,155,67,45,68,1,209],[100,80,8,43,154,1,51,26,71],[142,78,78,16,255,128,34,197,171],[41,40,5,102,211,183,4,1,221],[51,50,17,168,209,192,23,25,82]],[[138,31,36,171,27,166,38,44,229],[67,87,58,169,82,115,26,59,179],[63,59,90,180,59,166,93,73,154],[40,40,21,116,143,209,34,39,175],[47,15,16,183,34,223,49,45,183],[46,17,33,183,6,98,15,32,183],[57,46,22,24,128,1,54,17,37],[65,32,73,115,28,128,23,128,205],[40,3,9,115,51,192,18,6,223],[87,37,9,115,59,77,64,21,47]],[[104,55,44,218,9,54,53,130,226],[64,90,70,205,40,41,23,26,57],[54,57,112,184,5,41,38,166,213],[30,34,26,133,152,116,10,32,134],[39,19,53,221,26,114,32,73,255],[31,9,65,234,2,15,1,118,73],[75,32,12,51,192,255,160,43,51],[88,31,35,67,102,85,55,186,85],[56,21,23,111,59,205,45,37,192],[55,38,70,124,73,102,1,34,98]],[[125,98,42,88,104,85,117,175,82],[95,84,53,89,128,100,113,101,45],[75,79,123,47,51,128,81,171,1],[57,17,5,71,102,57,53,41,49],[38,33,13,121,57,73,26,1,85],[41,10,67,138,77,110,90,47,114],[115,21,2,10,102,255,166,23,6],[101,29,16,10,85,128,101,196,26],[57,18,10,102,102,213,34,20,43],[117,20,15,36,163,128,68,1,26]],[[102,61,71,37,34,53,31,243,192],[69,60,71,38,73,119,28,222,37],[68,45,128,34,1,47,11,245,171],[62,17,19,70,146,85,55,62,70],[37,43,37,154,100,163,85,160,1],[63,9,92,136,28,64,32,201,85],[75,15,9,9,64,255,184,119,16],[86,6,28,5,64,255,25,248,1],[56,8,17,132,137,255,55,116,128],[58,15,20,82,135,57,26,121,40]],[[164,50,31,137,154,133,25,35,218],[51,103,44,131,131,123,31,6,158],[86,40,64,135,148,224,45,183,128],[22,26,17,131,240,154,14,1,209],[45,16,21,91,64,222,7,1,197],[56,21,39,155,60,138,23,102,213],[83,12,13,54,192,255,68,47,28],[85,26,85,85,128,128,32,146,171],[18,11,7,63,144,171,4,4,246],[35,27,10,146,174,171,12,26,128]],[[190,80,35,99,180,80,126,54,45],[85,126,47,87,176,51,41,20,32],[101,75,128,139,118,146,116,128,85],[56,41,15,176,236,85,37,9,62],[71,30,17,119,118,255,17,18,138],[101,38,60,138,55,70,43,26,142],[146,36,19,30,171,255,97,27,20],[138,45,61,62,219,1,81,188,64],[32,41,20,117,151,142,20,21,163],[112,19,12,61,195,128,48,4,24]]],fi=[[[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[176,246,255,255,255,255,255,255,255,255,255],[223,241,252,255,255,255,255,255,255,255,255],[249,253,253,255,255,255,255,255,255,255,255]],[[255,244,252,255,255,255,255,255,255,255,255],[234,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255]],[[255,246,254,255,255,255,255,255,255,255,255],[239,253,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[251,255,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[251,254,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,254,253,255,254,255,255,255,255,255,255],[250,255,254,255,254,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[217,255,255,255,255,255,255,255,255,255,255],[225,252,241,253,255,255,254,255,255,255,255],[234,250,241,250,253,255,253,254,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[223,254,254,255,255,255,255,255,255,255,255],[238,253,254,254,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[249,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,255,255,255,255,255,255,255,255,255],[247,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[252,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[186,251,250,255,255,255,255,255,255,255,255],[234,251,244,254,255,255,255,255,255,255,255],[251,251,243,253,254,255,254,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[236,253,254,255,255,255,255,255,255,255,255],[251,253,253,254,254,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[254,254,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[254,254,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[248,255,255,255,255,255,255,255,255,255,255],[250,254,252,254,255,255,255,255,255,255,255],[248,254,249,253,255,255,255,255,255,255,255]],[[255,253,253,255,255,255,255,255,255,255,255],[246,253,253,255,255,255,255,255,255,255,255],[252,254,251,254,254,255,255,255,255,255,255]],[[255,254,252,255,255,255,255,255,255,255,255],[248,254,253,255,255,255,255,255,255,255,255],[253,255,254,254,255,255,255,255,255,255,255]],[[255,251,254,255,255,255,255,255,255,255,255],[245,251,254,255,255,255,255,255,255,255,255],[253,253,254,255,255,255,255,255,255,255,255]],[[255,251,253,255,255,255,255,255,255,255,255],[252,253,254,255,255,255,255,255,255,255,255],[255,254,255,255,255,255,255,255,255,255,255]],[[255,252,255,255,255,255,255,255,255,255,255],[249,255,254,255,255,255,255,255,255,255,255],[255,255,254,255,255,255,255,255,255,255,255]],[[255,255,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]]],pi=[0,1,2,3,6,4,5,6,6,6,6,6,6,6,6,7,0],mi=[],hi=[],gi=[],_i=1,vi=2,yi=[],bi=[];Tn(`UpsampleRgbLinePair`,jn,3),Tn(`UpsampleBgrLinePair`,K,3),Tn(`UpsampleRgbaLinePair`,Fn,4),Tn(`UpsampleBgraLinePair`,Pn,4),Tn(`UpsampleArgbLinePair`,Nn,4),Tn(`UpsampleRgba4444LinePair`,q,2),Tn(`UpsampleRgb565LinePair`,Mn,2);var xi=e.UpsampleRgbLinePair,Si=e.UpsampleBgrLinePair,Ci=e.UpsampleRgbaLinePair,wi=e.UpsampleBgraLinePair,Ti=e.UpsampleArgbLinePair,Ei=e.UpsampleRgba4444LinePair,Di=e.UpsampleRgb565LinePair,Oi=16,ki=1<c.ca.S||(alert(`todo:WebPInitConvertARGBToYUV`),c.ca.f.kb.F!=null&&wn()),c.Pb&&0(p=s.Md)?0:100m;++m)12>(g=l.pb[m]).lc&&(g.ia=p*Ui[0>g.lc?0:g.lc]>>3),h|=g.ia;h&&(alert(`todo:VP8InitRandom`),l.ia=1)}l.Ga=s.Id,100l.Ga&&(l.Ga=0)}(function(e,n){if(e==null)return 0;if(n==null)return rt(e,2,`NULL VP8Io parameter in VP8Decode().`);if(!e.cb&&!at(e,n))return 0;if(t(e.cb),n.ac==null||n.ac(n)){n.ob&&(e.L=0);var s=Hi[e.L];if(e.L==2?(e.yb=0,e.zb=0):(e.yb=n.v-s>>4,e.zb=n.j-s>>4,0>e.yb&&(e.yb=0),0>e.zb&&(e.zb=0)),e.Va=n.o+15+s>>4,e.Hb=n.va+15+s>>4,e.Hb>e.za&&(e.Hb=e.za),e.Va>e.Ub&&(e.Va=e.Ub),0s;++s){var l;if(e.Qa.Cb){var u=e.Qa.Lb[s];e.Qa.Fb||(u+=c.Tb)}else u=c.Tb;for(l=0;1>=l;++l){var d=e.gd[s][l],f=u;if(c.Pc&&(f+=c.vd[0],l&&(f+=c.od[0])),0<(f=0>f?0:63>2:p>>1)>9-c.wb&&(p=9-c.wb),1>p&&(p=1),d.dd=p,d.tc=2*f+p,d.ld=40<=f?2:+(15<=f)}else d.tc=0;d.La=l}}}s=0}else rt(e,6,`Frame setup failed`),s=e.a;if(s=s==0){if(s){e.$c=0,0e.Vb){if(e.Vb=0,e.Ec=a(d),e.Fc=0,e.Ec==null){s=rt(e,1,`no memory during frame initialization.`);break e}e.Vb=d}d=e.Ec,f=e.Fc,e.Ac=d,e.Bc=f,f+=c,e.Gd=o(m,Qe),e.Hd=0,e.rb=o(h+1,Je),e.sb=1,e.wa=g?o(g,qe):null,e.Y=0,e.D.Nb=0,e.D.wa=e.wa,e.D.Y=e.Y,0=s;++s)jr[255+s]=0>s?-s:s;for(s=-1020;1020>=s;++s)Mr[1020+s]=-128>s?-128:127=s;++s)Nr[112+s]=-16>s?-16:15=s;++s)Pr[255+s]=0>s?0:255d;++d){var v,y=m[0+d];for(v=0;4>v;++v){y=di[f[p+v]][y];for(var b=li[O(u,y[0])];0>3;for(b=0;256>b;b+=16)d[g+b]=E}C=1,w=p[0]}var D=15&u.la,k=15&_.la;for(b=0;4>b;++b){var A=1&k;for(E=S=0;4>E;++E)D=D>>1|(A=(T=oi(f,w,T=A+(1&D),h.Sc,C,d,g))>C)<<7,S=S<<2|(3>=4,k=k>>1|A<<7,v=(v<<8|S)>>>0}for(w=D,C=k>>4,x=0;4>x;x+=2){for(S=0,D=u.la>>4+x,k=_.la>>4+x,b=0;2>b;++b){for(A=1&k,E=0;2>E;++E)T=A+(1&D),D=D>>1|(A=0<(T=oi(f,p[2],T,h.Qc,0,d,g)))<<3,S=S<<2|(3>=2,k=k>>1|A<<5}y|=S<<4*x,w|=D<<4<=s.zb&&s.M<=s.Va,s.Aa==0)e:{if(o.M=s.M,o.uc=u,zn(s,o),l=1,o=(S=s.D).Nb,u=(y=Hi[s.L])*s.R,f=y/2*s.B,b=16*o*s.R,E=8*o*s.B,p=s.sa,m=s.ta-u+b,h=s.qa,d=s.ra-f+E,g=s.Ha,_=s.Ia-f+E,k=(D=S.M)==0,v=D>=s.Va-1,s.Aa==2&&zn(s,S),S.uc)for(A=(T=s).D.M,t(T.D.uc),S=T.yb;Sc.o&&(D=c.o),c.F=null,c.J=null,s.Fa!=null&&0>1),c.W+=s.B*(y>>1),c.F!=null&&(c.J+=c.width*y)),S>1,c.W+=c.v>>1,c.F!=null&&(c.J+=c.v),c.ka=S-c.j,c.U=c.va-c.v,c.T=D-S,l=c.put(c))}o+1!=s.Ic||v||(r(s.sa,s.ta-u,p,m+16*s.R,u),r(s.qa,s.ra-f,h,d+8*s.B,f),r(s.Ha,s.Ia-f,g,_+8*s.B,f))}if(!l)return rt(e,6,`Output aborted.`)}return 1}(e,n),n.bc!=null&&n.bc(n),s&=1}return s?(e.cb=0,s):0})(e,c)||(n=e.a)}}else n=e.a}n==0&&d.Oa!=null&&d.Oa.fd&&(n=Hn(d.ba))}d=n}u=d==0?11>u?f.f.RGBA.eb:f.f.kb.y:null}else u=null;return u};var Gi=[3,4,3,4,4,2,2,4,4,4,2,1,1]};function l(e,t){for(var n=``,r=0;r<4;r++)n+=String.fromCharCode(e[t++]);return n}function u(e,t){return e[t+0]|e[t+1]<<8}function d(e,t){return(e[t+0]|e[t+1]<<8|e[t+2]<<16)>>>0}function f(e,t){return(e[t+0]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}new c;var p=[0],m=[0],h=[],g=new c,_=e,v=function(e,t){var n={},r=0,i=!1,a=0,o=0;if(n.frames=[],!function(e,t){for(var n=0;n<4;n++)if(e[t+n]!=`RIFF`.charCodeAt(n))return!0;return!1}(e,t)){for(f(e,t+=4),t+=8;t>1&1}s!=`ANMF`&&(t+=p)}return n}}(_,0);v.response=_,v.rgbaoutput=!0,v.dataurl=!1;var y=v.header?v.header:null,b=v.frames?v.frames:null;if(y){y.loop_counter=y.loop_count,p=[y.canvas_height],m=[y.canvas_width];for(var x=0;x`+n.replace(/&/g,`&`).replace(//g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)+``,this.internal.__metadata__.metadataObjectNumber=this.internal.newObject(),this.internal.write(`<< /Type /Metadata /Subtype /XML /Length `+e.length+` >>`),this.internal.write(`stream`),this.internal.write(e),this.internal.write(`endstream`),this.internal.write(`endobj`)}function tI(){this.internal.__metadata__.metadataObjectNumber&&this.internal.write(`/Metadata `+this.internal.__metadata__.metadataObjectNumber+` 0 R`)}(function(e){var t,n,r,i,a,o,s,c,l,u=function(e){return e||={},this.isStrokeTransparent=e.isStrokeTransparent||!1,this.strokeOpacity=e.strokeOpacity||1,this.strokeStyle=e.strokeStyle||`#000000`,this.fillStyle=e.fillStyle||`#000000`,this.isFillTransparent=e.isFillTransparent||!1,this.fillOpacity=e.fillOpacity||1,this.font=e.font||`10px sans-serif`,this.textBaseline=e.textBaseline||`alphabetic`,this.textAlign=e.textAlign||`left`,this.lineWidth=e.lineWidth||1,this.lineJoin=e.lineJoin||`miter`,this.lineCap=e.lineCap||`butt`,this.path=e.path||[],this.transform=e.transform===void 0?new c:e.transform.clone(),this.globalCompositeOperation=e.globalCompositeOperation||`normal`,this.globalAlpha=e.globalAlpha||1,this.clip_path=e.clip_path||[],this.currentPoint=e.currentPoint||new o,this.miterLimit=e.miterLimit||10,this.lastPoint=e.lastPoint||new o,this.lineDashOffset=e.lineDashOffset||0,this.lineDash=e.lineDash||[],this.margin=e.margin||[0,0,0,0],this.prevPageLastElemOffset=e.prevPageLastElemOffset||0,this.ignoreClearRect=typeof e.ignoreClearRect!=`boolean`||e.ignoreClearRect,this};e.events.push([`initialized`,function(){this.context2d=new d(this),t=this.internal.f2,n=this.internal.getCoordinateString,r=this.internal.getVerticalCoordinateString,i=this.internal.getHorizontalCoordinate,a=this.internal.getVerticalCoordinate,o=this.internal.Point,s=this.internal.Rectangle,c=this.internal.Matrix,l=new u}]);var d=function(e){Object.defineProperty(this,"canvas",{get:function(){return{parentNode:!1,style:!1}}});var t=e;Object.defineProperty(this,"pdf",{get:function(){return t}});var n=!1;Object.defineProperty(this,"pageWrapXEnabled",{get:function(){return n},set:function(e){n=!!e}});var r=!1;Object.defineProperty(this,"pageWrapYEnabled",{get:function(){return r},set:function(e){r=!!e}});var i=0;Object.defineProperty(this,"posX",{get:function(){return i},set:function(e){isNaN(e)||(i=e)}});var a=0;Object.defineProperty(this,"posY",{get:function(){return a},set:function(e){isNaN(e)||(a=e)}}),Object.defineProperty(this,"margin",{get:function(){return l.margin},set:function(e){var t;typeof e==`number`?t=[e,e,e,e]:((t=[,,,,])[0]=e[0],t[1]=e.length>=2?e[1]:t[0],t[2]=e.length>=3?e[2]:t[0],t[3]=e.length>=4?e[3]:t[1]),l.margin=t}});var o=!1;Object.defineProperty(this,"autoPaging",{get:function(){return o},set:function(e){o=e}});var s=0;Object.defineProperty(this,"lastBreak",{get:function(){return s},set:function(e){s=e}});var c=[];Object.defineProperty(this,"pageBreaks",{get:function(){return c},set:function(e){c=e}}),Object.defineProperty(this,"ctx",{get:function(){return l},set:function(e){e instanceof u&&(l=e)}}),Object.defineProperty(this,"path",{get:function(){return l.path},set:function(e){l.path=e}});var d=[];Object.defineProperty(this,"ctxStack",{get:function(){return d},set:function(e){d=e}}),Object.defineProperty(this,"fillStyle",{get:function(){return this.ctx.fillStyle},set:function(e){var t=f(e);this.ctx.fillStyle=t.style,this.ctx.isFillTransparent=t.a===0,this.ctx.fillOpacity=t.a,this.pdf.setFillColor(t.r,t.g,t.b,{a:t.a}),this.pdf.setTextColor(t.r,t.g,t.b,{a:t.a})}}),Object.defineProperty(this,"strokeStyle",{get:function(){return this.ctx.strokeStyle},set:function(e){var t=f(e);this.ctx.strokeStyle=t.style,this.ctx.isStrokeTransparent=t.a===0,this.ctx.strokeOpacity=t.a,t.a===0?this.pdf.setDrawColor(255,255,255):(t.a,this.pdf.setDrawColor(t.r,t.g,t.b))}}),Object.defineProperty(this,"lineCap",{get:function(){return this.ctx.lineCap},set:function(e){[`butt`,`round`,`square`].indexOf(e)!==-1&&(this.ctx.lineCap=e,this.pdf.setLineCap(e))}}),Object.defineProperty(this,"lineWidth",{get:function(){return this.ctx.lineWidth},set:function(e){isNaN(e)||(this.ctx.lineWidth=e,this.pdf.setLineWidth(e))}}),Object.defineProperty(this,"lineJoin",{get:function(){return this.ctx.lineJoin},set:function(e){[`bevel`,`round`,`miter`].indexOf(e)!==-1&&(this.ctx.lineJoin=e,this.pdf.setLineJoin(e))}}),Object.defineProperty(this,"miterLimit",{get:function(){return this.ctx.miterLimit},set:function(e){isNaN(e)||(this.ctx.miterLimit=e,this.pdf.setMiterLimit(e))}}),Object.defineProperty(this,"textBaseline",{get:function(){return this.ctx.textBaseline},set:function(e){this.ctx.textBaseline=e}}),Object.defineProperty(this,"textAlign",{get:function(){return this.ctx.textAlign},set:function(e){[`right`,`end`,`center`,`left`,`start`].indexOf(e)!==-1&&(this.ctx.textAlign=e)}});var p=null,m=null,h=null;Object.defineProperty(this,"fontFaces",{get:function(){return h},set:function(e){p=null,m=null,h=e}}),Object.defineProperty(this,"font",{get:function(){return this.ctx.font},set:function(e){var t;if(this.ctx.font=e,(t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-_,\"\'\sa-z0-9]+?)\s*$/i.exec(e))!==null){var n=t[1];t[2];var r=t[3],i=t[4];t[5];var a=t[6],o=/^([.\d]+)((?:%|in|[cem]m|ex|p[ctx]))$/i.exec(i)[2];i=Math.floor(o===`px`?parseFloat(i)*this.pdf.internal.scaleFactor:o===`em`?parseFloat(i)*this.pdf.getFontSize():parseFloat(i)*this.pdf.internal.scaleFactor),this.pdf.setFontSize(i);var s=function(e){var t,n,r=[],i=e.trim();if(i===``)return LF;if(i in DF)return[DF[i]];for(;i!==``;){switch(n=null,t=(i=kF(i)).charAt(0)){case`"`:case`'`:n=AF(i.substring(1),t);break;default:n=jF(i)}if(n===null||(r.push(n[0]),(i=kF(n[1]))!==``&&i.charAt(0)!==`,`))return LF;i=i.replace(/^,/,``)}return r}(a);if(this.fontFaces){var c=function(e,t,n){for(var r=(n||={}).defaultFontFamily||`times`,i=Object.assign({},EF,n.genericFontFamilies||{}),a=null,o=null,s=0;s=700||n===`bold`)&&(l=`bold`),n===`italic`&&(l+=`italic`),l.length===0&&(l=`normal`);for(var u=``,d={arial:`Helvetica`,Arial:`Helvetica`,verdana:`Helvetica`,Verdana:`Helvetica`,helvetica:`Helvetica`,Helvetica:`Helvetica`,"sans-serif":`Helvetica`,fixed:`Courier`,monospace:`Courier`,terminal:`Courier`,cursive:`Times`,fantasy:`Times`,serif:`Times`},f=0;f=2*Math.PI&&(r=0,i=2*Math.PI),this.path.push({type:`arc`,x:e,y:t,radius:n,startAngle:r,endAngle:i,counterclockwise:a})},d.prototype.arcTo=function(e,t,n,r,i){throw Error(`arcTo not implemented.`)},d.prototype.rect=function(e,t,n,r){if(isNaN(e)||isNaN(t)||isNaN(n)||isNaN(r))throw QN.error(`jsPDF.context2d.rect: Invalid arguments`,arguments),Error(`Invalid arguments passed to jsPDF.context2d.rect`);this.moveTo(e,t),this.lineTo(e+n,t),this.lineTo(e+n,t+r),this.lineTo(e,t+r),this.lineTo(e,t),this.lineTo(e+n,t),this.lineTo(e,t)},d.prototype.fillRect=function(e,t,n,r){if(isNaN(e)||isNaN(t)||isNaN(n)||isNaN(r))throw QN.error(`jsPDF.context2d.fillRect: Invalid arguments`,arguments),Error(`Invalid arguments passed to jsPDF.context2d.fillRect`);if(!p.call(this)){var i={};this.lineCap!==`butt`&&(i.lineCap=this.lineCap,this.lineCap=`butt`),this.lineJoin!==`miter`&&(i.lineJoin=this.lineJoin,this.lineJoin=`miter`),this.beginPath(),this.rect(e,t,n,r),this.fill(),i.hasOwnProperty(`lineCap`)&&(this.lineCap=i.lineCap),i.hasOwnProperty(`lineJoin`)&&(this.lineJoin=i.lineJoin)}},d.prototype.strokeRect=function(e,t,n,r){if(isNaN(e)||isNaN(t)||isNaN(n)||isNaN(r))throw QN.error(`jsPDF.context2d.strokeRect: Invalid arguments`,arguments),Error(`Invalid arguments passed to jsPDF.context2d.strokeRect`);m.call(this)||(this.beginPath(),this.rect(e,t,n,r),this.stroke())},d.prototype.clearRect=function(e,t,n,r){if(isNaN(e)||isNaN(t)||isNaN(n)||isNaN(r))throw QN.error(`jsPDF.context2d.clearRect: Invalid arguments`,arguments),Error(`Invalid arguments passed to jsPDF.context2d.clearRect`);this.ignoreClearRect||(this.fillStyle=`#ffffff`,this.fillRect(e,t,n,r))},d.prototype.save=function(e){e=typeof e!=`boolean`||e;for(var t=this.pdf.internal.getCurrentPageInfo().pageNumber,n=0;n0||this.margin[1]>0||this.margin[2]>0||this.margin[3]>0};d.prototype.drawImage=function(e,t,n,r,i,a,o,l,u){var d=this.pdf.getImageProperties(e),f=1,p=1,m=1,_=1;r!==void 0&&l!==void 0&&(m=l/r,_=u/i,f=d.width/r*l/r,p=d.height/i*u/i),a===void 0&&(a=t,o=n,t=0,n=0),r!==void 0&&l===void 0&&(l=r,u=i),r===void 0&&l===void 0&&(l=d.width,u=d.height);var b=this.ctx.transform.decompose(),S=P(b.rotate.shx),C=new c,w=(C=(C=(C=C.multiply(b.translate)).multiply(b.skew)).multiply(b.scale)).applyToRectangle(new s(a-t*m,o-n*_,r*f,i*p));if(this.autoPaging){for(var T,E=g.call(this,w),D=[],O=0;Ok||jC||T0)){for(;c>=0;c--)if(!0!==i[c-1].close&&!0!==i[c-1].begin){i[c-1].deltas.push(n),i[c-1].abs.push(s);break}}break;case`bct`:n=[s.x1-a[o-1].x,s.y1-a[o-1].y,s.x2-a[o-1].x,s.y2-a[o-1].y,s.x-a[o-1].x,s.y-a[o-1].y],i[i.length-1].deltas.push(n);break;case`qct`:var l=a[o-1].x+2/3*(s.x1-a[o-1].x),u=a[o-1].y+2/3*(s.y1-a[o-1].y),d=s.x+2/3*(s.x1-s.x),f=s.y+2/3*(s.y1-s.y),h=s.x,g=s.y;n=[l-a[o-1].x,u-a[o-1].y,d-a[o-1].x,f-a[o-1].y,h-a[o-1].x,g-a[o-1].y],i[i.length-1].deltas.push(n);break;case`arc`:i.push({deltas:[],abs:[],arc:!0}),Array.isArray(i[i.length-1].abs)&&i[i.length-1].abs.push(s)}}r=t?null:e===`stroke`?`stroke`:`fill`;for(var _=!1,v=0;v=.01&&(r=this.pdf.internal.getFontSize(),this.pdf.setFontSize(r*e.scale),i=this.lineWidth,this.lineWidth=i*e.scale);var ee=this.autoPaging!==`text`;if(ee||L.y+L.h<=j){if(ee||L.y>=k&&L.x<=N){var R=ee?e.text:this.pdf.splitTextToSize(e.text,e.maxWidth||N-L.x)[0],te=v([JSON.parse(JSON.stringify(m))],this.posX+this.margin[3],-F+k+this.ctx.prevPageLastElemOffset)[0],z=ee&&(O>E||O=.01&&(this.pdf.setFontSize(r),this.lineWidth=i)}}else e.scale>=.01&&(r=this.pdf.internal.getFontSize(),this.pdf.setFontSize(r*e.scale),i=this.lineWidth,this.lineWidth=i*e.scale),this.pdf.text(e.text,d.x+this.posX,d.y+this.posY,{angle:e.angle,align:t,renderingMode:e.renderingMode,maxWidth:e.maxWidth}),e.scale>=.01&&(this.pdf.setFontSize(r),this.lineWidth=i)},k=function(e,t,i,a){i||=0,a||=0,this.pdf.internal.out(n(e+i)+` `+r(t+a)+` l`)},A=function(e,t,n){return this.pdf.lines(e,t,n,null,null)},j=function(e,n,r,o,s,c,l,u){this.pdf.internal.out([t(i(r+e)),t(a(o+n)),t(i(s+e)),t(a(c+n)),t(i(l+e)),t(a(u+n)),`c`].join(` `))},M=function(e,t,n,r){for(var i=2*Math.PI,a=Math.PI/2;t>n;)t-=i;var o=Math.abs(n-t);o1e-5;){var u=l+c*Math.min(o,a);s.push(N.call(this,e,l,u)),o-=Math.abs(u-l),l=u}return s},N=function(e,t,n){var r=(n-t)/2,i=e*Math.cos(r),a=e*Math.sin(r),o=i,s=-a,c=o*o+s*s,l=c+o*i+s*a,u=4/3*(Math.sqrt(2*c*l)-l)/(o*a-s*i),d=o-u*s,f=s+u*o,p=d,m=-f,h=r+t,g=Math.cos(h),_=Math.sin(h);return{x1:e*Math.cos(t),y1:e*Math.sin(t),x2:d*g-f*_,y2:d*_+f*g,x3:p*g-m*_,y3:p*_+m*g,x4:e*Math.cos(n),y4:e*Math.sin(n)}},P=function(e){return 180*e/Math.PI},F=function(e,t,n,r,i,a){var o=e+.5*(n-e),c=t+.5*(r-t),l=i+.5*(n-i),u=a+.5*(r-a),d=Math.min(e,i,o,l),f=Math.max(e,i,o,l),p=Math.min(t,a,c,u),m=Math.max(t,a,c,u);return new s(d,p,f-d,m-p)},I=function(e,t,n,r,i,a,o,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C=n-e,w=r-t,T=i-n,E=a-r,D=o-i,O=c-a;for(u=0;u<41;u++)_=(h=(d=e+(l=u/40)*C)+l*((p=n+l*T)-d))+l*(p+l*(i+l*D-p)-h),v=(g=(f=t+l*w)+l*((m=r+l*E)-f))+l*(m+l*(a+l*O-m)-g),u==0?(y=_,b=v,x=_,S=v):(y=Math.min(y,_),b=Math.min(b,v),x=Math.max(x,_),S=Math.max(S,v));return new s(Math.round(y),Math.round(b),Math.round(x-y),Math.round(S-b))},L=function(){if(this.prevLineDash||this.ctx.lineDash.length||this.ctx.lineDashOffset){var e,t,n=(e=this.ctx.lineDash,t=this.ctx.lineDashOffset,JSON.stringify({lineDash:e,lineDashOffset:t}));this.prevLineDash!==n&&(this.pdf.setLineDash(this.ctx.lineDash,this.ctx.lineDashOffset),this.prevLineDash=n)}}})(kP.API),function(e){var t=function(e){var t,n,r,i,a,o,s,c,l,u;for(/[^\x00-\xFF]/.test(e),n=[],r=0,i=(e+=t=`\0\0\0\0`.slice(e.length%4||4)).length;i>r;r+=4)(a=(e.charCodeAt(r)<<24)+(e.charCodeAt(r+1)<<16)+(e.charCodeAt(r+2)<<8)+e.charCodeAt(r+3))===0?n.push(122):(o=(a=((a=((a=((a=(a-(u=a%85))/85)-(l=a%85))/85)-(c=a%85))/85)-(s=a%85))/85)%85,n.push(o+33,s+33,c+33,l+33,u+33));return function(e,t){for(var n=t;n>0;n--)e.pop()}(n,t.length),String.fromCharCode.apply(String,n)+`~>`},n=function(e){var t,n,r,i,a,o=String,s=`length`,c=255,l=`charCodeAt`,u=`slice`,d=`replace`;for(e[u](-2),e=e[u](0,-2)[d](/\s/g,``)[d](`z`,`!!!!!`),r=[],i=0,a=(e+=t=`uuuuu`[u](e[s]%5||5))[s];a>i;i+=5)n=52200625*(e[l](i)-33)+614125*(e[l](i+1)-33)+7225*(e[l](i+2)-33)+85*(e[l](i+3)-33)+(e[l](i+4)-33),r.push(c&n>>24,c&n>>16,c&n>>8,c&n);return function(e,t){for(var n=t;n>0;n--)e.pop()}(r,t[s]),o.fromCharCode.apply(o,r)},r=function(e){return e.split(``).map(function(e){return(`0`+e.charCodeAt().toString(16)).slice(-2)}).join(``)+`>`},i=function(e){var t=new RegExp(/^([0-9A-Fa-f]{2})+$/);if((e=e.replace(/\s/g,``)).indexOf(`>`)!==-1&&(e=e.substr(0,e.indexOf(`>`))),e.length%2&&(e+=`0`),!1===t.test(e))return``;for(var n=``,r=0;rimport(`./html2canvas-B1jts0tz.js`).then(e=>l(e.default)),[])).catch(function(e){return Promise.reject(Error(`Could not load html2canvas: `+e))}).then(function(e){return e.default?e.default:e})}function n(){return(XN.DOMPurify?Promise.resolve(XN.DOMPurify):Gb(()=>import(`./purify.es-DlxR2Lg_.js`),[])).catch(function(e){return Promise.reject(Error(`Could not load dompurify: `+e))}).then(function(e){return e.default?e.default:e})}var r=function(e){var t=hD(e);return t===`undefined`?`undefined`:t===`string`||e instanceof String?`string`:t===`number`||e instanceof Number?`number`:t===`function`||e instanceof Function?`function`:e&&e.constructor===Array?`array`:e&&e.nodeType===1?`element`:t===`object`?`object`:`unknown`},i=function(e,t){var n=document.createElement(e);for(var r in t.className&&(n.className=t.className),t.innerHTML&&t.dompurify&&(n.innerHTML=t.dompurify.sanitize(t.innerHTML)),t.style)n.style[r]=t.style[r];return n},a=function e(t,n){for(var r=t.nodeType===3?document.createTextNode(t.nodeValue):t.cloneNode(!1),i=t.firstChild;i;i=i.nextSibling)!0!==n&&i.nodeType===1&&i.nodeName===`SCRIPT`||r.appendChild(e(i,n));return t.nodeType===1&&(t.nodeName===`CANVAS`?(r.width=t.width,r.height=t.height,r.getContext(`2d`).drawImage(t,0,0)):t.nodeName!==`TEXTAREA`&&t.nodeName!==`SELECT`||(r.value=t.value),r.addEventListener(`load`,function(){r.scrollTop=t.scrollTop,r.scrollLeft=t.scrollLeft},!0)),r},o=function e(t){var n=Object.assign(e.convert(Promise.resolve()),JSON.parse(JSON.stringify(e.template))),r=e.convert(Promise.resolve(),n);return(r=r.setProgress(1,e,1,[e])).set(t)};(o.prototype=Object.create(Promise.prototype)).constructor=o,o.convert=function(e,t){return e.__proto__=t||o.prototype,e},o.template={prop:{src:null,container:null,overlay:null,canvas:null,img:null,pdf:null,pageSize:null,callback:function(){}},progress:{val:0,state:null,n:0,stack:[]},opt:{filename:`file.pdf`,margin:[0,0,0,0],enableLinks:!0,x:0,y:0,html2canvas:{},jsPDF:{},backgroundColor:`transparent`}},o.prototype.from=function(e,t){return this.then(function(){switch(t||=function(e){switch(r(e)){case`string`:return`string`;case`element`:return e.nodeName.toLowerCase()===`canvas`?`canvas`:`element`;default:return`unknown`}}(e),t){case`string`:return this.then(n).then(function(t){return this.set({src:i(`div`,{innerHTML:e,dompurify:t})})});case`element`:return this.set({src:e});case`canvas`:return this.set({canvas:e});case`img`:return this.set({img:e});default:return this.error(`Unknown source type.`)}})},o.prototype.to=function(e){switch(e){case`container`:return this.toContainer();case`canvas`:return this.toCanvas();case`img`:return this.toImg();case`pdf`:return this.toPdf();default:return this.error(`Invalid target.`)}},o.prototype.toContainer=function(){return this.thenList([function(){return this.prop.src||this.error(`Cannot duplicate - no source HTML.`)},function(){return this.prop.pageSize||this.setPageSize()}]).then(function(){var e={position:`relative`,display:`inline-block`,width:(typeof this.opt.width!=`number`||isNaN(this.opt.width)||typeof this.opt.windowWidth!=`number`||isNaN(this.opt.windowWidth)?Math.max(this.prop.src.clientWidth,this.prop.src.scrollWidth,this.prop.src.offsetWidth):this.opt.windowWidth)+`px`,left:0,right:0,top:0,margin:`auto`,backgroundColor:this.opt.backgroundColor},t=a(this.prop.src,this.opt.html2canvas.javascriptEnabled);t.tagName===`BODY`&&(e.height=Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)+`px`),this.prop.overlay=i(`div`,{className:`html2pdf__overlay`,style:{position:`fixed`,overflow:`hidden`,zIndex:1e3,left:`-100000px`,right:0,bottom:0,top:0}}),this.prop.container=i(`div`,{className:`html2pdf__container`,style:e}),this.prop.container.appendChild(t),this.prop.container.firstChild.appendChild(i(`div`,{style:{clear:`both`,border:`0 none transparent`,margin:0,padding:0,height:0}})),this.prop.container.style.float=`none`,this.prop.overlay.appendChild(this.prop.container),document.body.appendChild(this.prop.overlay),this.prop.container.firstChild.style.position=`relative`,this.prop.container.height=Math.max(this.prop.container.firstChild.clientHeight,this.prop.container.firstChild.scrollHeight,this.prop.container.firstChild.offsetHeight)+`px`})},o.prototype.toCanvas=function(){return this.thenList([function(){return document.body.contains(this.prop.container)||this.toContainer()}]).then(t).then(function(e){var t=Object.assign({},this.opt.html2canvas);return delete t.onrendered,e(this.prop.container,t)}).then(function(e){(this.opt.html2canvas.onrendered||function(){})(e),this.prop.canvas=e,document.body.removeChild(this.prop.overlay)})},o.prototype.toContext2d=function(){return this.thenList([function(){return document.body.contains(this.prop.container)||this.toContainer()}]).then(t).then(function(e){var t=this.opt.jsPDF,n=this.opt.fontFaces,r=typeof this.opt.width!=`number`||isNaN(this.opt.width)||typeof this.opt.windowWidth!=`number`||isNaN(this.opt.windowWidth)?1:this.opt.width/this.opt.windowWidth,i=Object.assign({async:!0,allowTaint:!0,scale:r,scrollX:this.opt.scrollX||0,scrollY:this.opt.scrollY||0,backgroundColor:`#ffffff`,imageTimeout:15e3,logging:!0,proxy:null,removeContainer:!0,foreignObjectRendering:!1,useCORS:!1},this.opt.html2canvas);if(delete i.onrendered,t.context2d.autoPaging=this.opt.autoPaging===void 0||this.opt.autoPaging,t.context2d.posX=this.opt.x,t.context2d.posY=this.opt.y,t.context2d.margin=this.opt.margin,t.context2d.fontFaces=n,n)for(var a=0;ac&&(s=l,l=c,c=s);else{if(e!==`l`&&e!==`landscape`)throw`Invalid orientation: `+e;e=`l`,c>l&&(s=l,l=c,c=s)}return{width:l,height:c,unit:t,k:i,orientation:e}},e.html=function(e,t){(t||={}).callback=t.callback||function(){},t.html2canvas=t.html2canvas||{},t.html2canvas.canvas=t.html2canvas.canvas||this.canvas,t.jsPDF=t.jsPDF||this,t.fontFaces=t.fontFaces?t.fontFaces.map(wF):null;var n=new o(t);return t.worker?n:n.from(e).doCallback()}}(kP.API),kP.API.addJS=function(e){var t,n,r=function(e){for(var t=``,n=0;n=0&&e[a]===`\\`;a--)i++;t+=i%2==0?`\\`+r:r}else t+=r}return t}(e);return this.internal.events.subscribe(`postPutResources`,function(){t=this.internal.newObject(),this.internal.out(`<<`),this.internal.out(`/Names [(EmbeddedJS) `+(t+1)+` 0 R]`),this.internal.out(`>>`),this.internal.out(`endobj`),n=this.internal.newObject(),this.internal.out(`<<`),this.internal.out(`/S /JavaScript`),this.internal.out(`/JS (`+r+`)`),this.internal.out(`>>`),this.internal.out(`endobj`)}),this.internal.events.subscribe(`putCatalog`,function(){t!==void 0&&n!==void 0&&this.internal.out(`/Names <>`)}),this},function(e){var t;e.events.push([`postPutResources`,function(){var e=this,n=/^(\d+) 0 obj$/;if(this.outline.root.children.length>0)for(var r=e.outline.render().split(/\r\n/),i=0;i> endobj`)}var f=e.internal.newObject();for(e.internal.write(`<< /Names [ `),i=0;i>`,`endobj`),t=e.internal.newObject(),e.internal.write(`<< /Dests `+f+` 0 R`),e.internal.write(`>>`,`endobj`)}}]),e.events.push([`putCatalog`,function(){var e=this;e.outline.root.children.length>0&&(e.internal.write(`/Outlines`,this.outline.makeRef(this.outline.root)),this.outline.createNamedDestinations&&e.internal.write(`/Names `+t+` 0 R`))}]),e.events.push([`initialized`,function(){var e=this;e.outline={createNamedDestinations:!1,root:{children:[]}},e.outline.add=function(e,t,n){var r={title:t,options:n,children:[]};return e??=this.root,e.children.push(r),r},e.outline.render=function(){return this.ctx={},this.ctx.val=``,this.ctx.pdf=e,this.genIds_r(this.root),this.renderRoot(this.root),this.renderItems(this.root),this.ctx.val},e.outline.genIds_r=function(t){t.id=e.internal.newObjectDeferred();for(var n=0;n0&&(this.line(`/First `+this.makeRef(e.children[0])),this.line(`/Last `+this.makeRef(e.children[e.children.length-1]))),this.line(`/Count `+this.count_r({count:0},e)),this.objEnd()},e.outline.renderItems=function(t){for(var n=this.ctx.pdf.internal.getVerticalCoordinateString,r=0;r0&&this.line(`/Prev `+this.makeRef(t.children[r-1])),r0&&(this.line(`/First `+this.makeRef(i.children[0])),this.line(`/Last `+this.makeRef(i.children[i.children.length-1])));var a=this.count=this.count_r({count:0},i);if(a>0&&this.line(`/Count `+a),i.options&&i.options.pageNumber){var o=e.internal.getPageInfo(i.options.pageNumber);this.line(`/Dest [`+o.objId+` 0 R /XYZ 0 `+n(0)+` 0]`)}this.objEnd()}for(var s=0;s> \r endobj\r `},e.outline.count_r=function(e,t){for(var n=0;n1){o=!0,c=void 0;var v=t*n;l=new Uint8Array(v);for(var y=new DataView(r.buffer),b=0;b536870912)throw Error(`Image dimensions exceed 512MB, which is too large.`);this.data=new Uint8Array(t);try{this[e]()}catch(e){QN.log(`bit decode error:`+e)}},QF.prototype.bit1=function(){var e,t=Math.ceil(this.width/8),n=t%4;for(e=this.height-1;e>=0;e--){for(var r=this.bottom_up?e:this.height-1-e,i=0;i>7-s&1];this.data[o+4*s]=c.blue,this.data[o+4*s+1]=c.green,this.data[o+4*s+2]=c.red,this.data[o+4*s+3]=255}n!==0&&(this.pos+=4-n)}},QF.prototype.bit4=function(){for(var e=Math.ceil(this.width/2),t=e%4,n=this.height-1;n>=0;n--){for(var r=this.bottom_up?n:this.height-1-n,i=0;i>4,c=15&a,l=this.palette[s];if(this.data[o]=l.blue,this.data[o+1]=l.green,this.data[o+2]=l.red,this.data[o+3]=255,2*i+1>=this.width)break;l=this.palette[c],this.data[o+4]=l.blue,this.data[o+4+1]=l.green,this.data[o+4+2]=l.red,this.data[o+4+3]=255}t!==0&&(this.pos+=4-t)}},QF.prototype.bit8=function(){for(var e=this.width%4,t=this.height-1;t>=0;t--){for(var n=this.bottom_up?t:this.height-1-t,r=0;r=0;n--){for(var r=this.bottom_up?n:this.height-1-n,i=0;i>5&t)/t*255|0,c=(a>>10&t)/t*255|0,l=a>>15?255:0,u=r*this.width*4+4*i;this.data[u]=c,this.data[u+1]=s,this.data[u+2]=o,this.data[u+3]=l}this.pos+=e}},QF.prototype.bit16=function(){for(var e=this.width%3,t=31,n=63,r=this.height-1;r>=0;r--){for(var i=this.bottom_up?r:this.height-1-r,a=0;a>5&n)/n*255|0,l=(o>>11)/t*255|0,u=i*this.width*4+4*a;this.data[u]=l,this.data[u+1]=c,this.data[u+2]=s,this.data[u+3]=255}this.pos+=e}},QF.prototype.bit24=function(){for(var e=this.height-1;e>=0;e--){for(var t=this.bottom_up?e:this.height-1-e,n=0;n=0;e--)for(var t=this.bottom_up?e:this.height-1-e,n=0;nr&&(i.push(e.slice(c,a)),s=0,c=a),s+=t[a],a++;return c!==a&&i.push(e.slice(c,a)),i},IF=function(e,t,n){n||={};var r,i,a,o,s,c,l,u=[],d=[u],f=n.textIndent||0,p=0,m=0,h=e.split(` `),g=NF.apply(this,[` `,n])[0];if(c=n.lineIndent===-1?h[0].length+2:n.lineIndent||0){var _=Array(c).join(` `),v=[];h.map(function(e){(e=e.split(/\s*\n/)).length>1?v=v.concat(e.map(function(e,t){return(t&&e.length?` `:``)+e})):v.push(e[0])}),h=v,c=PF.apply(this,[_,n])}for(a=0,o=h.length;at||y){if(m>t){for(s=FF.apply(this,[r,i,t-(f+p),t]),u.push(s.shift()),u=[s.pop()];s.length;)d.push([s.shift()]);m=i.slice(r.length-(u[0]?u[0].length:0)).reduce(function(e,t){return e+t},0)}else u=[r];d.push(u),f=m+c,p=g}else u.push(r),f+=p+m,p=g}return l=c?function(e,t){return(t?_:``)+e.join(` `)}:function(e){return e.join(` `)},d.map(l)},MF.splitTextToSize=function(e,t,n){var r,i=(n||={}).fontSize||this.internal.getFontSize(),a=function(e){if(e.widths&&e.kerning)return{widths:e.widths,kerning:e.kerning};var t=this.internal.getFont(e.fontName,e.fontStyle),n=`Unicode`;return t.metadata[n]?{widths:t.metadata[n].widths||{0:1},kerning:t.metadata[n].kerning||{}}:{font:t.metadata,fontSize:this.internal.getFontSize(),charSpace:this.internal.getCharSpace()}}.call(this,n);r=Array.isArray(e)?e:String(e).split(/\r?\n/);var o=1*this.internal.scaleFactor*t/i;a.textIndent=n.textIndent?1*n.textIndent*this.internal.scaleFactor/i:0,a.lineIndent=n.lineIndent;var s,c,l=[];for(s=0,c=r.length;simport(`./index.es-Dm4MvI1O.js`),[])).catch(function(e){return Promise.reject(Error(`Could not load canvg: `+e))}).then(function(e){return e.default?e.default:e}).then(function(t){return t.fromString(l,e,u)},function(){return Promise.reject(Error(`Could not load canvg.`))}).then(function(e){return e.render(u)}).then(function(){d.addImage(c.toDataURL(`image/jpeg`,1),t,n,r,i,o,s)})},kP.API.putTotalPages=function(e){var t,n=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(t=new RegExp(e,`g`),n=this.internal.getNumberOfPages()):(t=new RegExp(this.pdfEscape16(e,this.internal.getFont()),`g`),n=this.pdfEscape16(this.internal.getNumberOfPages()+``,this.internal.getFont()));for(var r=1;r<=this.internal.getNumberOfPages();r++)for(var i=0;i1){for(u=0;u>`)}),this.internal.viewerpreferences.isSubscribed=!0),this.internal.viewerpreferences.configuration=n,this},kP.API.addMetadata=function(e,t){return this.internal.__metadata__===void 0&&(this.internal.__metadata__={metadata:e,namespaceUri:t??`http://jspdf.default.namespaceuri/`,rawXml:typeof t==`boolean`&&t},this.internal.events.subscribe(`putCatalog`,tI),this.internal.events.subscribe(`postPutResources`,eI)),this},function(e){var t=e.API,n=t.pdfEscape16=function(e,t){for(var n,r=t.metadata.Unicode.widths,i=[``,`0`,`00`,`000`,`0000`],a=[``],o=0,s=e.length;o> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange <0000> endcodespacerange`,r=[],o=0,s=(n=Object.keys(e).sort(function(e,t){return e-t})).length;o=100&&(a+=` `+r.length+` beginbfchar `+r.join(` `)+` endbfchar`,r=[]),e[t]!==void 0&&e[t]!==null&&typeof e[t].toString==`function`&&(i=(`0000`+e[t].toString(16)).slice(-4),t=(`0000`+(+t).toString(16)).slice(-4),r.push(`<`+t+`><`+i+`>`));return r.length&&(a+=` `+r.length+` beginbfchar `+r.join(` `)+` endbfchar `),a+`endcmap CMapName currentdict /CMap defineresource pop end end`};t.events.push([`putFont`,function(t){(function(t){var n=t.font,i=t.out,a=t.newObject,o=t.putStream;if(n.metadata instanceof e.API.TTFFont&&n.encoding===`Identity-H`){for(var s=n.metadata.Unicode.widths,c=n.metadata.subset.encode(n.metadata.glyIdsUsed,1),l=``,u=0;u>`),i(`endobj`);var m=a();i(`<<`),i(`/Type /Font`),i(`/BaseFont /`+CP(n.fontName)),i(`/FontDescriptor `+p+` 0 R`),i(`/W `+e.API.PDFObject.convert(s)),i(`/CIDToGIDMap /Identity`),i(`/DW 1000`),i(`/Subtype /CIDFontType2`),i(`/CIDSystemInfo`),i(`<<`),i(`/Supplement 0`),i(`/Registry (Adobe)`),i(`/Ordering (`+n.encoding+`)`),i(`>>`),i(`>>`),i(`endobj`),n.objectNumber=a(),i(`<<`),i(`/Type /Font`),i(`/Subtype /Type0`),i(`/ToUnicode `+f+` 0 R`),i(`/BaseFont /`+CP(n.fontName)),i(`/Encoding /`+n.encoding),i(`/DescendantFonts [`+m+` 0 R]`),i(`>>`),i(`endobj`),n.isAlreadyPutted=!0}})(t)}]),t.events.push([`putFont`,function(t){(function(t){var n=t.font,i=t.out,a=t.newObject,o=t.putStream;if(n.metadata instanceof e.API.TTFFont&&n.encoding===`WinAnsiEncoding`){for(var s=n.metadata.rawData,c=``,l=0;l>`),i(`endobj`),n.objectNumber=a();for(var p=0;p>`),i(`endobj`),n.isAlreadyPutted=!0}})(t)}]);var i=function(e){var t,r=e.text||``,i=e.x,a=e.y,o=e.options||{},s=e.mutex||{},c=s.pdfEscape,l=s.activeFontKey,u=s.fonts,d=l,f=``,p=0,m=``,h=u[d].encoding;if(u[d].encoding!==`Identity-H`)return{text:r,x:i,y:a,options:o,mutex:s};for(m=r,d=l,Array.isArray(r)&&(m=r[0]),p=0;p.<.[.].[.{.}.{.«.».«.‹.›.‹.⁅.⁆.⁅.⁽.⁾.⁽.₍.₎.₍.≤.≥.≤.〈.〉.〈.﹙.﹚.﹙.﹛.﹜.﹛.﹝.﹞.﹝.﹤.﹥.﹤`.split(`.`),h=new RegExp(/^([1-4|9]|1[0-9]|2[0-9]|3[0168]|4[04589]|5[012]|7[78]|159|16[0-9]|17[0-2]|21[569]|22[03489]|250)$/),g=!1,_=0;this.__bidiEngine__={};var v=function(e){var t=e.charCodeAt(),n=t>>8,r=p[n];return r===void 0?n===252||n===253?`AL`:h.test(n)?`L`:n===8?`R`:`N`:l[256*r+(255&t)]},y=function(e){for(var t,n=0;n=t.length||(c=o[s-1])!==`EN`&&c!==`AN`||(l=t[s+1])!==`EN`&&l!==`AN`?f=`N`:g&&(l=`AN`),f=l===c?l:`N`;break;case`ES`:f=(c=s>0?o[s-1]:`B`)===`EN`&&s+10&&o[s-1]===`EN`){f=`EN`;break}if(g){f=`N`;break}for(u=s+1,d=t.length;u=1425&&p<=2303||p===64286;if(c=t[u],m&&(c===`R`||c===`AL`)){f=`R`;break}}}f=s<1||(c=t[s-1])===`B`?`N`:o[s-1];break;case`B`:g=!1,n=!0,f=_;break;case`S`:r=!0,f=`N`}return f},x=function(e,t,n){var r=e.split(``);return n&&S(r,n,{hiLevel:_}),r.reverse(),t&&t.reverse(),r.join(``)},S=function(e,t,i){var a,o,s,c,l,p=-1,m=e.length,h=0,y=[],x=_?d:u,S=[];for(g=!1,n=!1,r=!1,o=0;o0)if(a===16){for(o=p;o-1){for(o=p;o=0&&e[i]===`WS`;i--)t[i]=_}}(S,t,m)},C=function(e,t,r,i,a){if(!(a.hiLevel=e){for(c=d+1;c=e;)c++;for(l=d,s=c-1;l=0&&(e[i]=m[r+1])}(r,n,i),C(2,r,t,n,i),C(1,r,t,n,i),r.join(``)};return this.__bidiEngine__.doBidiReorder=function(e,t,n){if(function(e,t){if(t)for(var n=0;n>16)&&(t=-(1+(65535^t))),this.italicAngle=+(t+`.`+n)):this.italicAngle=0,this.ascender=Math.round(this.ascender*this.scaleFactor),this.decender=Math.round(this.decender*this.scaleFactor),this.lineGap=Math.round(this.lineGap*this.scaleFactor),this.capHeight=this.os2.exists&&this.os2.capHeight||this.ascender,this.xHeight=this.os2.exists&&this.os2.xHeight||0,this.familyClass=(this.os2.exists&&this.os2.familyClass||0)>>8,this.isSerif=(i=this.familyClass)===1||i===2||i===3||i===4||i===5||i===7,this.isScript=this.familyClass===10,this.flags=0,this.post.isFixedPitch&&(this.flags|=1),this.isSerif&&(this.flags|=2),this.isScript&&(this.flags|=8),this.italicAngle!==0&&(this.flags|=64),this.flags|=32,!this.cmap.unicode)throw Error(`No unicode cmap for font`)},e.prototype.characterToGlyph=function(e){return this.cmap.unicode?.codeMap[e]||0},e.prototype.widthOfGlyph=function(e){var t;return t=1e3/this.head.unitsPerEm,this.hmtx.forGlyph(e).advance*t},e.prototype.widthOfString=function(e,t,n){var r,i,a,o;for(a=0,i=0,o=(e=``+e).length;0<=o?io;i=0<=o?++i:--i)r=e.charCodeAt(i),a+=this.widthOfGlyph(this.characterToGlyph(r))+1e3/t*n||0;return t/1e3*a},e.prototype.lineHeight=function(e,t){var n;return t??=!1,n=t?this.lineGap:0,(this.ascender+n-this.decender)/1e3*e},e}();var nI,rI=function(){function e(e){this.data=e??[],this.pos=0,this.length=this.data.length}return e.prototype.readByte=function(){return this.data[this.pos++]},e.prototype.writeByte=function(e){return this.data[this.pos++]=e},e.prototype.readUInt32=function(){return 16777216*this.readByte()+(this.readByte()<<16)+(this.readByte()<<8)+this.readByte()},e.prototype.writeUInt32=function(e){return this.writeByte(e>>>24&255),this.writeByte(e>>16&255),this.writeByte(e>>8&255),this.writeByte(255&e)},e.prototype.readInt32=function(){var e;return(e=this.readUInt32())>=2147483648?e-4294967296:e},e.prototype.writeInt32=function(e){return e<0&&(e+=4294967296),this.writeUInt32(e)},e.prototype.readUInt16=function(){return this.readByte()<<8|this.readByte()},e.prototype.writeUInt16=function(e){return this.writeByte(e>>8&255),this.writeByte(255&e)},e.prototype.readInt16=function(){var e;return(e=this.readUInt16())>=32768?e-65536:e},e.prototype.writeInt16=function(e){return e<0&&(e+=65536),this.writeUInt16(e)},e.prototype.readString=function(e){var t,n;for(n=[],t=0;0<=e?te;t=0<=e?++t:--t)n[t]=String.fromCharCode(this.readByte());return n.join(``)},e.prototype.writeString=function(e){var t,n,r;for(r=[],t=0,n=e.length;0<=n?tn;t=0<=n?++t:--t)r.push(this.writeByte(e.charCodeAt(t)));return r},e.prototype.readShort=function(){return this.readInt16()},e.prototype.writeShort=function(e){return this.writeInt16(e)},e.prototype.readLongLong=function(){var e,t,n,r,i,a,o,s;return e=this.readByte(),t=this.readByte(),n=this.readByte(),r=this.readByte(),i=this.readByte(),a=this.readByte(),o=this.readByte(),s=this.readByte(),128&e?-1*(72057594037927940*(255^e)+281474976710656*(255^t)+1099511627776*(255^n)+4294967296*(255^r)+16777216*(255^i)+65536*(255^a)+256*(255^o)+(255^s)+1):72057594037927940*e+281474976710656*t+1099511627776*n+4294967296*r+16777216*i+65536*a+256*o+s},e.prototype.writeLongLong=function(e){var t,n;return t=Math.floor(e/4294967296),n=4294967295&e,this.writeByte(t>>24&255),this.writeByte(t>>16&255),this.writeByte(t>>8&255),this.writeByte(255&t),this.writeByte(n>>24&255),this.writeByte(n>>16&255),this.writeByte(n>>8&255),this.writeByte(255&n)},e.prototype.readInt=function(){return this.readInt32()},e.prototype.writeInt=function(e){return this.writeInt32(e)},e.prototype.read=function(e){var t,n;for(t=[],n=0;0<=e?ne;n=0<=e?++n:--n)t.push(this.readByte());return t},e.prototype.write=function(e){var t,n,r,i;for(i=[],n=0,r=e.length;nr;n=0<=r?++n:--n)t={tag:e.readString(4),checksum:e.readInt(),offset:e.readInt(),length:e.readInt()},this.tables[t.tag]=t}return t.prototype.encode=function(t){var n,r,i,a,o,s,c,l,u,d,f,p,m;for(m in f=Object.keys(t).length,s=Math.log(2),u=16*Math.floor(Math.log(f)/s),a=Math.floor(u/s),l=16*f-u,(r=new rI).writeInt(this.scalarType),r.writeShort(f),r.writeShort(u),r.writeShort(a),r.writeShort(l),i=16*f,c=r.pos+i,o=null,p=[],t)for(d=t[m],r.writeString(m),r.writeInt(e(d)),r.writeInt(c),r.writeInt(d.length),p=p.concat(d),m===`head`&&(o=c),c+=d.length;c%4;)p.push(0),c++;return r.write(p),n=2981146554-e(r.data),r.pos=o+8,r.writeUInt32(n),r.data},e=function(e){var t,n,r,i;for(e=_I.call(e);e.length%4;)e.push(0);for(r=new rI(e),n=0,t=0,i=e.length;td;s=0<=d?++t:--t)n.push(e.readUInt16());return n}(),e.pos+=2,m=function(){var t,n;for(n=[],s=t=0;0<=d?td;s=0<=d?++t:--t)n.push(e.readUInt16());return n}(),c=function(){var t,n;for(n=[],s=t=0;0<=d?td;s=0<=d?++t:--t)n.push(e.readUInt16());return n}(),l=function(){var t,n;for(n=[],s=t=0;0<=d?td;s=0<=d?++t:--t)n.push(e.readUInt16());return n}(),r=(this.length-e.pos+this.offset)/2,o=function(){var t,n;for(n=[],s=t=0;0<=r?tr;s=0<=r?++t:--t)n.push(e.readUInt16());return n}(),s=g=0,v=i.length;g=h;n=p<=h?++_:--_)l[s]===0?a=n+c[s]:(a=o[l[s]/2+(n-p)-(d-s)]||0)!==0&&(a+=c[s]),this.codeMap[n]=65535&a}e.pos=u}return e.encode=function(e,t){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,ee,R,te,z,B,V,ne,re,ie,ae;switch(k=new rI,a=Object.keys(e).sort(function(e,t){return e-t}),t){case`macroman`:for(m=0,h=function(){var e=[];for(p=0;p<256;++p)e.push(0);return e}(),_={0:0},i={},A=0,P=a.length;A=32768)for(s.push(0),x.push(2*(f.length+w-p)),r=N=E;E<=l?N<=l:N>=l;r=E<=l?++N:--N)f.push(n[r].new);else s.push(O-E),x.push(0)}for(k.writeUInt16(3),k.writeUInt16(1),k.writeUInt32(12),k.writeUInt16(4),k.writeUInt16(16+8*w+2*f.length),k.writeUInt16(0),k.writeUInt16(T),k.writeUInt16(C),k.writeUInt16(d),k.writeUInt16(S),B=0,L=u.length;Br;n=0<=r?++n:--n)t=new cI(e,this.offset),this.tables.push(t),t.isUnicode&&this.unicode==null&&(this.unicode=t);return!0},e.encode=function(e,t){var n,r;return t??=`macroman`,n=cI.encode(e,t),(r=new rI).writeUInt16(0),r.writeUInt16(1),n.table=r.data.concat(n.subtable),n},e}(),uI=function(){function e(){return e.__super__.constructor.apply(this,arguments)}return oI(e,nI),e.prototype.tag=`hhea`,e.prototype.parse=function(e){return e.pos=this.offset,this.version=e.readInt(),this.ascender=e.readShort(),this.decender=e.readShort(),this.lineGap=e.readShort(),this.advanceWidthMax=e.readShort(),this.minLeftSideBearing=e.readShort(),this.minRightSideBearing=e.readShort(),this.xMaxExtent=e.readShort(),this.caretSlopeRise=e.readShort(),this.caretSlopeRun=e.readShort(),this.caretOffset=e.readShort(),e.pos+=8,this.metricDataFormat=e.readShort(),this.numberOfMetrics=e.readUInt16()},e}(),dI=function(){function e(){return e.__super__.constructor.apply(this,arguments)}return oI(e,nI),e.prototype.tag=`OS/2`,e.prototype.parse=function(e){if(e.pos=this.offset,this.version=e.readUInt16(),this.averageCharWidth=e.readShort(),this.weightClass=e.readUInt16(),this.widthClass=e.readUInt16(),this.type=e.readShort(),this.ySubscriptXSize=e.readShort(),this.ySubscriptYSize=e.readShort(),this.ySubscriptXOffset=e.readShort(),this.ySubscriptYOffset=e.readShort(),this.ySuperscriptXSize=e.readShort(),this.ySuperscriptYSize=e.readShort(),this.ySuperscriptXOffset=e.readShort(),this.ySuperscriptYOffset=e.readShort(),this.yStrikeoutSize=e.readShort(),this.yStrikeoutPosition=e.readShort(),this.familyClass=e.readShort(),this.panose=function(){var t,n;for(n=[],t=0;t<10;++t)n.push(e.readByte());return n}(),this.charRange=function(){var t,n;for(n=[],t=0;t<4;++t)n.push(e.readInt());return n}(),this.vendorID=e.readString(4),this.selection=e.readShort(),this.firstCharIndex=e.readShort(),this.lastCharIndex=e.readShort(),this.version>0&&(this.ascent=e.readShort(),this.descent=e.readShort(),this.lineGap=e.readShort(),this.winAscent=e.readShort(),this.winDescent=e.readShort(),this.codePageRange=function(){var t,n;for(n=[],t=0;t<2;t=++t)n.push(e.readInt());return n}(),this.version>1))return this.xHeight=e.readShort(),this.capHeight=e.readShort(),this.defaultChar=e.readShort(),this.breakChar=e.readShort(),this.maxContext=e.readShort()},e}(),fI=function(){function e(){return e.__super__.constructor.apply(this,arguments)}return oI(e,nI),e.prototype.tag=`post`,e.prototype.parse=function(e){var t,n,r;switch(e.pos=this.offset,this.format=e.readInt(),this.italicAngle=e.readInt(),this.underlinePosition=e.readShort(),this.underlineThickness=e.readShort(),this.isFixedPitch=e.readInt(),this.minMemType42=e.readInt(),this.maxMemType42=e.readInt(),this.minMemType1=e.readInt(),this.maxMemType1=e.readInt(),this.format){case 65536:case 196608:break;case 131072:var i;for(n=e.readUInt16(),this.glyphNameIndex=[],i=0;0<=n?in;i=0<=n?++i:--i)this.glyphNameIndex.push(e.readUInt16());for(this.names=[],r=[];e.posn;i=0<=n?++t:--t)r.push(e.readUInt32());return r}.call(this)}},e}(),pI=function(e,t){this.raw=e,this.length=e.length,this.platformID=t.platformID,this.encodingID=t.encodingID,this.languageID=t.languageID},mI=function(){function e(){return e.__super__.constructor.apply(this,arguments)}return oI(e,nI),e.prototype.tag=`name`,e.prototype.parse=function(e){var t,n,r,i,a,o,s,c,l,u,d;for(e.pos=this.offset,e.readShort(),t=e.readShort(),o=e.readShort(),n=[],i=0;0<=t?it;i=0<=t?++i:--i)n.push({platformID:e.readShort(),encodingID:e.readShort(),languageID:e.readShort(),nameID:e.readShort(),length:e.readShort(),offset:this.offset+o+e.readShort()});for(s={},i=l=0,u=n.length;lo;t=0<=o?++t:--t)this.metrics.push({advance:e.readUInt16(),lsb:e.readInt16()});for(r=this.file.maxp.numGlyphs-this.file.hhea.numberOfMetrics,this.leftSideBearings=function(){var n,i;for(i=[],t=n=0;0<=r?nr;t=0<=r?++n:--n)i.push(e.readInt16());return i}(),this.widths=function(){var e,t,n,r;for(r=[],e=0,t=(n=this.metrics).length;er;t=0<=r?++a:--a)s.push(this.widths.push(n));return s},e.prototype.forGlyph=function(e){return e in this.metrics?this.metrics[e]:{advance:this.metrics[this.metrics.length-1].advance,lsb:this.leftSideBearings[e-this.metrics.length]}},e}(),_I=[].slice,vI=function(){function e(){return e.__super__.constructor.apply(this,arguments)}return oI(e,nI),e.prototype.tag=`glyf`,e.prototype.parse=function(){return this.cache={}},e.prototype.glyphFor=function(e){var t,n,r,i,a,o,s,c,l,u;return e in this.cache?this.cache[e]:(i=this.file.loca,t=this.file.contents,n=i.indexOf(e),(r=i.lengthOf(e))===0?this.cache[e]=null:(t.pos=this.offset+n,a=(o=new rI(t.read(r))).readShort(),c=o.readShort(),u=o.readShort(),s=o.readShort(),l=o.readShort(),this.cache[e]=a===-1?new bI(o,c,u,s,l):new yI(o,a,c,u,s,l),this.cache[e]))},e.prototype.encode=function(e,t,n){var r,i,a,o,s;for(a=[],i=[],o=0,s=t.length;o0&&(r+=s)}for(var c=Array(4*n.length),l=0;l>8,c[4*l+1]=(16711680&n[l])>>16,c[4*l]=(4278190080&n[l])>>24;return c},e}(),SI=function(){function e(e){this.font=e,this.subset={},this.unicodes={},this.next=33}return e.prototype.generateCmap=function(){var e,t,n,r,i;for(t in r=this.font.cmap.tables[0].codeMap,e={},i=this.subset)n=i[t],e[t]=r[n];return e},e.prototype.glyphsFor=function(e){var t,n,r,i,a,o,s;for(r={},a=0,o=e.length;a0)for(i in s=this.glyphsFor(t))n=s[i],r[i]=n;return r},e.prototype.encode=function(e,t){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g;for(r in n=lI.encode(this.generateCmap(),`unicode`),a=this.glyphsFor(e),f={0:0},g=n.charMap)f[(s=g[r]).old]=s.new;for(p in d=n.maxGlyphID,a)p in f||(f[p]=d++);return l=function(e){var t,n;for(t in n={},e)n[e[t]]=t;return n}(f),u=Object.keys(l).sort(function(e,t){return e-t}),m=function(){var e,t,n;for(n=[],e=0,t=u.length;e>`),a.join(` `)}return``+n},t}();function CI(e,t,n,r,i){r||={};var a=1.15,o=i.internal.scaleFactor,s=i.internal.getFontSize()/o,c=s*(i.getLineHeightFactor?i.getLineHeightFactor():a),l=/\r\n|\r|\n/g,u=``,d=1;if((r.valign===`middle`||r.valign===`bottom`||r.halign===`center`||r.halign===`right`)&&(u=typeof e==`string`?e.split(l):e,d=u.length||1),n+=s*(2-a),r.valign===`middle`?n-=d/2*c:r.valign===`bottom`&&(n-=d*c),r.halign===`center`||r.halign===`right`){var f=s;if(r.halign===`center`&&(f*=.5),u&&d>=1){for(var p=0;p0,r=t||t===0;return n&&r?`DF`:n?`S`:r?`F`:null}function PI(e,t){if(e||=t,Array.isArray(e)){if(e.length>=4)return{top:e[0],right:e[1],bottom:e[2],left:e[3]};if(e.length===3)return{top:e[0],right:e[1],bottom:e[2],left:e[1]};if(e.length===2)return{top:e[0],right:e[1],bottom:e[0],left:e[1]};e=e.length===1?e[0]:t}return typeof e==`object`?(typeof e.vertical==`number`&&(e.top=e.vertical,e.bottom=e.vertical),typeof e.horizontal==`number`&&(e.right=e.horizontal,e.left=e.horizontal),{left:e.left??t,top:e.top??t,right:e.right??t,bottom:e.bottom??t}):(typeof e!=`number`&&(e=t),{top:e,right:e,bottom:e,left:e})}function FI(e,t){var n=PI(t.settings.margin,0);return e.pageSize().width-(n.left+n.right)}function II(e,t,n,r,i){var a={},o=96/72,s=RI(t,function(e){return i.getComputedStyle(e).backgroundColor});s!=null&&(a.fillColor=s);var c=RI(t,function(e){return i.getComputedStyle(e).color});c!=null&&(a.textColor=c);var l=BI(r,n);l&&(a.cellPadding=l);var u=`borderTopColor`,d=o*n,f=r.borderTopWidth;if(r.borderBottomWidth===f&&r.borderRightWidth===f&&r.borderLeftWidth===f){var p=(parseFloat(f)||0)/d;p&&(a.lineWidth=p)}else a.lineWidth={top:(parseFloat(r.borderTopWidth)||0)/d,right:(parseFloat(r.borderRightWidth)||0)/d,bottom:(parseFloat(r.borderBottomWidth)||0)/d,left:(parseFloat(r.borderLeftWidth)||0)/d},a.lineWidth.top||(a.lineWidth.right?u=`borderRightColor`:a.lineWidth.bottom?u=`borderBottomColor`:a.lineWidth.left&&(u=`borderLeftColor`));var m=RI(t,function(e){return i.getComputedStyle(e)[u]});m!=null&&(a.lineColor=m);var h=[`left`,`right`,`center`,`justify`];h.indexOf(r.textAlign)!==-1&&(a.halign=r.textAlign),h=[`middle`,`bottom`,`top`],h.indexOf(r.verticalAlign)!==-1&&(a.valign=r.verticalAlign);var g=parseInt(r.fontSize||``);isNaN(g)||(a.fontSize=g/o);var _=LI(r);_&&(a.fontStyle=_);var v=(r.fontFamily||``).toLowerCase();return e.indexOf(v)!==-1&&(a.font=v),a}function LI(e){var t=``;return(e.fontWeight===`bold`||e.fontWeight===`bolder`||parseInt(e.fontWeight)>=700)&&(t=`bold`),(e.fontStyle===`italic`||e.fontStyle===`oblique`)&&(t+=`italic`),t}function RI(e,t){var n=zI(e,t);if(!n)return null;var r=n.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!r||!Array.isArray(r))return null;var i=[parseInt(r[1]),parseInt(r[2]),parseInt(r[3])];return parseInt(r[4])===0||isNaN(i[0])||isNaN(i[1])||isNaN(i[2])?null:i}function zI(e,t){var n=t(e);return n===`rgba(0, 0, 0, 0)`||n===`transparent`||n===`initial`||n===`inherit`?e.parentElement==null?null:zI(e.parentElement,t):n}function BI(e,t){var n=[e.paddingTop,e.paddingRight,e.paddingBottom,e.paddingLeft],r=96/(72/t),i=(parseInt(e.lineHeight)-parseInt(e.fontSize))/t/2,a=PI(n.map(function(e){return parseInt(e||`0`)/r}),0);return i>a.top&&(a.top=i),i>a.bottom&&(a.bottom=i),a}function VI(e,t,n,r,i){r===void 0&&(r=!1),i===void 0&&(i=!1);var a=typeof t==`string`?n.document.querySelector(t):t,o=Object.keys(e.getFontList()),s=e.scaleFactor(),c=[],l=[],u=[];if(!a)return console.error(`Html table could not be found with input: `,t),{head:c,body:l,foot:u};for(var d=0;d0&&(i||d.display!==`none`))return o}function UI(e){var t=e.cloneNode(!0);return t.innerHTML=t.innerHTML.replace(/\n/g,``).replace(/ +/g,` `),t.innerHTML=t.innerHTML.split(//).map(function(e){return e.trim()}).join(` `),t.innerText||t.textContent||``}function WI(e,t,n){for(var r=0,i=[e,t,n];r0?`_${a}`:``);var s={dataKey:o};i.push(s)}}),i}var $I=function(){function e(e,t,n){this.table=t,this.pageNumber=t.pageNumber,this.settings=t.settings,this.cursor=n,this.doc=e.getDocument()}return e}(),eL=function(e){DI(t,e);function t(t,n,r,i,a,o){var s=e.call(this,t,n,o)||this;return s.cell=r,s.row=i,s.column=a,s.section=i.section,s}return t}($I),tL=function(){function e(e,t){this.pageNumber=1,this.id=e.id,this.settings=e.settings,this.styles=e.styles,this.hooks=e.hooks,this.columns=t.columns,this.head=t.head,this.body=t.body,this.foot=t.foot}return e.prototype.getHeadHeight=function(e){return this.head.reduce(function(t,n){return t+n.getMaxCellHeight(e)},0)},e.prototype.getFootHeight=function(e){return this.foot.reduce(function(t,n){return t+n.getMaxCellHeight(e)},0)},e.prototype.allRows=function(){return this.head.concat(this.body).concat(this.foot)},e.prototype.callCellHooks=function(e,t,n,r,i,a){for(var o=0,s=t;o1:!1}).length>0},e.prototype.canEntireRowFit=function(e,t){return this.getMaxCellHeight(t)<=e},e.prototype.getMinimumRowHeight=function(e,t){var n=this;return e.reduce(function(e,r){var i=n.cells[r.index];if(!i)return 0;var a=t.getLineHeight(i.styles.fontSize),o=i.padding(`vertical`)+a;return o>e?o:e},0)},e}(),rL=function(){function e(e,t,n){this.contentHeight=0,this.contentWidth=0,this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.height=0,this.x=0,this.y=0,this.styles=t,this.section=n,this.raw=e;var r=e;typeof e==`object`&&e&&!Array.isArray(e)?(this.rowSpan=e.rowSpan||1,this.colSpan=e.colSpan||1,r=e.content??e,e._element&&(this.raw=e._element)):(this.rowSpan=1,this.colSpan=1);var i=r==null?``:``+r,a=/\r\n|\r|\n/g;this.text=i.split(a)}return e.prototype.getTextPos=function(){var e;if(this.styles.valign===`top`)e=this.y+this.padding(`top`);else if(this.styles.valign===`bottom`)e=this.y+this.height-this.padding(`bottom`);else{var t=this.height-this.padding(`vertical`);e=this.y+t/2+this.padding(`top`)}var n;if(this.styles.halign===`right`)n=this.x+this.width-this.padding(`right`);else if(this.styles.halign===`center`){var r=this.width-this.padding(`horizontal`);n=this.x+r/2+this.padding(`left`)}else n=this.x+this.padding(`left`);return{x:n,y:e}},e.prototype.getContentHeight=function(e,t){t===void 0&&(t=1.15);var n=(Array.isArray(this.text)?this.text.length:1)*(this.styles.fontSize/e*t)+this.padding(`vertical`);return Math.max(n,this.styles.minCellHeight)},e.prototype.padding=function(e){var t=PI(this.styles.cellPadding,0);return e===`vertical`?t.top+t.bottom:e===`horizontal`?t.left+t.right:t[e]},e}(),iL=function(){function e(e,t,n){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=e,this.raw=t,this.index=n}return e.prototype.getMaxCustomCellWidth=function(e){for(var t=0,n=0,r=e.allRows();n.1/e.scaleFactor()&&(i=i<1?i:Math.round(i),console.log(`Of the table content, ${i} units width could not fit page`)),lL(t),uL(t,e),cL(t)}function oL(e,t){var n=e.scaleFactor(),r=t.settings.horizontalPageBreak,i=FI(e,t);t.allRows().forEach(function(a){for(var o=0,s=t.columns;oi?(l.minWidth=i,l.wrappedWidth=i):(l.minWidth=l.contentWidth,l.wrappedWidth=l.contentWidth);else{var f=10/n;l.minWidth=l.styles.minCellWidth||f,l.wrappedWidth=l.contentWidth,l.minWidth>l.wrappedWidth&&(l.wrappedWidth=l.minWidth)}}}}),t.allRows().forEach(function(e){for(var n=0,r=t.columns;n1&&!i.minWidth&&(i.minWidth=a.minWidth),a.colSpan>1&&!i.wrappedWidth&&(i.wrappedWidth=a.minWidth))}})}function sL(e,t,n){for(var r=t,i=e.reduce(function(e,t){return e+t.wrappedWidth},0),a=0;an(e):!0});d.length&&(t=sL(d,t,n))}return t}function cL(e){for(var t={},n=1,r=e.allRows(),i=0;i1)n--,delete a.cells[c.index];else if(l)l.cell.height+=a.height,n=l.cell.colSpan,delete a.cells[c.index],l.left--,l.left<=1&&delete t[c.index];else{var u=a.cells[c.index];if(!u)continue;if(u.height=a.height,u.rowSpan>1){var d=r.length-i,f=u.rowSpan>d?d:u.rowSpan;t[c.index]={cell:u,left:f,row:a}}}}}function lL(e){for(var t=e.allRows(),n=0;n1&&e.columns[s+1])a+=c.width,delete r.cells[c.index];else if(i){var l=i;delete r.cells[c.index],i=null,l.width=c.width+a}else{var l=r.cells[c.index];if(!l)continue;if(o=l.colSpan,a=0,l.colSpan>1){i=l,a+=c.width;continue}l.width=c.width+a}}}function uL(e,t){for(var n={count:0,height:0},r=0,i=e.allRows();r1&&n.count*n.height0&&n.height>f&&(f=n.height),f>a.height&&(a.height=f)}}n.count--}}function dL(e,t,n,r,i){return e.map(function(e){return fL(e,t,n,r,i)})}function fL(e,t,n,r,i){var a=1e4*r.scaleFactor();if(t=Math.ceil(t*a)/a,t>=jI(e,n,r))return e;for(;t0?n:null}function _L(e,t){if(e===`head`){if(typeof t==`object`)return t.header||null;if(typeof t==`string`||typeof t==`number`)return t}else if(e===`foot`&&typeof t==`object`)return t.footer;return null}function vL(e){return e.map(function(e,t){return new iL(typeof e==`object`?e.dataKey??t:t,e,t)})}function yL(e,t,n,r,i,a,o){var s=AI(r),c;e===`head`?c=i.headStyles:e===`body`?c=i.bodyStyles:e===`foot`&&(c=i.footStyles);var l=GI({},s.table,s[e],i.styles,c),u=i.columnStyles[t.dataKey]||i.columnStyles[t.index]||{},d=e===`body`?u:{},f=e===`body`&&n%2==0?GI({},s.alternateRow,i.alternateRowStyles):{};return GI(GI({},kI(a),l,f,d),o)}function bL(e,t,n){n===void 0&&(n={});var r=FI(e,t),i=new Map,a=[],o=[],s=[];Array.isArray(t.settings.horizontalPageBreakRepeat)?s=t.settings.horizontalPageBreakRepeat:(typeof t.settings.horizontalPageBreakRepeat==`string`||typeof t.settings.horizontalPageBreakRepeat==`number`)&&(s=[t.settings.horizontalPageBreakRepeat]),s.forEach(function(e){var n=t.columns.find(function(t){return t.dataKey===e||t.index===e});n&&!i.has(n.index)&&(i.set(n.index,!0),a.push(n.index),o.push(t.columns[n.index]),r-=n.wrappedWidth)});for(var c=!0,l=n?.start??0;l=u)c=!1,a.push(l),o.push(t.columns[l]),r-=u;else break;l++}return{colIndexes:a,columns:o,lastIndex:l-1}}function xL(e,t){for(var n=[],r=0;rl.pageSize().height)&&(LL(l),a.y=i.top),t.callWillDrawPageHooks(l,a);var u=GI({},a);t.startPageNumber=l.pageNumber(),n.horizontalPageBreak?CL(l,t,u,a):(l.applyStyles(l.userStyles),(n.showHead===`firstPage`||n.showHead===`everyPage`)&&t.head.forEach(function(e){return ML(l,t,e,a,t.columns)}),l.applyStyles(l.userStyles),t.body.forEach(function(e,n){jL(l,t,e,n===t.body.length-1,u,a,t.columns)}),l.applyStyles(l.userStyles),(n.showFoot===`lastPage`||n.showFoot===`everyPage`)&&t.foot.forEach(function(e){return ML(l,t,e,a,t.columns)})),MI(l,t,u,a),t.callEndPageHooks(l,a),t.finalY=a.y,e.lastAutoTable=t,l.applyStyles(l.userStyles)}function CL(e,t,n,r){var i=xL(e,t);if(t.settings.horizontalPageBreakBehaviour===`afterAllRows`)i.forEach(function(i,a){e.applyStyles(e.userStyles),a>0?IL(e,t,n,r,i.columns,!0):wL(e,t,r,i.columns),TL(e,t,n,r,i.columns),DL(e,t,r,i.columns)});else for(var a=-1,o=i[0],s=function(){var s=a;if(o){e.applyStyles(e.userStyles);var c=o.columns;a>=0?IL(e,t,n,r,c,!0):wL(e,t,r,c),s=EL(e,t,a+1,r,c),DL(e,t,r,c)}var l=s-a;i.slice(1).forEach(function(i){e.applyStyles(e.userStyles),IL(e,t,n,r,i.columns,!0),EL(e,t,a+1,r,i.columns,l),DL(e,t,r,i.columns)}),a=s};ad&&(u.text=l.text.splice(d,l.text.length));var f=r.scaleFactor(),p=r.getLineHeightFactor();l.contentHeight=l.getContentHeight(f,p),l.contentHeight>=t&&(l.contentHeight=t,u.styles.minCellHeight-=t),l.contentHeight>e.height&&(e.height=l.contentHeight),u.contentHeight=u.getContentHeight(f,p),u.contentHeight>a&&(a=u.contentHeight),i[c.index]=u}}var m=new nL(e.raw,-1,e.section,i,!0);m.height=a;for(var h=0,g=n.columns;ho)return console.log(`Will not be able to print row ${t.index} correctly since it's minimum height is larger than page height`),!0;if(!c)return!1;var l=t.hasRowSpan(r.columns);return t.getMaxCellHeight(r.columns)>o?(l&&console.log(`The content of row ${t.index} will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.`),!0):!(l||r.settings.rowPageBreak===`avoid`)}function jL(e,t,n,r,i,a,o){var s=FL(e,t,r,a);if(n.canEntireRowFit(s,o))ML(e,t,n,a,o);else if(AL(e,n,s,t)){var c=kL(n,s,t,e);ML(e,t,n,a,o),IL(e,t,i,a,o),jL(e,t,c,r,i,a,o)}else IL(e,t,i,a,o),jL(e,t,n,r,i,a,o)}function ML(e,t,n,r,i){r.x=t.settings.margin.left;for(var a=0,o=i;a`u`)return console.error(`Cannot run autoTableHtmlToJson in non browser environment`),null;var n=VI(new TI(this),e,window,t,!1),r=n.head,i=n.body;return{columns:r[0]?.map(function(e){return e.content})||[],rows:i,data:i}}}function zL(e,t){SL(e,pL(e,KI(e,t)))}try{if(typeof window<`u`&&window){var BL=window,VL=BL.jsPDF||BL.jspdf?.jsPDF;VL&&RL(VL)}}catch(e){console.error(`Could not apply autoTable plugin`,e)}function HL(e,t){let n=new kP({orientation:`portrait`,unit:`mm`,format:`a4`}),r=n.internal.pageSize.getWidth();n.setFillColor(15,23,42),n.rect(0,0,r,40,`F`),n.setTextColor(255,255,255),n.setFont(`helvetica`,`bold`),n.setFontSize(18),n.text(`HYDRO BUILDER`,15,18),n.setFont(`helvetica`,`normal`),n.setFontSize(10),n.setTextColor(148,163,184),n.text(`BILL OF MATERIALS`,15,24),n.setTextColor(255,255,255),n.setFont(`helvetica`,`bold`),n.setFontSize(11);let i=t.length>30?t.substring(0,27)+`...`:t;n.text(i,r-15,18,{align:`right`}),n.setFont(`helvetica`,`normal`),n.setFontSize(9),n.setTextColor(148,163,184),n.text(`Date: ${new Date().toLocaleDateString()}`,r-15,24,{align:`right`});let a=50;if(n.setFillColor(248,250,252),n.setDrawColor(226,232,240),n.rect(15,a,r-30,22,`FD`),n.setFont(`helvetica`,`normal`),n.setFontSize(8),n.setTextColor(100,116,139),n.text(`TOTAL ESTIMATED COST`,23,a+7),n.text(`PART COUNT`,80,a+7),n.text(`LINE ITEMS`,130,a+7),n.setFont(`helvetica`,`bold`),n.setFontSize(12),n.setTextColor(14,116,144),n.text(oD(e.totalCost),23,a+15),n.setTextColor(15,23,42),n.text(`${e.partCount} parts`,80,a+15),n.text(`${e.lines.length} items`,130,a+15),e.cutLists.length>0){let t=e.cutLists.reduce((e,t)=>e+t.sticksToBuy,0);n.setFont(`helvetica`,`normal`),n.setFontSize(8),n.setTextColor(100,116,139),n.text(`PVC STICKS (10 FT)`,165,a+7),n.setFont(`helvetica`,`bold`),n.setFontSize(12),n.setTextColor(15,23,42),n.text(`${t} sticks`,165,a+15)}a+=32,n.setFont(`helvetica`,`bold`),n.setFontSize(11),n.setTextColor(15,23,42),n.text(`Line Items`,15,a),a+=4;let o=[`Category`,`Description`,`Spec`,`Qty`,`Unit`,`Unit Cost`,`Total`],s=e.lines.map(e=>[e.category,e.description,e.spec??``,e.qty,e.unit,oD(e.unitCost),oD(e.totalCost)+(e.estimated?` (est.)`:``)]);if(zL(n,{startY:a,head:[o],body:s,margin:{left:15,right:15},theme:`grid`,styles:{fontSize:8,cellPadding:2,font:`helvetica`},headStyles:{fillColor:[39,39,42],textColor:[255,255,255],fontStyle:`bold`},columnStyles:{0:{cellWidth:25},1:{cellWidth:50},2:{cellWidth:40},3:{cellWidth:12,halign:`center`},4:{cellWidth:15,halign:`center`},5:{cellWidth:18,halign:`right`},6:{cellWidth:20,halign:`right`}}}),a=n.lastAutoTable.finalY+10,e.cutLists.length>0){a>n.internal.pageSize.getHeight()-40&&(n.addPage(),a=20),n.setFont(`helvetica`,`bold`),n.setFontSize(11),n.setTextColor(15,23,42),n.text(`PVC Cut Lists (10 ft / 120 in sticks)`,15,a),a+=4;let t=[`Diameter`,`Stick`,`Cuts (in)`,`Used`,`Leftover`],r=[];for(let t of e.cutLists)for(let e of t.sticks){let n=e.cuts.map(e=>aD(e)).join(`, `);r.push([iD(t.diameterIn),`Stick ${e.index}`,n,aD(e.usedIn),aD(e.leftoverIn)])}zL(n,{startY:a,head:[t],body:r,margin:{left:15,right:15},theme:`grid`,styles:{fontSize:8,cellPadding:2,font:`helvetica`},headStyles:{fillColor:[71,85,105],textColor:[255,255,255],fontStyle:`bold`},columnStyles:{0:{cellWidth:25},1:{cellWidth:25},2:{cellWidth:90},3:{cellWidth:20,halign:`right`},4:{cellWidth:20,halign:`right`}}}),a=n.lastAutoTable.finalY+10}a>n.internal.pageSize.getHeight()-50&&(n.addPage(),a=20),n.setFont(`helvetica`,`bold`),n.setFontSize(11),n.setTextColor(15,23,42),n.text(`Category Subtotals`,15,a),a+=4;let c=[`Category`,`Subtotal`],l=e.categories.map(e=>[e.name,oD(e.subtotal)]);l.push([`Grand Total (Estimated)`,oD(e.totalCost)]),zL(n,{startY:a,head:[c],body:l,margin:{left:15,right:r-100},theme:`grid`,styles:{fontSize:8,cellPadding:2.5,font:`helvetica`},headStyles:{fillColor:[15,23,42],textColor:[255,255,255],fontStyle:`bold`},columnStyles:{0:{cellWidth:50},1:{cellWidth:35,halign:`right`,fontStyle:`bold`}},didParseCell:e=>{e.row.index===l.length-1&&(e.cell.styles.fillColor=[241,245,249],e.cell.styles.fontStyle=`bold`,e.column.index===1&&(e.cell.styles.textColor=[14,116,144]))}});let u=t.replace(/[^a-z0-9-_ ]/gi,``).trim()||`hydro-system`;n.save(`${u}-bom.pdf`)}var UL={POSITION:[`byte`,`byte normalized`,`unsigned byte`,`unsigned byte normalized`,`short`,`short normalized`,`unsigned short`,`unsigned short normalized`],NORMAL:[`byte normalized`,`short normalized`],TANGENT:[`byte normalized`,`short normalized`],TEXCOORD:[`byte`,`byte normalized`,`unsigned byte`,`short`,`short normalized`,`unsigned short`]},WL=class{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new dR(e)}),this.register(function(e){return new fR(e)}),this.register(function(e){return new gR(e)}),this.register(function(e){return new _R(e)}),this.register(function(e){return new vR(e)}),this.register(function(e){return new yR(e)}),this.register(function(e){return new pR(e)}),this.register(function(e){return new mR(e)}),this.register(function(e){return new hR(e)}),this.register(function(e){return new bR(e)}),this.register(function(e){return new xR(e)}),this.register(function(e){return new SR(e)}),this.register(function(e){return new CR(e)}),this.register(function(e){return new wR(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}setTextureUtils(e){return this.textureUtils=e,this}parse(e,t,n,r){let i=new uR,a=[];for(let e=0,t=this.pluginCallbacks.length;e4?n=e.array[i*e.itemSize+t]:(t===0?n=e.getX(i):t===1?n=e.getY(i):t===2?n=e.getZ(i):t===3&&(n=e.getW(i)),e.normalized===!0&&(n=jn.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}function oR(e){return Math.ceil(e/4)*4}function sR(e,t=0){let n=oR(e.byteLength);if(n!==e.byteLength){let r=new Uint8Array(n);if(r.set(new Uint8Array(e)),t!==0)for(let i=e.byteLength;i`u`&&typeof OffscreenCanvas<`u`?new OffscreenCanvas(1,1):document.createElement(`canvas`)}function lR(e,t){if(typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas){let n;return t===`image/jpeg`?n=.92:t===`image/webp`&&(n=.8),e.convertToBlob({type:t,quality:n})}else return new Promise(n=>e.toBlob(n,t))}var uR=class{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:`2.0`,generator:`THREE.GLTFExporter r184`}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},n),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);let r=this,i=r.buffers,a=r.json;n=r.options;let o=r.extensionsUsed,s=r.extensionsRequired,c=new Blob(i,{type:`application/octet-stream`}),l=Object.keys(o),u=Object.keys(s);if(l.length>0&&(a.extensionsUsed=l),u.length>0&&(a.extensionsRequired=u),a.buffers&&a.buffers.length>0&&(a.buffers[0].byteLength=c.size),n.binary===!0){let e=new FileReader;e.readAsArrayBuffer(c),e.onloadend=function(){let n=sR(e.result),r=new DataView(new ArrayBuffer($L));r.setUint32(0,n.byteLength,!0),r.setUint32(4,tR,!0);let i=sR(rR(JSON.stringify(a)),32),o=new DataView(new ArrayBuffer($L));o.setUint32(0,i.byteLength,!0),o.setUint32(4,eR,!0);let s=new ArrayBuffer(XL),c=new DataView(s);c.setUint32(0,ZL,!0),c.setUint32(4,QL,!0);let l=XL+o.byteLength+i.byteLength+r.byteLength+n.byteLength;c.setUint32(8,l,!0);let u=new Blob([s,o,i,r,n],{type:`application/octet-stream`}),d=new FileReader;d.readAsArrayBuffer(u),d.onloadend=function(){t(d.result)}}}else if(a.buffers&&a.buffers.length>0){let e=new FileReader;e.readAsDataURL(c),e.onloadend=function(){let n=e.result;a.buffers[0].uri=n,t(a)}}else t(a)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let e in i.gltfExtensions)t.extensions[e]=i.gltfExtensions[e],r[e]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(t){console.warn(`THREE.GLTFExporter: userData of '`+e.name+`' won't be serialized because of JSON.stringify error - `+t.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let t=new q;for(let n=0,r=e.count;n5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new q;for(let e=0,t=n.count;e4?r=e.array[i*e.itemSize+n]:(n===0?r=e.getX(i):n===1?r=e.getY(i):n===2?r=e.getZ(i):n===3&&(r=e.getW(i)),e.normalized===!0&&(r=jn.normalize(r,e.array))),t===GL.FLOAT?l.setFloat32(u,r,!0):t===GL.INT?l.setInt32(u,r,!0):t===GL.UNSIGNED_INT?l.setUint32(u,r,!0):t===GL.SHORT?l.setInt16(u,r,!0):t===GL.UNSIGNED_SHORT?l.setUint16(u,r,!0):t===GL.BYTE?l.setInt8(u,r):t===GL.UNSIGNED_BYTE&&l.setUint8(u,r),u+=o}u%s!==0&&(u+=s-u%s)}let d={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:c};return i!==void 0&&(d.target=i),i===GL.ARRAY_BUFFER&&(d.byteStride=s),this.byteOffset+=c,a.bufferViews.push(d),{id:a.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||=[],new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=sR(i.result),a={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let i=this.json,a={1:`SCALAR`,2:`VEC2`,3:`VEC3`,4:`VEC4`,9:`MAT3`,16:`MAT4`},o;if(e.array.constructor===Float32Array)o=GL.FLOAT;else if(e.array.constructor===Int32Array)o=GL.INT;else if(e.array.constructor===Uint32Array)o=GL.UNSIGNED_INT;else if(e.array.constructor===Int16Array)o=GL.SHORT;else if(e.array.constructor===Uint16Array)o=GL.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)o=GL.BYTE;else if(e.array.constructor===Uint8Array)o=GL.UNSIGNED_BYTE;else throw Error(`THREE.GLTFExporter: Unsupported bufferAttribute component type: `+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let s=aR(e,n,r),c;t!==void 0&&(c=e===t.index?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER);let l=this.processBufferView(e,o,n,r,c),u={bufferView:l.id,byteOffset:l.byteOffset,componentType:o,count:r,max:s.max,min:s.min,type:a[e.itemSize]};return e.normalized===!0&&(u.normalized=!0),i.accessors||=[],i.accessors.push(u)-1}processImage(e,t,n,r=`image/png`){if(e!==null){let i=this,a=i.cache,o=i.json,s=i.options,c=i.pending;a.images.has(e)||a.images.set(e,{});let l=a.images.get(e),u=r+`:flipY/`+n.toString();if(l[u]!==void 0)return l[u];o.images||=[];let d={mimeType:r},f=cR();f.width=Math.min(e.width,s.maxTextureSize),f.height=Math.min(e.height,s.maxTextureSize);let p=f.getContext(`2d`,{willReadFrequently:!0});if(n===!0&&(p.translate(0,f.height),p.scale(1,-1)),e.data!==void 0){t!==1023&&console.error(`GLTFExporter: Only RGBAFormat is supported.`,t),(e.width>s.maxTextureSize||e.height>s.maxTextureSize)&&console.warn(`GLTFExporter: Image size is bigger than maxTextureSize`,e);let n=new Uint8ClampedArray(e.height*e.width*4);for(let t=0;ti.processBufferViewImage(e)).then(e=>{d.bufferView=e})):d.uri=Wn.getDataURL(f,r);let m=o.images.push(d)-1;return l[u]=m,m}else throw Error(`THREE.GLTFExporter: No valid image data found. Unable to process texture.`)}processSampler(e){let t=this.json;t.samplers||=[];let n={magFilter:qL[e.magFilter],minFilter:qL[e.minFilter],wrapS:qL[e.wrapS],wrapT:qL[e.wrapT]};return t.samplers.push(n)-1}async processTextureAsync(e){let t=this.options,n=this.cache,r=this.json;if(n.textures.has(e))return n.textures.get(e);r.textures||=[],e instanceof ds&&(e=await this.decompressTextureAsync(e,t.maxTextureSize));let i=e.userData.mimeType,a=this.processImage(e.image,e.format,e.flipY,i),o={sampler:this.processSampler(e)};i===`image/webp`?(o.extensions=o.extensions||{},o.extensions.EXT_texture_webp={source:a},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):o.source=a,e.name&&(o.name=e.name),await this._invokeAllAsync(async function(t){t.writeTexture&&await t.writeTexture(e,o)});let s=r.textures.push(o)-1;return n.textures.set(e,s),s}async processMaterialAsync(e){let t=this.cache,n=this.json;if(t.materials.has(e))return t.materials.get(e);if(e.isShaderMaterial)return console.warn(`GLTFExporter: THREE.ShaderMaterial not supported.`),null;n.materials||=[];let r={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn(`GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.`);let i=e.color.toArray().concat([e.opacity]);if(nR(i,[1,1,1,1])||(r.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(r.pbrMetallicRoughness.metallicFactor=e.metalness,r.pbrMetallicRoughness.roughnessFactor=e.roughness):(r.pbrMetallicRoughness.metallicFactor=0,r.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){let t=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),n={index:await this.processTextureAsync(t),texCoord:t.channel};this.applyTextureTransform(n,t),r.pbrMetallicRoughness.metallicRoughnessTexture=n}if(e.map){let t={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(t,e.map),r.pbrMetallicRoughness.baseColorTexture=t}if(e.emissive){let t=e.emissive;if(Math.max(t.r,t.g,t.b)>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap){let t={index:await this.processTextureAsync(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap){let t={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(t.strength=e.aoMapIntensity),this.applyTextureTransform(t,e.aoMap),r.occlusionTexture=t}e.transparent?r.alphaMode=`BLEND`:e.alphaTest>0&&(r.alphaMode=`MASK`,r.alphaCutoff=e.alphaTest),e.side===2&&(r.doubleSided=!0),e.name!==``&&(r.name=e.name),this.serializeUserData(e,r),await this._invokeAllAsync(async function(t){t.writeMaterialAsync&&await t.writeMaterialAsync(e,r)});let a=n.materials.push(r)-1;return t.materials.set(e,a),a}async processMeshAsync(e){let t=this.cache,n=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let t=0,n=e.material.length;t0){let n=[],r=[],i={};if(e.morphTargetDictionary!==void 0)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o0&&(s.extras={},s.extras.targetNames=r)}let m=Array.isArray(e.material);if(m&&a.groups.length===0)return null;let h=!1;if(m&&a.index===null){let e=[];for(let t=0,n=a.attributes.position.count;t0&&(n.targets=u),a.index!==null){let r=this.getUID(a.index);(_[e].start!==void 0||_[e].count!==void 0)&&(r+=`:`+_[e].start+`:`+_[e].count),t.attributes.has(r)?n.indices=t.attributes.get(r):(n.indices=this.processAccessor(a.index,a,_[e].start,_[e].count),t.attributes.set(r,n.indices)),n.indices===null&&delete n.indices}let r=await this.processMaterialAsync(g[_[e].materialIndex]);r!==null&&(n.material=r),l.push(n)}h===!0&&a.setIndex(null),s.primitives=l,n.meshes||=[],await this._invokeAllAsync(function(t){t.writeMesh&&t.writeMesh(e,s)});let v=n.meshes.push(s)-1;return t.meshes.set(i,v),v}detectMeshQuantization(e,t){if(this.extensionsUsed[KL])return;let n;switch(t.array.constructor){case Int8Array:n=`byte`;break;case Uint8Array:n=`unsigned byte`;break;case Int16Array:n=`short`;break;case Uint16Array:n=`unsigned short`;break;default:return}t.normalized&&(n+=` normalized`);let r=e.split(`_`,1)[0];UL[r]&&UL[r].includes(n)&&(this.extensionsUsed[KL]=!0,this.extensionsRequired[KL]=!0)}processCamera(e){let t=this.json;t.cameras||=[];let n=e.isOrthographicCamera,r={type:n?`orthographic`:`perspective`};return n?r.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:jn.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==``&&(r.name=e.type),t.cameras.push(r)-1}processAnimation(e,t){let n=this.json,r=this.nodeMap;n.animations||=[],e=WL.Utils.mergeMorphTargetTracks(e.clone(),t);let i=e.tracks,a=[],o=[];for(let e=0;e0){let t=[];for(let r=0,i=e.children.length;r0&&(i.children=t)}return await this._invokeAllAsync(function(t){t.writeNode&&t.writeNode(e,i)}),a}async _processNodeWithPivotAsync(e){let t=this.json,n=this.options,r=this.nodeMap,i=e.pivot,a={},o=e.quaternion.toArray(),s=[e.position.x+i.x,e.position.y+i.y,e.position.z+i.z],c=e.scale.toArray();nR(o,[0,0,0,1])||(a.rotation=o),nR(s,[0,0,0])||(a.translation=s),nR(c,[1,1,1])||(a.scale=c),a.extras={pivot:i.toArray()},e.name!==``&&(a.name=String(e.name)),this.serializeUserData(e,a);let l=t.nodes.push(a)-1;r.set(e,l);let u={},d=[-i.x,-i.y,-i.z];if(nR(d,[0,0,0])||(u.translation=d),e.isMesh||e.isLine||e.isPoints){let t=await this.processMeshAsync(e);t!==null&&(u.mesh=t)}else e.isCamera&&(u.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let f=[t.nodes.push(u)-1];if(e.children.length>0){let t=[];for(let r=0,i=e.children.length;r0&&(u.children=t)}return a.children=f,await this._invokeAllAsync(function(t){t.writeNode&&t.writeNode(e,a)}),l}async processSceneAsync(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==``&&(r.name=e.name),t.scenes.push(r);let i=[];for(let t=0,r=e.children.length;t0&&(r.nodes=i),this.serializeUserData(e,r)}async processObjectsAsync(e){let t=new Vr;t.name=`AuxScene`;for(let n=0;n0&&await this.processObjectsAsync(n);for(let e=0;e0&&(a.range=e.distance)):e.isSpotLight&&(a.type=`spot`,e.distance>0&&(a.range=e.distance),a.spot={},a.spot.innerConeAngle=(1-e.penumbra)*e.angle,a.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn(`THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2.`),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn(`THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1.`),i[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},i[this.name]=!0);let o=r.extensions[this.name].lights;o.push(a),t.extensions=t.extensions||{},t.extensions[this.name]={light:o.length-1}}},fR=class{constructor(e){this.writer=e,this.name=`KHR_materials_unlit`}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},n[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},pR=class{constructor(e){this.writer=e,this.name=`KHR_materials_clearcoat`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){let t={index:await n.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(t,e.clearcoatMap),i.clearcoatTexture=t}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let t={index:await n.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(t,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=t}if(e.clearcoatNormalMap){let t={index:await n.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(t.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},mR=class{constructor(e){this.writer=e,this.name=`KHR_materials_dispersion`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let n=this.writer.extensionsUsed,r={};r.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},hR=class{constructor(e){this.writer=e,this.name=`KHR_materials_iridescence`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){let t={index:await n.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(t,e.iridescenceMap),i.iridescenceTexture=t}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){let t={index:await n.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(t,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},gR=class{constructor(e){this.writer=e,this.name=`KHR_materials_transmission`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){let t={index:await n.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(t,e.transmissionMap),i.transmissionTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},_R=class{constructor(e){this.writer=e,this.name=`KHR_materials_volume`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){let t={index:await n.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(t,e.thicknessMap),i.thicknessTexture=t}e.attenuationDistance!==1/0&&(i.attenuationDistance=e.attenuationDistance),i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},vR=class{constructor(e){this.writer=e,this.name=`KHR_materials_ior`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let n=this.writer.extensionsUsed,r={};r.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},yR=class{constructor(e){this.writer=e,this.name=`KHR_materials_specular`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(YL)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.specularIntensityMap){let t={index:await n.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(t,e.specularIntensityMap),i.specularTexture=t}if(e.specularColorMap){let t={index:await n.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(t,e.specularColorMap),i.specularColorTexture=t}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},bR=class{constructor(e){this.writer=e,this.name=`KHR_materials_sheen`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.sheenRoughnessMap){let t={index:await n.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(t,e.sheenRoughnessMap),i.sheenRoughnessTexture=t}if(e.sheenColorMap){let t={index:await n.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(t,e.sheenColorMap),i.sheenColorTexture=t}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},xR=class{constructor(e){this.writer=e,this.name=`KHR_materials_anisotropy`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.anisotropyMap){let t={index:await n.processTextureAsync(e.anisotropyMap)};n.applyTextureTransform(t,e.anisotropyMap),i.anisotropyTexture=t}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},SR=class{constructor(e){this.writer=e,this.name=`KHR_materials_emissive_strength`}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let n=this.writer.extensionsUsed,r={};r.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},CR=class{constructor(e){this.writer=e,this.name=`EXT_materials_bump`}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.bumpMap){let t={index:await n.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(t,e.bumpMap),i.bumpTexture=t}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},wR=class{constructor(e){this.writer=e,this.name=`EXT_mesh_gpu_instancing`}writeNode(e,t){if(!e.isInstancedMesh)return;let n=this.writer,r=e,i=new Float32Array(r.count*3),a=new Float32Array(r.count*4),o=new Float32Array(r.count*3),s=new J,c=new q,l=new Mn,u=new q;for(let e=0;ee.times[e.times.length-1]){if(Math.abs(e.times[e.times.length-1]-t)t){i.set(e.times.slice(0,c+1),0),i[c+1]=t,i.set(e.times.slice(c+1),c+2),a.set(e.values.slice(0,(c+1)*r),0),a.set(o.evaluate(t),(c+1)*r),a.set(e.values.slice((c+1)*r),(c+2)*r),s=c+1;break}}return e.times=i,e.values=a,s},mergeMorphTargetTracks:function(e,t){let n=[],r={},i=e.tracks;for(let e=0;e{if(e.name===`part-body-mesh`){let n=e.clone(!0),r=[];n.traverse(e=>{e instanceof La&&!e.castShadow&&r.push(e)});for(let e of r)e.parent?.remove(e);e.updateWorldMatrix(!0,!1),n.position.set(0,0,0),n.rotation.set(0,0,0),n.scale.set(1,1,1),n.updateMatrix(),n.applyMatrix4(e.matrixWorld),t.add(n)}}),t}function DR(e,t,n){let r=new Blob([e],{type:t}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function OR(e,t){let n=ER(e);new WL().parse(n,e=>{DR(typeof e==`string`?e:JSON.stringify(e,null,2),`application/json`,`${t.replace(/\s+/g,`_`)||`hydro_system`}.gltf`)},e=>{console.error(`Failed to export glTF:`,e)},{binary:!1})}function kR(e,t){let n=ER(e);DR(new TR().parse(n),`text/plain`,`${t.replace(/\s+/g,`_`)||`hydro_system`}.obj`)}function AR({onClose:e}){let t=Q(e=>e.parts),n=Q(e=>e.activeRoomId),r=Q(e=>e.projectName),i=Q(e=>e.scene),a=(0,v.useMemo)(()=>Object.values(t).filter(e=>e.roomId===n),[t,n]),o=(0,v.useMemo)(()=>WE(a),[a]),[s,c]=(0,v.useState)(!1),l=(0,v.useRef)(null);(0,v.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t),l.current&&clearTimeout(l.current)}},[e]);let u=async()=>{try{await navigator.clipboard.writeText(pD(o)),c(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>c(!1),1500)}catch{}},d=()=>{let e=window.open(``,`_blank`,`width=720,height=900`);if(!e)return;let t=e=>e.replace(/&/g,`&`).replace(//g,`>`);e.document.write(`${t(r)} — Bill of Materials
`+t(pD(o))+`
`),e.document.close(),e.focus(),e.print()},f=(0,v.useMemo)(()=>{let e=new Map;for(let t of o.lines){let n=e.get(t.category);n?n.push(t):e.set(t.category,[t])}return[...e.entries()]},[o]),p=e=>o.categories.find(t=>t.name===e)?.subtotal??0;return(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex justify-end`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-[2px]`,onClick:e,"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`relative flex h-full w-full max-w-xl flex-col border-l border-zinc-800 bg-zinc-950 shadow-2xl`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-zinc-800 px-5 py-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-bold tracking-wide text-zinc-100`,children:`Bill of Materials`}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-zinc-500`,children:r})]}),(0,Z.jsx)(`button`,{onClick:e,title:`Close (Esc)`,className:`rounded-md px-2 py-1 text-sm text-zinc-400 transition hover:bg-zinc-800 hover:text-zinc-100`,children:`✕`})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-end justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`text-2xl font-bold text-sky-400 tabular-nums`,children:[oD(o.totalCost),(0,Z.jsx)(`span`,{className:`ml-1.5 text-xs font-medium text-zinc-500`,children:`est. total`})]}),(0,Z.jsxs)(`div`,{className:`text-[11px] text-zinc-500 tabular-nums`,children:[o.partCount,` parts · `,o.lines.length,` line items`,o.cutLists.length>0&&` · ${o.cutLists.reduce((e,t)=>e+t.sticksToBuy,0)} PVC sticks`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 justify-end`,children:[(0,Z.jsx)(MR,{onClick:()=>mD(o,r),title:`Download as CSV`,children:`Export CSV`}),(0,Z.jsx)(MR,{onClick:()=>HL(o,r),title:`Download as PDF`,children:`Export PDF`}),(0,Z.jsx)(MR,{onClick:u,title:`Copy shopping list to clipboard`,children:s?`Copied`:`Copy as text`}),(0,Z.jsx)(MR,{onClick:d,title:`Print shopping list`,children:`Print`}),(0,Z.jsx)(MR,{onClick:()=>i&&OR(i,`${r}.gltf`),title:i?`Export 3D layout as glTF`:`Scene loading...`,disabled:!i,children:`Export glTF`}),(0,Z.jsx)(MR,{onClick:()=>i&&kR(i,`${r}.obj`),title:i?`Export 3D layout as OBJ`:`Scene loading...`,disabled:!i,children:`Export OBJ`})]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4`,children:o.partCount===0?(0,Z.jsx)(`p`,{className:`py-10 text-center text-xs text-zinc-600`,children:`Nothing here yet — place some parts in the scene to build a shopping list.`}):(0,Z.jsxs)(Z.Fragment,{children:[f.map(([e,t])=>(0,Z.jsxs)(`section`,{className:`mb-5`,children:[(0,Z.jsxs)(`div`,{className:`mb-1.5 flex items-baseline justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:e}),(0,Z.jsx)(`span`,{className:`text-[11px] font-semibold text-zinc-400 tabular-nums`,children:oD(p(e))})]}),(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-zinc-800`,children:t.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-3 py-2 ${t%2==1?`bg-zinc-900/40`:`bg-zinc-900/10`}`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`text-xs font-medium text-zinc-200`,children:[e.description,e.qty>1||e.unit===`stick`?(0,Z.jsxs)(`span`,{className:`ml-1.5 text-zinc-500`,children:[`×`,e.qty]}):null,e.estimated&&(0,Z.jsx)(`span`,{className:`ml-1.5 rounded bg-amber-950/80 px-1 py-px text-[9px] font-semibold text-amber-400 ring-1 ring-amber-900`,children:`est.`})]}),e.spec&&(0,Z.jsx)(`div`,{className:`mt-0.5 text-[10px] text-zinc-500`,children:e.spec})]}),(0,Z.jsxs)(`div`,{className:`shrink-0 text-right`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-zinc-200 tabular-nums`,children:oD(e.totalCost)}),e.qty>1&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-zinc-500 tabular-nums`,children:[oD(e.unitCost),` / `,e.unit]})]})]},e.key))})]},e)),o.cutLists.length>0&&(0,Z.jsxs)(`section`,{className:`mb-5`,children:[(0,Z.jsx)(`h3`,{className:`mb-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:`Cut list — 10 ft sticks`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.cutLists.map(e=>(0,Z.jsx)(jR,{list:e},e.diameterIn))})]})]})}),(0,Z.jsx)(`div`,{className:`shrink-0 border-t border-zinc-800 px-5 py-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-zinc-500`,children:`Prices are rough US retail estimates, not quotes.`}),(0,Z.jsx)(`span`,{className:`font-bold text-zinc-100 tabular-nums`,children:oD(o.totalCost)})]})})]})]})}function jR({list:e}){let[t,n]=(0,v.useState)(!1);return(0,Z.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-zinc-800 bg-zinc-900/30`,children:[(0,Z.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-left transition hover:bg-zinc-800/50`,children:[(0,Z.jsxs)(`span`,{className:`text-xs font-semibold text-zinc-200`,children:[iD(e.diameterIn),` PVC`,(0,Z.jsxs)(`span`,{className:`ml-2 font-normal text-zinc-500`,children:[`buy `,e.sticksToBuy,` stick`,e.sticksToBuy===1?``:`s`,` · `,e.cuts.length,` `,`cuts · `,aD(e.totalLeftoverIn),` scrap`]})]}),(0,Z.jsx)(`span`,{className:`text-[10px] text-zinc-500`,children:t?`Hide`:`Show`})]}),t&&(0,Z.jsxs)(`div`,{className:`border-t border-zinc-800 px-3 py-2`,children:[e.sticks.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2 py-0.5`,children:[(0,Z.jsxs)(`span`,{className:`w-14 shrink-0 text-[10px] font-semibold text-zinc-500`,children:[`Stick `,e.index]}),(0,Z.jsxs)(`span`,{className:`text-[11px] text-zinc-300 tabular-nums`,children:[e.cuts.map(e=>aD(e)).join(`, `),(0,Z.jsxs)(`span`,{className:`ml-1.5 text-zinc-500`,children:[`— `,aD(e.leftoverIn),` left`]})]})]},e.index)),e.spliceCount>0&&(0,Z.jsxs)(`p`,{className:`mt-1 text-[10px] text-amber-400/90`,children:[e.spliceCount,` coupling`,e.spliceCount===1?``:`s`,` needed to splice runs longer than 10 ft.`]})]})]})}function MR({children:e,onClick:t,title:n,disabled:r}){return(0,Z.jsx)(`button`,{onClick:t,title:n,disabled:r,className:`rounded-md px-2.5 py-1.5 text-xs font-medium transition ${r?`bg-zinc-800 text-zinc-500 ring-1 ring-zinc-700 cursor-not-allowed opacity-50`:`bg-sky-500/15 text-sky-300 ring-1 ring-sky-700 hover:bg-sky-500/25`}`,children:e})}var NR=(e,t=1)=>Number(e.toFixed(t)).toString(),PR=.8;function FR(e,t){let n=e.partsMap[t];if(!n)return 0;let r=e.graph.connectorsByPart.get(t)??[],i=r.find(e=>e.connectorId===`out`)??r[r.length-1];if(!i)return 0;let a=n.position[1],o=[i.partId],s=new Set([t]);for(;o.length>0;){let t=o.shift();if(s.has(t))continue;s.add(t);let n=e.partsMap[t];n&&(a=Math.max(a,n.position[1]));let r=e.graph.neighbors.get(t);if(r)for(let e of r)s.has(e)||o.push(e)}return Math.max(0,a-n.position[1])}function IR(e){let t=[];for(let n of e.sim?.pumps??[]){let r=e.partsMap[n?.pumpId??``];if(!r||uS(r))continue;let i=n.maxHeadFt??0,a=FR(e,r.id);if(i<=0)continue;let o=a/i;if(o<=.8)continue;let s=lS(r),c=`Choose a higher-head pump or lower the highest point by ${NR(Math.max(.1,a-PR*i))} ft`;o>=1?t.push({id:`pump-head:${r.id}`,severity:`error`,title:`Pump cannot reach the highest point`,detail:`${s} must lift water ${NR(a)} ft but its max head is ${NR(i)} ft — it delivers no flow.`,partIds:[r.id],fix:c}):t.push({id:`pump-head:${r.id}`,severity:`warning`,title:`Pump near its limit (${Math.round(o*100)}%), keep \u226520% margin`,detail:`${s} is lifting ${NR(a)} ft of ${NR(i)} ft max head, so flow is heavily reduced and the pump will wear quickly.`,partIds:[r.id],fix:c})}return t}function LR(e,t,n){let r=[];for(let{a:t,b:i}of e.graph.joints)t.key===n&&r.push(i.partId),i.key===n&&r.push(t.partId);let i=new Set([t,...r]),a=[...r];for(;a.length;){let t=a.shift();if(e.partsMap[t]?.type===`reservoir`)return!0;for(let n of e.graph.neighbors.get(t)??[])i.has(n)||(i.add(n),a.push(n))}return!1}function RR(e){let t=[];for(let n of e.parts){if(n.type!==`pump`)continue;let r=lS(n);if(uS(n)){t.push({id:`pump-dead:${n.id}`,severity:`error`,title:`Pump is switched off`,detail:`${r} is powered off, so it delivers no flow.`,partIds:[n.id],fix:`Turn the pump on (power toggle in the inspector).`});continue}let i=e.graph.connectorsByPart.get(n.id)??[],a=i.find(e=>e.connectorId===`in`)??i[0],o=i.find(e=>e.connectorId===`out`)??i[i.length-1],s=o&&e.graph.joinedKeys.has(o.key),c=a&&e.graph.joinedKeys.has(a.key),l=e.sim?.pumps?.find(e=>e?.pumpId===n.id);if(l&&(l.gph??0)>0&&s&&c)continue;let u=FR(e,n.id);if(l&&(l.maxHeadFt??0)>0&&u>=(l.maxHeadFt??0))continue;let d,f;a&&!e.graph.joinedKeys.has(a.key)?(d=`${r}'s inlet is not connected to anything — there is no water source.`,f=`Connect the pump inlet to a reservoir.`):a&&!LR(e,n.id,a.key)?(d=`${r}'s inlet line never reaches a reservoir — there is no water source.`,f=`Route the inlet line back to a reservoir.`):o&&!e.graph.joinedKeys.has(o.key)?(d=`${r}'s outlet is not connected to anything — water has nowhere to go.`,f=`Connect the pump outlet to your plumbing.`):(d=e.sim?.warnings?.find(e=>e?.partId===n.id&&e?.level!==`info`)?.message??`${r} delivers no flow.`,f=`Check for closed valves and verify the line reaches an outlet.`),t.push({id:`pump-dead:${n.id}`,severity:`error`,title:`Pump delivers no flow`,detail:d,partIds:[n.id],fix:f})}return t}function zR(e,t){return e.type===`reducer`||e.type===`reducingElbow`?t===`a`?e.params.diameterA??1.5:e.params.diameterB??1:e.type===`reducingTee`?t===`c`||t===`branch`?e.params.diameterB??1:e.params.diameterA??1.5:e.params.diameter??1}function BR(e){let t=[],n=new Set;for(let{a:r,b:i}of e.graph.joints){let a=e.partsMap[r.partId],o=e.partsMap[i.partId];if(!a||!o)continue;let s=zR(a,r.connectorId),c=zR(o,i.connectorId);if(Math.abs(s-c)<.01)continue;let l=[r.partId,i.partId].sort().join(`:`);if(n.has(l))continue;n.add(l);let u=lS(a),d=lS(o);t.push({id:`diameter-mismatch:${l}`,severity:`warning`,title:`Mismatched pipe diameters at a joint`,detail:`${u} (${NR(s,2)} in) is joined to ${d} (${NR(c,2)} in) — the abrupt size change causes turbulence and pressure loss.`,partIds:[r.partId,i.partId],fix:`Add a reducer or match diameters (${u} is ${NR(s,2)} in, ${d} is ${NR(c,2)} in)`})}return t}function VR(e){let t=e.sim?.flows??{},n=new Set(Object.keys(t).filter(e=>(t[e]??0)>0));if(!n.size)return[];let r=[];for(let t of e.parts){let i=e.graph.connectorsByPart.get(t.id)??[];if(!i.length||t.type===`pump`||dS(t))continue;let a=i.filter(t=>e.graph.joinedKeys.has(t.key)).length;if(a===0||a===i.length)continue;let o=[t.id],s=null,c=t.id,l=null;for(let t=0;te!==s&&!o.includes(e));if(t.length!==1)break;let n=t[0],r=e.partsMap[n],i=(e.graph.neighbors.get(n)?.size??0)>=3;if(!r||r.type===`pump`||dS(r)||i){l=n;break}o.push(n),s=c,c=n}(l!==null&&n.has(l)||o.some(e=>n.has(e)))&&(o.some(t=>dS(e.partsMap[t]))||r.push({id:`dead-leg:${t.id}`,severity:`warning`,title:`Dead leg — stagnant water`,detail:`${lS(t)} ends a flowing branch with no reservoir, emitter, drain or grow part — water will sit stagnant (or leak) here.`,partIds:o,fix:`Cap with an emitter/drain or remove`}))}return r}function HR(e){let t=[];for(let n of e.parts){if(n.type!==`pipe`)continue;let r=e.graph.connectorsByPart.get(n.id)??[];if(r.length<2)continue;let[i,a]=[r[0].pos,r[r.length-1].pos];if(Math.abs(i[1]-a[1])>.3)continue;let o=(i[1]+a[1])/2;if(o<=1.5)continue;let s=n.params?.length??Math.hypot(a[0]-i[0],a[2]-i[2]);if(s<=4)continue;let c=t=>e.parts.some(r=>{if(r.id===n.id)return!1;let i=fS(r,e.graph.connectorsByPart.get(r.id)??[]),a=.3;return t[0]>=i.min[0]-a&&t[0]<=i.max[0]+a&&t[2]>=i.min[2]-a&&t[2]<=i.max[2]+a&&i.max[1]>=t[1]-.6&&i.min[1]<=t[1]-.6});c(i)||c(a)||t.push({id:`unsupported-span:${n.id}`,severity:`info`,title:`Unsupported span ${NR(s)} ft`,detail:`${lS(n)} runs ${NR(s)} ft at ${NR(o)} ft height with nothing beneath either end — it will sag over time.`,partIds:[n.id],fix:`Add a lattice/structure support`})}return t}function UR(e){let t=e.sim?.flows??{},n=[];for(let r of e.sim?.pumps??[]){if((r?.gph??0)<=0)continue;let i=r.pumpId,a=e.graph.nodeOfConnector.get(`${i}:out`),o=a?e.graph.nodes.get(a):void 0;if(!o)continue;let s=o.pos[1],c=0,l=i,u=s,d=new Set([`P:${i}`,o.id]),f=[{id:o.id,pathMax:s,highPart:i}];for(;f.length;){let{id:n,pathMax:r,highPart:a}=f.pop(),o=e.graph.nodes.get(n);if(o)for(let n of o.edges){if(d.has(n.to)||(t[n.partId]??0)<=0&&n.partId!==i)continue;d.add(n.to);let o=e.graph.nodes.get(n.to);if(!o)continue;let p=r,m=a;o.pos[1]>p&&(p=o.pos[1],m=n.partId);let h=p-o.pos[1];p>s+.5&&h>c&&(c=h,l=m,u=p),f.push({id:n.to,pathMax:p,highPart:m})}}c>=2&&n.push({id:`siphon:${i}`,severity:`info`,title:`Possible siphon on shutdown`,detail:`Flow from ${lS(e.partsMap[i])} climbs to ${NR(u)} ft and then descends ${NR(c)} ft — when the pump stops, gravity can keep siphoning water through the line.`,partIds:[l],fix:`Add an air gap or check valve at the high point`})}return n}function WR(e){let t=[];for(let n of e.parts){if(!(n.type===`drain`||typeof n.params?.capacityGph==`number`))continue;let r=n.params?.capacityGph??250,i=e.sim?.drains?.find?.(e=>e?.partId===n.id)?.inflowGph??e.sim?.flows?.[n.id]??0;if(i<=r+.5)continue;let a=Math.ceil(i/25)*25;t.push({id:`drain-capacity:${n.id}`,severity:`error`,title:`Undersized drain — will overflow`,detail:`${lS(n)} receives ${Math.round(i)} GPH but is rated for ${Math.round(r)} GPH — the excess will back up and flood.`,partIds:[n.id],fix:`Upsize drain to \u2265 ${a} GPH capacity`})}return t}function GR(e){let t=[];for(let n of e.sim?.netPots??[]){if(!n?.overflowing)continue;let r=e.partsMap[n.partId];if(!r)continue;let i=e.partsMap[n.sourcePartId];t.push({id:`net-pot-spill:${n.partId}`,severity:`error`,title:`Net pot will overflow from backed-up plumbing`,detail:`${lS(r)} sits above ${lS(i)}. Water is rising to ${NR(n.waterHeightFt)} ft while the pot rim is ${NR(n.rimHeightFt)} ft, so nutrient solution will spill out of the top.`,partIds:i?[n.partId,i.id]:[n.partId],fix:`Add a drain/outlet, lower water level, or move the net pot off the flooded line.`})}return t}function KR(e){let t=[];for(let n of e.parts){let r=e.graph.connectorsByPart.get(n.id)??[];r.length&&(r.some(t=>e.graph.joinedKeys.has(t.key))||t.push({id:`orphan:${n.id}`,severity:`info`,title:`Not connected to anything`,detail:`${lS(n)} has no connections — it is not part of any water circuit.`,partIds:[n.id],fix:`Drag it onto a matching connector, or delete it if unused.`}))}return t}function qR(e){let t=[];for(let n of e.parts){if(n.type!==`valve`||n.params?.open!==0)continue;let r=e.graph.componentOf.get(n.id);r!==void 0&&[...e.graph.components[r]].some(t=>{let n=e.partsMap[t];return n?.type===`pump`&&!uS(n)})&&t.push({id:`closed-valve:${n.id}`,severity:`info`,title:`Closed valve blocking a flowing line`,detail:`${lS(n)} is fully closed — everything beyond it gets no water.`,partIds:[n.id],fix:`Open the valve, or remove it if the branch is unused.`})}return t}function JR(e){let t=[];for(let n of e.roomMetrics){let r=e.partsMap[n.roomId],i=(r?.params.width??0)*(r?.params.depth??0);if(!n.sealed&&n.co2TankCount>0&&t.push({id:`room-co2-open:${n.roomId}`,severity:`warning`,title:`CO2 enrichment wasted in open-air room`,detail:`${n.label} is marked open air but has ${n.co2TankCount} CO2 tank${n.co2TankCount===1?``:`s`} — outside air exchange will purge enrichment before plants can use it.`,partIds:[n.roomId],fix:`Seal the room or remove CO2 hardware.`}),n.sealed&&n.airChangesPerMinute>1&&t.push({id:`room-sealed-exhaust:${n.roomId}`,severity:`warning`,title:`Sealed room exhausting too aggressively`,detail:`${n.label} is marked sealed but exhausts ${n.airChangesPerMinute.toFixed(2)} room volumes per minute — that behaves more like an open-air room and dumps conditioned CO2-rich air.`,partIds:[n.roomId],fix:`Reduce exhaust CFM or switch the room to open air.`}),!n.sealed&&n.airChangesPerMinute<.5&&t.push({id:`room-vent-low:${n.roomId}`,severity:`info`,title:`Low air exchange for open-air room`,detail:`${n.label} exchanges only ${n.airChangesPerMinute.toFixed(2)} room volumes per minute — heat and humidity can linger unless intake/exhaust is stronger.`,partIds:[n.roomId],fix:`Increase exhaust capacity or reduce room volume.`}),n.sealed&&n.co2TankCount===0&&n.lightWatts>=600&&t.push({id:`room-co2-missing:${n.roomId}`,severity:`info`,title:`High-light sealed room without CO2`,detail:`${n.label} is sealed and carries ${Math.round(n.lightWatts)} W of lighting but no CO2 source — the room can be enriched, but currently cannot take advantage of the sealed configuration.`,partIds:[n.roomId],fix:`Add a CO2 tank or switch to open-air ventilation.`}),i>0&&n.lightWatts>0){let e=n.lightWatts/i;e<25?t.push({id:`room-light-low:${n.roomId}`,severity:`info`,title:`Low lighting density`,detail:`${n.label} provides ${e.toFixed(1)} W/ft2 across ${i.toFixed(1)} ft2 — useful for propagation or low-light crops, but light-hungry plants will underperform.`,partIds:[n.roomId],fix:`Add more fixture wattage or reduce active canopy area.`}):e>55&&t.push({id:`room-light-high:${n.roomId}`,severity:`warning`,title:`Very high lighting density`,detail:`${n.label} is carrying ${e.toFixed(1)} W/ft2 — that is intense enough to demand strong cooling, CO2 strategy, and careful canopy distance management.`,partIds:[n.roomId],fix:`Raise fixtures, reduce wattage, or tighten environmental control.`})}n.lightWatts>0&&(n.roomDLI<10?t.push({id:`room-dli-low:${n.roomId}`,severity:`warning`,title:`Daily Light Integral (DLI) is too low`,detail:`${n.label} active DLI is ${n.roomDLI.toFixed(1)} — DLI < 10 is insufficient for healthy growth and will cause the crop to stretch.`,partIds:[n.roomId],fix:`Increase grow lights wattage, increase photoperiod (hours on), or decrease room/canopy area.`}):n.roomDLI>45&&t.push({id:`room-dli-high:${n.roomId}`,severity:`warning`,title:`Daily Light Integral (DLI) is too high`,detail:`${n.label} active DLI is ${n.roomDLI.toFixed(1)} — DLI > 45 risks phototoxic bleaching and leaf tissue damage.`,partIds:[n.roomId],fix:`Reduce grow lights wattage, decrease photoperiod (hours on), or raise the fixtures.`})),n.sealed&&n.lightWatts>400&&n.roomCo2===150&&t.push({id:`room-co2-starved:${n.roomId}`,severity:`warning`,title:`Sealed room CO₂ starvation risk`,detail:`${n.label} is sealed and runs high-wattage lighting (${n.lightWatts.toFixed(0)} W > 400 W), but CO₂ levels drop to 150 PPM due to lack of a CO₂ tank.`,partIds:[n.roomId],fix:`Add a CO₂ tank or switch to open-air ventilation.`});let a=Q.getState().growthStage??`vegetative`,o=.8,s=1.6;a===`seedling`?(o=.4,s=.8):a===`vegetative`?(o=.8,s=1.2):a===`flowering`&&(o=1.2,s=1.6),n.roomVPDs&&t.push({id:`room-vpd-high:${n.roomId}`,severity:`warning`,title:`Vapor Pressure Deficit (VPD) is too high`,detail:`${n.label} VPD is ${n.roomVPD.toFixed(2)} kPa, which is above the optimal range of ${o}-${s} kPa for the ${a} stage. High VPD causes excessive transpiration, leading to plant stress and wilting.`,partIds:[n.roomId],fix:`Lower the temperature, increase relative humidity, or reduce lighting intensity.`})}return t}var YR=[{id:`pump-head`,description:`Pumps should keep ≥20% head margin below their max head.`,run:IR},{id:`pump-dead`,description:`Pumps that are off, starved of source water, or dead-ended.`,run:RR},{id:`diameter-mismatch`,description:`Joined connectors whose parts have different pipe diameters.`,run:BR},{id:`dead-leg`,description:`Flowing branches that terminate with no exit part (stagnation).`,run:VR},{id:`unsupported-span`,description:`Long elevated horizontal pipes with nothing beneath their ends.`,run:HR},{id:`siphon`,description:`Flow paths that climb then descend ≥2 ft (siphon on shutdown).`,run:UR},{id:`drain-capacity`,description:`Drains receiving more flow than their rated capacity.`,run:WR},{id:`net-pot-spill`,description:`Net pots positioned over backed-up wet lines that will spill from the rim.`,run:GR},{id:`orphan`,description:`Flow-capable parts with no connections at all.`,run:KR},{id:`closed-valve`,description:`Fully closed valves on an otherwise powered circuit.`,run:qR},{id:`room-environment`,description:`Grow-room ventilation, sealed/open-air behavior, CO2 use, and light density.`,run:JR},{id:`reservoir-chemistry`,description:`Reservoir temperature, pH, and EC/nutrient concentration values.`,run:XR},{id:`part-overlap`,description:`Parts that are overlapping or morphing into one another.`,run:ZR}];function XR(e){let t=[],n=e.parts.filter(e=>e.type===`reservoir`);for(let r of n){let n=nC(r,e.partsMap),i=e.sim?.reservoirRuntime?.[r.id];i?.empty?t.push({id:`res-empty:${r.id}`,severity:`error`,title:`Reservoir runs dry under current load`,detail:`${r.label||`Reservoir #${r.id}`} is fully depleted by the current pump/drain demand, so downstream flow stops entirely.`,partIds:[r.id],fix:`Increase reservoir volume, reduce draw rate, or close the loop with return flow.`}):i&&i.minutesRemaining!==null&&i.minutesRemaining<30&&t.push({id:`res-runtime-low:${r.id}`,severity:`warning`,title:`Reservoir runtime is too short`,detail:`${r.label||`Reservoir #${r.id}`} has only ${i.minutesRemaining.toFixed(1)} minutes of water left at the current net draw of ${i.netOutflowGph.toFixed(1)} GPH.`,partIds:[r.id],fix:`Increase source volume, reduce pump flow, or return more water to this reservoir.`}),n.tempF>73&&t.push({id:`res-temp-high:${r.id}`,severity:`warning`,title:`Reservoir water temperature too high`,detail:`${r.label||`Reservoir #${r.id}`} water temperature is ${n.tempF.toFixed(1)}°F — water above 73°F holds significantly less dissolved oxygen and increases Pythium (root rot) risks.`,partIds:[r.id],fix:`Add a water chiller, reduce room ambient temperature, or turn off unneeded inline pumps.`}),n.ph<5.5?t.push({id:`res-ph-low:${r.id}`,severity:`warning`,title:`Water pH is too low (acidic)`,detail:`${r.label||`Reservoir #${r.id}`} pH is ${n.ph.toFixed(1)} — pH below 5.5 locks out Calcium, Magnesium, and Phosphorus, starving the plant.`,partIds:[r.id],fix:`Add pH Up (potassium hydroxide) or dilute with fresh water to raise pH to 5.8 - 6.2.`}):n.ph>6.5&&t.push({id:`res-ph-high:${r.id}`,severity:`warning`,title:`Water pH is too high (alkaline)`,detail:`${r.label||`Reservoir #${r.id}`} pH is ${n.ph.toFixed(1)} — pH above 6.5 locks out Iron, Manganese, Boron, and Zinc, causing leaf chlorosis.`,partIds:[r.id],fix:`Add pH Down (phosphoric/citric acid) to lower pH to 5.8 - 6.2.`});let a=Q.getState().growthStage,o=1,s=1.6,c=`Add more concentrated nutrient solution (part A/B) to raise EC to 1.0 - 1.6 mS/cm.`,l=`Dilute the reservoir with fresh water to reduce nutrient concentration (EC).`;a===`seedling`?(o=.4,s=.8,c=`Add dilute nutrient solution to raise EC to 0.4 - 0.8 mS/cm for seedlings.`,l=`Dilute the reservoir with fresh water to lower EC to 0.4 - 0.8 mS/cm for seedlings.`):a===`flowering`&&(o=1.5,s=2.2,c=`Add bloom nutrients to raise EC to 1.5 - 2.2 mS/cm for flowering.`,l=`Dilute the reservoir with fresh water to lower EC to 1.5 - 2.2 mS/cm for flowering.`),n.ecs&&t.push({id:`res-ec-high:${r.id}`,severity:`warning`,title:`High nutrient concentration (EC)`,detail:`${r.label||`Reservoir #${r.id}`} EC is ${n.ec.toFixed(1)} mS/cm — EC above ${s.toFixed(1)} risks nutrient burn or root dehydration in the ${a} stage.`,partIds:[r.id],fix:l})}return t}function ZR(e){let t=[],n=new Set;for(let r=0;r[e.id,e])):e,r=Object.values(n),i=t;if(!i)try{i=JS(n)}catch{i=void 0}let a={partsMap:n,parts:r,sim:i,graph:mS(r),roomMetrics:KT(n)},o=[];for(let e of YR)try{o.push(...e.run(a))}catch(t){console.warn(`[design-check] rule "${e.id}" failed:`,t)}return o.sort((e,t)=>QR[e.severity]-QR[t.severity])}var ez=[`error`,`warning`,`info`],tz={error:{heading:`Errors`,noun:[`error`,`errors`],card:`border-rose-900/60 bg-rose-950/40`,dot:`bg-rose-500`,text:`text-rose-300`},warning:{heading:`Warnings`,noun:[`warning`,`warnings`],card:`border-amber-900/60 bg-amber-950/30`,dot:`bg-amber-400`,text:`text-amber-300`},info:{heading:`Tips`,noun:[`tip`,`tips`],card:`border-sky-900/60 bg-sky-950/30`,dot:`bg-sky-400`,text:`text-sky-300`}};function nz(e){let t=[];for(let n of ez){let r=e.filter(e=>e.severity===n).length;r>0&&t.push(`${r} ${tz[n].noun[r===1?0:1]}`)}return t.join(` · `)}function rz({finding:e,onSelectPart:t,onApplyFix:n}){let r=tz[e.severity],i=e.id.startsWith(`dead-leg:`)||e.id.startsWith(`diameter-mismatch:`)||e.id.startsWith(`pump-dead:`);return(0,Z.jsx)(`div`,{className:`rounded-lg border px-3 py-2.5 ${r.card}`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`span`,{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${r.dot}`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-semibold leading-snug ${r.text}`,children:e.title}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-zinc-400`,children:e.detail}),e.fix&&(0,Z.jsxs)(`p`,{className:`mt-1.5 rounded-md bg-zinc-900/80 px-2 py-1 text-[11px] leading-snug text-zinc-300`,children:[(0,Z.jsx)(`span`,{className:`font-semibold text-sky-400`,children:`Fix: `}),e.fix]}),e.partIds.length>0&&t&&(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:[e.partIds.map((n,r)=>(0,Z.jsxs)(`button`,{onClick:()=>t(n),className:`rounded-md border border-zinc-700 bg-zinc-900 px-2 py-0.5 text-[10px] font-semibold text-sky-400 hover:border-sky-700 hover:bg-zinc-800`,children:[`Show part`,e.partIds.length>1?` ${r+1}`:``]},n)),i&&n&&(0,Z.jsx)(`button`,{onClick:()=>n(e),className:`rounded-md border border-emerald-700 bg-emerald-950 px-2 py-0.5 text-[10px] font-semibold text-emerald-300 hover:border-emerald-500 hover:bg-emerald-900`,children:`Apply fix`})]})]})]})})}function iz({findings:e,onSelectPart:t,onApplyFix:n,onClose:r}){let i=e.length===0;return(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex justify-end`,role:`dialog`,"aria-modal":`true`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-black/50`,onClick:r}),(0,Z.jsxs)(`aside`,{className:`relative flex h-full w-[26rem] max-w-full flex-col border-l border-zinc-800 bg-zinc-950 shadow-2xl`,children:[(0,Z.jsxs)(`header`,{className:`flex items-start justify-between gap-3 border-b border-zinc-800 px-4 py-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-bold tracking-wide text-zinc-100`,children:`Design Check`}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] text-zinc-500`,children:i?`All rules passed`:nz(e)})]}),(0,Z.jsx)(`button`,{onClick:r,"aria-label":`Close design check`,className:`rounded-md border border-zinc-800 bg-zinc-900 px-2 py-1 text-xs font-semibold text-zinc-400 hover:border-zinc-600 hover:text-zinc-200`,children:`Close`})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-3`,children:i?(0,Z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 text-center`,children:[(0,Z.jsx)(`span`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-emerald-950 ring-1 ring-emerald-800`,children:(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,className:`h-6 w-6 text-emerald-400`,fill:`none`,children:(0,Z.jsx)(`path`,{d:`M4 10.5l4 4 8-9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),(0,Z.jsx)(`p`,{className:`text-sm font-semibold text-emerald-400`,children:`Build validated — no issues`}),(0,Z.jsx)(`p`,{className:`max-w-[16rem] text-[11px] text-zinc-500`,children:`Every design rule passed. Press Play to watch the water run.`})]}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-4`,children:ez.map(r=>{let i=e.filter(e=>e.severity===r);if(!i.length)return null;let a=tz[r];return(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`h3`,{className:`mb-1.5 flex items-center gap-1.5 text-[10px] font-bold tracking-wider text-zinc-500 uppercase`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${a.dot}`}),a.heading,(0,Z.jsx)(`span`,{className:`font-mono text-zinc-600`,children:i.length})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:i.map(e=>(0,Z.jsx)(rz,{finding:e,onSelectPart:t,onApplyFix:n},e.id))})]},r)})})})]})]})}var az=[`#38bdf8`,`#3d7bfa`,`#34d399`,`#3b7a57`,`#fbbf24`,`#f97316`,`#e0564f`,`#a78bfa`],oz=e=>{let t=0;for(let n=0;ne.parts),n=Q(e=>e.projectName),[r,i]=(0,v.useState)({}),a=(0,v.useRef)(null),o=(0,v.useRef)(t),s=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{if(!e)return;let t=window.location.protocol===`https:`?`wss:`:`ws:`,r=window.location.port===`5173`?`3000`:window.location.port,c=`${t}//${window.location.hostname}${r?`:${r}`:``}`,l=new WebSocket(c);return a.current=l,l.onopen=()=>{let t=oz(e.email);l.send(JSON.stringify({type:`join`,projectRoom:n,userId:e.id,userName:e.email,color:t,activeRoomId:Q.getState().activeRoomId}))},l.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`mutation`?(s.current=!0,o.current=t.parts,Q.getState().syncParts(t.parts)):t.type===`cursor`?i(e=>({...e,[t.userId]:{position:t.position,userName:t.userName,color:t.color,activeRoomId:t.activeRoomId}})):t.type===`leave`&&i(e=>{let n={...e};return delete n[t.userId],n})}catch(e){console.error(`Error handling WebSocket message:`,e)}},l.onclose=()=>{console.log(`Collaboration WebSocket disconnected`)},l.onerror=e=>{console.error(`Collaboration WebSocket error:`,e)},()=>{l.close(),a.current=null}},[e,n]),(0,v.useEffect)(()=>{if(s.current){s.current=!1,o.current=t;return}if(t!==o.current){o.current=t;let e=a.current;e&&e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`mutation`,parts:t}))}},[t]),(0,v.useEffect)(()=>{let e=0,t=t=>{let n=Date.now();if(n-e<50)return;e=n;let r=t.detail,i=a.current;i&&i.readyState===WebSocket.OPEN&&i.send(JSON.stringify({type:`cursor`,position:[r.x,r.y,r.z],activeRoomId:Q.getState().activeRoomId}))};return window.addEventListener(`collab:cursor`,t),()=>{window.removeEventListener(`collab:cursor`,t)}},[]),{remoteCursors:r}}var cz=()=>{let{login:e,signup:t,error:n,clearError:r}=wE(),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-zinc-950 overflow-y-auto px-4 py-8`,children:[(0,Z.jsx)(`div`,{className:`absolute top-0 left-0 right-0 bottom-0 bg-[radial-gradient(circle_at_30%_20%,rgba(14,165,233,0.1),transparent_40%)] pointer-events-none`}),(0,Z.jsxs)(`div`,{className:`w-full max-w-5xl grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-12 items-center relative z-10 my-auto`,children:[(0,Z.jsxs)(`div`,{className:`lg:col-span-7 flex flex-col text-left space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`grid h-8 w-8 place-items-center rounded-lg bg-gradient-to-br from-sky-400 to-blue-600 text-sm font-black text-white shadow-md shadow-sky-500/10`,children:`H`}),(0,Z.jsx)(`span`,{className:`text-sm font-bold tracking-wider text-sky-400 uppercase`,children:`Hydro Builder`})]}),(0,Z.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-black text-white leading-tight tracking-tight`,children:[`Stop Guessing. `,(0,Z.jsx)(`br`,{className:`hidden sm:inline`}),(0,Z.jsx)(`span`,{className:`bg-gradient-to-r from-sky-400 to-blue-500 bg-clip-text text-transparent`,children:`Precision-Plumb`}),` Your Grow.`]}),(0,Z.jsx)(`p`,{className:`text-sm sm:text-base text-zinc-400 max-w-xl leading-relaxed`,children:`Eliminate design errors, head-loss issues, and unnecessary trips to the hardware store. Design, simulate, and size your entire water system in full interactive 3D.`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5 pt-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-base`,children:`💧`}),(0,Z.jsx)(`h3`,{className:`text-sm font-bold text-zinc-200`,children:`Real-Time Fluid Simulation`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-zinc-400 leading-relaxed pl-6`,children:`Instant calculations for GPH flow rates, water velocities (ft/s), and system pressures.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-base`,children:`📋`}),(0,Z.jsx)(`h3`,{className:`text-sm font-bold text-zinc-200`,children:`BOM & Cut List Generator`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-zinc-400 leading-relaxed pl-6`,children:`One-click material summaries of every fitting, adapter, and pipe length. Your design is your shopping list.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-base`,children:`📐`}),(0,Z.jsx)(`h3`,{className:`text-sm font-bold text-zinc-200`,children:`Auto-Snapping & Route Tools`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-zinc-400 leading-relaxed pl-6`,children:`Automatic elbow insertions, grid snaps, and open-ended pipe caps. Plumb runs in seconds.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-base`,children:`🔍`}),(0,Z.jsx)(`h3`,{className:`text-sm font-bold text-zinc-200`,children:`Pro Design Check Diagnostics`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-zinc-400 leading-relaxed pl-6`,children:`Automated error checks for dead-legs, backwards slopes, and diameter size mismatches.`})]})]}),(0,Z.jsxs)(`div`,{className:`border border-zinc-800 bg-zinc-900/30 rounded-xl p-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 max-w-xl`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold text-sky-400 uppercase tracking-widest block`,children:`Pricing model`}),(0,Z.jsx)(`span`,{className:`text-sm font-bold text-zinc-200`,children:`1 free workspace forever`})]}),(0,Z.jsx)(`div`,{className:`hidden sm:block h-6 w-px bg-zinc-800`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold text-emerald-400 uppercase tracking-widest block`,children:`Unlimited building`}),(0,Z.jsx)(`span`,{className:`text-sm font-bold text-zinc-200`,children:`Only $5 per additional build slot`})]})]})]}),(0,Z.jsx)(`div`,{className:`lg:col-span-5 w-full flex justify-center`,children:(0,Z.jsxs)(`div`,{className:`w-full max-w-md overflow-hidden rounded-2xl border border-zinc-850 bg-zinc-900/80 p-8 shadow-2xl backdrop-blur-md`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col items-center mb-6 text-center`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-zinc-100`,children:i?`Create your free account`:`Welcome Back`}),(0,Z.jsx)(`p`,{className:`text-xs text-zinc-400 mt-1`,children:i?`Get instant access to your free build slot`:`Sign in to access your designs`})]}),(f||n)&&(0,Z.jsx)(`div`,{className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/10 p-3 text-xs text-red-400`,children:f||n}),(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),!o||!c){p(`Please fill in all fields`);return}d(!0),p(null),r();try{i?await t(o,c):await e(o,c)}catch(e){p(e instanceof Error?e.message:`Authentication failed`)}finally{d(!1)}},className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-semibold text-zinc-400 mb-1`,htmlFor:`email`,children:`Email Address`}),(0,Z.jsx)(`input`,{id:`email`,type:`email`,autoComplete:`email`,value:o,onChange:e=>s(e.target.value),className:`w-full rounded-lg border border-zinc-800 bg-zinc-950 px-3.5 py-2.5 text-sm text-zinc-200 outline-none transition focus:border-sky-500 focus:bg-zinc-950`,placeholder:`you@example.com`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-semibold text-zinc-400 mb-1`,htmlFor:`password`,children:`Password`}),(0,Z.jsx)(`input`,{id:`password`,type:`password`,autoComplete:i?`new-password`:`current-password`,value:c,onChange:e=>l(e.target.value),className:`w-full rounded-lg border border-zinc-800 bg-zinc-950 px-3.5 py-2.5 text-sm text-zinc-200 outline-none transition focus:border-sky-500 focus:bg-zinc-950`,placeholder:`••••••••`,required:!0})]}),(0,Z.jsx)(`button`,{type:`submit`,disabled:u,className:`w-full rounded-lg bg-gradient-to-r from-sky-500 to-blue-600 py-3 text-sm font-semibold text-white transition hover:from-sky-400 hover:to-blue-500 disabled:opacity-50 flex items-center justify-center gap-2 cursor-pointer shadow-lg shadow-sky-500/10`,children:u?(0,Z.jsx)(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent`}):i?`Sign Up & Build`:`Sign In`})]}),(0,Z.jsx)(`div`,{className:`mt-5 text-center`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{a(!i),p(null),r()},className:`text-xs font-medium text-sky-400 hover:text-sky-300 transition`,children:i?`Already have an account? Sign In`:`Don't have an account? Sign Up`})})]})})]})]})};function lz(e,t){let{user:n}=wE(),r=n&&n.purchased_slots>0;(0,v.useEffect)(()=>{if(t)return;let n=r?yE(e):null;n&&n.parts.length>0?Q.getState().loadParts(n.parts,n.name):Q.getState().loadParts(dT(),`Demo: pump loop`)},[e,t,r])}function uz(e,t){let{user:n}=wE(),r=n&&n.purchased_slots>0,i=EE(e=>e.setStatus);(0,v.useEffect)(()=>{if(t)return;if(!r){i(`unsaved`);return}let n,a=!1,o=Q.subscribe((t,r)=>{t.parts!==r.parts&&(a=!0,i(`unsaved`));let o=t.draggingId!==null||t.gizmoDragging,s=(r.draggingId!==null||r.gizmoDragging)&&!o,c=t.parts!==r.parts&&!o;a&&(s||c)?(clearTimeout(n),i(`saving`),n=setTimeout(()=>{vE(Q.getState().projectName,Object.values(Q.getState().parts),e),a=!1,i(`saved`)},600)):o&&(clearTimeout(n),n=void 0)});return()=>{o(),clearTimeout(n)}},[e,t,r,i])}function dz(){(0,v.useEffect)(()=>{let e=e=>{let t=e.target;if(/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))return;let n=Q.getState(),r=e.metaKey||e.ctrlKey;if(r&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?n.redo():n.undo();return}if(r&&e.key.toLowerCase()===`y`){e.preventDefault(),n.redo();return}if(r&&e.key.toLowerCase()===`a`){e.preventDefault(),n.selectAll();return}if(r&&e.key.toLowerCase()===`c`){let t=n.selectedIds.map(e=>n.parts[e]).filter(Boolean);t.length>0&&(e.preventDefault(),navigator.clipboard.writeText(JSON.stringify({app:`hydro-builder-clip`,parts:t})),bS(`Copied ${t.length} parts`,`info`));return}if(r&&e.key.toLowerCase()===`v`){e.preventDefault(),navigator.clipboard.readText().then(e=>{try{let t=JSON.parse(e);t&&t.app===`hydro-builder-clip`&&Array.isArray(t.parts)&&bS(`Pasted ${n.pasteParts(t.parts).length} parts`,`success`)}catch{bS(`Clipboard does not contain valid hydro parts`,`error`)}}).catch(()=>{bS(`Could not read clipboard`,`error`)});return}if(r)return;let i=iT(e.key);if(i){e.preventDefault(),n.tool!==`select`&&n.setTool(`select`),n.setPlacingType(n.placingType===i?null:i);return}switch(e.key){case` `:e.preventDefault(),n.toggleSimRunning();break;case`Escape`:n.colorPopover?n.closeColorPopover():(n.setTool(`select`),n.setSelected(null));break;case`Delete`:case`Backspace`:n.removeParts(n.selectedIds);break;case`r`:case`R`:n.rotateParts(n.selectedIds,1,(e.shiftKey?-1:1)*(Math.PI/2));break;case`d`:case`D`:e.preventDefault(),n.duplicateParts(n.selectedIds);break;case`q`:case`Q`:n.translateParts(n.selectedIds,[0,-n.gridSize,0],`nudge`);break;case`e`:case`E`:n.translateParts(n.selectedIds,[0,n.gridSize,0],`nudge`);break}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[])}function fz(){let{user:e,loading:t}=wE(),n=e?.email;lz(n,t),uz(n,t),dz();let{remoteCursors:r}=sz(),i=Q(e=>e.placingType),a=Q(e=>e.tool),o=Q(e=>e.selectedIds.length),s=Q(e=>e.viewMode),c=Q(e=>e.renderMode),l=Q(e=>e.parts),u=Q(e=>e.activeRoomId),d=YS(),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(null),g=(0,v.useMemo)(()=>Object.values(l).filter(e=>e.roomId===u),[l,u]);return t?(0,Z.jsxs)(`div`,{className:`flex h-screen flex-col items-center justify-center bg-zinc-950 text-zinc-100`,children:[(0,Z.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-sky-500 border-t-transparent mb-4`}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold tracking-wider text-zinc-400`,children:`Hydro Builder initializing...`})]}):e?(0,Z.jsxs)(`div`,{className:`flex h-screen flex-col bg-zinc-950 text-zinc-100 select-none`,children:[(0,Z.jsx)(OE,{onOpenBom:()=>p(!0),onCheckBuild:()=>{h($R(g,d))}}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Z.jsx)(HT,{}),(0,Z.jsxs)(`main`,{className:`relative min-w-0 flex-1`,onDragOver:e=>e.preventDefault(),onDrop:e=>{let t=e.dataTransfer.getData(`application/x-hydro-part`);if(!t)return;e.preventDefault();let n=jw(e.clientX,e.clientY);if(!n)return;let r=Q.getState(),i=e=>r.snapToGrid?NS(e,r.gridSize):e,a=[`pipe`,`elbow`,`tee`,`valve`,`emitter`].includes(t)?.25:0;r.addPart(t,[i(n[0]),a,i(n[2])])},children:[(0,Z.jsx)(nT,{remoteCursors:r}),(i||a===`measure`||a===`pipeRun`)&&(0,Z.jsx)(`div`,{className:`pointer-events-none absolute top-3 left-1/2 -translate-x-1/2 rounded-full border border-sky-800 bg-sky-950/90 px-4 py-1.5 text-xs font-medium text-sky-200 shadow-lg`,children:i?`Click to place · Shift-click to stamp copies · 1-9 switches parts · Esc to cancel`:a===`pipeRun`?`Pipe Run: click points · Shift-click to keep routing · Esc to exit`:`Measure: click two points · Esc to exit`}),!i&&a!==`measure`&&o>0&&(0,Z.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full border border-zinc-800 bg-zinc-950/85 px-4 py-1.5 text-[11px] font-medium text-zinc-400 shadow-lg backdrop-blur`,children:o>1?`${o} parts — drag moves all · ⌥drag clones · ⇧click adds/removes · ⌘click color · D duplicate · ⌫ delete`:`Drag body or gizmo to move · double-click plumbing to grab the whole run · selected pipes show stretch handles · drag a connector dot to snap${s===`orbit`?` · ⇧drag for vertical`:``} · ${c===`xray`?`X-Ray shows internals`:c===`water`?`Water mode isolates flow`:`Builder mode keeps solids primary`} · ⌥drag clones · ⌘click color · R rotate`}),(0,Z.jsx)(YT,{})]}),(0,Z.jsx)(QT,{})]}),(0,Z.jsx)(NE,{}),f&&(0,Z.jsx)(AR,{onClose:()=>p(!1)}),m&&(0,Z.jsx)(iz,{findings:m,onSelectPart:e=>{let t=Q.getState();if(t.setSelected(e),e){let n=t.parts[e];n&&t.setFocusTarget(n.position)}},onApplyFix:e=>{let t=Q.getState();if(e.id.startsWith(`dead-leg:`))t.fixDeadLeg(e.partIds);else if(e.id.startsWith(`diameter-mismatch:`))t.fixDiameterMismatch(e.partIds);else if(e.id.startsWith(`pump-dead:`)){let n=e.partIds[0];if(n){let e=t.parts[n];e&&(e.params.on===0||e.params.enabled===0)?t.updatePart(n,{params:{...e.params,on:1,enabled:1}}):t.fixPumpDeadEnd(n)}}else if(e.id.startsWith(`pump-head:`)){let n=e.partIds[0];if(n){let e=t.parts[n];if(e){let r=Math.ceil((e.params.maxHeadFt||8)*1.5);t.updatePart(n,{params:{...e.params,maxHeadFt:Math.min(30,r)}})}}}else if(e.id.startsWith(`unsupported-span:`)){let n=e.partIds[0];if(n){let e=t.parts[n];if(e){let n=e.position[1],r=Math.max(.5,n-.1),i=t.addPart(`lattice`,[e.position[0],r/2,e.position[2]],{snap:!1}),a=Q.getState().parts[i];a&&t.updatePart(i,{params:{...a.params,height:r}})}}}else if(e.id.startsWith(`drain-capacity:`)){let n=e.partIds[0];if(n){let e=t.parts[n];if(e){let r=d.drains?.find(e=>e?.partId===n)?.inflowGph??d.flows?.[n]??0,i=Math.ceil(r/25)*25;t.updatePart(n,{params:{...e.params,capacityGph:Math.min(2e3,i)}})}}}else if(e.id.startsWith(`res-temp-high:`)){let e=Object.values(t.parts).filter(e=>e.type===`waterChiller`);for(let n of e)t.updatePart(n.id,{params:{...n.params,on:1,targetTemp:68}})}else if(e.id.startsWith(`res-ph-low:`)||e.id.startsWith(`res-ph-high:`)){let n=e.partIds[0];if(n){let e=t.parts[n];e&&t.updatePart(n,{params:{...e.params,ph:6}})}}else if(e.id.startsWith(`res-ec-low:`)||e.id.startsWith(`res-ec-high:`)){let n=e.partIds[0];if(n){let e=t.parts[n];e&&t.updatePart(n,{params:{...e.params,ec:1.2}})}}else if(e.id.startsWith(`room-co2-open:`)||e.id.startsWith(`room-co2-missing:`)||e.id.startsWith(`room-co2-starved:`)){let n=e.partIds[0];if(n){let r=t.parts[n];if(r){let i=e.id.startsWith(`room-co2-open:`);t.updatePart(n,{params:{...r.params,sealed:+!!i}})}}}else if(e.id.startsWith(`room-sealed-exhaust:`)){let n=e.partIds[0];if(n){let e=t.parts[n];e&&t.updatePart(n,{params:{...e.params,sealed:0}})}}else if(e.id.startsWith(`room-vent-low:`)){let e=Object.values(t.parts).filter(e=>e.type===`inlineFan`);for(let n of e)t.updatePart(n.id,{params:{...n.params,cfm:600}})}else if(e.id.startsWith(`room-light-low:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,watts:Math.min(1e3,(n.params.watts??650)+150)}})}else if(e.id.startsWith(`room-light-high:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,watts:Math.max(100,(n.params.watts??650)-200)}})}else if(e.id.startsWith(`room-dli-low:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,photoperiod:Math.min(24,(n.params.photoperiod??18)+4)}})}else if(e.id.startsWith(`room-dli-high:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,photoperiod:Math.max(0,(n.params.photoperiod??18)-6)}})}else if(e.id.startsWith(`room-vpd-low:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,watts:Math.min(1e3,(n.params.watts??650)+150)}})}else if(e.id.startsWith(`room-vpd-high:`)){let e=Object.values(t.parts).filter(e=>e.type===`growLight`);for(let n of e)t.updatePart(n.id,{params:{...n.params,watts:Math.max(100,(n.params.watts??650)-150)}})}else if(e.id.startsWith(`closed-valve:`)){let n=e.partIds[0];if(n){let e=t.parts[n];e&&t.updatePart(n,{params:{...e.params,open:100}})}}else if(e.id.startsWith(`part-overlap:`)){let n=e.partIds;n.length>=2&&t.removeParts([n[1]])}else e.id.startsWith(`orphan:`)&&t.removeParts(e.partIds);setTimeout(()=>{h($R(Object.values(Q.getState().parts),d))},50)},onClose:()=>h(null)}),(0,Z.jsx)(SS,{})]}):(0,Z.jsx)(cz,{})}function pz(){return(0,Z.jsx)(CE,{children:(0,Z.jsx)(fz,{})})}(0,y.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(v.StrictMode,{children:(0,Z.jsx)(pz,{})}));export{o as n,l as r,hD as t};