@thatopen/components 3.4.7 → 3.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var t=Object.defineProperty,e=(e,i,n)=>(((e,i,n)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n})(e,"symbol"!=typeof i?i+"":i,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@thatopen/fragments"),n=require("three"),s=require("three/webgpu"),r=require("three/tsl"),o=require("web-ifc"),a=require("camera-controls"),l=require("three/examples/jsm/controls/TransformControls.js");function c(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const h=c(i),u=c(n),d=c(s),p=c(o);class f{constructor(){e(this,"enabled",!0),e(this,"trigger",t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class m{constructor(t){e(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),e(this,"isResizeable",()=>"resize"in this&&"getSize"in this),e(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),e(this,"isHideable",()=>"visible"in this),e(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),e(this,"isSerializable",()=>"import"in this&&"export"in this),this.components=t}}class g extends m{}class w extends m{constructor(t){super(t),e(this,"worlds",new i.DataMap),e(this,"onWorldChanged",new f),e(this,"_currentWorld",null),this.onWorldChanged.add(({world:t,action:e})=>{"removed"===e&&this.worlds.delete(t.uuid)})}set currentWorld(t){this._currentWorld=t}get currentWorld(){return this._currentWorld}}class y extends w{constructor(){super(...arguments),e(this,"hasCameraControls",()=>"controls"in this)}}class _ extends w{constructor(){super(...arguments),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"onResize",new f),e(this,"onClippingPlanesUpdated",new f),e(this,"clippingPlanes",[]),e(this,"localClippingPlanes",!1)}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i=this.localClippingPlanes){e.isLocal=i;const n=this.clippingPlanes.indexOf(e);t&&-1===n?this.clippingPlanes.push(e):!t&&n>-1&&this.clippingPlanes.splice(n,1),this.three.clippingPlanes=this.clippingPlanes.filter(t=>!t.isLocal),this.updateClippingPlanes()}}const b=class t extends g{constructor(i){super(i),e(this,"_disposedComponents",new Set),e(this,"enabled",!0),i.add(t.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const n=t;n.dispose&&n.dispose(),this.disposeGeometryAndMaterials(t,e),i&&n.children&&n.children.length&&this.disposeChildren(n),t.children.length=0}disposeGeometry(t){t.boundsTree&&t.disposeBoundsTree&&t.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(e,i){const n=e;n.geometry&&this.disposeGeometry(n.geometry),i&&n.material&&t.disposeMaterial(n),n.material=[],n.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};e(b,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let v=b;class x extends w{constructor(t){super(t),e(this,"onDisposed",new f),e(this,"directionalLights",new Map),e(this,"ambientLights",new Map)}dispose(){const t=this.components.get(v);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,t]of this.directionalLights)t.removeFromParent(),t.target.removeFromParent(),t.dispose();this.directionalLights.clear();for(const[,t]of this.ambientLights)t.removeFromParent(),t.dispose();this.ambientLights.clear()}}class C extends Set{constructor(t){super(t),e(this,"onItemAdded",new f),e(this,"onItemDeleted",new f),e(this,"onCleared",new f),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}add(...t){for(const e of t){if(this.has(e))continue;this.guard(e)&&(super.add(e),this.onItemAdded||(this.onItemAdded=new f),this.onItemAdded.trigger(e))}return this}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(),e}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}const S=class t{static create(){const e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return`${t._lut[255&e]+t._lut[e>>8&255]+t._lut[e>>16&255]+t._lut[e>>24&255]}-${t._lut[255&i]}${t._lut[i>>8&255]}-${t._lut[i>>16&15|64]}${t._lut[i>>24&255]}-${t._lut[63&n|128]}${t._lut[n>>8&255]}-${t._lut[n>>16&255]}${t._lut[n>>24&255]}${t._lut[255&s]}${t._lut[s>>8&255]}${t._lut[s>>16&255]}${t._lut[s>>24&255]}`.toLowerCase()}static validate(e){if(!t._pattern.test(e))throw new Error(`${e} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};e(S,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),e(S,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let A=S;const P=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",T=new RegExp("^"+("["+P+"]["+(P+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function M(t,e){const i=[];let n=e.exec(t);for(;n;){const s=[];s.startIndex=e.lastIndex-n[0].length;const r=n.length;for(let t=0;t<r;t++)s.push(n[t]);i.push(s),n=e.exec(t)}return i}const E=function(t){const e=T.exec(t);return!(null==e)};const I=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],D=["__proto__","constructor","prototype"],z={allowBooleanAttributes:!1,unpairedTags:[]};function k(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function B(t,e){const i=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const n=t.substr(i,e-i);if(e>5&&"xml"===n)return j("InvalidXml","XML declaration allowed only at the start of the document.",G(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function O(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&(i--,0===i))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}const V='"',L="'";function N(t,e){let i="",n="",s=!1;for(;e<t.length;e++){if(t[e]===V||t[e]===L)""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){s=!0;break}i+=t[e]}return""===n&&{value:i,index:e,tagClosed:s}}const F=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function R(t,e){const i=M(t,F),n={};for(let t=0;t<i.length;t++){if(0===i[t][1].length)return j("InvalidAttr","Attribute '"+i[t][2]+"' has no space in starting.",H(i[t]));if(void 0!==i[t][3]&&void 0===i[t][4])return j("InvalidAttr","Attribute '"+i[t][2]+"' is without value.",H(i[t]));if(void 0===i[t][3]&&!e.allowBooleanAttributes)return j("InvalidAttr","boolean attribute '"+i[t][2]+"' is not allowed.",H(i[t]));const s=i[t][2];if(!$(s))return j("InvalidAttr","Attribute '"+s+"' is an invalid name.",H(i[t]));if(Object.prototype.hasOwnProperty.call(n,s))return j("InvalidAttr","Attribute '"+s+"' is repeated.",H(i[t]));n[s]=1}return!0}function U(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);let i=0;for(;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function j(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function $(t){return E(t)}function W(t){return E(t)}function G(t,e){const i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function H(t){return t.startIndex+t[1].length}const q={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",euro:"€",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},Z={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},Y={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},X=new Set("!?\\\\/[]$%{}^&*()<>|+");function K(t){if("#"===t[0])throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${t}"`);for(const e of t)if(X.has(e))throw new Error(`[EntityReplacer] Invalid character '${e}' in entity name: "${t}"`);return t}function Q(...t){const e=Object.create(null);for(const i of t)if(i)for(const t of Object.keys(i)){const n=i[t];if("string"==typeof n)e[t]=n;else if(n&&"object"==typeof n&&void 0!==n.val){const i=n.val;"string"==typeof i&&(e[t]=i)}}return e}const J="external",tt="base",et="all";const it=Object.freeze({allow:0,leave:1,remove:2,throw:3}),nt=new Set([9,10,13]);class st{constructor(t={}){var e;this._limit=t.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck="function"==typeof t.postCheck?t.postCheck:t=>t,this._limitTiers=(e=this._limit.applyLimitsTo??J)&&e!==J?e===et?new Set([et]):e===tt?new Set([tt]):Array.isArray(e)?new Set(e):new Set([J]):new Set([J]),this._numericAllowed=t.numericAllowed??!0,this._baseMap=Q(Z,t.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(t.remove&&Array.isArray(t.remove)?t.remove:[]),this._leaveSet=new Set(t.leave&&Array.isArray(t.leave)?t.leave:[]);const i=function(t){if(!t)return{xmlVersion:1,onLevel:it.allow,nullLevel:it.remove};const e=1.1===t.xmlVersion?1.1:1,i=it[t.onNCR]??it.allow,n=it[t.nullNCR]??it.remove;return{xmlVersion:e,onLevel:i,nullLevel:Math.max(n,it.remove)}}(t.ncr);this._ncrXmlVersion=i.xmlVersion,this._ncrOnLevel=i.onLevel,this._ncrNullLevel=i.nullLevel}setExternalEntities(t){if(t)for(const e of Object.keys(t))K(e);this._externalMap=Q(t)}addExternalEntity(t,e){K(t),"string"==typeof e&&-1===e.indexOf("&")&&(this._externalMap[t]=e)}addInputEntities(t){this._totalExpansions=0,this._expandedLength=0,this._inputMap=Q(t)}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(t){this._ncrXmlVersion=1.1===t?1.1:1}decode(t){if("string"!=typeof t||0===t.length)return t;const e=t,i=[],n=t.length;let s=0,r=0;const o=this._maxTotalExpansions>0,a=this._maxExpandedLength>0,l=o||a;for(;r<n;){if(38!==t.charCodeAt(r)){r++;continue}let e=r+1;for(;e<n&&59!==t.charCodeAt(e)&&e-r<=32;)e++;if(e>=n||59!==t.charCodeAt(e)){r++;continue}const c=t.slice(r+1,e);if(0===c.length){r++;continue}let h,u;if(this._removeSet.has(c))h="",void 0===u&&(u=J);else{if(this._leaveSet.has(c)){r++;continue}if(35===c.charCodeAt(0)){const t=this._resolveNCR(c);if(void 0===t){r++;continue}h=t,u=tt}else{const t=this._resolveName(c);h=null==t?void 0:t.value,u=null==t?void 0:t.tier}}if(void 0!==h){if(r>s&&i.push(t.slice(s,r)),i.push(h),s=e+1,r=s,l&&this._tierCounts(u)){if(o&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(a){const t=h.length-(c.length+2);if(t>0&&(this._expandedLength+=t,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}else r++}s<n&&i.push(t.slice(s));const c=0===i.length?t:i.join("");return this._postCheck(c,e)}_tierCounts(t){return!!this._limitTiers.has(et)||this._limitTiers.has(t)}_resolveName(t){return t in this._inputMap?{value:this._inputMap[t],tier:J}:t in this._externalMap?{value:this._externalMap[t],tier:J}:t in this._baseMap?{value:this._baseMap[t],tier:tt}:void 0}_classifyNCR(t){return 0===t?this._ncrNullLevel:t>=55296&&t<=57343||1===this._ncrXmlVersion&&t>=1&&t<=31&&!nt.has(t)?it.remove:-1}_applyNCRAction(t,e,i){switch(t){case it.allow:return String.fromCodePoint(i);case it.remove:return"";case it.leave:return;case it.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${e}; (U+${i.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(i)}}_resolveNCR(t){const e=t.charCodeAt(1);let i;if(i=120===e||88===e?parseInt(t.slice(2),16):parseInt(t.slice(1),10),Number.isNaN(i)||i<0||i>1114111)return;const n=this._classifyNCR(i);if(!this._numericAllowed&&n<it.remove)return;const s=-1===n?this._ncrOnLevel:Math.max(this._ncrOnLevel,n);return this._applyNCRAction(s,t,i)}}const rt=t=>I.includes(t)?"__"+t:t,ot={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:rt};function at(t,e){if("string"!=typeof t)return;const i=t.toLowerCase();if(I.some(t=>i===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);if(D.some(t=>i===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`)}function lt(t,e){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:Math.max(1,t.maxEntitySize??1e4),maxExpansionDepth:Math.max(1,t.maxExpansionDepth??1e4),maxTotalExpansions:Math.max(1,t.maxTotalExpansions??1/0),maxExpandedLength:Math.max(1,t.maxExpandedLength??1e5),maxEntityCount:Math.max(1,t.maxEntityCount??1e3),allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null,appliesTo:t.appliesTo??"all"}:lt(!0)}const ct=function(t){const e=Object.assign({},ot,t),i=[{value:e.attributeNamePrefix,name:"attributeNamePrefix"},{value:e.attributesGroupName,name:"attributesGroupName"},{value:e.textNodeName,name:"textNodeName"},{value:e.cdataPropName,name:"cdataPropName"},{value:e.commentPropName,name:"commentPropName"}];for(const{value:t,name:e}of i)t&&at(t,e);return null===e.onDangerousProperty&&(e.onDangerousProperty=rt),e.processEntities=lt(e.processEntities,e.htmlEntities),e.unpairedTagsSet=new Set(e.unpairedTags),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),e};let ht;ht="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class ut{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][ht]={startIndex:e})}static getMetaDataSymbol(){return ht}}class dt{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const i=Object.create(null);let n=0;if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let s=1,r=!1,o=!1,a="";for(;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,s--):s--,0===s)break}else"["===t[e]?r=!0:a+=t[e];else{if(r&&ft(t,"!ENTITY",e)){let s,r;if(e+=7,[s,r,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===r.indexOf("&")){if(!1!==this.options.enabled&&null!=this.options.maxEntityCount&&n>=this.options.maxEntityCount)throw new Error(`Entity count (${n+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);i[s]=r,n++}}else if(r&&ft(t,"!ELEMENT",e)){e+=8;const{index:i}=this.readElementExp(t,e+1);e=i}else if(r&&ft(t,"!ATTLIST",e))e+=8;else if(r&&ft(t,"!NOTATION",e)){e+=9;const{index:i}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=i}else{if(!ft(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}s++,a=""}if(0!==s)throw new Error("Unclosed DOCTYPE")}return{entities:i,i:e}}readEntityExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)e++;let n=t.substring(i,e);if(mt(n),e=pt(t,e),!this.suppressValidationErr){if("SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported")}let s="";if([e,s]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&null!=this.options.maxEntitySize&&s.length>this.options.maxEntitySize)throw new Error(`Entity "${n}" size (${s.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[n,s,--e]}readNotationExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);!this.suppressValidationErr&&mt(n),e=pt(t,e);const s=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==s&&"PUBLIC"!==s)throw new Error(`Expected SYSTEM or PUBLIC, found "${s}"`);e+=s.length,e=pt(t,e);let r=null,o=null;if("PUBLIC"===s)[e,r]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=pt(t,e)]&&"'"!==t[e]||([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===s&&([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:r,systemIdentifier:o,index:--e}}readIdentifierVal(t,e,i){let n="";const s=t[e];if('"'!==s&&"'"!==s)throw new Error(`Expected quoted string, found "${s}"`);const r=++e;for(;e<t.length&&t[e]!==s;)e++;if(n=t.substring(r,e),t[e]!==s)throw new Error(`Unterminated ${i} value`);return[++e,n]}readElementExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);if(!this.suppressValidationErr&&!E(n))throw new Error(`Invalid element name: "${n}"`);let s="";if("E"===t[e=pt(t,e)]&&ft(t,"MPTY",e))e+=4;else if("A"===t[e]&&ft(t,"NY",e))e+=2;else if("("===t[e]){const i=++e;for(;e<t.length&&")"!==t[e];)e++;if(s=t.substring(i,e),")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:n,contentModel:s.trim(),index:e}}readAttlistExp(t,e){let i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);for(mt(n),i=e=pt(t,e);e<t.length&&!/\s/.test(t[e]);)e++;let s=t.substring(i,e);if(!mt(s))throw new Error(`Invalid attribute name: "${s}"`);e=pt(t,e);let r="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(r="NOTATION","("!==t[e=pt(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let i=[];for(;e<t.length&&")"!==t[e];){const n=e;for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)e++;let s=t.substring(n,e);if(s=s.trim(),!mt(s))throw new Error(`Invalid notation name: "${s}"`);i.push(s),"|"===t[e]&&(e++,e=pt(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,r+=" ("+i.join("|")+")"}else{const i=e;for(;e<t.length&&!/\s/.test(t[e]);)e++;r+=t.substring(i,e);const n=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!n.includes(r.toUpperCase()))throw new Error(`Invalid attribute type: "${r}"`)}e=pt(t,e);let o="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(o="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(o="#IMPLIED",e+=7):[e,o]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:n,attributeName:s,attributeType:r,defaultValue:o,index:e}}}const pt=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function ft(t,e,i){for(let n=0;n<e.length;n++)if(e[n]!==t[i+n+1])return!1;return!0}function mt(t){if(E(t))return t;throw new Error(`Invalid entity name ${t}`)}const gt=/^[-+]?0x[a-fA-F0-9]+$/,wt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,yt={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original"};function _t(t,e={}){if(e=Object.assign({},yt,e),!t||"string"!=typeof t)return t;let i=t.trim();if(0===i.length)return t;if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===i)return 0;if(e.hex&&gt.test(i))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(i,16);if(isFinite(i)){if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const n=e.match(bt);if(n){let s=n[1]||"";const r=-1===n[3].indexOf("e")?"E":"e",o=n[2],a=s?t[o.length+1]===r:t[o.length]===r;return o.length>1&&a?t:(1!==o.length||!n[3].startsWith(`.${r}`)&&n[3][0]!==r)&&o.length>0?i.leadingZeros&&!a?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,i,e);{const n=wt.exec(i);if(n){const s=n[1]||"",r=n[2];let o=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),t;return t}(n[3]);const a=s?"."===t[r.length+1]:"."===t[r.length];if(!e.leadingZeros&&(r.length>1||1===r.length&&!a))return t;{const n=Number(i),a=String(n);if(0===n)return n;if(-1!==a.search(/[eE]/))return e.eNotation?n:t;if(-1!==i.indexOf("."))return"0"===a||a===o||a===`${s}${o}`?n:t;let l=r?o:i;return r?l===a||s+l===a?n:t:l===a||l===s+a?n:t}}return t}}return function(t,e,i){const n=e===1/0;switch(i.infinity.toLowerCase()){case"null":return null;case"infinity":return e;case"string":return n?"Infinity":"-Infinity";default:return t}}(t,Number(i),e)}const bt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class vt{constructor(t,e={},i){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=i,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,n="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(n.trim()&&(e.push(this._parseSegment(n.trim())),n=""),e.push({type:"deep-wildcard"}),i+=2):(n.trim()&&e.push(this._parseSegment(n.trim())),n="",i++):(n+=t[i],i++);return n.trim()&&e.push(this._parseSegment(n.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,n=t;const s=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(s&&(n=s[1]+s[3],s[2])){const t=s[2].slice(1,-1);t&&(i=t)}let r,o,a=n;if(n.includes("::")){const e=n.indexOf("::");if(r=n.substring(0,e).trim(),a=n.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let l=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,l=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(l){const t=l.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=l}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class xt{constructor(){this._byDepthAndTag=new Map,this._wildcardByDepth=new Map,this._deepWildcards=[],this._patterns=new Set,this._sealed=!1}add(t){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(t.pattern))return this;if(this._patterns.add(t.pattern),t.hasDeepWildcard())return this._deepWildcards.push(t),this;const e=t.length,i=t.segments[t.segments.length-1],n=null==i?void 0:i.tag;if(n&&"*"!==n){const i=`${e}:${n}`;this._byDepthAndTag.has(i)||this._byDepthAndTag.set(i,[]),this._byDepthAndTag.get(i).push(t)}else this._wildcardByDepth.has(e)||this._wildcardByDepth.set(e,[]),this._wildcardByDepth.get(e).push(t);return this}addAll(t){for(const e of t)this.add(e);return this}has(t){return this._patterns.has(t.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(t){return null!==this.findMatch(t)}findMatch(t){const e=t.getDepth(),i=`${e}:${t.getCurrentTag()}`,n=this._byDepthAndTag.get(i);if(n)for(let e=0;e<n.length;e++)if(t.matches(n[e]))return n[e];const s=this._wildcardByDepth.get(e);if(s)for(let e=0;e<s.length;e++)if(t.matches(s[e]))return s[e];for(let e=0;e<this._deepWildcards.length;e++)if(t.matches(this._deepWildcards[e]))return this._deepWildcards[e];return null}}class Ct{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){var e;const i=this._matcher.path;if(0!==i.length)return null==(e=i[i.length-1].values)?void 0:e[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const i=e[e.length-1];return void 0!==i.values&&t in i.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class St{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new Ct(this)}push(t,e=null,i=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const n=this.path.length;this.siblingStacks[n]||(this.siblingStacks[n]=new Map);const s=this.siblingStacks[n],r=i?`${i}:${t}`:t,o=s.get(r)||0;let a=0;for(const t of s.values())a+=t;s.set(r,o+1);const l={tag:t,position:a,counter:o};null!=i&&(l.namespace=i),null!=e&&(l.values=e),this.path.push(l)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){var e;if(0!==this.path.length)return null==(e=this.path[this.path.length-1].values)?void 0:e[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;if(i===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const n=t[i];if("deep-wildcard"===n.type){if(i--,i<0)return!0;const n=t[i];let s=!1;for(let t=e;t>=0;t--)if(this._matchSegment(n,this.path[t],t===this.path.length-1)){e=t-1,i--,s=!0;break}if(!s)return!1}else{if(!this._matchSegment(n,this.path[e],e===this.path.length-1))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!i)return!1;const n=e.counter??0;if("first"===t.position&&0!==n)return!1;if("odd"===t.position&&n%2!=1)return!1;if("even"===t.position&&n%2!=0)return!1;if("nth"===t.position&&n!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function At(t,e){if(!t)return{};const i=e.attributesGroupName?t[e.attributesGroupName]:t;if(!i)return{};const n={};for(const t in i)if(t.startsWith(e.attributeNamePrefix)){n[t.substring(e.attributeNamePrefix.length)]=i[t]}else n[t]=i[t];return n}function Pt(t){if(!t||"string"!=typeof t)return;const e=t.indexOf(":");if(-1!==e&&e>0){const i=t.substring(0,e);if("xmlns"!==i)return i}}class Tt{constructor(t,e){var i;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=zt,this.parseTextData=Mt,this.resolveNameSpace=Et,this.buildAttributesMap=Dt,this.isItStopNode=Vt,this.replaceEntitiesValue=Bt,this.readStopNodeData=Rt,this.saveTextToParentTag=Ot,this.addChild=kt,this.ignoreAttributesFn="function"==typeof(i=this.options.ignoreAttributes)?i:Array.isArray(i)?t=>{for(const e of i){if("string"==typeof e&&t===e)return!0;if(e instanceof RegExp&&e.test(t))return!0}}:()=>!1,this.entityExpansionCount=0,this.currentExpandedLength=0;let n={...Z};this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:("object"==typeof this.options.htmlEntities?n=this.options.htmlEntities:!0===this.options.htmlEntities&&(n={...Y,...q}),this.entityDecoder=new st({namedEntities:{...n,...e},numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo}})),this.matcher=new St,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new xt;const s=this.options.stopNodes;if(s&&s.length>0){for(let t=0;t<s.length;t++){const e=s[t];"string"==typeof e?this.stopNodeExpressionsSet.add(new vt(e)):e instanceof vt&&this.stopNodeExpressionsSet.add(e)}this.stopNodeExpressionsSet.seal()}}}function Mt(t,e,i,n,s,r,o){const a=this.options;if(void 0!==t&&(a.trimValues&&!n&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));const n=a.jPath?i.toString():i,l=a.tagValueProcessor(e,t,n,s,r);if(null==l)return t;if(typeof l!=typeof t||l!==t)return l;if(a.trimValues)return Ut(t,a.parseTagValue,a.numberParseOptions);return t.trim()===t?Ut(t,a.parseTagValue,a.numberParseOptions):t}}function Et(t){if(this.options.removeNSPrefix){const e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}const It=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function Dt(t,e,i,n=!1){const s=this.options;if(!0===n||!0!==s.ignoreAttributes&&"string"==typeof t){const n=M(t,It),r=n.length,o={},a=new Array(r);let l=!1;const c={};for(let t=0;t<r;t++){const e=this.resolveNameSpace(n[t][1]),r=n[t][4];if(e.length&&void 0!==r){let n=r;s.trimValues&&(n=n.trim()),n=this.replaceEntitiesValue(n,i,this.readonlyMatcher),a[t]=n,c[e]=n,l=!0}}l&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(c);const h=s.jPath?e.toString():this.readonlyMatcher;let u=!1;for(let t=0;t<r;t++){const e=this.resolveNameSpace(n[t][1]);if(this.ignoreAttributesFn(e,h))continue;let i=s.attributeNamePrefix+e;if(e.length)if(s.transformAttributeName&&(i=s.transformAttributeName(i)),i=$t(i,s),void 0!==n[t][4]){const n=a[t],r=s.attributeValueProcessor(e,n,h);o[i]=null==r?n:typeof r!=typeof n||r!==n?r:Ut(n,s.parseAttributeValue,s.numberParseOptions),u=!0}else s.allowBooleanAttributes&&(o[i]=!0,u=!0)}if(!u)return;if(s.attributesGroupName&&!s.preserveOrder){const t={};return t[s.attributesGroupName]=o,t}return o}}const zt=function(t){t=t.replace(/\r\n?/g,"\n");const e=new ut("!xml");let i=e,n="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const s=this.options,r=new dt(s.processEntities),o=t.length;for(let a=0;a<o;a++){if("<"===t[a]){const l=t.charCodeAt(a+1);if(47===l){const e=Lt(t,">",a,"Closing Tag is not closed.");let r=t.substring(a+2,e).trim();if(s.removeNSPrefix){const t=r.indexOf(":");-1!==t&&(r=r.substr(t+1))}r=jt(s.transformTagName,r,"",s).tagName,i&&(n=this.saveTextToParentTag(n,i,this.readonlyMatcher));const o=this.matcher.getCurrentTag();if(r&&s.unpairedTagsSet.has(r))throw new Error(`Unpaired tag can not be used as closing tag: </${r}>`);o&&s.unpairedTagsSet.has(o)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,i=this.tagsNodeStack.pop(),n="",a=e}else if(63===l){let e=Ft(t,a,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");n=this.saveTextToParentTag(n,i,this.readonlyMatcher);const r=this.buildAttributesMap(e.tagExp,this.matcher,e.tagName,!0);if(r){const t=r[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(t)||1)}if(s.ignoreDeclaration&&"?xml"===e.tagName||s.ignorePiTags);else{const t=new ut(e.tagName);t.add(s.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&!0!==s.ignoreAttributes&&(t[":@"]=r),this.addChild(i,t,this.readonlyMatcher,a)}a=e.closeIndex+1}else if(33===l&&45===t.charCodeAt(a+2)&&45===t.charCodeAt(a+3)){const e=Lt(t,"--\x3e",a+4,"Comment is not closed.");if(s.commentPropName){const r=t.substring(a+4,e-2);n=this.saveTextToParentTag(n,i,this.readonlyMatcher),i.add(s.commentPropName,[{[s.textNodeName]:r}])}a=e}else if(33===l&&68===t.charCodeAt(a+2)){const e=r.readDocType(t,a);this.entityDecoder.addInputEntities(e.entities),a=e.i}else if(33===l&&91===t.charCodeAt(a+2)){const e=Lt(t,"]]>",a,"CDATA is not closed.")-2,r=t.substring(a+9,e);n=this.saveTextToParentTag(n,i,this.readonlyMatcher);let o=this.parseTextData(r,i.tagname,this.readonlyMatcher,!0,!1,!0,!0);null==o&&(o=""),s.cdataPropName?i.add(s.cdataPropName,[{[s.textNodeName]:r}]):i.add(s.textNodeName,o),a=e+2}else{let r=Ft(t,a,s.removeNSPrefix);if(!r){const e=t.substring(Math.max(0,a-50),Math.min(o,a+50));throw new Error(`readTagExp returned undefined at position ${a}. Context: "${e}"`)}let l=r.tagName;const c=r.rawTagName;let h=r.tagExp,u=r.attrExpPresent,d=r.closeIndex;if(({tagName:l,tagExp:h}=jt(s.transformTagName,l,h,s)),s.strictReservedNames&&(l===s.commentPropName||l===s.cdataPropName||l===s.textNodeName||l===s.attributesGroupName))throw new Error(`Invalid tag name: ${l}`);i&&n&&"!xml"!==i.tagname&&(n=this.saveTextToParentTag(n,i,this.readonlyMatcher,!1));const p=i;p&&s.unpairedTagsSet.has(p.tagname)&&(i=this.tagsNodeStack.pop(),this.matcher.pop());let f=!1;h.length>0&&h.lastIndexOf("/")===h.length-1&&(f=!0,"/"===l[l.length-1]?(l=l.substr(0,l.length-1),h=l):h=h.substr(0,h.length-1),u=l!==h);let m,g=null;m=Pt(c),l!==e.tagname&&this.matcher.push(l,{},m),l!==h&&u&&(g=this.buildAttributesMap(h,this.matcher,l),g&&At(g,s)),l!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());const w=a;if(this.isCurrentNodeStopNode){let e="";if(f)a=r.closeIndex;else if(s.unpairedTagsSet.has(l))a=r.closeIndex;else{const i=this.readStopNodeData(t,c,d+1);if(!i)throw new Error(`Unexpected end of ${c}`);a=i.i,e=i.tagContent}const n=new ut(l);g&&(n[":@"]=g),n.add(s.textNodeName,e),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(i,n,this.readonlyMatcher,w)}else{if(f){({tagName:l,tagExp:h}=jt(s.transformTagName,l,h,s));const t=new ut(l);g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(s.unpairedTagsSet.has(l)){const t=new ut(l);g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),this.matcher.pop(),this.isCurrentNodeStopNode=!1,a=r.closeIndex;continue}{const t=new ut(l);if(this.tagsNodeStack.length>s.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),i=t}}n="",a=d}}}else n+=t[a]}return e.child};function kt(t,e,i,n){this.options.captureMetaData||(n=void 0);const s=this.options.jPath?i.toString():i,r=this.options.updateTag(e.tagname,s,e[":@"]);!1===r||("string"==typeof r?(e.tagname=r,t.addChild(e,n)):t.addChild(e,n))}function Bt(t,e,i){const n=this.options.processEntities;if(!n||!n.enabled)return t;if(n.allowedTags){const s=this.options.jPath?i.toString():i;if(!(Array.isArray(n.allowedTags)?n.allowedTags.includes(e):n.allowedTags(e,s)))return t}if(n.tagFilter){const s=this.options.jPath?i.toString():i;if(!n.tagFilter(e,s))return t}return this.entityDecoder.decode(t)}function Ot(t,e,i,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function Vt(){return 0!==this.stopNodeExpressionsSet.size&&this.matcher.matchesAny(this.stopNodeExpressionsSet)}function Lt(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s+e.length-1}function Nt(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s}function Ft(t,e,i,n=">"){const s=function(t,e,i=">"){let n=0;const s=t.length,r=i.charCodeAt(0),o=i.length>1?i.charCodeAt(1):-1;let a="",l=e;for(let i=e;i<s;i++){const e=t.charCodeAt(i);if(n)e===n&&(n=0);else if(34===e||39===e)n=e;else if(e===r){if(-1===o)return a+=t.substring(l,i),{data:a,index:i};if(t.charCodeAt(i+1)===o)return a+=t.substring(l,i),{data:a,index:i}}else 9!==e||n||(a+=t.substring(l,i)+" ",l=i+1)}}(t,e+1,n);if(!s)return;let r=s.data;const o=s.index,a=r.search(/\s/);let l=r,c=!0;-1!==a&&(l=r.substring(0,a),r=r.substring(a+1).trimStart());const h=l;if(i){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),c=l!==s.data.substr(t+1))}return{tagName:l,tagExp:r,closeIndex:o,attrExpPresent:c,rawTagName:h}}function Rt(t,e,i){const n=i;let s=1;const r=t.length;for(;i<r;i++)if("<"===t[i]){const r=t.charCodeAt(i+1);if(47===r){const r=Nt(t,">",i,`${e} is not closed`);if(t.substring(i+2,r).trim()===e&&(s--,0===s))return{tagContent:t.substring(n,i),i:r};i=r}else if(63===r){i=Lt(t,"?>",i+1,"StopNode is not closed.")}else if(33===r&&45===t.charCodeAt(i+2)&&45===t.charCodeAt(i+3)){i=Lt(t,"--\x3e",i+3,"StopNode is not closed.")}else if(33===r&&91===t.charCodeAt(i+2)){i=Lt(t,"]]>",i,"StopNode is not closed.")-2}else{const n=Ft(t,i,">");if(n){(n&&n.tagName)===e&&"/"!==n.tagExp[n.tagExp.length-1]&&s++,i=n.closeIndex}}}}function Ut(t,e,i){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&_t(t,i)}return void 0!==t?t:""}function jt(t,e,i,n){if(t){const n=t(e);i===e&&(i=n),e=n}return{tagName:e=$t(e,n),tagExp:i}}function $t(t,e){if(D.includes(t))throw new Error(`[SECURITY] Invalid name: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);return I.includes(t)?e.onDangerousProperty(t):t}const Wt=ut.getMetaDataSymbol();function Gt(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;const i={};for(const n in t)if(n.startsWith(e)){i[n.substring(e.length)]=t[n]}else i[n]=t[n];return i}function Ht(t,e,i,n){return qt(t,e,i,n)}function qt(t,e,i,n){let s;const r={};for(let o=0;o<t.length;o++){const a=t[o],l=Zt(a);if(void 0!==l&&l!==e.textNodeName){const t=Gt(a[":@"]||{},e.attributeNamePrefix);i.push(l,t)}if(l===e.textNodeName)void 0===s?s=a[l]:s+=""+a[l];else{if(void 0===l)continue;if(a[l]){let t=qt(a[l],e,i,n);const s=Xt(t,e);if(a[":@"]?Yt(t,a[":@"],n,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==a[Wt]&&"object"==typeof t&&null!==t&&(t[Wt]=a[Wt]),void 0!==r[l]&&Object.prototype.hasOwnProperty.call(r,l))Array.isArray(r[l])||(r[l]=[r[l]]),r[l].push(t);else{const i=e.jPath?n.toString():n;e.isArray(l,i,s)?r[l]=[t]:r[l]=t}void 0!==l&&l!==e.textNodeName&&i.pop()}}}return"string"==typeof s?s.length>0&&(r[e.textNodeName]=s):void 0!==s&&(r[e.textNodeName]=s),r}function Zt(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const i=e[t];if(":@"!==i)return i}}function Yt(t,e,i,n){if(e){const s=Object.keys(e),r=s.length;for(let o=0;o<r;o++){const r=s[o],a=r.startsWith(n.attributeNamePrefix)?r.substring(n.attributeNamePrefix.length):r,l=n.jPath?i.toString()+"."+a:i;n.isArray(r,l,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function Xt(t,e){const{textNodeName:i}=e,n=Object.keys(t).length;return 0===n||!(1!==n||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}class Kt{constructor(t){this.externalEntities={},this.options=ct(t)}parse(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");if(e){!0===e&&(e={});const i=function(t,e){e=Object.assign({},z,e);const i=[];let n=!1,s=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=B(t,r),r.err)return r}else{if("<"!==t[r]){if(k(t[r]))continue;return j("InvalidChar","char '"+t[r]+"' is not expected.",G(t,r))}{let o=r;if(r++,"!"===t[r]){r=O(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let l="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)l+=t[r];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),r--),!W(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",j("InvalidTag",e,G(t,r))}const c=N(t,r);if(!1===c)return j("InvalidAttr","Attributes for '"+l+"' have open quote.",G(t,r));let h=c.value;if(r=c.index,"/"===h[h.length-1]){const i=r-h.length;h=h.substring(0,h.length-1);const s=R(h,e);if(!0!==s)return j(s.err.code,s.err.msg,G(t,i+s.err.line));n=!0}else if(a){if(!c.tagClosed)return j("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",G(t,r));if(h.trim().length>0)return j("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",G(t,o));if(0===i.length)return j("InvalidTag","Closing tag '"+l+"' has not been opened.",G(t,o));{const e=i.pop();if(l!==e.tagName){let i=G(t,e.tagStartPos);return j("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+i.line+", col "+i.col+") instead of closing tag '"+l+"'.",G(t,o))}0==i.length&&(s=!0)}}else{const a=R(h,e);if(!0!==a)return j(a.err.code,a.err.msg,G(t,r-h.length+a.err.line));if(!0===s)return j("InvalidXml","Multiple possible root nodes found.",G(t,r));-1!==e.unpairedTags.indexOf(l)||i.push({tagName:l,tagStartPos:o}),n=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=O(t,r);continue}if("?"!==t[r+1])break;if(r=B(t,++r),r.err)return r}else if("&"===t[r]){const e=U(t,r);if(-1==e)return j("InvalidChar","char '&' is not expected.",G(t,r));r=e}else if(!0===s&&!k(t[r]))return j("InvalidXml","Extra text at the end",G(t,r));"<"===t[r]&&r--}}}return n?1==i.length?j("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",G(t,i[0].tagStartPos)):!(i.length>0)||j("InvalidXml","Invalid '"+JSON.stringify(i.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):j("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==i)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const i=new Tt(this.options,this.externalEntities),n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:Ht(n,this.options,i.matcher,i.readonlyMatcher)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return ut.getMetaDataSymbol()}}function Qt(t,e){let i="";e.format&&e.indentBy.length>0&&(i="\n");const n=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const i=e.stopNodes[t];"string"==typeof i?n.push(new vt(i)):i instanceof vt&&n.push(i)}return Jt(t,e,i,new St,n)}function Jt(t,e,i,n,s){let r="",o=!1;if(e.maxNestedTags&&n.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=oe(i,e),i}return""}for(let a=0;a<t.length;a++){const l=t[a],c=ne(l);if(void 0===c)continue;const h=te(l[":@"],e);n.push(c,h);const u=re(n,s);if(c===e.textNodeName){let t=l[c];u||(t=e.tagValueProcessor(c,t),t=oe(t,e)),o&&(r+=i),r+=t,o=!1,n.pop();continue}if(c===e.cdataPropName){o&&(r+=i);const t=l[c][0][e.textNodeName];r+=`<![CDATA[${String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}]]>`,o=!1,n.pop();continue}if(c===e.commentPropName){const t=l[c][0][e.textNodeName];r+=i+`\x3c!--${String(t).replace(/--/g,"- -").replace(/-$/,"- ")}--\x3e`,o=!0,n.pop();continue}if("?"===c[0]){const t=se(l[":@"],e,u),s="?xml"===c?"":i;let a=l[c][0][e.textNodeName];a=0!==a.length?" "+a:"",r+=s+`<${c}${a}${t}?>`,o=!0,n.pop();continue}let d=i;""!==d&&(d+=e.indentBy);const p=i+`<${c}${se(l[":@"],e,u)}`;let f;f=u?ee(l[c],e):Jt(l[c],e,d,n,s),-1!==e.unpairedTags.indexOf(c)?e.suppressUnpairedNode?r+=p+">":r+=p+"/>":f&&0!==f.length||!e.suppressEmptyNode?f&&f.endsWith(">")?r+=p+`>${f}${i}</${c}>`:(r+=p+">",f&&""!==i&&(f.includes("/>")||f.includes("</"))?r+=i+e.indentBy+f+i:r+=f,r+=`</${c}>`):r+=p+"/>",o=!0,n.pop()}return r}function te(t,e){if(!t||e.ignoreAttributes)return null;const i={};let n=!1;for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;i[s.startsWith(e.attributeNamePrefix)?s.substr(e.attributeNamePrefix.length):s]=t[s],n=!0}return n?i:null}function ee(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let n=0;n<t.length;n++){const s=t[n],r=ne(s);if(r===e.textNodeName)i+=s[r];else if(r===e.cdataPropName)i+=s[r][0][e.textNodeName];else if(r===e.commentPropName)i+=s[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=ie(s[":@"],e),n=ee(s[r],e);n&&0!==n.length?i+=`<${r}${t}>${n}</${r}>`:i+=`<${r}${t}/>`}}}return i}function ie(t,e){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let s=t[n];!0===s&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return i}function ne(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i];if(Object.prototype.hasOwnProperty.call(t,n)&&":@"!==n)return n}}function se(t,e,i){let n="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let r;i?r=t[s]:(r=e.attributeValueProcessor(s,t[s]),r=oe(r,e)),!0===r&&e.suppressBooleanAttributes?n+=` ${s.substr(e.attributeNamePrefix.length)}`:n+=` ${s.substr(e.attributeNamePrefix.length)}="${r}"`}return n}function re(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function oe(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const n=e.entities[i];t=t.replace(n.regex,n.val)}return t}const ae={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0};function le(t){if(this.options=Object.assign({},ae,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new vt(e)):e instanceof vt&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ue),this.processTextOrObjNode=ce,this.options.format?(this.indentate=he,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function ce(t,e,i,n){const s=this.extractAttributes(t);n.push(e,s);if(this.checkStopNode(n)){const s=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return n.pop(),this.buildObjectNode(s,e,r,i)}const r=this.j2x(t,i+1,n);return n.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i,n):this.buildObjectNode(r.val,e,r.attrStr,i)}function he(t){return this.options.indentBy.repeat(t)}function ue(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}le.prototype.build=function(t){if(this.options.preserveOrder)return Qt(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new St;return this.j2x(t,0,e).val}},le.prototype.j2x=function(t,e,i){let n="",s="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const r=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(s+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?s+="":"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)s+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const l=this.isAttribute(a);if(l&&!this.ignoreAttributesFn(l,r))n+=this.buildAttrPairStr(l,""+t[a],o);else if(!l)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);s+=this.replaceEntitiesValue(e)}else{i.push(a);const n=this.checkStopNode(i);if(i.pop(),n){const i=""+t[a];s+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else s+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const n=t[a].length;let r="",o="";for(let l=0;l<n;l++){const n=t[a][l];if(void 0===n);else if(null===n)"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){i.push(a);const t=this.j2x(n,e+1,i);i.pop(),r+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(n,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,n);t=this.replaceEntitiesValue(t),r+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+n;r+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else r+=this.buildTextValNode(n,a,"",e,i)}}this.options.oneListGroup&&(r=this.buildObjectNode(r,a,o,e)),s+=r}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let s=0;s<i;s++)n+=this.buildAttrPairStr(e[s],""+t[a][e[s]],o)}else s+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:n,val:s}},le.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},le.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const n=t[this.options.attributesGroupName];for(let t in n){if(!Object.prototype.hasOwnProperty.call(n,t))continue;e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=n[t],i=!0}}else for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const s=this.isAttribute(n);s&&(e[s]=t[n],i=!0)}return i?e:null},le.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const n=t[i];if(i===this.options.textNodeName)e+=n;else if(Array.isArray(n)){for(let t of n)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const n=this.buildRawContent(t),s=this.buildAttributesForStopNode(t);e+=""===n?`<${i}${s}/>`:`<${i}${s}>${n}</${i}>`}}else if("object"==typeof n&&null!==n){const t=this.buildRawContent(n),s=this.buildAttributesForStopNode(n);e+=""===t?`<${i}${s}/>`:`<${i}${s}>${t}</${i}>`}else e+=`<${i}>${n}</${i}>`}return e},le.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const n=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,s=i[t];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const n=this.isAttribute(i);if(n){const s=t[i];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}return e},le.prototype.buildObjectNode=function(t,e,i,n){if(""===t)return"?"===e[0]?this.indentate(n)+"<"+e+i+"?"+this.tagEndChar:this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let s="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",s=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(n)+"<"+e+i+r+this.tagEndChar+t+this.indentate(n)+s:this.indentate(n)+"<"+e+i+r+">"+t+s}},le.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},le.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},le.prototype.buildTextValNode=function(t,e,i,n,s){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName){const e=String(t).replace(/\]\]>/g,"]]]]><![CDATA[>");return this.indentate(n)+`<![CDATA[${e}]]>`+this.newLine}if(!1!==this.options.commentPropName&&e===this.options.commentPropName){const e=String(t).replace(/--/g,"- -").replace(/-$/,"- ");return this.indentate(n)+`\x3c!--${e}--\x3e`+this.newLine}if("?"===e[0])return this.indentate(n)+"<"+e+i+"?"+this.tagEndChar;{let s=this.options.tagValueProcessor(e,t);return s=this.replaceEntitiesValue(s),""===s?this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(n)+"<"+e+i+">"+s+"</"+e+this.tagEndChar}},le.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};class de{}e(de,"parser",new Kt({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0})),e(de,"builder",new le({attributeNamePrefix:"$",ignoreAttributes:!1,suppressBooleanAttributes:!1}));class pe{static join(t){const e={};for(const i of t)for(const t in i)if(e[t])for(const n of i[t])e[t].add(n);else e[t]=new Set(i[t]);return e}static intersect(t){if(0===t.length)return{};let e=pe.clone(t[0]);for(let i=1;i<t.length;i++){const n=t[i],s={};for(const t in e)if(n[t]){const i=new Set;for(const s of e[t])n[t].has(s)&&i.add(s);i.size>0&&(s[t]=i)}e=s}return e}static clone(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}static remove(t,e,i=!1){i&&(t=pe.clone(t));for(const i in e)if(t[i]){for(const n of e[i])t[i].delete(n);0===t[i].size&&delete t[i]}}static add(t,e,i=!1){i&&(t=pe.clone(t));for(const i in e)if(t[i])for(const n of e[i])t[i].add(n);else t[i]=new Set(e[i])}static append(t,e,...i){let n=t[e];n||(n=new Set,t[e]=n);for(const t of i)n.add(t)}static isEqual(t,e){const i=Object.keys(t),n=Object.keys(e);if(i.length!==n.length)return!1;for(const n of i){if(!e[n])return!1;if(t[n].size!==e[n].size)return!1;for(const i of t[n])if(!e[n].has(i))return!1}return!0}static isEmpty(t){return 0===Object.values(t).reduce((t,e)=>t+e.size,0)}static toRaw(t){const e={};for(const i in t)e[i]=Array.from(t[i]);return e}static fromRaw(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}}class fe extends Map{constructor(t){super(t),e(this,"onItemSet",new f),e(this,"onItemUpdated",new f),e(this,"onItemDeleted",new f),e(this,"onCleared",new f),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}set(t,e){const i=this.has(t);if(!(this.guard??(()=>!0))(t,e))return this;const n=super.set(t,e);return i?(this.onItemUpdated||(this.onItemUpdated=new f),this.onItemUpdated.trigger({key:t,value:e})):(this.onItemSet||(this.onItemSet=new f),this.onItemSet.trigger({key:t,value:e})),n}add(t){const e=A.create();return this.set(e,t),e}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(t),e}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class me{static isEntry(t){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(t.type)}static copySchema(t,e={}){for(const i in t){const n=t[i];this.isEntry(n)?e[i]=this.copyEntry(n):(e[i]={},this.copySchema(n,e[i]))}return e}static copyEntry(t){if("Boolean"===t.type){const e=t;return{type:e.type,value:e.value}}if("Color"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("Text"===t.type){const e=t;return{type:e.type,value:e.value}}if("Number"===t.type){const e=t;return{type:e.type,value:e.value,min:e.min,max:e.max,interpolable:e.interpolable}}if("Select"===t.type){const e=t;return{type:e.type,value:e.value,multiple:e.multiple,options:new Set(e.options)}}if("Vector3"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("TextSet"===t.type){const e=t;return{type:e.type,value:new Set(e.value)}}if("None"===t.type){const e=t;return{type:e.type,value:e.value}}throw new Error("Invalid entry!")}}class ge{constructor(t,i,n,s){e(this,"_component"),e(this,"name"),e(this,"uuid"),this._component=t,this.name=n,this.uuid=s??A.create();i.get(ye).list.set(this.uuid,this)}get controls(){return me.copySchema(this._config)}set(t){for(const e in t)if(e in this){this[e]=t[e].value}}export(t=this._config,e={}){for(const i in t){const n=t[i];if(me.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:{r:t,g:s,b:r}}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:{x:t,y:s,z:r}}}else if("TextSet"===n.type){const t=Array.from(n.value);e[i]={...n,value:t}}else if("Select"===n.type){const t=Array.from(n.options);e[i]={...n,options:t}}else e[i]={...n};else e[i]={},this.export(n,e[i])}return e}import(t,e={},i=!0){for(const i in t){const n=t[i];if(me.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:new u.Color(t,s,r)}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:new u.Vector3(t,s,r)}}else"TextSet"===n.type?e[i]={...n,value:new Set(n.value)}:"Select"===n.type?e[i]={...n,options:new Set(n.options)}:e[i]={...n};else e[i]={},this.import(n,e[i],!1)}i&&this.set(e)}}const we=class t extends g{constructor(n){super(n),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}};e(we,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let ye=we;class _e{constructor(t){e(this,"_event"),e(this,"_position",new u.Vector2),e(this,"onDisposed",new f),e(this,"updateMouseInfo",t=>{this._event=t}),this.dom=t,this.setupEvents(!0)}get position(){return this.updatePosition(!1),this._position.clone()}get rawPosition(){return this.updatePosition(!0),this._position.clone()}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}updatePosition(t){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event,t),this._position.y=this.getPositionY(e,this._event,t)}}getPositionY(t,e,i){const n=this.getDataObject(e);return i?n.clientY:-(n.clientY-t.top)/(t.bottom-t.top)*2+1}getPositionX(t,e,i){const n=this.getDataObject(e);return i?n.clientX:(n.clientX-t.left)/(t.right-t.left)*2-1}getDataObject(t){return t instanceof MouseEvent?t:t.touches[0]}setupEvents(t){t?(this.dom.addEventListener("pointermove",this.updateMouseInfo),this.dom.addEventListener("touchstart",this.updateMouseInfo)):(this.dom.removeEventListener("pointermove",this.updateMouseInfo),this.dom.removeEventListener("touchstart",this.updateMouseInfo))}}const be=1.25,ve=32,xe=Math.pow(2,-24),Ce=Symbol("SKIP_GENERATION"),Se={strategy:0,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ce]:!1};function Ae(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function Pe(t){let e=-1,i=-1/0;for(let n=0;n<3;n++){const s=t[n+3]-t[n];s>i&&(i=s,e=n)}return e}function Te(t,e){e.set(t)}function Me(t,e,i){let n,s;for(let r=0;r<3;r++){const o=r+3;n=t[r],s=e[r],i[r]=n<s?n:s,n=t[o],s=e[o],i[o]=n>s?n:s}}function Ee(t,e,i){for(let n=0;n<3;n++){const s=e[t+2*n],r=e[t+2*n+1],o=s-r,a=s+r;o<i[n]&&(i[n]=o),a>i[n+3]&&(i[n+3]=a)}}function Ie(t){const e=t[3]-t[0],i=t[4]-t[1],n=t[5]-t[2];return 2*(e*i+i*n+n*e)}function De(t,e){return 65535===e[t+15]}function ze(t,e){return e[t+6]}function ke(t,e){return e[t+14]}function Be(t){return t+8}function Oe(t,e){return t+8*e[t+6]}function Ve(t,e){return e[t+7]}function Le(t){return t}function Ne(t,e,i,n,s){let r=1/0,o=1/0,a=1/0,l=-1/0,c=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const w=t.offset||0;for(let n=6*(e-w),s=6*(e+i-w);n<s;n+=6){const e=t[n+0],i=t[n+1],s=e-i,w=e+i;s<r&&(r=s),w>l&&(l=w),e<u&&(u=e),e>f&&(f=e);const y=t[n+2],_=t[n+3],b=y-_,v=y+_;b<o&&(o=b),v>c&&(c=v),y<d&&(d=y),y>m&&(m=y);const x=t[n+4],C=t[n+5],S=x-C,A=x+C;S<a&&(a=S),A>h&&(h=A),x<p&&(p=x),x>g&&(g=x)}n[0]=r,n[1]=o,n[2]=a,n[3]=l,n[4]=c,n[5]=h,s[0]=u,s[1]=d,s[2]=p,s[3]=f,s[4]=m,s[5]=g}const Fe=32,Re=(t,e)=>t.candidate-e.candidate,Ue=new Array(Fe).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),je=new Float32Array(6);class $e{constructor(){this.boundingData=new Float32Array(6)}}let We,Ge,He,qe;const Ze=Math.pow(2,32);function Ye(t){return"count"in t?1:1+Ye(t.left)+Ye(t.right)}function Xe(t,e,i){return We=new Float32Array(i),Ge=new Uint32Array(i),He=new Uint16Array(i),qe=new Uint8Array(i),Ke(t,e)}function Ke(t,e){const i=t/4,n=t/2,s="count"in e,r=e.boundingData;for(let t=0;t<6;t++)We[i+t]=r[t];if(s)return e.buffer?(qe.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(Ge[i+6]=e.offset,He[n+14]=e.count,He[n+15]=65535,t+ve);{const{left:n,right:s,splitAxis:r}=e;let o=Ke(t+ve,n);const a=o/ve-t/ve;if(a>Ze)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ge[i+6]=a,Ge[i+7]=r,Ke(o,s)}}function Qe(t,e,i,n,s,r){const{maxDepth:o,verbose:a,maxLeafSize:l,strategy:c,onProgress:h}=s,u=t.primitiveBuffer,d=t.primitiveBufferStride,p=new Float32Array(6);let f=!1;const m=new $e;return Ne(e,i,n,m.boundingData,p),function t(i,n,s,r=null,h=0){!f&&h>=o&&(f=!0,a&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));if(s<=l||h>=o)return g(n+s),i.offset=n,i.count=s,i;const m=function(t,e,i,n,s,r){let o=-1,a=0;if(0===r)o=Pe(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=Pe(t),-1!==o&&(a=function(t,e,i,n){let s=0;const r=t.offset;for(let o=e,a=e+i;o<a;o++)s+=t[6*(o-r)+2*n];return s/i}(i,n,s,o));else if(2===r){const r=Ie(t);let l=be*s;const c=i.offset||0,h=6*(n-c),u=6*(n+s-c);for(let t=0;t<3;t++){const n=e[t],c=(e[t+3]-n)/Fe;if(s<8){const e=[...Ue];e.length=s;let n=0;for(let s=h;s<u;s+=6,n++){const r=e[n];r.candidate=i[s+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Ee(s,i,o)}e.sort(Re);let c=s;for(let t=0;t<c;t++){const i=e[t];for(;t+1<c&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),c--}for(let n=h;n<u;n+=6){const s=i[n+2*t];for(let t=0;t<c;t++){const r=e[t];s>=r.candidate?Ee(n,i,r.rightCacheBounds):(Ee(n,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<c;i++){const n=e[i],c=n.count,h=s-n.count,u=n.leftCacheBounds,d=n.rightCacheBounds;let p=0;0!==c&&(p=Ie(u)/r);let f=0;0!==h&&(f=Ie(d)/r);const m=1+be*(p*c+f*h);m<l&&(o=t,l=m,a=n.candidate)}}else{for(let t=0;t<Fe;t++){const e=Ue[t];e.count=0,e.candidate=n+c+t*c;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=h;e<u;e+=6){let s=~~((i[e+2*t]-n)/c);s>=Fe&&(s=31);const r=Ue[s];r.count++,Ee(e,i,r.bounds)}const e=Ue[31];Te(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Ue[t],i=Ue[t+1];Me(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let e=0;e<31;e++){const i=Ue[e],n=i.count,c=i.bounds,h=Ue[e+1].rightCacheBounds;0!==n&&(0===d?Te(c,je):Me(c,je,je)),d+=n;let u=0,p=0;0!==d&&(u=Ie(je)/r);const f=s-d;0!==f&&(p=Ie(h)/r);const m=1+be*(u*d+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(i.boundingData,r,e,n,s,c);if(-1===m.axis)return g(n+s),i.offset=n,i.count=s,i;const w=function(t,e,i,n,s,r){let o=n,a=n+s-1;const l=r.pos,c=2*r.axis,h=i.offset||0;for(;;){for(;o<=a&&i[6*(o-h)+c]<l;)o++;for(;o<=a&&i[6*(a-h)+c]>=l;)a--;if(!(o<a))return o;for(let i=0;i<e;i++){let n=t[o*e+i];t[o*e+i]=t[a*e+i],t[a*e+i]=n}for(let t=0;t<6;t++){const e=o-h,n=a-h,s=i[6*e+t];i[6*e+t]=i[6*n+t],i[6*n+t]=s}o++,a--}}(u,d,e,n,s,m);if(w===n||w===n+s)g(n+s),i.offset=n,i.count=s;else{i.splitAxis=m.axis;const r=new $e,o=n,a=w-n;i.left=r,Ne(e,o,a,r.boundingData,p),t(r,o,a,p,h+1);const l=new $e,c=w,u=s-a;i.right=l,Ne(e,c,u,l.boundingData,p),t(l,c,u,p,h+1)}return i}(m,i,n,p),m;function g(t){h&&h((t-r.offset)/r.count)}}function Je(t,e){const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=t.getRootRanges(e.range),s=n[0],r=n[n.length-1],o={offset:s.offset,count:r.offset+r.count-s.offset},a=new Float32Array(6*o.count);a.offset=o.offset,t.computePrimitiveBounds(o.offset,o.count,a),t._roots=n.map(n=>{const s=Qe(t,a,n.offset,n.count,e,o),r=Ye(s),l=new i(ve*r);return Xe(0,s,l),l})}class ti{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class ei{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}}const ii=new ei;let ni,si;const ri=[],oi=new ti(()=>new n.Box3);function ai(t,e,i,n,s,r){ni=oi.getPrimitive(),si=oi.getPrimitive(),ri.push(ni,si),ii.setBuffer(t._roots[e]);const o=li(0,t.geometry,i,n,s,r);ii.clearBuffer(),oi.releasePrimitive(ni),oi.releasePrimitive(si),ri.pop(),ri.pop();const a=ri.length;return a>0&&(si=ri[a-1],ni=ri[a-2]),o}function li(t,e,i,n,s=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:c}=ii;let h=2*t;if(De(h,l)){const e=ze(t,c),i=ke(h,l);return Ae(t,a,ni),n(e,i,!1,o,r+t/8,ni)}{let h=function(t){const{uint16Array:e,uint32Array:i}=ii;let n=2*t;for(;!De(n,e);)n=2*(t=Be(t));return ze(t,i)},u=function(t){const{uint16Array:e,uint32Array:i}=ii;let n=2*t;for(;!De(n,e);)n=2*(t=Oe(t,i));return ze(t,i)+ke(n,e)};const d=Be(t),p=Oe(t,c);let f,m,g,w,y=d,_=p;if(s&&(g=ni,w=si,Ae(y,a,g),Ae(_,a,w),f=s(g),m=s(w),m<f)){y=p,_=d;const t=f;f=m,m=t,g=w}g||(g=ni,Ae(y,a,g));const b=i(g,De(2*y,l),f,o+1,r+y/8);let v;if(2===b){const t=h(y);v=n(t,u(y)-t,!0,o+1,r+y/8,g)}else v=b&&li(y,e,i,n,s,r,o+1);if(v)return!0;w=si,Ae(_,a,w);const x=i(w,De(2*_,l),m,o+1,r+_/8);let C;if(2===x){const t=h(_);C=n(t,u(_)-t,!0,o+1,r+_/8,w)}else C=x&&li(_,e,i,n,s,r,o+1);return!!C}}const ci=new ii.constructor,hi=new ii.constructor,ui=new ti(()=>new n.Box3),di=new n.Box3,pi=new n.Box3,fi=new n.Box3,mi=new n.Box3;let gi=!1;function wi(t,e,i,n,s,r=0,o=0,a=0,l=0,c=null,h=!1){let u,d;h?(u=hi,d=ci):(u=ci,d=hi);const p=u.float32Array,f=u.uint32Array,m=u.uint16Array,g=d.float32Array,w=d.uint32Array,y=d.uint16Array,_=2*e,b=De(2*t,m),v=De(_,y);let x=!1;if(v&&b)x=h?s(ze(e,w),ke(2*e,y),ze(t,f),ke(2*t,m),l,o+e/8,a,r+t/8):s(ze(t,f),ke(2*t,m),ze(e,w),ke(2*e,y),a,r+t/8,l,o+e/8);else if(v){const c=ui.getPrimitive();Ae(e,g,c),c.applyMatrix4(i);const u=Be(t),d=Oe(t,f);Ae(u,p,di),Ae(d,p,pi);const m=c.intersectsBox(di),w=c.intersectsBox(pi);x=m&&wi(e,u,n,i,s,o,r,l,a+1,c,!h)||w&&wi(e,d,n,i,s,o,r,l,a+1,c,!h),ui.releasePrimitive(c)}else{const u=Be(e),d=Oe(e,w);Ae(u,g,fi),Ae(d,g,mi);const m=c.intersectsBox(fi),y=c.intersectsBox(mi);if(m&&y)x=wi(t,u,i,n,s,r,o,a,l+1,c,h)||wi(t,d,i,n,s,r,o,a,l+1,c,h);else if(m)if(b)x=wi(t,u,i,n,s,r,o,a,l+1,c,h);else{const e=ui.getPrimitive();e.copy(fi).applyMatrix4(i);const c=Be(t),d=Oe(t,f);Ae(c,p,di),Ae(d,p,pi);const m=e.intersectsBox(di),g=e.intersectsBox(pi);x=m&&wi(u,c,n,i,s,o,r,l,a+1,e,!h)||g&&wi(u,d,n,i,s,o,r,l,a+1,e,!h),ui.releasePrimitive(e)}else if(y)if(b)x=wi(t,d,i,n,s,r,o,a,l+1,c,h);else{const e=ui.getPrimitive();e.copy(mi).applyMatrix4(i);const c=Be(t),u=Oe(t,f);Ae(c,p,di),Ae(u,p,pi);const m=e.intersectsBox(di),g=e.intersectsBox(pi);x=m&&wi(d,c,n,i,s,o,r,l,a+1,e,!h)||g&&wi(d,u,n,i,s,o,r,l,a+1,e,!h),ui.releasePrimitive(e)}}return x}const yi=new n.Box3,_i=new Float32Array(6);class bi{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){Je(this,t={...Se,...t})}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,n){let s=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,c=-1/0;for(let i=t,n=t+e;i<n;i++){this.writePrimitiveBounds(i,_i,0);const[t,e,n,h,u,d]=_i;t<s&&(s=t),h>a&&(a=h),e<r&&(r=e),u>l&&(l=u),n<o&&(o=n),d>c&&(c=d)}return i[n+0]=s,i[n+1]=r,i[n+2]=o,i[n+3]=a,i[n+4]=l,i[n+5]=c,i}computePrimitiveBounds(t,e,i){const n=i.offset||0;for(let s=t,r=t+e;s<r;s++){this.writePrimitiveBounds(s,_i,0);const[t,e,r,o,a,l]=_i,c=(t+o)/2,h=(e+a)/2,u=(r+l)/2,d=(o-t)/2,p=(a-e)/2,f=(l-r)/2,m=6*(s-n);i[m+0]=c,i[m+1]=d+(Math.abs(c)+d)*xe,i[m+2]=h,i[m+3]=p+(Math.abs(h)+p)*xe,i[m+4]=u,i[m+5]=f+(Math.abs(u)+f)*xe}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,n=e.length;i<n;i++)e[i]+=t;else{const e=this._roots;for(let i=0;i<e.length;i++){const n=e[i],s=new Uint32Array(n),r=new Uint16Array(n),o=n.byteLength/ve;for(let e=0;e<o;e++){const i=8*e;De(2*i,r)&&(s[i+6]+=t)}}}}traverse(t,e=0){const i=this._roots[e],n=new Uint32Array(i),s=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=De(a,s);if(l){const e=n[r+6],c=s[a+14];t(o,l,new Float32Array(i,4*r,6),e,c)}else{const s=Be(r),a=Oe(r,n),c=Ve(r,n);t(o,l,new Float32Array(i,4*r,6),c)||(e(s,o+1),e(a,o+1))}}(0)}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const i=t[e],n=new Uint32Array(i),s=new Uint16Array(i),r=new Float32Array(i);for(let t=i.byteLength/ve-1;t>=0;t--){const e=8*t,i=2*e;if(De(i,s)){const t=ze(e,n),o=ke(i,s);this.writePrimitiveRangeBounds(t,o,_i,0),r.set(_i,e)}else{const t=Be(e),i=Oe(e,n);for(let n=0;n<3;n++){const s=r[t+n],o=r[t+n+3],a=r[i+n],l=r[i+n+3];r[e+n]=s<a?s:a,r[e+n+3]=o>l?o:l}}}}}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{Ae(0,new Float32Array(e),yi),t.union(yi)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:n,intersectsPrimitive:s,scratchPrimitive:r,iterate:o}=t;if(n&&s){const t=n;n=(e,i,n,a,l)=>!!t(e,i,n,a,l)||o(e,i,this,s,n,a,r)}else n||(n=s?(t,e,i,n)=>o(t,e,this,s,i,n,r):(t,e,i)=>i);let a=!1,l=0;const c=this._roots;for(let t=0,s=c.length;t<s;t++){const s=c[t];if(a=ai(this,t,i,n,e,l),a)break;l+=s.byteLength/ve}return a}bvhcast(t,e,i){let{intersectsRanges:s}=i;return function(t,e,i,s){if(gi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");gi=!0;const r=t._roots,o=e._roots;let a,l=0,c=0;const h=(new n.Matrix4).copy(i).invert();for(let t=0,e=r.length;t<e;t++){ci.setBuffer(r[t]),c=0;const e=ui.getPrimitive();Ae(Le(0),ci.float32Array,e),e.applyMatrix4(h);for(let t=0,n=o.length;t<n&&(hi.setBuffer(o[t]),a=wi(0,0,i,h,s,l,c,0,0,e),hi.clearBuffer(),c+=o[t].byteLength/ve,!a);t++);if(ui.releasePrimitive(e),ci.clearBuffer(),l+=r[t].byteLength/ve,a)break}return gi=!1,a}(this,t,e,s)}}function vi(t){return t.index?t.index.count:t.attributes.position.count}function xi(t){return vi(t)/3}function Ci(t,e){if(!t.index){const i=t.attributes.position.count,s=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new n.BufferAttribute(s,1));for(let t=0;t<i;t++)s[t]=t}}function Si(t,e,i){const n=function(t,e,i){const n=vi(t)/i,s=e||t.drawRange,r=s.start/i,o=(s.start+s.count)/i,a=Math.max(0,r),l=Math.min(n,o)-a;return{offset:Math.floor(a),count:Math.floor(l)}}(t,e,i),s=function(t,e){return t.groups.map(t=>({offset:t.start/e,count:t.count/e}))}(t,i);if(!s.length)return[n];const r=[],o=n.offset,a=n.offset+n.count,l=vi(t)/i,c=[];for(const t of s){const{offset:e,count:i}=t,n=e,s=e+(isFinite(i)?i:l-e);n<a&&s>o&&(c.push({pos:Math.max(o,n),isStart:!0}),c.push({pos:Math.min(a,s),isStart:!1}))}c.sort((t,e)=>t.pos!==e.pos?t.pos-e.pos:"end"===t.type?-1:1);let h=0,u=null;for(const t of c){const e=t.pos;0!==h&&e!==u&&r.push({offset:u,count:e-u}),h+=t.isStart?1:-1,u=e}return r}class Ai extends bi{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("BVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");if(e.useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?t=>this._indirectBuffer[t]:t=>t,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,(e={...Se,...e})[Ce]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const n=function(t,e){const i=t[t.length-1],n=i.offset+i.count>65536,s=t.reduce((t,e)=>t+e.count,0),r=n?4:2,o=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),a=n?new Uint32Array(o):new Uint16Array(o);let l=0;for(let e=0;e<t.length;e++){const{offset:i,count:n}=t[e];for(let t=0;t<n;t++)a[l+t]=i+t;l+=n}return a}(Si(e,t.range,i),t.useSharedArrayBuffer);this._indirectBuffer=n}else Ci(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new n.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Si(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class Pi{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,n=-1/0;for(let s=0,r=t.length;s<r;s++){const r=t[s][e];i=r<i?r:i,n=r>n?r:n}this.min=i,this.max=n}setFromPoints(t,e){let i=1/0,n=-1/0;for(let s=0,r=e.length;s<r;s++){const r=e[s],o=t.dot(r);i=o<i?o:i,n=o>n?o:n}this.min=i,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Pi.prototype.setFromBox=function(){const t=new n.Vector3;return function(e,i){const n=i.min,s=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=n.x*i+s.x*(1-i),t.y=n.y*a+s.y*(1-a),t.z=n.z*l+s.z*(1-l);const c=e.dot(t);r=Math.min(c,r),o=Math.max(c,o)}this.min=r,this.max=o}}();const Ti=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Vector3;return function(n,s,r){const o=n.start,a=t,l=s.start,c=e;i.subVectors(o,l),t.subVectors(n.end,n.start),e.subVectors(s.end,s.start);const h=i.dot(c),u=c.dot(a),d=c.dot(c),p=i.dot(a),f=a.dot(a)*d-u*u;let m,g;m=0!==f?(h*u-p*d)/f:0,g=(h+m*u)/d,r.x=m,r.y=g}}(),Mi=function(){const t=new n.Vector2,e=new n.Vector3,i=new n.Vector3;return function(n,s,r,o){Ti(n,s,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return n.at(a,r),void s.at(l,o);if(a>=0&&a<=1)return l<0?s.at(0,o):s.at(1,o),void n.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?n.at(0,r):n.at(1,r),void s.closestPointToPoint(r,!0,o);{let t,c;t=a<0?n.start:n.end,c=l<0?s.start:s.end;const h=e,u=i;return n.closestPointToPoint(c,!0,e),s.closestPointToPoint(t,!0,i),h.distanceToSquared(c)<=u.distanceToSquared(t)?(r.copy(h),void o.copy(c)):(r.copy(t),void o.copy(u))}}}(),Ei=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Plane,s=new n.Line3;return function(n,r){const{radius:o,center:a}=n,{a:l,b:c,c:h}=r;s.start=l,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=l,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=c,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const u=r.getPlane(i);if(Math.abs(u.distanceToPoint(a))<=o){const t=u.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}(),Ii=["x","y","z"],Di=1e-15;function zi(t){return Math.abs(t)<Di}class ki extends n.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new n.Vector3),this.satBounds=new Array(4).fill().map(()=>new Pi),this.points=[this.a,this.b,this.c],this.plane=new n.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new n.Line3,this.needsUpdate=!0}intersectsSphere(t){return Ei(t,this)}update(){const t=this.a,e=this.b,i=this.c,n=this.points,s=this.satAxes,r=this.satBounds,o=s[0],a=r[0];this.getNormal(o),a.setFromPoints(o,n);const l=s[1],c=r[1];l.subVectors(t,e),c.setFromPoints(l,n);const h=s[2],u=r[2];h.subVectors(e,i),u.setFromPoints(h,n);const d=s[3],p=r[3];d.subVectors(i,t),p.setFromPoints(d,n);const f=l.length(),m=h.length(),g=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,f<Di?m<Di||g<Di?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):m<Di?g<Di?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):g<Di&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}ki.prototype.closestPointToSegment=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Line3;return function(n,s=null,r=null){const{start:o,end:a}=n,l=this.points;let c,h=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),Mi(i,n,t,e),c=t.distanceToSquared(e),c<h&&(h=c,s&&s.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),c=o.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),c=a.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(a)),Math.sqrt(h)}}(),ki.prototype.intersectsTriangle=function(){const t=new ki,e=new Pi,i=new Pi,s=new n.Vector3,r=new n.Vector3,o=new n.Vector3,a=new n.Vector3,l=new n.Line3,c=new n.Line3,h=new n.Vector3,u=new n.Vector2,d=new n.Vector2;function p(t,n,r,o){const l=s;t.isDegenerateIntoPoint||t.isDegenerateIntoSegment?l.copy(n.plane.normal):l.copy(t.plane.normal);const c=t.satBounds,h=t.satAxes;for(let s=1;s<4;s++){const r=c[s],o=h[s];if(e.setFromPoints(o,n.points),r.isSeparated(e))return!1;if(a.copy(l).cross(o),e.setFromPoints(a,t.points),i.setFromPoints(a,n.points),e.isSeparated(i))return!1}const u=n.satBounds,d=n.satAxes;for(let s=1;s<4;s++){const r=u[s],o=d[s];if(e.setFromPoints(o,t.points),r.isSeparated(e))return!1;if(a.crossVectors(l,o),e.setFromPoints(a,t.points),i.setFromPoints(a,n.points),e.isSeparated(i))return!1}return r&&(o||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),r.start.set(0,0,0),r.end.set(0,0,0)),!0}function f(t,e,i,n,s,r,o,a,l,c,h){let u=o/(o-a);c.x=n+(s-n)*u,h.start.subVectors(e,t).multiplyScalar(u).add(t),u=o/(o-l),c.y=n+(r-n)*u,h.end.subVectors(i,t).multiplyScalar(u).add(t)}function m(t,e,i,n,s,r,o,a,l,c,h){if(s>0)f(t.c,t.a,t.b,n,e,i,l,o,a,c,h);else if(r>0)f(t.b,t.a,t.c,i,e,n,a,o,l,c,h);else if(a*l>0||0!=o)f(t.a,t.b,t.c,e,i,n,o,a,l,c,h);else if(0!=a)f(t.b,t.a,t.c,i,e,n,a,o,l,c,h);else{if(0==l)return!0;f(t.c,t.a,t.b,n,e,i,l,o,a,c,h)}return!1}function g(t,e,i,n){const r=e.degenerateSegment,o=t.plane.distanceToPoint(r.start),a=t.plane.distanceToPoint(r.end);return zi(o)?zi(a)?p(t,e,i,n):(i&&(i.start.copy(r.start),i.end.copy(r.start)),t.containsPoint(r.start)):zi(a)?(i&&(i.start.copy(r.end),i.end.copy(r.end)),t.containsPoint(r.end)):null!=t.plane.intersectLine(r,s)&&(i&&(i.start.copy(s),i.end.copy(s)),t.containsPoint(s))}function w(t,e,i){const n=e.a;return!(!zi(t.plane.distanceToPoint(n))||!t.containsPoint(n))&&(i&&(i.start.copy(n),i.end.copy(n)),!0)}function y(t,e,i){const n=t.degenerateSegment,r=e.a;return n.closestPointToPoint(r,!0,s),r.distanceToSquared(s)<1e-30&&(i&&(i.start.copy(r),i.end.copy(r)),!0)}return function(e,i=null,n=!1){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);const a=function(t,e,i,n){if(t.isDegenerateIntoSegment){if(e.isDegenerateIntoSegment){const n=t.degenerateSegment,a=e.degenerateSegment,l=r,c=o;n.delta(l),a.delta(c);const h=s.subVectors(a.start,n.start),u=l.x*c.y-l.y*c.x;if(zi(u))return!1;const d=(h.x*c.y-h.y*c.x)/u,p=-(l.x*h.y-l.y*h.x)/u;return!(d<0||d>1||p<0||p>1)&&(!!zi(n.start.z+l.z*d-(a.start.z+c.z*p))&&(i&&(i.start.copy(n.start).addScaledVector(l,d),i.end.copy(n.start).addScaledVector(l,d)),!0))}return e.isDegenerateIntoPoint?y(t,e,i):g(e,t,i,n)}return t.isDegenerateIntoPoint?e.isDegenerateIntoPoint?e.a.distanceToSquared(t.a)<1e-30&&(i&&(i.start.copy(t.a),i.end.copy(t.a)),!0):e.isDegenerateIntoSegment?y(e,t,i):w(e,t,i):e.isDegenerateIntoPoint?w(t,e,i):e.isDegenerateIntoSegment?g(t,e,i,n):void 0}(this,e,i,n);if(void 0!==a)return a;const f=this.plane,_=e.plane;let b=_.distanceToPoint(this.a),v=_.distanceToPoint(this.b),x=_.distanceToPoint(this.c);zi(b)&&(b=0),zi(v)&&(v=0),zi(x)&&(x=0);const C=b*v,S=b*x;if(C>0&&S>0)return!1;let A=f.distanceToPoint(e.a),P=f.distanceToPoint(e.b),T=f.distanceToPoint(e.c);zi(A)&&(A=0),zi(P)&&(P=0),zi(T)&&(T=0);const M=A*P,E=A*T;if(M>0&&E>0)return!1;r.copy(f.normal),o.copy(_.normal);const I=r.cross(o);let D=0,z=Math.abs(I.x);const k=Math.abs(I.y);k>z&&(z=k,D=1);Math.abs(I.z)>z&&(D=2);const B=Ii[D],O=this.a[B],V=this.b[B],L=this.c[B],N=e.a[B],F=e.b[B],R=e.c[B];if(m(this,O,V,L,C,S,b,v,x,u,l))return p(this,e,i,n);if(m(e,N,F,R,M,E,A,P,T,d,c))return p(this,e,i,n);if(u.y<u.x){const t=u.y;u.y=u.x,u.x=t,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}if(d.y<d.x){const t=d.y;d.y=d.x,d.x=t,h.copy(c.start),c.start.copy(c.end),c.end.copy(h)}return!(u.y<d.x||d.y<u.x)&&(i&&(d.x>u.x?i.start.copy(c.start):i.start.copy(l.start),d.y<u.y?i.end.copy(c.end):i.end.copy(l.end)),!0)}}(),ki.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),ki.prototype.distanceToTriangle=function(){const t=new n.Vector3,e=new n.Vector3,i=["a","b","c"],s=new n.Line3,r=new n.Line3;return function(n,o=null,a=null){const l=o||a?s:null;if(this.intersectsTriangle(n,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let c=1/0;for(let e=0;e<3;e++){let s;const r=i[e],l=n[r];this.closestPointToPoint(l,t),s=l.distanceToSquared(t),s<c&&(c=s,o&&o.copy(t),a&&a.copy(l));const h=this[r];n.closestPointToPoint(h,t),s=h.distanceToSquared(t),s<c&&(c=s,o&&o.copy(h),a&&a.copy(t))}for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];s.set(this[h],this[u]);for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];r.set(n[h],n[u]),Mi(s,r,t,e);const d=t.distanceToSquared(e);d<c&&(c=d,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(c)}}();class Bi{constructor(t,e,i){this.isOrientedBox=!0,this.min=new n.Vector3,this.max=new n.Vector3,this.matrix=new n.Matrix4,this.invMatrix=new n.Matrix4,this.points=new Array(8).fill().map(()=>new n.Vector3),this.satAxes=new Array(3).fill().map(()=>new n.Vector3),this.satBounds=new Array(3).fill().map(()=>new Pi),this.alignedSatBounds=new Array(3).fill().map(()=>new Pi),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Bi.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,n=this.points;for(let s=0;s<=1;s++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=n[1*s|2*r|4*o];a.x=s?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const s=this.satBounds,r=this.satAxes,o=n[0];for(let t=0;t<3;t++){const e=r[t],i=s[t],a=n[1<<t];e.subVectors(o,a),i.setFromPoints(e,n)}const a=this.alignedSatBounds;a[0].setFromPointsField(n,"x"),a[1].setFromPointsField(n,"y"),a[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Bi.prototype.intersectsBox=function(){const t=new Pi;return function(e){this.needsUpdate&&this.update();const i=e.min,n=e.max,s=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=n.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=n.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=n.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const n=r[i],o=s[i];if(t.setFromBox(n,e),o.isSeparated(t))return!1}return!0}}(),Bi.prototype.intersectsTriangle=function(){const t=new ki,e=new Array(3),i=new Pi,s=new Pi,r=new n.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(t.copy(n),t.update(),n=t);const o=this.satBounds,a=this.satAxes;e[0]=n.a,e[1]=n.b,e[2]=n.c;for(let t=0;t<3;t++){const n=o[t],s=a[t];if(i.setFromPoints(s,e),n.isSeparated(i))return!1}const l=n.satBounds,c=n.satAxes,h=this.points;for(let t=0;t<3;t++){const e=l[t],n=c[t];if(i.setFromPoints(n,h),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const n=a[t];for(let t=0;t<4;t++){const o=c[t];if(r.crossVectors(n,o),i.setFromPoints(r,e),s.setFromPoints(r,h),i.isSeparated(s))return!1}}return!0}}(),Bi.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Bi.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Bi.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new n.Line3),i=new Array(12).fill().map(()=>new n.Line3),s=new n.Vector3,r=new n.Vector3;return function(n,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||l)&&(n.getCenter(r),this.closestPointToPoint(r,s),n.closestPointToPoint(s,r),a&&a.copy(s),l&&l.copy(r)),0;const c=o*o,h=n.min,u=n.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(h,u);const i=e.distanceToSquared(r);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(r),i<c))return Math.sqrt(i)}let f=0;for(let n=0;n<3;n++)for(let s=0;s<=1;s++)for(let r=0;r<=1;r++){const o=(n+1)%3,a=(n+2)%3,l=1<<n|s<<o|r<<a,c=d[s<<o|r<<a],p=d[l];e[f].set(c,p);const m=t[n],g=t[o],w=t[a],y=i[f],_=y.start,b=y.end;_[m]=h[m],_[g]=s?h[g]:u[g],_[w]=r?h[w]:u[g],b[m]=u[m],b[g]=s?h[g]:u[g],b[w]=r?h[w]:u[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){r.x=t?u.x:h.x,r.y=e?u.y:h.y,r.z=i?u.z:h.z,this.closestPointToPoint(r,s);const n=r.distanceToSquared(s);if(n<p&&(p=n,a&&a.copy(s),l&&l.copy(r),n<c))return Math.sqrt(n)}for(let t=0;t<12;t++){const n=e[t];for(let t=0;t<12;t++){const e=i[t];Mi(n,e,s,r);const o=s.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(s),l&&l.copy(r),o<c))return Math.sqrt(o)}}return Math.sqrt(p)}}();class Oi extends ti{constructor(){super(()=>new ki)}}const Vi=new Oi,Li=new n.Vector3,Ni=new n.Vector3;const Fi=parseInt(n.REVISION)>=169,Ri=parseInt(n.REVISION)<=161,Ui=new n.Vector3,ji=new n.Vector3,$i=new n.Vector3,Wi=new n.Vector2,Gi=new n.Vector2,Hi=new n.Vector2,qi=new n.Vector3,Zi=new n.Vector3,Yi=new n.Vector3,Xi=new n.Vector3;function Ki(t,e,i,s,r,o,a,l,c,h,u){Ui.fromBufferAttribute(e,o),ji.fromBufferAttribute(e,a),$i.fromBufferAttribute(e,l);const d=function(t,e,i,s,r,o,a,l){let c;if(c=o===n.BackSide?t.intersectTriangle(s,i,e,!0,r):t.intersectTriangle(e,i,s,o!==n.DoubleSide,r),null===c)return null;const h=t.origin.distanceTo(r);return h<a||h>l?null:{distance:h,point:r.clone()}}(t,Ui,ji,$i,Xi,c,h,u);if(d){if(s){Wi.fromBufferAttribute(s,o),Gi.fromBufferAttribute(s,a),Hi.fromBufferAttribute(s,l),d.uv=new n.Vector2;const t=n.Triangle.getInterpolation(Xi,Ui,ji,$i,Wi,Gi,Hi,d.uv);Fi||(d.uv=t)}if(r){Wi.fromBufferAttribute(r,o),Gi.fromBufferAttribute(r,a),Hi.fromBufferAttribute(r,l),d.uv1=new n.Vector2;const t=n.Triangle.getInterpolation(Xi,Ui,ji,$i,Wi,Gi,Hi,d.uv1);Fi||(d.uv1=t),Ri&&(d.uv2=d.uv1)}if(i){qi.fromBufferAttribute(i,o),Zi.fromBufferAttribute(i,a),Yi.fromBufferAttribute(i,l),d.normal=new n.Vector3;const e=n.Triangle.getInterpolation(Xi,Ui,ji,$i,qi,Zi,Yi,d.normal);d.normal.dot(t.direction)>0&&d.normal.multiplyScalar(-1),Fi||(d.normal=e)}const e={a:o,b:a,c:l,normal:new n.Vector3,materialIndex:0};if(n.Triangle.getNormal(Ui,ji,$i,e.normal),d.face=e,d.faceIndex=o,Fi){const t=new n.Vector3;n.Triangle.getBarycoord(Xi,Ui,ji,$i,t),d.barycoord=t}}return d}function Qi(t){return t&&t.isMaterial?t.side:t}function Ji(t,e,i,n,s,r,o){const a=3*n;let l=a+0,c=a+1,h=a+2;const{index:u,groups:d}=t;t.index&&(l=u.getX(l),c=u.getX(c),h=u.getX(h));const{position:p,normal:f,uv:m,uv1:g}=t.attributes;if(Array.isArray(e)){const t=3*n;for(let a=0,u=d.length;a<u;a++){const{start:u,count:w,materialIndex:y}=d[a];if(t>=u&&t<u+w){const t=Ki(i,p,f,m,g,l,c,h,Qi(e[y]),r,o);if(t){if(t.faceIndex=n,t.face.materialIndex=y,!s)return t;s.push(t)}}}}else{const t=Ki(i,p,f,m,g,l,c,h,Qi(e),r,o);if(t){if(t.faceIndex=n,t.face.materialIndex=0,!s)return t;s.push(t)}}return null}function tn(t,e,i,n){const s=t.a,r=t.b,o=t.c;let a=e,l=e+1,c=e+2;i&&(a=i.getX(a),l=i.getX(l),c=i.getX(c)),s.x=n.getX(a),s.y=n.getY(a),s.z=n.getZ(a),r.x=n.getX(l),r.y=n.getY(l),r.z=n.getZ(l),o.x=n.getX(c),o.y=n.getY(c),o.z=n.getZ(c)}function en(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,tn(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}function nn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(t,i,r=!1){const c=2*t;if(De(c,a)){const e=ze(t,o);let i=1/0,r=1/0,h=1/0,u=-1/0,d=-1/0,p=-1/0;for(let t=3*e,o=3*(e+ke(c,a));t<o;t++){let e=n[t];const o=s.getX(e),a=s.getY(e),l=s.getZ(e);o<i&&(i=o),o>u&&(u=o),a<r&&(r=a),a>d&&(d=a),l<h&&(h=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==h||l[t+3]!==u||l[t+4]!==d||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=h,l[t+3]=u,l[t+4]=d,l[t+5]=p,!0)}{const n=Be(t),s=Oe(t,o);let a=r,c=!1,h=!1;if(e){if(!a){const t=n/8+i/ve,r=s/8+i/ve;c=e.has(t),h=e.has(r),a=!c&&!h}}else c=!0,h=!0;const d=a||h;let p=!1;(a||c)&&(p=u(n,i,a));let f=!1;d&&(f=u(s,i,a));const m=p||f;if(m)for(let e=0;e<3;e++){const i=n+e,r=s+e,o=l[i],a=l[i+3],c=l[r],h=l[r+3];l[t+e]=o<c?o:c,l[t+e+3]=a>h?a:h}return m}}}function sn(t,e,i,n,s){let r,o,a,l,c,h;const u=1/i.direction.x,d=1/i.direction.y,p=1/i.direction.z,f=i.origin.x,m=i.origin.y,g=i.origin.z;let w=e[t],y=e[t+3],_=e[t+1],b=e[t+3+1],v=e[t+2],x=e[t+3+2];return u>=0?(r=(w-f)*u,o=(y-f)*u):(r=(y-f)*u,o=(w-f)*u),d>=0?(a=(_-m)*d,l=(b-m)*d):(a=(b-m)*d,l=(_-m)*d),!(r>l||a>o)&&((a>r||isNaN(r))&&(r=a),(l<o||isNaN(o))&&(o=l),p>=0?(c=(v-g)*p,h=(x-g)*p):(c=(x-g)*p,h=(v-g)*p),!(r>h||c>o)&&((c>r||r!=r)&&(r=c),(h<o||o!=o)&&(o=h),r<=s&&o>=n))}function rn(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let a=t,h=e+t;a<h;a++){let t;if(t=i.resolveTriangleIndex(a),tn(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}function on(t,e,i,n,s,r,o){ii.setBuffer(t._roots[e]),an(0,t,i,n,s,r,o),ii.clearBuffer()}function an(t,e,i,n,s,r,o){const{float32Array:a,uint16Array:l,uint32Array:c}=ii,h=2*t;if(De(h,l)){!function(t,e,i,n,s,r,o,a){const{geometry:l,_indirectBuffer:c}=t;for(let t=n,c=n+s;t<c;t++)Ji(l,e,i,t,r,o,a)}(e,i,n,ze(t,c),ke(h,l),s,r,o)}else{const l=Be(t);sn(l,a,n,r,o)&&an(l,e,i,n,s,r,o);const h=Oe(t,c);sn(h,a,n,r,o)&&an(h,e,i,n,s,r,o)}}const ln=["x","y","z"];function cn(t,e,i,n,s,r){ii.setBuffer(t._roots[e]);const o=hn(0,t,i,n,s,r);return ii.clearBuffer(),o}function hn(t,e,i,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:l}=ii;let c=2*t;if(De(c,a)){return function(t,e,i,n,s,r,o){const{geometry:a,_indirectBuffer:l}=t;let c=1/0,h=null;for(let t=n,l=n+s;t<l;t++){let n;n=Ji(a,e,i,t,null,r,o),n&&n.distance<c&&(h=n,c=n.distance)}return h}(e,i,n,ze(t,l),ke(c,a),s,r)}{const a=Ve(t,l),c=ln[a],h=n.direction[c]>=0;let u,d;h?(u=Be(t),d=Oe(t,l)):(u=Oe(t,l),d=Be(t));const p=sn(u,o,n,s,r)?hn(u,e,i,n,s,r):null;if(p){const t=p.point[c];if(h?t<=o[d+a]:t>=o[d+a+3])return p}const f=sn(d,o,n,s,r)?hn(d,e,i,n,s,r):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const un=new n.Box3,dn=new ki,pn=new ki,fn=new n.Matrix4,mn=new Bi,gn=new Bi;function wn(t,e,i,n){ii.setBuffer(t._roots[e]);const s=yn(0,t,i,n);return ii.clearBuffer(),s}function yn(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ii;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),mn.set(i.boundingBox.min,i.boundingBox.max,n),s=mn);if(!De(l,o)){const o=Be(t),l=Oe(t,a);Ae(o,r,un);if(s.intersectsBox(un)&&yn(o,e,i,n,s))return!0;Ae(l,r,un);return!!(s.intersectsBox(un)&&yn(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=ze(t,a),f=ke(l,o);if(fn.copy(n).invert(),i.boundsTree){Ae(t,r,gn),gn.matrix.copy(fn),gn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>gn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(tn(pn,e,c,h),pn.needsUpdate=!0,t.intersectsTriangle(pn))return!0;return!1}})}{const t=xi(i);for(let e=3*p,i=3*(f+p);e<i;e+=3){tn(dn,e,c,h),dn.a.applyMatrix4(fn),dn.b.applyMatrix4(fn),dn.c.applyMatrix4(fn),dn.needsUpdate=!0;for(let e=0,i=3*t;e<i;e+=3)if(tn(pn,e,u,d),pn.needsUpdate=!0,dn.intersectsTriangle(pn))return!0}}}}const _n=new n.Matrix4,bn=new Bi,vn=new Bi,xn=new n.Vector3,Cn=new n.Vector3,Sn=new n.Vector3,An=new n.Vector3;function Pn(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),bn.set(e.boundingBox.min,e.boundingBox.max,i),bn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=Vi.getPrimitive(),p=Vi.getPrimitive();let f=xn,m=Cn,g=null,w=null;s&&(g=Sn,w=An);let y=1/0,_=null,b=null;return _n.copy(i).invert(),vn.matrix.copy(_n),t.shapecast({boundsTraverseOrder:t=>bn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(vn.min.copy(t.min),vn.max.copy(t.max),vn.needsUpdate=!0),!0),intersectsRange:(t,n)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>vn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,s)=>{for(let o=e,a=e+s;o<a;o++){tn(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){tn(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),w&&w.copy(g),y=t,_=e,b=o),t<r)return!0}}}})}for(let s=0,o=xi(e);s<o;s++){tn(p,3*s,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){tn(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),w&&w.copy(g),y=t,_=e,b=s),t<r)return!0}}}}),Vi.releasePrimitive(d),Vi.releasePrimitive(p),y===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=y,n.faceIndex=_,s&&(s.point?s.point.copy(w):s.point=w.clone(),s.point.applyMatrix4(_n),m.applyMatrix4(_n),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}function Tn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(i,r,c=!1){const h=2*i;if(De(h,a)){const e=ze(i,o);let r=1/0,c=1/0,u=1/0,d=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+ke(h,a);i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=n?n[i]:i;const o=s.getX(i),a=s.getY(i),l=s.getZ(i);o<r&&(r=o),o>d&&(d=o),a<c&&(c=a),a>p&&(p=a),l<u&&(u=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==c||l[i+2]!==u||l[i+3]!==d||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=c,l[i+2]=u,l[i+3]=d,l[i+4]=p,l[i+5]=f,!0)}{const t=Be(i),n=Oe(i,o);let s=c,a=!1,h=!1;if(e){if(!s){const i=t/8+r/ve,o=n/8+r/ve;a=e.has(i),h=e.has(o),s=!a&&!h}}else a=!0,h=!0;const d=s||h;let p=!1;(s||a)&&(p=u(t,r,s));let f=!1;d&&(f=u(n,r,s));const m=p||f;if(m)for(let e=0;e<3;e++){const s=t+e,r=n+e,o=l[s],a=l[s+3],c=l[r],h=l[r+3];l[i+e]=o<c?o:c,l[i+e+3]=a>h?a:h}return m}}}function Mn(t,e,i,n,s,r,o){ii.setBuffer(t._roots[e]),En(0,t,i,n,s,r,o),ii.clearBuffer()}function En(t,e,i,n,s,r,o){const{float32Array:a,uint16Array:l,uint32Array:c}=ii,h=2*t;if(De(h,l)){!function(t,e,i,n,s,r,o,a){const{geometry:l,_indirectBuffer:c}=t;for(let t=n,h=n+s;t<h;t++)Ji(l,e,i,c?c[t]:t,r,o,a)}(e,i,n,ze(t,c),ke(h,l),s,r,o)}else{const l=Be(t);sn(l,a,n,r,o)&&En(l,e,i,n,s,r,o);const h=Oe(t,c);sn(h,a,n,r,o)&&En(h,e,i,n,s,r,o)}}const In=["x","y","z"];function Dn(t,e,i,n,s,r){ii.setBuffer(t._roots[e]);const o=zn(0,t,i,n,s,r);return ii.clearBuffer(),o}function zn(t,e,i,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:l}=ii;let c=2*t;if(De(c,a)){return function(t,e,i,n,s,r,o){const{geometry:a,_indirectBuffer:l}=t;let c=1/0,h=null;for(let t=n,u=n+s;t<u;t++){let n;n=Ji(a,e,i,l?l[t]:t,null,r,o),n&&n.distance<c&&(h=n,c=n.distance)}return h}(e,i,n,ze(t,l),ke(c,a),s,r)}{const a=Ve(t,l),c=In[a],h=n.direction[c]>=0;let u,d;h?(u=Be(t),d=Oe(t,l)):(u=Oe(t,l),d=Be(t));const p=sn(u,o,n,s,r)?zn(u,e,i,n,s,r):null;if(p){const t=p.point[c];if(h?t<=o[d+a]:t>=o[d+a+3])return p}const f=sn(d,o,n,s,r)?zn(d,e,i,n,s,r):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const kn=new n.Box3,Bn=new ki,On=new ki,Vn=new n.Matrix4,Ln=new Bi,Nn=new Bi;function Fn(t,e,i,n){ii.setBuffer(t._roots[e]);const s=Rn(0,t,i,n);return ii.clearBuffer(),s}function Rn(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ii;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),Ln.set(i.boundingBox.min,i.boundingBox.max,n),s=Ln);if(!De(l,o)){const o=Be(t),l=Oe(t,a);Ae(o,r,kn);if(s.intersectsBox(kn)&&Rn(o,e,i,n,s))return!0;Ae(l,r,kn);return!!(s.intersectsBox(kn)&&Rn(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=ze(t,a),f=ke(l,o);if(Vn.copy(n).invert(),i.boundsTree){Ae(t,r,Nn),Nn.matrix.copy(Vn),Nn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>Nn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let i=p,n=f+p;i<n;i++)if(tn(On,3*e.resolveTriangleIndex(i),c,h),On.needsUpdate=!0,t.intersectsTriangle(On))return!0;return!1}})}{const t=xi(i);for(let i=p,n=f+p;i<n;i++){const n=e.resolveTriangleIndex(i);tn(Bn,3*n,c,h),Bn.a.applyMatrix4(Vn),Bn.b.applyMatrix4(Vn),Bn.c.applyMatrix4(Vn),Bn.needsUpdate=!0;for(let e=0,i=3*t;e<i;e+=3)if(tn(On,e,u,d),On.needsUpdate=!0,Bn.intersectsTriangle(On))return!0}}}}const Un=new n.Matrix4,jn=new Bi,$n=new Bi,Wn=new n.Vector3,Gn=new n.Vector3,Hn=new n.Vector3,qn=new n.Vector3;function Zn(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),jn.set(e.boundingBox.min,e.boundingBox.max,i),jn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=Vi.getPrimitive(),p=Vi.getPrimitive();let f=Wn,m=Gn,g=null,w=null;s&&(g=Hn,w=qn);let y=1/0,_=null,b=null;return Un.copy(i).invert(),$n.matrix.copy(Un),t.shapecast({boundsTraverseOrder:t=>jn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&($n.min.copy(t.min),$n.max.copy(t.max),$n.needsUpdate=!0),!0),intersectsRange:(n,s)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>$n.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,o)=>{for(let v=e,x=e+o;v<x;v++){const e=a.resolveTriangleIndex(v);tn(p,3*e,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);tn(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<y&&(m.copy(f),w&&w.copy(g),y=n,_=e,b=v),n<r)return!0}}}})}for(let o=0,a=xi(e);o<a;o++){tn(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);tn(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<y&&(m.copy(f),w&&w.copy(g),y=n,_=e,b=o),n<r)return!0}}}}),Vi.releasePrimitive(d),Vi.releasePrimitive(p),y===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=y,n.faceIndex=_,s&&(s.point?s.point.copy(w):s.point=w.clone(),s.point.applyMatrix4(Un),m.applyMatrix4(Un),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}function Yn(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t)}const Xn=new Bi,Kn=new n.Ray,Qn=new n.Vector3,Jn=new n.Matrix4,ts=new n.Vector3,es=["getX","getY","getZ"];class is extends Ai{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,n=t._roots,s=t._indirectBuffer,r=i.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(o.roots=n.map(t=>t.slice()),o.index=r?r.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=n,o.index=r?r.array:null,o.indirectBuffer=s),o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:s,roots:r,indirectBuffer:o}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),function(t){for(let e=0;e<t.length;e++){const i=t[e],n=new Uint32Array(i),s=new Uint16Array(i);for(let t=0,e=i.byteLength/ve;t<e;t++){const e=8*t;De(2*e,s)||(n[e+6]=n[e+6]/8-t)}}}(r));const a=new is(e,{...i,[Ce]:!0});if(a._roots=r,a._indirectBuffer=o||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new n.BufferAttribute(t.index,1,!1);e.setIndex(i)}else i.array!==s&&(i.array.set(s),i.needsUpdate=!0)}return a}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),e={...e,maxLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const n=this.geometry,s=this._indirectBuffer,r=n.attributes.position,o=n.index?n.index.array:null,a=3*(s?s[t]:t);let l=a+0,c=a+1,h=a+2;o&&(l=o[l],c=o[c],h=o[h]);for(let t=0;t<3;t++){const n=r[es[t]](l),s=r[es[t]](c),o=r[es[t]](h);let a=n;s<a&&(a=s),o<a&&(a=o);let u=n;s>u&&(u=s),o>u&&(u=o),e[i+t]=a,e[i+t+3]=u}return e}computePrimitiveBounds(t,e,i){const n=this.geometry,s=this._indirectBuffer,r=n.attributes.position,o=n.index?n.index.array:null,a=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=r.array,c=r.offset||0;let h=3;r.isInterleavedBufferAttribute&&(h=r.data.stride);const u=["getX","getY","getZ"],d=i.offset;for(let n=t,p=t+e;n<p;n++){const t=3*(s?s[n]:n),e=6*(n-d);let p=t+0,f=t+1,m=t+2;o&&(p=o[p],f=o[f],m=o[m]),a||(p=p*h+c,f=f*h+c,m=m*h+c);for(let t=0;t<3;t++){let n,s,o;a?(n=r[u[t]](p),s=r[u[t]](f),o=r[u[t]](m)):(n=l[p+t],s=l[f+t],o=l[m+t]);let c=n;s<c&&(c=s),o<c&&(c=o);let h=n;s>h&&(h=s),o>h&&(h=o);const d=(h-c)/2,g=2*t;i[e+g+0]=c+d,i[e+g+1]=d+(Math.abs(c)+d)*xe}}return i}raycastObject3D(t,e,i=[]){const{material:n}=t;if(void 0===n)return;Jn.copy(t.matrixWorld).invert(),Kn.copy(e.ray).applyMatrix4(Jn),ts.setFromMatrixScale(t.matrixWorld),Qn.copy(Kn.direction).multiply(ts);const s=Qn.length(),r=e.near/s,o=e.far/s;if(!0===e.firstHitOnly){let s=this.raycastFirst(Kn,n,r,o);s=Yn(s,t,e),s&&i.push(s)}else{const s=this.raycast(Kn,n,r,o);for(let n=0,r=s.length;n<r;n++){const r=Yn(s[n],t,e);r&&i.push(r)}}return i}refit(t=null){return(this.indirect?Tn:nn)(this,t)}raycast(t,e=n.FrontSide,i=0,s=1/0){const r=this._roots,o=[],a=this.indirect?Mn:on;for(let n=0,l=r.length;n<l;n++)a(this,n,e,t,o,i,s);return o}raycastFirst(t,e=n.FrontSide,i=0,s=1/0){const r=this._roots;let o=null;const a=this.indirect?Dn:cn;for(let n=0,l=r.length;n<l;n++){const r=a(this,n,e,t,i,s);null!=r&&(null==o||r.distance<o.distance)&&(o=r)}return o}intersectsGeometry(t,e){let i=!1;const n=this._roots,s=this.indirect?Fn:wn;for(let r=0,o=n.length;r<o&&(i=s(this,r,t,e),!i);r++);return i}shapecast(t){const e=Vi.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?rn:en});return Vi.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:n,intersectsTriangles:s}=i;const r=Vi.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?t=>{const e=this.resolveTriangleIndex(t);tn(r,3*e,o,a)}:t=>{tn(r,3*t,o,a)},c=Vi.getPrimitive(),h=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?e=>{const i=t.resolveTriangleIndex(e);tn(c,3*i,h,u)}:t=>{tn(c,3*t,h,u)};if(s){if(!(t instanceof is))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const i=(t,i,n,o,a,h,u,p)=>{for(let f=n,m=n+o;f<m;f++){d(f),c.a.applyMatrix4(e),c.b.applyMatrix4(e),c.c.applyMatrix4(e),c.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++)if(l(e),r.needsUpdate=!0,s(r,c,e,f,a,h,u,p))return!0}return!1};if(n){const t=n;n=function(e,n,s,r,o,a,l,c){return!!t(e,n,s,r,o,a,l,c)||i(e,n,s,r,o,a,l,c)}}else n=i}return super.bvhcast(t,e,{intersectsRanges:n})}intersectsBox(t,e){return Xn.set(t.min,t.max,e),Xn.needsUpdate=!0,this.shapecast({intersectsBounds:t=>Xn.intersectsBox(t),intersectsTriangle:t=>Xn.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},n={},s=0,r=1/0){return(this.indirect?Zn:Pn)(this,t,e,i,n,s,r)}closestPointToPoint(t,e={},i=0,n=1/0){return function(t,e,i={},n=0,s=1/0){const r=n*n,o=s*s;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(Li.copy(e).clamp(t.min,t.max),Li.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,Li);const n=e.distanceToSquared(Li);return n<a&&(Ni.copy(Li),a=n,l=i),n<r}}),a===1/0)return null;const c=Math.sqrt(a);return i.point?i.point.copy(Ni):i.point=Ni.clone(),i.distance=c,i.faceIndex=l,i}(this,t,e,i,n)}}const ns=new n.Matrix4,ss=new n.Ray,rs=new ti(()=>new n.Line3),os=new n.Vector3,as=new n.Vector3,ls=new n.Box3,cs=["getX","getY","getZ"];class hs extends Ai{get primitiveStride(){return 2}writePrimitiveBounds(t,e,i){const n=this._indirectBuffer,{geometry:s,primitiveStride:r}=this,o=s.attributes.position,a=s.index,l=a?a.count:o.count;let c=(n?n[t]:t)*r,h=(c+1)%l;a&&(c=a.getX(c),h=a.getX(h));for(let t=0;t<3;t++){const n=o[cs[t]](c),s=o[cs[t]](h),r=n<s?n:s,a=n>s?n:s;e[i+t]=r,e[i+t+3]=a}return e}shapecast(t){const e=rs.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsLine,scratchPrimitive:e,iterate:us});return rs.releasePrimitive(e),i}raycastObject3D(t,e,i=[]){const{matrixWorld:n}=t,{firstHitOnly:s}=e;ns.copy(n).invert(),ss.copy(e.ray).applyMatrix4(ns);const r=e.params.Line.threshold/((t.scale.x+t.scale.y+t.scale.z)/3),o=r*r;let a=null,l=1/0;return this.shapecast({boundsTraverseOrder:t=>t.distanceToPoint(ss.origin),intersectsBounds:t=>(ls.copy(t).expandByScalar(Math.abs(r)),ss.intersectsBox(ls)?1:0),intersectsLine:(r,c)=>{if(ss.distanceSqToSegment(r.start,r.end,os,as)>o)return;os.applyMatrix4(t.matrixWorld);const h=e.ray.origin.distanceTo(os);h<e.near||h>e.far||s&&h>=l||(l=h,c=this.resolvePrimitiveIndex(c),a={distance:h,point:as.clone().applyMatrix4(n),index:c*this.primitiveStride,face:null,faceIndex:null,barycoord:null,object:t},s||i.push(a))}}),s&&a&&i.push(a),i}}function us(t,e,i,n,s,r,o){const{geometry:a,primitiveStride:l}=i,{index:c}=a,h=a.attributes.position,u=c?c.count:h.count;for(let a=t,d=e+t;a<d;a++){let t=i.resolvePrimitiveIndex(a)*l,e=(t+1)%u;if(c&&(t=c.getX(t),e=c.getX(e)),o.start.fromBufferAttribute(h,t),o.end.fromBufferAttribute(h,e),n(o,a,s,r))return!0}return!1}const ds={Mesh:n.Mesh.prototype.raycast,Line:n.Line.prototype.raycast,LineSegments:n.LineSegments.prototype.raycast,LineLoop:n.LineLoop.prototype.raycast,Points:n.Points.prototype.raycast,BatchedMesh:n.BatchedMesh.prototype.raycast},ps=new n.Mesh,fs=[];function ms(t,e){if(this.isBatchedMesh)gs.call(this,t,e);else{const{geometry:i}=this;if(i.boundsTree)i.boundsTree.raycastObject3D(this,t,e);else{let i;if(this instanceof n.Mesh)i=ds.Mesh;else if(this instanceof n.LineSegments)i=ds.LineSegments;else if(this instanceof n.LineLoop)i=ds.LineLoop;else if(this instanceof n.Line)i=ds.Line;else{if(!(this instanceof n.Points))throw new Error("BVH: Fallback raycast function not found.");i=ds.Points}i.call(this,t,e)}}}function gs(t,e){if(this.boundsTrees){const i=this.boundsTrees,s=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,o=this.matrixWorld;ps.material=this.material,ps.geometry=this.geometry;const a=ps.geometry.boundsTree,l=ps.geometry.drawRange;null===ps.geometry.boundingSphere&&(ps.geometry.boundingSphere=new n.Sphere);for(let n=0,a=s.length;n<a;n++){if(!this.getVisibleAt(n))continue;const a=s[n].geometryIndex;if(ps.geometry.boundsTree=i[a],this.getMatrixAt(n,ps.matrixWorld).premultiply(o),!ps.geometry.boundsTree){this.getBoundingBoxAt(a,ps.geometry.boundingBox),this.getBoundingSphereAt(a,ps.geometry.boundingSphere);const t=r[a];ps.geometry.setDrawRange(t.start,t.count)}ps.raycast(t,fs);for(let t=0,i=fs.length;t<i;t++){const i=fs[t];i.object=this,i.batchId=n,e.push(i)}fs.length=0}ps.geometry.boundsTree=a,ps.geometry.drawRange=l,ps.material=null,ps.geometry=null}else ds.BatchedMesh.call(this,t,e)}function ws(t={}){const{type:e=is}=t;return this.boundsTree=new e(this,t),this.boundsTree}function ys(){this.boundsTree=null}const _s=class t extends g{constructor(i){super(i),e(this,"onDisposed",new f),e(this,"onBeforeDispose",new f),e(this,"onFragmentsLoaded",new f),e(this,"baseCoordinationModel",""),e(this,"baseCoordinationMatrix",new u.Matrix4),e(this,"enabled",!0),e(this,"_core"),this.components.add(t.uuid,this)}static getWorker(){return i.FragmentsModels.getWorker()}get initialized(){return!!this._core}get list(){return this.core.models.list}get core(){if(!this._core)throw new Error("FragmentsManager not initialized. Call init() first.");return this._core}get _hasCoordinationModel(){return""!==this.baseCoordinationModel}dispose(){this.onBeforeDispose.trigger(),this._core&&(this.core.dispose(),this._core=void 0),this.baseCoordinationModel="",this.onFragmentsLoaded.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}init(t,e){this._core=new i.FragmentsModels(t,e),this.core.onModelLoaded.add(async()=>{if(this._hasCoordinationModel)return;const t=[...this.list.values()][0];t&&(this.baseCoordinationModel=t.modelId,this.baseCoordinationMatrix=await t.getCoordinationMatrix())}),this.list.onItemDeleted.add(()=>{this.list.size>0||(this.baseCoordinationModel="",this.baseCoordinationMatrix=new u.Matrix4)})}async raycast(t){const e=[];for(const i of this.core.models.list.values())if(t.snappingClasses&&t.snappingClasses.length>0){const n=await i.raycastWithSnapping(t);if(n&&n.length>0)e.push(n[0]);else{const n=await i.raycast(t);n&&e.push(n)}}else{const n=await i.raycast(t);n&&e.push(n)}if(await Promise.all(e),0===e.length)return;let i=e[0],n=i.distance;for(let t=1;t<e.length;t++)e[t].distance<n&&(n=e[t].distance,i=e[t]);return i}async getPositions(t){const e=[],i=async(t,i)=>{const n=await t.getPositions(i);for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async getBBoxes(t){const e=[],i=async(t,i)=>{const n=await t.getBoxes(i);if(n)for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async highlight(t,e){await this.forEachModel(e,"highlight",t)}async getData(t,e){const i={};for(const[n,s]of Object.entries(t)){const t=this.list.get(n);if(!t)continue;if(0===s.size){i[n]=[];continue}const r=await t.getItemsData([...s],e);i[n]=r}return i}async resetHighlight(t){await this.forEachModel(t,"resetHighlight")}async forEachModel(t,e,...i){const n={};if(t)for(const e in t){const i=t[e];n[e]=Array.from(i)}else for(const t of this.core.models.list.keys())n[t]=void 0;const s=[];for(const t in n){const r=this.core.models.list.get(t);if(r){const o=n[t],a=r[e](o,...i);s.push(a)}}await Promise.all(s)}async guidsToModelIdMap(t){const e={};for(const[i,n]of this.list){const s=(await n.getLocalIdsByGuids([...t])).filter(t=>null!==t);e[i]=new Set(s)}return e}async modelIdMapToGuids(t){const e=[];for(const[i,n]of Object.entries(t)){const t=this.list.get(i);if(!t)continue;const s=(await t.getGuidsByLocalIds([...n])).filter(t=>null!==t);e.push(...s)}return e}applyBaseCoordinateSystem(t,e){const i=new u.Matrix4;return e&&i.copy(e.clone()).invert(),i.multiply(this.baseCoordinationMatrix),t.applyMatrix4(i),i}};e(_s,"uuid","fef46874-46a3-461b-8c44-2922ab77c806");let bs=_s;function vs(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16}class xs{constructor(t,e={}){const{pixelsPerMeter:i=.1}=e;this.pixelsPerMeter=i,this.renderer=t}async cull(t){t=function(t){const e=new Set;return t.traverse(t=>{t.isMesh&&e.add(t)}),Array.from(e)}(t);const{renderer:e,pixelsPerMeter:i}=this,s=new n.Vector3,r=new n.OrthographicCamera,o=new n.Box3,a=new n.WebGLRenderTarget(1,1);o.makeEmpty(),t.forEach(t=>{o.expandByObject(t)}),o.getSize(s);const l=Math.min(e.capabilities.maxTextureSize,8192),c=Math.ceil(s.x/i),h=Math.ceil(s.z/i),u=Math.ceil(c/l),d=Math.ceil(h/l);a.setSize(Math.ceil(c/u),Math.ceil(h/d));const p=.01*Math.max(s.y,1);r.rotation.x=-Math.PI/2,r.near=0,r.far=s.y+2*p,r.position.y=o.max.y+p;const f=new n.Scene,m=new Map,g=new Map,w=[];for(let e=0;e<t.length;e++){const i=t[e];m.set(i,i.material),g.set(i,i.parent);const n=new Cs;n.objectId=e,w.push(n),i.material=n,f.add(i)}const y=e.getClearColor(new n.Color),_=e.getClearAlpha(),b=e.getRenderTarget(),v=e.autoClear;e.autoClear=!0,e.setClearColor(0,0),e.setRenderTarget(a);const x=new Uint8Array(a.width*a.height*4),C=new Set,S=s.x/u,A=s.z/d;for(let i=0;i<u;i++)for(let n=0;n<d;n++){const s=o.min.x+S*i,l=s+S,c=o.min.z+A*n,h=(s+l)/2,u=(c+(c+A))/2;r.position.set(h,o.max.y+p,u);const d=S/2,m=A/2;r.left=-d,r.right=d,r.top=m,r.bottom=-m,r.updateProjectionMatrix(),e.render(f,r);const g=await e.readRenderTargetPixelsAsync(a,0,0,a.width,a.height,x);for(let e=0,i=g.length;e<i;e+=4){if(0===g[e+3])continue;const i=vs(g,e);C.add(t[i])}}for(const e of t){e.material=m.get(e);const t=g.get(e);t?t.add(e):f.remove(e)}e.setClearColor(y,_),e.setRenderTarget(b),e.autoClear=v;for(const t of w)t.dispose();return a.dispose(),Array.from(C)}}class Cs extends n.ShaderMaterial{get objectId(){return this._objectId}set objectId(t){var e,i;this._objectId=t,e=t,(i=this.uniforms.objectId.value).x=(255&e)/255,i.y=(e>>8&255)/255,i.z=(e>>16&255)/255,i.w=1}constructor(t){super({glslVersion:n.GLSL3,blending:n.NoBlending,side:n.DoubleSide,uniforms:{objectId:{value:new n.Vector4}},vertexShader:"\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\t\t\t\tlayout(location = 0) out vec4 out_id;\n\t\t\t\tuniform vec4 objectId;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tout_id = objectId;\n\n\t\t\t\t}\n\t\t\t"}),this._objectId=0,this.setValues(t)}}const Ss=1e-16,As=new n.Vector3(0,1,0),Ps=new n.Vector3;function Ts(t){return t.delta(Ps).normalize(),Math.abs(Ps.dot(As))>=1-Ss}function Ms(t,e){const{start:i,end:n}=e,s=t.points;let r=!1,o=!1;for(let t=0;t<3;t++){const e=s[t];if(!r&&i.distanceToSquared(e)<=Ss&&(r=!0),!o&&n.distanceToSquared(e)<=Ss&&(o=!0),r&&o)return!0}return r&&o}const Es=new n.Line3;function Is(t,e,i=!1,n=[]){let s=[[0,1]];for(let t=0,i=e.length;t<i;t++){const i=s[t],n=e[t];i[1]=n[0],s.push([n[1],1])}i&&([e,s]=[s,e]);for(let e=0,i=s.length;e<i;e++){const{start:i,end:r}=t;Es.start.lerpVectors(i,r,s[e][0]),Es.end.lerpVectors(i,r,s[e][1]),n.push(new Float32Array([Es.start.x,Es.start.y,Es.start.z,Es.end.x,Es.end.y,Es.end.z]))}return n}const Ds=new n.Vector3(0,1,0),zs=new n.Vector3,ks=new n.Vector3,Bs=new n.Vector3,Os=new n.Triangle;function*Vs(t,e=[],i={}){const{projectionDirection:s=Ds,thresholdAngle:r=1,iterationTime:o=30}=i,a=Math.pow(10,4),l=Math.cos(n.MathUtils.DEG2RAD*r),c=t.getIndex(),h=t.getAttribute("position"),u=c?c.count:h.count,d=[0,0,0],p=["a","b","c"],f=new Array(3),m={};let g=performance.now();for(let t=0;t<u;t+=3){performance.now()-g>o&&(yield,g=performance.now()),c?(d[0]=c.getX(t),d[1]=c.getX(t+1),d[2]=c.getX(t+2)):(d[0]=t,d[1]=t+1,d[2]=t+2);const{a:i,b:r,c:u}=Os;if(i.fromBufferAttribute(h,d[0]),r.fromBufferAttribute(h,d[1]),u.fromBufferAttribute(h,d[2]),Os.getNormal(Bs),f[0]=`${Math.round(i.x*a)},${Math.round(i.y*a)},${Math.round(i.z*a)}`,f[1]=`${Math.round(r.x*a)},${Math.round(r.y*a)},${Math.round(r.z*a)}`,f[2]=`${Math.round(u.x*a)},${Math.round(u.y*a)},${Math.round(u.z*a)}`,f[0]!==f[1]&&f[1]!==f[2]&&f[2]!==f[0])for(let t=0;t<3;t++){const i=(t+1)%3,r=f[t],o=f[i],a=Os[p[t]],c=Os[p[i]],h=`${r}_${o}`,u=`${o}_${r}`;if(u in m&&m[u]){const t=m[u].normal,i=Bs.dot(t)<=l;let r=!1;if(null!==s){let e=s.dot(Bs);e=Math.abs(e)<1e-10?0:e;let i=s.dot(t);i=Math.abs(i)<1e-10?0:i,r=Math.sign(e)!==Math.sign(i)}if(i||r){const t=new n.Line3;t.start.copy(a),t.end.copy(c),e.push(t)}m[u]=null}else h in m||(m[h]={index0:d[t],index1:d[i],normal:Bs.clone()})}}for(const t in m)if(m[t]){const{index0:i,index1:s}=m[t];zs.fromBufferAttribute(h,i),ks.fromBufferAttribute(h,s);const r=new n.Line3;r.start.copy(zs),r.end.copy(ks),e.push(r)}return e}const Ls=new n.Line3;function Ns(t,e,i,n=[]){return t.bvhcast(e,i,{intersectsTriangles:(t,e)=>!function(t,e){const i=["a","b","c"];let n=0;for(let s=0;s<3;s++)for(let r=0;r<3;r++){Fs(t[i[s]],e[i[r]])&&n++}return n>=2}(t,e)&&(t.needsUpdate&&t.update(),e.needsUpdate&&e.update(),!(Math.abs(t.plane.normal.dot(e.plane.normal))>.999999)&&void(!t.intersectsTriangle(e,Ls,!0)||Ms(t,Ls)||Ms(e,Ls)||n.push(Ls.clone())))}),n}function Fs(t,e){return t.distanceTo(e)<1e-10}function Rs(t){Us(t);let e=[];return t.traverse(t=>{t.geometry&&t.visible&&e.push(t)}),e}const Us=t=>{if(void 0===t)return;const e=[...t.children];for(const i of e)void 0===i?t.children.splice(t.children.indexOf(i),1):Us(i)},js=new n.Matrix4,$s=new n.Matrix4;class Ws{constructor(){this.projectionDirection=new n.Vector3(0,1,0),this.thresholdAngle=50,this.iterationTime=30}getEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.getEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*getEdgesGenerator(t,e=[],i=null){const{projectionDirection:s,thresholdAngle:r,iterationTime:o}=this;if(t.isObject3D){const a=Rs(t);let l=null;s&&(l=new n.Vector3);let c=performance.now();for(let t=0;t<a.length;t++){c-performance.now()>o&&(yield);const n=a[t];l&&($s.copy(n.matrixWorld).invert(),l.copy(s).transformDirection($s).normalize());const h=yield*Vs(n.geometry,[],{projectionDirection:l,thresholdAngle:r,iterationTime:o});Gs(h,n.matrixWorld);for(let t=0;t<h.length;t++)e.push(h[t]);if(null!==i)for(let t=0;t<h.length;t++)i.push(n)}return e}return yield*Vs(t,e,{projectionDirection:s,thresholdAngle:r,iterationTime:o})}getIntersectionEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.getIntersectionEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*getIntersectionEdgesGenerator(t,e=[],i=null){const{iterationTime:n}=this;if(t.isObject3D){const s=Rs(t),r=new Map;let o=performance.now();for(let t=0;t<s.length;t++){performance.now()-o>n&&(yield,o=performance.now());const e=s[t].geometry;if(!r.has(e)){const t=e.boundsTree||new is(e,{maxLeafSize:1});r.set(e,t)}}o=performance.now();for(let t=0;t<s.length;t++)for(let a=t;a<s.length;a++){performance.now()-o>n&&(yield,o=performance.now());const l=s[t],c=s[a],h=r.get(l.geometry),u=r.get(c.geometry);js.copy(l.matrixWorld).invert().multiply(c.matrixWorld);const d=Ns(h,u,js,[]);Gs(d,l.matrixWorld);for(let t=0;t<d.length;t++)e.push(d[t]);if(null!==i)for(let t=0;t<d.length;t++)i.push(l)}return e}{let i;return t.isBufferGeometry?i=t.boundsTree||new is(t,{maxLeafSize:1}):(i=t,t=i.geometry),js.identity(),Ns(i,i,js,e)}}}function Gs(t,e,i=1e-6){for(let n=0;n<t.length;n++){const s=t[n];s.applyMatrix4(e),s.start.y+=i,s.end.y+=i}}class Hs extends bi{get lines(){return this.primitiveBuffer}constructor(t,e){super(e),this.primitiveBuffer=t,this.primitiveBufferStride=1,this.heightOffset=e.heightOffset??1e3,this.init(e)}writePrimitiveBounds(t,e,i){const{primitiveBuffer:n,heightOffset:s}=this,{start:r,end:o}=n[t];e[i+0]=Math.min(r.x,o.x),e[i+1]=Math.min(r.y,o.y),e[i+2]=Math.min(r.z,o.z),e[i+3]=Math.max(r.x,o.x),e[i+4]=Math.max(r.y,o.y)+s,e[i+5]=Math.max(r.z,o.z)}getRootRanges(){return[{offset:0,count:this.primitiveBuffer.length}]}}const qs=new n.Vector3(0,1,0),Zs=new n.Plane,Ys=new n.Vector3,Xs=new n.Vector3;function Ks(t,e,i){t.needsUpdate&&t.update(),Zs.copy(t.plane),Zs.normal.dot(qs)<0&&(Zs.normal.multiplyScalar(-1),Zs.constant*=-1);const s=Zs.distanceToPoint(e.start),r=Zs.distanceToPoint(e.end),o=Math.abs(s)<1e-16,a=s<0,l=r<0;if(e.delta(Xs).normalize(),Math.abs(Zs.normal.dot(Xs))<1e-16)return!(o||!a)&&(i.copy(e),!0);if(a&&l)return i.copy(e),!0;if(!a&&!l)return!1;{const t=n.MathUtils.mapLinear(0,s,r,0,1);if(e.at(t,Ys),a)return i.start.copy(e.start),i.end.copy(Ys),!0;if(l)return i.end.copy(e.end),i.start.copy(Ys),!0}return!1}const Qs=new n.Plane,Js=new n.Vector3,tr=new n.Vector3,er=new ki,ir=new n.Line3,nr=new n.Line3,sr=new n.Vector3,rr=new n.Vector3,or=new n.Vector3;function ar(t,e,i=new n.Line3){if(er.copy(e),er.a.y=0,er.b.y=0,er.c.y=0,er.update(),ir.copy(t),ir.start.y=0,ir.end.y=0,er.getArea()<=1e-16)return null;const s=ir.distance();ir.delta(sr).divideScalar(s),rr.copy(sr).cross(er.plane.normal).normalize(),Qs.setFromNormalAndCoplanarPoint(rr,ir.start);let r=0;const{points:o}=er;for(let t=0;t<3;t++){const e=o[t],i=o[(t+1)%3],n=Qs.distanceToPoint(e),s=Qs.distanceToPoint(i),a=Math.abs(n)<1e-16,l=Math.abs(s)<1e-16;let c=!1;if(!a&&!l&&n*s<0){const t=n/(n-s);Js.lerpVectors(e,i,t),c=!0}if((c&&!l||a)&&(a&&!c&&Js.copy(e),0===r?nr.start.copy(Js):nr.end.copy(Js),r++,2===r))break}if(2===r){if(nr.delta(or).normalize(),sr.dot(or)<0){const t=nr.start;nr.start=nr.end,nr.end=t}const e=0,n=tr.subVectors(ir.end,ir.start).dot(sr),r=tr.subVectors(nr.start,ir.start).dot(sr),o=tr.subVectors(nr.end,ir.start).dot(sr);return n<=r||o<=e?null:(t.at(Math.max(e,r)/s,i.start),t.at(Math.min(n,o)/s,i.end),i)}return null}const lr=new n.Vector3,cr=new n.Vector3,hr=new n.Vector3;function ur(t,e,i){const n=function(t,e){t.delta(lr),cr.subVectors(e.start,t.start),hr.subVectors(e.end,t.start);const i=lr.length();let n=cr.length()/i,s=hr.length()/i;if(n=Math.min(Math.max(n,0),1),s=Math.min(Math.max(s,0),1),Math.abs(n-s)<=1e-16)return null;return[n,s]}(t,e);return!!n&&(dr(n,i),!0)}function dr(t,e){let[i,n]=t,s=0,r=e.length;for(;s<r;){const t=s+r>>>1;e[t][0]<=i?s=t+1:r=t}let o=Math.max(0,s-1),a=0;for(let t=o,s=e.length;t<s;t++){const[s,r]=e[t];if(i<=r&&n>=s)i=Math.min(s,i),n=Math.max(r,n),a++;else{if(!(i>=s))break;o=t+1}}e.splice(o,a,[i,n])}const pr=new n.Vector3(0,1,0),fr=new n.Line3,mr=new n.Line3,gr=new ki;function wr(t,e,i,s,r=null){const{geometry:o,matrixWorld:a,material:l}=i,c=l.side,h=a.determinant()<0,u=t.lines;t.bvhcast(e,a,{intersectsRanges:(t,e,i,l)=>{r&&(r.candidates+=e*l);for(let d=i,p=l+i;d<p;d++){let i=3*d+0,l=3*d+1,p=3*d+2;o.index&&(i=o.index.getX(i),l=o.index.getX(l),p=o.index.getX(p));const{a:f,b:m,c:g}=gr;if(f.fromBufferAttribute(o.attributes.position,i).applyMatrix4(a),m.fromBufferAttribute(o.attributes.position,l).applyMatrix4(a),g.fromBufferAttribute(o.attributes.position,p).applyMatrix4(a),gr.needsUpdate=!0,gr.update(),c!==n.DoubleSide){if(gr.plane.normal.dot(pr)!==h===(c===n.BackSide)){r&&(r.backFaceCulled+=e);continue}}const w=Math.max(f.y,m.y,g.y),y=Math.min(f.y,m.y,g.y),_=gr.plane.normal;let b=_.x,v=_.y,x=_.z,C=gr.plane.constant;v<0&&(b=-b,v=-v,x=-x,C=-C);for(let i=t,n=e+t;i<n;i++){const t=u[i],e=Math.min(t.start.y,t.end.y),n=Math.max(t.start.y,t.end.y);if(w<=e){r&&r.yBoundsCulled++;continue}const o=t.end.x-t.start.x,a=t.end.z-t.start.z,l=o*o+a*a;if(l>1e-20){const e=1/Math.sqrt(l),i=o*e,n=a*e,s=-n,c=i,h=f.x-t.start.x,u=f.z-t.start.z,d=m.x-t.start.x,p=m.z-t.start.z,w=g.x-t.start.x,y=g.z-t.start.z,_=h*i+u*n,b=d*i+p*n,v=w*i+y*n,x=1/e,C=Math.min(_,b,v);if(Math.max(_,b,v)<0||C>x){r&&r.xzBoundsCulled++;continue}const S=h*s+u*c,A=d*s+p*c,P=w*s+y*c,T=Math.min(S,A,P),M=Math.max(S,A,P);if(T>0||M<0){r&&r.xzBoundsCulled++;continue}}const c=b*t.start.x+v*t.start.y+x*t.start.z+C,h=b*t.end.x+v*t.end.y+x*t.end.z+C;if(c>=0&&h>=0)r&&r.planeTrimCulled++;else if(Ms(gr,t))r&&r.triangleEdgeCulled++;else{if(n<y)fr.copy(t);else if(!Ks(gr,t,fr)){r&&r.planeTrimCulled++;continue}fr.distance()<1e-10?r&&r.distThresholdCulled++:ar(fr,gr,mr)?(r&&r.used++,ur(t,mr,s[i])):r&&r.noOverlapCulled++}}}}})}gr.update=()=>{gr.plane.setFromCoplanarPoints(...gr.points)};let yr=!1;const _r={},br={};let vr=null,xr=0,Cr=0;const Sr={get enabled(){return yr},set enabled(t){yr=t},reset(){for(const t in _r)delete _r[t];for(const t in br)delete br[t];vr=null,xr=0,Cr=0},setStat(t,e){br[t]=e},startTotal(){yr&&(Cr=performance.now())},startStep(t){yr&&(null!==vr&&this.endStep(),vr=t,xr=performance.now())},endStep(){if(!yr||null===vr)return;const t=performance.now()-xr;_r[vr]=t,vr=null},printSummary(){if(!yr)return;null!==vr&&this.endStep();const t=performance.now()-Cr;console.log("\n=== Projection Summary ==="),console.log(`Total time: ${t.toFixed(1)}ms\n`);for(const[e,i]of Object.entries(_r)){const n=(i/t*100).toFixed(1);console.log(` ${e}: ${i.toFixed(1)}ms (${n}%)`)}if(Object.keys(br).length>0){console.log("\n--- Stats ---");for(const[t,e]of Object.entries(br))console.log(` ${t}: ${e}`)}console.log("")}},Ar=1e-5,Pr=1e-16,Tr=1e-16;function Mr(t,e,i,n,s){t.bvhcast(e,i.matrixWorld,{intersectsRanges:(t,e,i,r)=>{n._edgeOffsets.push(t),n._edgeCounts.push(e),n._meshOffsets.push(i),n._meshCounts.push(r),n._meshIndex.push(s),n.groupCount++}})}let Er=null;async function Ir(t,e,i,n,s=null){const o=await async function(){return null===Er&&(Er=new d.WebGPURenderer,await Er.init()),Er}();t._edgeOffsets&&(t.edgeOffsets=new Uint32Array(t._edgeOffsets),t.edgeCounts=new Uint32Array(t._edgeCounts),t.meshOffsets=new Uint32Array(t._meshOffsets),t.meshCounts=new Uint32Array(t._meshCounts),t.meshIndex=new Uint32Array(t._meshIndex),t._edgeOffsets=null,t._edgeCounts=null,t._meshOffsets=null,t._meshCounts=null,t._meshIndex=null);const a=r.instancedArray(function(t){const e=new Float32Array(6*t.length);for(let i=0;i<t.length;i++){const n=t[i];e[6*i+0]=n.start.x,e[6*i+1]=n.start.y,e[6*i+2]=n.start.z,e[6*i+3]=n.end.x,e[6*i+4]=n.end.y,e[6*i+5]=n.end.z}return e}(i.lines),"float");Sr.enabled&&console.log("Number of meshes:",e.length),Sr.enabled&&console.log("Group count:",t.groupCount);const l=[];{let t=0;for(;t<e.length;){let i=t,n=0;for(;i<e.length;){const s=e[i].geometry,r=s.index?s.index.count/3:s.attributes.position.count/3;if(i>t&&(i-t>=1e3||n+r>1e5))break;n+=r,i++}l.push({start:t,end:i}),t=i}}Sr.enabled&&console.log(`Split ${e.length} meshes into ${l.length} batches`);let c=0,h=0,u=0,p=0,f=0;for(let i=0;i<l.length;i++){const{start:d,end:m}=l[i],g=m-d;Sr.enabled&&console.log(`Processing batch ${i+1}/${l.length} (meshes ${d}-${m-1})`);let w=0,y=0;const _=[];for(let t=d;t<m;t++){const i=e[t].geometry;_.push(y/3),w+=i.attributes.position.array.length,y+=i.index.array.length}const b=new Float32Array(w),v=new Uint32Array(y);let x=0,C=0,S=0;for(let t=d;t<m;t++){const i=e[t].geometry,n=i.attributes.position.array,s=i.index.array;b.set(n,x),x+=n.length;for(let t=0;t<s.length;t++)v[C+t]=s[t]+S;C+=s.length,S+=i.attributes.position.count}const A=new Float32Array(16*g);for(let t=d;t<m;t++){const i=t-d;A.set(e[t].matrixWorld.elements,16*i)}const P=[];for(let e=0;e<t.groupCount;e++){const i=t.meshIndex[e];if(i>=d&&i<m){const n=i-d,s=_[n]+t.meshOffsets[e];P.push({edgeOffset:t.edgeOffsets[e],edgeCount:t.edgeCounts[e],triOffset:s,triCount:t.meshCounts[e],meshIdx:n})}}if(0===P.length){Sr.enabled&&console.log(` Batch ${i+1}: no groups, skipping`);continue}const T=new Uint32Array(5*P.length);for(let t=0;t<P.length;t++){const e=P[t],i=5*t;T[i+0]=e.edgeOffset,T[i+1]=e.edgeCount,T[i+2]=e.triOffset,T[i+3]=e.triCount,T[i+4]=e.meshIdx}let M=0;for(let t=0;t<P.length;t++)M+=P[t].edgeCount*P[t].triCount;s&&(s.candidates+=M);let E=Math.min(Math.ceil(.1*M),2e6),I=Math.max(E,1e4);Sr.enabled&&console.log(` Batch ${i+1}: ${P.length} groups, ${w/3} vertices, ${y/3} triangles, ${M} pairs, buffer for ${I} overlaps`);const D=performance.now(),z=r.instancedArray(b,"float"),k=r.instancedArray(v,"uint"),B=r.instancedArray(A,"float"),O=r.instancedArray(T,"uint");let V=r.instancedArray(new Uint32Array([0]),"uint").toAtomic(),L=r.instancedArray(new Float32Array(3*I),"float");p+=performance.now()-D;const N=performance.now(),F=r.Fn(()=>{const t=r.instanceIndex.mul(5),e=O.element(t),i=O.element(t.add(1)),n=O.element(t.add(2)),s=O.element(t.add(3)),o=O.element(t.add(4)).mul(16),l=r.mat4(B.element(o),B.element(o.add(1)),B.element(o.add(2)),B.element(o.add(3)),B.element(o.add(4)),B.element(o.add(5)),B.element(o.add(6)),B.element(o.add(7)),B.element(o.add(8)),B.element(o.add(9)),B.element(o.add(10)),B.element(o.add(11)),B.element(o.add(12)),B.element(o.add(13)),B.element(o.add(14)),B.element(o.add(15)));r.Loop({start:r.int(0),end:s.toInt(),type:"int",condition:"<",name:"triIdx"},({triIdx:t})=>{const s=n.add(t.toUint()).mul(3),o=k.element(s),c=k.element(s.add(1)),h=k.element(s.add(2)),u=r.vec3(z.element(o.mul(3)),z.element(o.mul(3).add(1)),z.element(o.mul(3).add(2))),d=r.vec3(z.element(c.mul(3)),z.element(c.mul(3).add(1)),z.element(c.mul(3).add(2))),p=r.vec3(z.element(h.mul(3)),z.element(h.mul(3).add(1)),z.element(h.mul(3).add(2))),f=l.mul(r.vec4(u,r.float(1))).xyz,m=l.mul(r.vec4(d,r.float(1))).xyz,g=l.mul(r.vec4(p,r.float(1))).xyz,w=m.sub(f),y=g.sub(f),_=r.cross(w,y),b=_.dot(_);r.If(b.lessThan(r.float(4e-16*Pr)),()=>{r.Continue()}),r.If(_.y.lessThan(0),()=>{r.Continue()});const v=r.max(f.y,r.max(m.y,g.y));r.Loop({start:r.int(0),end:i.toInt(),type:"int",condition:"<",name:"edgeIdx"},({edgeIdx:t})=>{const i=e.add(t.toUint()),n=i.mul(6),s=r.vec3(a.element(n),a.element(n.add(1)),a.element(n.add(2))),o=r.vec3(a.element(n.add(3)),a.element(n.add(4)),a.element(n.add(5))),l=r.min(s.y,o.y);r.If(v.lessThanEqual(l),()=>{r.Continue()});const c=r.normalize(_),h=c.dot(f).negate(),u=c.y.lessThan(0),d=r.select(u,c.negate(),c),p=r.select(u,h.negate(),h),w=d.dot(s).add(p),y=d.dot(o).add(p),b=w.lessThan(0),x=y.lessThan(0),C=r.abs(w).lessThan(r.float(Ar)),S=b.not().and(x.not()),A=y.sub(w),P=r.abs(A).lessThan(r.float(Ar)),T=P.and(C.or(b.not()));r.If(T,()=>{r.Continue()}),r.If(S.and(P.not()),()=>{r.Continue()});const M=w.negate().div(A),E=r.mix(s,o,M),D=r.vec3(r.select(P.or(b),s.x,E.x),r.select(P.or(b),s.y,E.y),r.select(P.or(b),s.z,E.z)),z=r.vec3(r.select(P.or(x),o.x,E.x),r.select(P.or(x),o.y,E.y),r.select(P.or(x),o.z,E.z)),k=z.sub(D),B=k.dot(k);r.If(B.lessThan(r.float(Ar)),()=>{r.Continue()});const O=s.sub(f),N=s.sub(m),F=s.sub(g),R=o.sub(f),U=o.sub(m),j=o.sub(g),$=O.dot(O).lessThanEqual(r.float(Ar)),W=N.dot(N).lessThanEqual(r.float(Ar)),G=F.dot(F).lessThanEqual(r.float(Ar)),H=R.dot(R).lessThanEqual(r.float(Ar)),q=U.dot(U).lessThanEqual(r.float(Ar)),Z=j.dot(j).lessThanEqual(r.float(Ar)),Y=$.or(W).or(G),X=H.or(q).or(Z),K=Y.and(X);r.If(K,()=>{r.Continue()});const Q=r.vec3(f.x,r.float(0),f.z),J=r.vec3(m.x,r.float(0),m.z),tt=r.vec3(g.x,r.float(0),g.z),et=r.vec3(D.x,r.float(0),D.z),it=r.vec3(z.x,r.float(0),z.z),nt=r.vec3(s.x,r.float(0),s.z),st=r.vec3(o.x,r.float(0),o.z).sub(nt),rt=st.dot(st);r.If(rt.lessThan(r.float(Ar)),()=>{r.Continue()});const ot=rt.sqrt(),at=J.sub(Q),lt=tt.sub(Q),ct=r.cross(at,lt),ht=ct.dot(ct);r.If(ht.lessThanEqual(r.float(4e-16*Pr)),()=>{r.Continue()});const ut=it.sub(et),dt=ut.dot(ut);r.If(dt.lessThan(r.float(Ar)),()=>{r.Continue()});const pt=dt.sqrt(),ft=ut.div(pt),mt=st.div(ot),gt=r.normalize(ct),wt=r.cross(ft,gt),yt=r.float(0).toVar(),_t=r.float(0).toVar(),bt=r.float(0).toVar(),vt=r.float(0).toVar(),xt=r.uint(0).toVar(),Ct=wt.dot(Q.sub(et)),St=wt.dot(J.sub(et)),At=r.abs(Ct).lessThan(r.float(Tr)),Pt=r.abs(St).lessThan(r.float(Tr)),Tt=At.not().and(Pt.not()).and(Ct.mul(St).lessThan(0));r.If(Tt,()=>{const t=Ct.div(Ct.sub(St)),e=r.mix(Q.x,J.x,t),i=r.mix(Q.z,J.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(At,()=>{r.If(xt.equal(0),()=>{yt.assign(Q.x),_t.assign(Q.z)}).Else(()=>{bt.assign(Q.x),vt.assign(Q.z)}),xt.addAssign(1)});const Mt=St,Et=wt.dot(tt.sub(et)),It=Pt,Dt=r.abs(Et).lessThan(r.float(Tr)),zt=It.not().and(Dt.not()).and(Mt.mul(Et).lessThan(0));r.If(xt.lessThan(2),()=>{r.If(zt,()=>{const t=Mt.div(Mt.sub(Et)),e=r.mix(J.x,tt.x,t),i=r.mix(J.z,tt.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(It.and(Tt.not()).and(At.not()),()=>{r.If(xt.equal(0),()=>{yt.assign(J.x),_t.assign(J.z)}).Else(()=>{bt.assign(J.x),vt.assign(J.z)}),xt.addAssign(1)})});const kt=Et,Bt=Ct,Ot=Dt,Vt=At,Lt=Ot.not().and(Vt.not()).and(kt.mul(Bt).lessThan(0));r.If(xt.lessThan(2),()=>{r.If(Lt,()=>{const t=kt.div(kt.sub(Bt)),e=r.mix(tt.x,Q.x,t),i=r.mix(tt.z,Q.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(Ot.and(zt.not()).and(It.not()),()=>{r.If(xt.equal(0),()=>{yt.assign(tt.x),_t.assign(tt.z)}).Else(()=>{bt.assign(tt.x),vt.assign(tt.z)}),xt.addAssign(1)})}),r.If(xt.notEqual(2),()=>{r.Continue()});const Nt=r.vec3(yt,r.float(0),_t),Ft=r.vec3(bt,r.float(0),vt).sub(Nt).dot(ft),Rt=r.vec3(yt,r.float(0),_t).toVar(),Ut=r.vec3(bt,r.float(0),vt).toVar();r.If(Ft.lessThan(0),()=>{const t=yt,e=_t;Rt.x.assign(bt),Rt.z.assign(vt),Ut.x.assign(t),Ut.z.assign(e)});const jt=r.float(0),$t=pt,Wt=Rt.sub(et).dot(ft),Gt=Ut.sub(et).dot(ft),Ht=$t.lessThanEqual(Wt).or(Gt.lessThanEqual(jt));r.If(Ht,()=>{r.Continue()});const qt=r.max(jt,Wt),Zt=r.min($t,Gt),Yt=et.add(ft.mul(qt)),Xt=et.add(ft.mul(Zt)),Kt=Yt.sub(nt).dot(mt).div(ot),Qt=Xt.sub(nt).dot(mt).div(ot),Jt=r.max(r.float(0),r.min(r.float(1),Kt)),te=r.max(r.float(0),r.min(r.float(1),Qt)),ee=r.abs(te.sub(Jt));r.If(ee.lessThanEqual(r.float(Tr)),()=>{r.Continue()});const ie=r.atomicAdd(V.element(0),1);r.If(ie.lessThan(r.uint(I)),()=>{const t=ie.mul(3);L.element(t).assign(i.toFloat()),L.element(t.add(1)).assign(Jt),L.element(t.add(2)).assign(te)})})})})().compute(P.length);f+=performance.now()-N;const R=performance.now();await o.computeAsync(F),c+=performance.now()-R;const U=performance.now(),j=await o.getArrayBufferAsync(V.value),$=new Uint32Array(j)[0];if(s&&(s.used+=Math.min($,I)),Sr.enabled&&console.log(` Batch ${i+1}: ${$} overlaps found (capacity: ${I})`),$>I&&Sr.enabled&&console.warn(` WARNING: Overlap buffer overflow! ${$} > ${I}. Some occlusion data lost.`),$>0){const t=await o.getArrayBufferAsync(L.value),e=new Float32Array(t);h+=performance.now()-U;const i=performance.now(),s=Math.min($,I);for(let t=0;t<s;t++){const i=3*t,s=Math.round(e[i]);dr([e[i+1],e[i+2]],n[s])}u+=performance.now()-i,Sr.enabled&&console.log(` Processed ${s} overlaps into hiddenOverlapMap`)}else h+=performance.now()-U}o.dispose(),Er=null;const m=p+f+c+h+u;Sr.enabled&&(console.log(`WebGPU timing breakdown (total: ${m.toFixed(1)}ms):`),console.log(` Buffer creation: ${p.toFixed(1)}ms`),console.log(` Shader build: ${f.toFixed(1)}ms`),console.log(` GPU compute: ${c.toFixed(1)}ms`),console.log(` Readback: ${h.toFixed(1)}ms`),console.log(` CPU merge: ${u.toFixed(1)}ms`))}const Dr=new n.Vector3(0,1,0);function zr(t,e=null){const i=new Float32Array(6*t.length);let s=0;for(let e=0,n=t.length;e<n;e++){const n=t[e];i[s++]=n[0],i[s++]=0,i[s++]=n[2],i[s++]=n[3],i[s++]=0,i[s++]=n[5]}const r=new n.BufferGeometry,o=new n.BufferAttribute(i,3,!0);if(r.setAttribute("position",o),e){const i=new Float32Array(2*t.length);for(let t=0,n=e.length;t<n;t++)i[2*t]=e[t],i[2*t+1]=e[t];r.setAttribute("group",new n.BufferAttribute(i,1))}return r}class kr{constructor(t,e=!0){this.meshes=Rs(t),this.bvhs=new Map,this.visibleEdges=[],this.hiddenEdges=[],this.visibleGroupIndices=[],this.hiddenGroupIndices=[],this.groupKeyToIndex=null,this.hasGroups=!1,this.iterationTime=30,this.useWebGPU=e}reset(){this.visibleEdges.length=0,this.hiddenEdges.length=0,this.visibleGroupIndices.length=0,this.hiddenGroupIndices.length=0,this.groupKeyToIndex=null,this.hasGroups=!1}getVisibleLineGeometry(){return zr(this.visibleEdges,this.groupKeyToIndex?this.visibleGroupIndices:null)}getHiddenLineGeometry(){return zr(this.hiddenEdges,this.groupKeyToIndex?this.hiddenGroupIndices:null)}getGroupKeys(){return this.groupKeyToIndex?Object.fromEntries(this.groupKeyToIndex):{}}addEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.addEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*addEdgesGenerator(t,e={}){const{meshes:i,bvhs:n,visibleEdges:s,hiddenEdges:r,iterationTime:o}=this;let a=performance.now();Sr.startStep("Building mesh BVH");for(let t=0;t<i.length;t++){performance.now()-a>o&&(yield,a=performance.now());const e=i[t].geometry;if(!n.has(e)){const t=e.boundsTree||new is(e);n.set(e,t)}}let l=0;for(let t=0;t<i.length;t++){const e=i[t].geometry;l+=e.index?e.index.count/3:e.attributes.position.count/3}const c={};for(let e=0;e<t.length;e++)c[e]=[];Sr.startStep("Building line BVH");const h=new Hs(t,{maxLeafSize:2,strategy:2});Sr.startStep("BVHcast overlaps"),a=performance.now();const u={candidates:0,backFaceCulled:0,yBoundsCulled:0,xzBoundsCulled:0,triangleEdgeCulled:0,planeTrimCulled:0,distThresholdCulled:0,noOverlapCulled:0,used:0,totalEdges:t.length,totalTriangles:l},d=this.useWebGPU,p={};d&&(p._edgeOffsets=[],p._edgeCounts=[],p._meshOffsets=[],p._meshCounts=[],p._meshIndex=[],p.groupCount=0);for(let t=0;t<i.length;t++){performance.now()-a>o&&(e.onProgress&&e.onProgress(t,i.length),yield,a=performance.now());const s=i[t];d?Mr(h,n.get(s.geometry),s,p,t):wr(h,n.get(s.geometry),s,c,u)}if(d){let t=!1;for(Ir(p,i,h,c,u).then(()=>{t=!0});!t;)yield}const f=u.totalEdges*u.totalTriangles;if(Sr.setStat("Total edges",u.totalEdges.toLocaleString()),Sr.setStat("Total triangles",u.totalTriangles.toLocaleString()),Sr.setStat("Brute-force pairs (edges × triangles)",f.toLocaleString()),Sr.setStat("BVH candidate pairs",u.candidates.toLocaleString()),f>0&&Sr.setStat("BVH reduction",(u.candidates/f*100).toFixed(3)+"% of brute-force"),u.candidates>0){const t=u.candidates,e=e=>(e/t*100).toFixed(2)+"%";d||(Sr.setStat("Rejected: back-face culling",u.backFaceCulled.toLocaleString()+" ("+e(u.backFaceCulled)+")"),Sr.setStat("Rejected: Y-bounds (tri below edge)",u.yBoundsCulled.toLocaleString()+" ("+e(u.yBoundsCulled)+")"),Sr.setStat("Rejected: XZ-bounds (no 2D overlap)",u.xzBoundsCulled.toLocaleString()+" ("+e(u.xzBoundsCulled)+")"),Sr.setStat("Rejected: edge lies on triangle",u.triangleEdgeCulled.toLocaleString()+" ("+e(u.triangleEdgeCulled)+")"),Sr.setStat("Rejected: line above tri plane",u.planeTrimCulled.toLocaleString()+" ("+e(u.planeTrimCulled)+")"),Sr.setStat("Rejected: trimmed edge too small",u.distThresholdCulled.toLocaleString()+" ("+e(u.distThresholdCulled)+")"),Sr.setStat("Rejected: no projected overlap",u.noOverlapCulled.toLocaleString()+" ("+e(u.noOverlapCulled)+")")),Sr.setStat("Producing overlaps",u.used.toLocaleString()+" ("+e(u.used)+")")}Sr.startStep("Converting overlaps to lines");const m=this.hasGroups;for(let e=0;e<t.length;e++){performance.now()-a>o&&(yield,a=performance.now());const i=t[e],n=c[e],l=s.length,h=r.length;if(Is(i,n,!1,s),Is(i,n,!0,r),m){const t=i.groupIndex;for(let e=l;e<s.length;e++)this.visibleGroupIndices.push(t);for(let e=h;e<r.length;e++)this.hiddenGroupIndices.push(t)}}}}class Br{constructor(){this.iterationTime=30,this.angleThreshold=50,this.includeIntersectionEdges=!0,this.useWebGPU=!0}generateAsync(t,e={}){return new Promise((i,n)=>{const{signal:s}=e,r=this.generate(t,e);!function t(){if(s&&s.aborted)return void n(new Error("ProjectionGenerator: Process aborted via AbortSignal."));const e=r.next();e.done?i(e.value):requestAnimationFrame(t)}()})}*generate(t,e){const{iterationTime:i,angleThreshold:s,includeIntersectionEdges:r}=this,{onProgress:o=()=>{},visibilityCuller:a=null,groupFn:l=null}=e;if(Sr.reset(),Sr.startTotal(),t.isBufferGeometry&&(t=new n.Mesh(t)),a){Sr.startStep("Visibility culling");let e=!1;for(a.cull(t).then(i=>{(t=new n.Scene).children=i,e=!0});!e;)yield}const c=new Ws;c.iterationTime=i,c.thresholdAngle=s,c.projectionDirection.copy(Dr),Sr.startStep("Generating candidate edges"),o("Generating candidate edges");let h=[],u=l?[]:null;if(yield*c.getEdgesGenerator(t,h,u),r&&(Sr.startStep("Generating intersection edges"),o("Generating intersection edges"),yield*c.getIntersectionEdgesGenerator(t,h,u)),Sr.startStep("Pre-filtering edges"),o("Pre-filtering edges"),u){const t=[],e=[];for(let i=0;i<h.length;i++)Ts(h[i])||(t.push(h[i]),e.push(u[i]));h=t,u=e}else h=h.filter(t=>!Ts(t));yield;const d=new kr(t,this.useWebGPU);if(d.iterationTime=i,l&&u){const t=new Map;for(let e=0;e<h.length;e++){const i=l(u[e]);t.has(i)||t.set(i,t.size),h[e].groupIndex=t.get(i)}d.groupKeyToIndex=t,d.hasGroups=!0}return o("Building BVH & computing overlaps"),yield*d.addEdgesGenerator(h,{onProgress:o?(t,e)=>{o("Building BVH & computing overlaps",t/e,d)}:null}),Sr.printSummary(),d}}new n.Line3,new n.Line3,new n.Vector3;const Or=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"generator",new Br),e(this,"cullerPixelsPerMeter",.05),e(this,"projectionDirection",new u.Vector3(0,-1,0)),e(this,"nearPlane",-1/0),e(this,"farPlane",1/0),this.components.add(t.uuid,this),this.generator.includeIntersectionEdges=!1}async get(t,e,i){const n=this.components.get(bs),s=new u.Group,r=new Map;for(const[e,i]of Object.entries(t)){const t=n.list.get(e);if(!t)continue;const o=(await t.getItemsIdsWithGeometry()).filter(t=>i.has(t));if(0===o.length)continue;const a=await t.getItemsGeometry(o);for(const i in a){const n=a[i];for(const i of n){if(!(i.positions&&i.indices&&i.transform&&i.representationId))continue;const n=i.representationId;if(!r.has(n)){const t=new u.BufferGeometry;t.setAttribute("position",new u.Float32BufferAttribute(i.positions,3)),i.normals&&t.setAttribute("normal",new u.Float32BufferAttribute(i.normals,3)),t.setIndex(Array.from(i.indices)),r.set(n,t)}const o=r.get(n),a=new u.Mesh(o);a.applyMatrix4(i.transform),a.applyMatrix4(t.object.matrixWorld),a.updateWorldMatrix(!0,!0),a.userData._edgeProjectorModelId=e,a.userData._edgeProjectorLocalId=i.localId,s.add(a)}}}const o=this.projectionDirection.clone().normalize(),a=new u.Vector3(0,-1,0),l=(new u.Quaternion).setFromUnitVectors(o,a),c=(new u.Matrix4).makeRotationFromQuaternion(l),h=c.clone().invert();for(const t of s.children)t.applyMatrix4(c),t.updateWorldMatrix(!1,!1);if(s.traverse(t=>{const e=t;if(e.geometry&&!e.geometry.boundsTree){const t=e.geometry.index?e.geometry.index.count:e.geometry.attributes.position.count;e.geometry.groups.forEach(e=>{e.count===1/0&&(e.count=t-e.start)}),e.geometry.boundsTree=new is(e.geometry,{maxLeafSize:1,strategy:2})}}),this.nearPlane!==-1/0||this.farPlane!==1/0){const t=new u.Box3,e=[];for(const i of s.children){const n=i;n.geometry&&(t.setFromObject(n),(t.max.y<this.nearPlane||t.min.y>this.farPlane)&&e.push(n))}for(const t of e)s.remove(t)}const d=e.renderer.three,p=new xs(d,{pixelsPerMeter:this.cullerPixelsPerMeter}),f=await this.generator.generateAsync(s,{visibilityCuller:p,groupFn:t=>`${t.userData._edgeProjectorModelId??"unknown"}:${t.userData._edgeProjectorLocalId??0}`,onProgress:null==i?void 0:i.onProgress}),m=f.getVisibleLineGeometry(),g=f.getHiddenLineGeometry();m.applyMatrix4(h),g.applyMatrix4(h);const w=f.getGroupKeys(),y={};for(const[t,e]of Object.entries(w)){const i=t.lastIndexOf(":"),n=t.substring(0,i),s=Number(t.substring(i+1));y[e]={modelId:n,localId:s}}for(const t of r.values())t.dispose();return{visible:m,hidden:g,groups:y}}dispose(){this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}};e(Or,"uuid","f2e76c3a-8b1d-4d5e-9a3f-7c6b2d4e8f1a");let Vr=Or;class Lr{constructor(){e(this,"wasm",{path:"",absolute:!1,logLevel:p.LogLevel.LOG_LEVEL_OFF}),e(this,"webIfc",{COORDINATE_TO_ORIGIN:!0}),e(this,"autoSetWasm",!0),e(this,"customLocateFileHandler",null)}}const Nr=class t extends g{constructor(i){super(i),e(this,"onDisposed",new f),e(this,"onIfcStartedLoading",new f),e(this,"onIfcImporterInitialized",new f),e(this,"onSetup",new f),e(this,"settings",new Lr),e(this,"webIfc",new p.IfcAPI),e(this,"enabled",!0),this.components.add(t.uuid,this)}dispose(){this.webIfc=null,this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async setup(t){this.settings={...this.settings,...t},this.settings.autoSetWasm&&await this.autoSetWasm(),this.onSetup.trigger()}async load(t,e,i,n){const s=this.components.get(bs);if(!s.initialized)throw new Error("You need to initialize fragments first.");this.settings.autoSetWasm&&await this.autoSetWasm(),s.core.settings.autoCoordinate=e;const r=new h.IfcImporter;r.wasm.path=this.settings.wasm.path,r.wasm.absolute=this.settings.wasm.absolute,r.webIfcSettings=this.settings.webIfc,this.onIfcImporterInitialized.trigger(r),(null==n?void 0:n.instanceCallback)&&n.instanceCallback(r);const o=await r.process({...null==n?void 0:n.processData,bytes:t});return await s.core.load(o,{modelId:i,userData:null==n?void 0:n.userData})}async readIfcFile(t){const{path:e,absolute:i,logLevel:n}=this.settings.wasm;return this.webIfc.SetWasmPath(e,i),await this.webIfc.Init(this.settings.customLocateFileHandler||void 0),n&&this.webIfc.SetLogLevel(n),this.webIfc.OpenModel(t,this.settings.webIfc)}cleanUp(){try{this.webIfc.Dispose()}catch(t){console.log("Web-ifc wasn't disposed.")}this.webIfc=null,this.webIfc=new p.IfcAPI}async autoSetWasm(){const t=await fetch(`https://unpkg.com/@thatopen/components@${Oo.release}/package.json`);if(!t.ok)return void console.warn("Couldn't get openbim-components package.json. Set wasm settings manually.");const e=await t.json();if("web-ifc"in e.peerDependencies){const t=e.peerDependencies["web-ifc"];this.settings.wasm.path=`https://unpkg.com/web-ifc@${t}/`,this.settings.wasm.absolute=!0}else console.warn("Couldn't get web-ifc from peer dependencies in openbim-components. Set wasm settings manually.")}};e(Nr,"uuid","a659add7-1418-4771-a0d6-7d4d438e4624");let Fr=Nr;const Rr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),this.components.add(t.uuid,this)}async set(t,e){const i=this.components.get(bs),n=[];if(e)for(const[s,r]of Object.entries(e)){const e=i.list.get(s);e&&n.push(e.setVisible([...r],t))}else for(const e of i.list.values())n.push(e.setVisible(void 0,t));await Promise.all(n),await i.core.update(!0)}async isolate(t){await Promise.all([this.set(!1),this.set(!0,t)])}async toggle(t){const e=[],i=this.components.get(bs);for(const[n,s]of Object.entries(t)){const t=i.list.get(n);t&&e.push(t.toggleVisible([...s]))}await Promise.all(e),await i.core.update(!0)}async getVisibilityMap(t,e){const i=[],n=[],s=this.components.get(bs);if(e)for(const r of e){const e=s.list.get(r);e&&(i.push(e.modelId),n.push(e.getItemsByVisibility(t)))}else for(const e of s.list.values())i.push(e.modelId),n.push(e.getItemsByVisibility(t));const r=await Promise.all(n),o={};for(const[t,e]of i.entries())o[e]=r[t];return o}};e(Rr,"uuid","dd9ccf2d-8a21-4821-b7f6-2949add16a29");let Ur=Rr;const jr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"list",new h.DataSet),this.components.add(t.uuid,this)}dispose(e=!0){this.list.clear(),this.onDisposed.trigger(t.uuid),e&&(this.onDisposed.reset(),this.list.eventsEnabled=!1,this.list.dispose())}get(){const t=new u.Box3;for(const e of this.list)t.union(e);return t}async addFromModelIdMap(t){const e=this.components.get(bs),i=new u.Box3;for(const[n,s]of Object.entries(t)){const t=e.list.get(n);if(!t)continue;const r=await t.getMergedBox([...s]);i.union(r)}this.list.add(i)}addFromModels(t){const e=this.components.get(bs);for(const[i,n]of e.list)t&&!t.some(t=>t.test(i))||this.list.add(n.box)}async getCenter(t){this.list.clear(),await this.addFromModelIdMap(t);const e=this.get();this.list.clear();const i=new u.Vector3;return e.getCenter(i),i}async getCameraOrientation(t,e=1){const i=this.components.get(bs);this.list.clear();for(const[t,e]of i.list)this.list.add(e.box);const n=this.get();this.list.clear();const s=new u.Vector3;n.getCenter(s);const r=new u.Vector3;n.getSize(r);const o=Math.max(r.x,r.y,r.z)*e,a=new u.Vector3;switch(t){case"front":default:a.set(s.x,s.y,s.z+o);break;case"back":a.set(s.x,s.y,s.z-o);break;case"left":a.set(s.x-o,s.y,s.z);break;case"right":a.set(s.x+o,s.y,s.z);break;case"top":a.set(s.x,s.y+o,s.z);break;case"bottom":a.set(s.x,s.y-o,s.z)}return{position:a,target:s}}};e(jr,"uuid","d1444724-dba6-4cdd-a0c7-68ee1450d166");let $r=jr;class Wr{constructor(t,i){e(this,"name","Query"),e(this,"customData",{}),e(this,"_components"),e(this,"_queries",[]),e(this,"_aggregation","exclusive"),e(this,"result",null),e(this,"cache",!0),e(this,"serializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>t.source),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.serializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.serializeQueryParameters(t.relation.query):void 0}:void 0}}),e(this,"deserializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>new RegExp(t)),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.deserializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.deserializeQueryParameters(t.relation.query):void 0}:void 0}}),this._components=t,this.queries=i}set queries(t){this._queries=t,this.clearCache()}get queries(){return this._queries}set aggregation(t){t!==this._aggregation&&this.clearCache(),this._aggregation=t}get aggregation(){return this._aggregation}async test(t){const{modelIds:e,force:i}={force:!1,...t};if(this.result&&!i)return this.result;const n=this._components.get(Hr),s=await n.getItems(this.queries,{modelIds:e,aggregation:this.aggregation});return this.cache&&(this.result=s),s}clearCache(){this.result=null}serializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>t.source):t.value instanceof RegExp?t.value.source:t.value;return{name:t.name.source,value:e,type:t.type instanceof RegExp?t.type.source:t.type,negate:t.negate,itemIds:t.itemIds}}toJSON(){return{guid:this._components.get(Hr).list.getKey(this)??A.create(),name:this.name,customData:this.customData,queries:this.queries.map(this.serializeQueryParameters),aggregation:this.aggregation,cache:this.cache}}deserializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>new RegExp(t)):"string"==typeof t.value?new RegExp(t.value):t.value;return{name:new RegExp(t.name),value:e,type:t.type?new RegExp(t.type):void 0,negate:t.negate,itemIds:t.itemIds}}fromJSON(t){return this.name=t.name,this.customData=t.customData,this.aggregation=t.aggregation,this.cache=t.cache,this.queries=t.queries.map(this.deserializeQueryParameters),this}}const Gr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new h.DataMap),i.add(t.uuid,this)}async getItems(t,e){let i;if(e){const{modelIds:t,items:n}=e;if(n){const t=Object.keys(n);t.length>0&&(i=t.map(t=>new RegExp(`^${t}$`)))}else t&&(i=t)}const n=(null==e?void 0:e.aggregation)??"exclusive",s=this.components.get(bs),r=await Promise.all(t.map(async t=>{const n={};return await Promise.all(Array.from(s.list).map(async([s,r])=>{var o;if(i&&!i.some(t=>t.test(s)))return;const a=null==(o=null==e?void 0:e.items)?void 0:o[s],l=await r.getItemsByQuery(t,{localIds:a?[...a]:void 0});n[s]=new Set(l)})),n}));return"inclusive"===n?pe.join(r):pe.intersect(r)}create(t,e){const i=new Wr(this.components,e);return this.list.set(t,i),i}async addFromCategories(t){const e=new Set,i=this.components.get(bs);for(const[n,s]of i.list){if(t&&!t.some(t=>t.test(n)))continue;const i=(await s.getItemsWithGeometryCategories()).filter(t=>null!==t),r=new Set(i);for(const t of r)this.list.has(t)||(this.create(t,[{categories:[new RegExp(`^${t}$`)]}]),e.add(t))}return[...e]}import(t){const{data:e}=t,i=[];if(!e)return i;for(const t of e){const e=this.create(t.guid,[]);e.fromJSON(t),i.push(e)}return i}export(){const t=[];for(const[e,i]of this.list.entries()){const n={...i.toJSON(),name:e};t.push(n)}return{data:t}}};e(Gr,"uuid","0da7ad77-f734-42ca-942f-a074adfd1e3a");let Hr=Gr;const qr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"list",new h.DataMap),e(this,"defaultSaveFunction",t=>"value"in t.Name?t.Name.value:null),e(this,"onBeforeFragmentsDispose",async t=>{const{key:e,value:i}=t,n=await i.getLocalIds(),s={[e]:new Set(n)};this.removeItems(s)}),i.add(t.uuid,this),this.setupEvents();i.get(bs).list.onBeforeDelete.add(this.onBeforeFragmentsDispose)}setupEvents(){this.list.onBeforeDelete.add(({value:t})=>t.dispose())}getClassificationGroups(t){let e=this.list.get(t);return e||(e=new h.DataMap,this.list.set(t,e)),e}getModelItems(t,e,i){const{map:n}=this.getGroupData(t,e);let s=n[i];return s||(s=new Set,n[i]=s),s}getGroupData(t,e){const i=this.components.get(Hr),n=this.getClassificationGroups(t);let s=n.get(e);return s||(s={map:{},get:()=>new Promise(t=>{if(s)if(s.query){const{name:e,config:n}=s.query,r=i.list.get(e);if(!r)throw new Error("Classifier: the query name associated with the group doesn't exist in the ItemsFinder component");r.test(n).then(e=>{if(!s)return void t({});const i=pe.join([e,s.map]);t(i)})}else t(s.map);else t({})})},n.set(e,s)),s}async aggregateItems(t,e,i){const n=(null==i?void 0:i.data)??void 0,s=(null==i?void 0:i.aggregationCallback)??this.defaultSaveFunction,r=this.components.get(bs),o=this.components.get(Hr),a=await o.getItems([e],{modelIds:null==i?void 0:i.modelIds});for(const[e,i]of Object.entries(a)){const o=r.list.get(e);if(!o)continue;const a=(i,...n)=>{const s=this.getModelItems(t,i,e);for(const t of n)s.add(t)},l=await o.getItemsData([...i],n);for(const t of l)s(t,a)}}addGroupItems(t,e,i){const{map:n}=this.getGroupData(t,e);pe.add(n,i)}setGroupQuery(t,e,i){this.getGroupData(t,e).query=i}async find(t){const e=[];for(const[i,n]of Object.entries(t)){const t=[],s=this.list.get(i);if(!s)continue;for(const e of n){const i=s.get(e);if(!i)continue;const n=await i.get();t.push(n)}const r=pe.join(t);e.push(r)}return pe.intersect(e)}async aggregateItemRelations(t,e,i,n){const s=(null==n?void 0:n.attribute)??"Name",r={relations:{[i]:{attributes:!0,relations:!1}}};await this.aggregateItems(t,e,{modelIds:null==n?void 0:n.modelIds,data:r,aggregationCallback:(t,e)=>{if(!(null==t?void 0:t[s]))return;const n=t[s];if(!("value"in n))return;const r=t[i];if(Array.isArray(r))for(const t of r)"value"in t._localId&&e(n.value,t._localId.value)}})}async byIfcBuildingStorey(t){await this.aggregateItemRelations((null==t?void 0:t.classificationName)??"Storeys",{categories:[/BUILDINGSTOREY/]},"ContainsElements",{modelIds:null==t?void 0:t.modelIds})}async byCategory(t){const e=this.components.get(Hr),i=await e.addFromCategories(null==t?void 0:t.modelIds);for(const e of i)this.setGroupQuery((null==t?void 0:t.classificationName)??"Categories",e,{name:e})}dispose(){this.list.clear();this.components.get(bs).list.onBeforeDelete.remove(this.onBeforeFragmentsDispose),this.onDisposed.trigger()}removeItems(t,e){if(e&&e.classificationName){const i=this.list.get(e.classificationName);if(!i)return;if(e.groupName){if(!i.get(e.groupName))return}for(const[,e]of i)pe.remove(e.map,t);return}for(const[,e]of this.list.entries())for(const[,i]of e)pe.remove(i.map,t)}async byModel(t){const e=this.components.get(bs),i=(null==t?void 0:t.classificationName)??"Models";for(const[n,s]of e.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(n)))continue;const e=await s.getItemsIdsWithGeometry(),r={[n]:new Set(e)};this.getGroupData(i,n),this.addGroupItems(i,n,r)}}};e(qr,"uuid","e25a7f3c-46c4-4a14-9d3d-5115f24ebeb7");let Zr=qr;const Yr=class t{constructor(t,i){if(e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new f),e(this,"mouse"),e(this,"world"),e(this,"debugMode",!1),e(this,"_renderTarget"),e(this,"_renderTargetSize",new u.Vector2),e(this,"_debugCanvas"),e(this,"_debugContainer"),e(this,"_idMaterial"),e(this,"_depthMaterial"),e(this,"_normalMaterial"),e(this,"_originalMaterials",new Map),e(this,"_hiddenLods",[]),e(this,"_ownMeshes",new Map),!i.renderer)throw new Error("A renderer is needed for the FastModelPicker to work!");this.world=i,this.mouse=new _e(i.renderer.three.domElement),this.components=t,this._idMaterial=this.buildIdMaterial(),this._depthMaterial=this.buildDepthMaterial(),this._normalMaterial=this.buildNormalMaterial(),this.setupRenderTarget()}async getModelAt(t){const e=await this.runIdPass(t);return e?e.modelId:null}async getItemAt(t){const e=await this.runIdPass(t);if(!e)return null;const i=this.components.get(bs).list.get(e.modelId);if(!i)return null;const n=await i.getLocalIdsFromItemIds([e.itemId]),s=null==n?void 0:n[0];return null==s?null:{modelId:e.modelId,localId:s,itemId:e.itemId}}async getPointAt(t){if(!this.enabled)return null;if(!this._renderTarget||!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;this.renderDepthPass();const i=t??this.mouse.position,n=this.readPixelAt(i);if(!n)return null;if(0===n[0]&&0===n[1]&&0===n[2]&&0===n[3])return null;const s=function(t){const e=t[0]/255,i=t[1]/255,n=t[2]/255,s=t[3]/255;return 255/256*(e/16777216+i/65536+n/256+s)}(n);return s>=.999999?null:function(t,e,i){const n=new u.Vector3(t.x,t.y,2*e-1);return n.unproject(i),n}(i,s,this.world.camera.three)}async getNormalAt(t){if(!this.enabled)return null;if(!this._renderTarget||!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;this.renderNormalPass();const i=t??this.mouse.position,n=this.readPixelAt(i);if(!n)return null;if(0===n[3])return null;const s=n[0]/255*2-1,r=n[1]/255*2-1,o=n[2]/255*2-1,a=new u.Vector3(s,r,o);return a.lengthSq()<1e-8?null:a.normalize()}async getFullPick(t){const e=await this.getItemAt(t);if(!e)return null;const i=await this.getPointAt(t);if(!i)return null;const n=await this.getNormalAt(t),s=i.distanceTo(this.world.camera.three.position);return{...e,point:i,normal:n,distance:s}}setDebugMode(t){this.debugMode=t,t?this.setupDebugCanvas():this.removeDebugCanvas()}dispose(){this.mouse.dispose(),this.removeDebugCanvas(),this._idMaterial.dispose(),this._depthMaterial.dispose(),this._normalMaterial.dispose(),this._renderTarget&&this._renderTarget.dispose(),this._renderTarget=void 0,this._originalMaterials.clear(),this._hiddenLods.length=0,this.onDisposed.trigger(),this.onDisposed.reset()}async runIdPass(t){if(!this.enabled)return null;if(!this._renderTarget)return null;if(!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;const i=this.applyIdMaterial();if(0===i.size)return this.restoreOriginalMaterials(),null;const n=t??this.mouse.position;this.renderIdPass(i,n),this.restoreOriginalMaterials(),this.debugMode&&this._debugCanvas&&this.updateDebugCanvas();const s=this.readPixelAt(this._renderTarget,n);if(!s)return null;const r=s[0];if(0===r)return null;const o=i.get(r);if(!o)return null;const a=s[1]<<16|s[2]<<8|s[3];if(0===a)return null;return{modelId:o,itemId:a-1}}applyIdMaterial(){const e=this.components.get(bs),i=new Map,n=this.getModelRoots();this._ownMeshes.clear();let s=1;for(const[r,o]of e.list){if(s>t.MAX_MODELS)break;const e=[];this.traverseOwn(o.object,n,t=>{if(!(t instanceof u.Mesh))return;const i=t.geometry;if(!i)return;if(!i.attributes||!i.attributes.id)return void(t.visible&&(this._hiddenLods.push(t),t.visible=!1));this._originalMaterials.set(t,t.material);const n=t.material,s=Array.isArray(n)?n.length:1;t.material=new Array(s).fill(this._idMaterial),e.push(t)}),e.length&&(this._ownMeshes.set(r,e),i.set(s,r),s+=1)}return i}getModelRoots(){const t=this.components.get(bs),e=new Set;for(const[,i]of t.list)e.add(i.object);return e}traverseOwn(t,e,i){const n=[t];for(;n.length;){const s=n.pop();if(s===t||!e.has(s)){i(s);for(const t of s.children)n.push(t)}}}renderIdPass(t,e){this.renderPickPass(t,this._renderTarget,this._idMaterial,e)}renderPickPass(t,e,i,n){const s=this.world.renderer.three,r=this.world.scene.three,o=this.world.camera.three,a=this.components.get(bs),l=s.clippingPlanes??[];i.clippingPlanes=l,i.clipping=l.length>0;const c=s.getRenderTarget(),h=s.autoClear,d=s.getClearColor(new u.Color),p=s.getClearAlpha(),f=s.getScissorTest(),m=s.getScissor(new u.Vector4);s.setRenderTarget(e),s.setClearColor(0,0),s.autoClear=!1,s.setScissorTest(!1),s.clear(!0,!0,!1);const g=e.width,w=e.height,y=Math.floor(.5*(n.x+1)*g),_=Math.floor(.5*(n.y+1)*(w-1)),b=Math.max(0,Math.min(g-4,y-2)),v=Math.max(0,Math.min(w-4,_-2)),x=s.getPixelRatio();s.setScissor(b/x,v/x,4/x,4/x),s.setScissorTest(!0);const C=new Map;for(const[t,e]of a.list)C.set(t,e.object);const S=new Set(C.values()),A=new Map;r.traverse(t=>{t!==r&&t.isMesh&&((t=>{let e=t;for(;e;){if(S.has(e))return!0;e=e.parent}return!1})(t)||(A.set(t,t.visible),t.visible=!1))});const P=new Map;for(const[t,e]of C){let i=!0,n=e;for(;n;){if(!n.visible){i=!1;break}n=n.parent}P.set(t,i)}const T=new Map;for(const t of C.values())T.set(t,t.visible),t.visible=!0;const M=new Map;for(const t of this._ownMeshes.values())for(const e of t)M.set(e,e.visible),e.visible=!1;for(const[e,n]of t){if(!P.get(n))continue;const t=this._ownMeshes.get(n);if(t){for(const e of t)e.visible=M.get(e);i.uniforms.modelByte.value=e,s.render(r,o);for(const e of t)e.visible=!1}}for(const[t,e]of M)t.visible=e;for(const[t,e]of T)t.visible=e;for(const[t,e]of A)t.visible=e;s.setScissorTest(f),s.setScissor(m),s.setRenderTarget(c),s.autoClear=h,s.setClearColor(d,p)}renderWithTileMaterial(t){const e=this.world.renderer.three,i=this.world.scene.three,n=this.world.camera.three,s=this.components.get(bs),r=e.clippingPlanes??[];t.clippingPlanes=r,t.clipping=r.length>0;const o=e.getRenderTarget(),a=e.autoClear,l=e.getClearColor(new u.Color),c=e.getClearAlpha(),h=new Map,d=[],p=this.getModelRoots();for(const[,e]of s.list)this.traverseOwn(e.object,p,e=>{if(!(e instanceof u.Mesh))return;const i=e.geometry;if(!i)return;if(!i.attributes||!i.attributes.id)return void(e.visible&&(d.push(e),e.visible=!1));if(!e.visible)return;h.set(e,e.material);const n=e.material,s=Array.isArray(n)?n.length:1;e.material=new Array(s).fill(t)});const f=new Set;for(const[,t]of s.list)f.add(t.object);const m=new Map;i.traverse(t=>{t!==i&&t.isMesh&&((t=>{let e=t;for(;e;){if(f.has(e))return!0;e=e.parent}return!1})(t)||(m.set(t,t.visible),t.visible=!1))}),e.setRenderTarget(this._renderTarget),e.setClearColor(0,0),e.autoClear=!1,e.clear(!0,!0,!1),e.render(i,n);for(const[t,e]of h)t.material=e;for(const t of d)t.visible=!0;for(const[t,e]of m)t.visible=e;e.setRenderTarget(o),e.autoClear=a,e.setClearColor(l,c)}renderDepthPass(){this.renderWithTileMaterial(this._depthMaterial)}renderNormalPass(){this.renderWithTileMaterial(this._normalMaterial)}restoreOriginalMaterials(){for(const[t,e]of this._originalMaterials)t.material=e;this._originalMaterials.clear(),this._ownMeshes.clear();for(const t of this._hiddenLods)t.visible=!0;this._hiddenLods.length=0}readPixelAt(t,e){let i,n;t instanceof u.WebGLRenderTarget?(i=t,n=e):(i=this._renderTarget,n=t);const s=this.world.renderer.three,r=this._renderTargetSize,o=Math.floor(.5*(n.x+1)*r.x),a=Math.floor(.5*(n.y+1)*(r.y-1)),l=Math.max(0,Math.min(r.x-1,o)),c=Math.max(0,Math.min(r.y-1,a)),h=new Uint8Array(4);return s.readRenderTargetPixels(i,l,c,1,1,h),h}buildIdMaterial(){return new u.ShaderMaterial({uniforms:{modelByte:{value:1}},vertexShader:"\n attribute vec4 id;\n varying vec4 vId;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vId = id;\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n precision highp float;\n uniform float modelByte;\n varying vec4 vId;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n gl_FragColor = vec4(modelByte / 255.0, vId.y / 255.0, vId.z / 255.0, vId.w / 255.0);\n }\n ",side:u.DoubleSide})}buildDepthMaterial(){return new u.ShaderMaterial({uniforms:{},vertexShader:"\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n float v = gl_FragCoord.z;\n vec4 r = vec4(\n fract(v * 16777216.0),\n fract(v * 65536.0),\n fract(v * 256.0),\n v\n );\n r.yzw -= r.xyz * (1.0 / 256.0);\n gl_FragColor = r * (256.0 / 255.0);\n }\n ",side:u.DoubleSide})}buildNormalMaterial(){return new u.ShaderMaterial({uniforms:{},vertexShader:"\n varying vec3 vWorldNormal;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vWorldNormal = normalize(\n (modelMatrix * vec4(normal, 0.0)).xyz\n );\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n varying vec3 vWorldNormal;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n vec3 n = normalize(vWorldNormal);\n if (!gl_FrontFacing) n = -n;\n gl_FragColor = vec4(n * 0.5 + 0.5, 1.0);\n }\n ",side:u.DoubleSide})}setupRenderTarget(){const t=this.world.renderer.three.getSize(new u.Vector2);this._renderTargetSize.copy(t);const e={format:u.RGBAFormat,type:u.UnsignedByteType,minFilter:u.NearestFilter,magFilter:u.NearestFilter,depthBuffer:!0};this._renderTarget=new u.WebGLRenderTarget(t.x,t.y,e),this.debugMode&&this.setupDebugCanvas(),this.world.renderer.onResize.add(t=>{this._renderTargetSize.copy(t),this._renderTarget.setSize(t.x,t.y),this._debugCanvas&&(this._debugCanvas.width=t.x,this._debugCanvas.height=t.y)})}setupDebugCanvas(){if(this._debugCanvas)return;const t=this.world.renderer.three.getSize(new u.Vector2);this._debugContainer=document.createElement("div"),this._debugContainer.style.position="fixed",this._debugContainer.style.top="10px",this._debugContainer.style.right="10px",this._debugContainer.style.width="300px",this._debugContainer.style.height="300px",this._debugContainer.style.border="2px solid #fff",this._debugContainer.style.backgroundColor="#000",this._debugContainer.style.zIndex="10000",this._debugContainer.style.pointerEvents="none",this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=t.x,this._debugCanvas.height=t.y,this._debugCanvas.style.width="100%",this._debugCanvas.style.height="100%",this._debugCanvas.style.imageRendering="pixelated",this._debugContainer.appendChild(this._debugCanvas),document.body.appendChild(this._debugContainer)}removeDebugCanvas(){this._debugContainer&&(this._debugContainer.remove(),this._debugContainer=void 0,this._debugCanvas=void 0)}updateDebugCanvas(){if(!this._debugCanvas||!this._renderTarget||!this.world.renderer)return;const t=this.world.renderer.three,e=this._renderTargetSize,i=new Uint8Array(e.x*e.y*4);t.readRenderTargetPixels(this._renderTarget,0,0,e.x,e.y,i);const n=this._debugCanvas.getContext("2d");if(!n)return;const s=n.createImageData(e.x,e.y),r=4*e.x;for(let t=0;t<e.y;t++){const n=t*r,o=(e.y-1-t)*r;s.data.set(i.subarray(n,n+r),o)}n.putImageData(s,0,0)}};e(Yr,"MAX_MODELS",254);let Xr=Yr;const Kr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new f),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new Xr(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(Kr,"uuid","4a82430c-7ff2-49ea-9401-60807502dad6");let Qr=Kr;var Jr=(t=>(t[t.POINT=0]="POINT",t[t.LINE=1]="LINE",t[t.FACE=2]="FACE",t))(Jr||{});const to=1e3;class eo{constructor(t){e(this,"onDisposed",new f),e(this,"maxDistance",1),e(this,"maxCacheSize",1e3),e(this,"components"),e(this,"_precision","half"),e(this,"cache",new Map),this.components=t}get precision(){return this._precision}set precision(t){t!==this._precision&&(this._precision=t,this.clear())}dispose(){this.cache.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}async resolve(t,e,i,n){const s=eo.keyOf(e,i);let r=this.cache.get(s);if(r)this.cache.delete(s),this.cache.set(s,r);else{if(r=await this.fetchItemSnapData(e,i),!r)return null;this.storeWithLRU(s,r)}const o=this.snap(t,r,2),a=new Set(n),l=[0,1,2];let c=null;for(const e of l){if(!a.has(e))continue;const i=this.snap(t,r,e);if(i){c=i.result;break}}if(!c)return o?o.result:null;if(o&&2!==c.snappingClass){const t=o.result;!c.normal&&t.normal&&(c.normal=t.normal),!c.facePoints&&t.facePoints&&(c.facePoints=t.facePoints),!c.faceIndices&&t.faceIndices&&(c.faceIndices=t.faceIndices)}return c}async prefetch(t,e){const i=eo.keyOf(t,e);if(this.cache.has(i))return;const n=await this.fetchItemSnapData(t,e);n&&this.storeWithLRU(i,n)}invalidate(t,e){const i=eo.keyOf(t,e);this.cache.delete(i)}clear(){this.cache.clear()}static keyOf(t,e){return`${t}:${e}`}storeWithLRU(t,e){for(this.cache.set(t,e);this.cache.size>this.maxCacheSize;){const t=this.cache.keys().next().value;if(void 0===t)break;this.cache.delete(t)}}async fetchItemSnapData(t,e){const i=this.components.get(bs).list.get(t);if(!i)return null;const n=await i._getItemSnapData(e);if(!n)return null;const s=i.object.matrixWorld,r=[];for(const t of Object.keys(n.samples??{})){const e=n.samples[Number(t)],i=n.representations[e.representation];if(!i||1!==i.representationClass)continue;const o=i.geometry;if(!o)continue;const a=n.localTransforms[e.localTransform],l=co(s,n.globalTransforms[e.item],a);this.collectPolygonsFromShell(o,l,r)}if(0===r.length)return null;return{faces:r,edges:function(t,e){const i=new Set,n=[];for(const e of t){const t=e.points,s=t.length/3;for(let e=0;e<s;e++){const r=(e+1)%s,o=t[3*e],a=t[3*e+1],l=t[3*e+2],c=t[3*r],h=t[3*r+1],u=t[3*r+2],d=po(o,a,l,c,h,u);i.has(d)||(i.add(d),n.push(o,a,l,c,h,u))}}return new("full"===e?Float64Array:Float32Array)(n)}(r,this._precision),vertices:function(t,e){const i=new Set,n=[];for(const e of t){const t=e.points,s=t.length/3;for(let e=0;e<s;e++){const s=t[3*e],r=t[3*e+1],o=t[3*e+2],a=uo(s,r,o);i.has(a)||(i.add(a),n.push(s,r,o))}}return new("full"===e?Float64Array:Float32Array)(n)}(r,this._precision)}}collectPolygonsFromShell(t,e,i){const n=t.points,s=t.profiles??new Map,r=t.bigProfiles??new Map,o=new u.Vector3,a=t=>{if(t.length<3)return;const s=new("full"===this._precision?Float64Array:Float32Array)(3*t.length);for(let i=0;i<t.length;i++){const r=n[t[i]];o.set(r[0],r[1],r[2]).applyMatrix4(e),s[3*i]=o.x,s[3*i+1]=o.y,s[3*i+2]=o.z}const r=function(t){const e=new u.Vector3,i=t.length/3;for(let n=0;n<i;n++){const s=(n+1)%i,r=t[3*n],o=t[3*n+1],a=t[3*n+2],l=t[3*s],c=t[3*s+1],h=t[3*s+2];e.x+=(o-c)*(a+h),e.y+=(a-h)*(r+l),e.z+=(r-l)*(o+c)}const n=e.length();return n<1e-10?null:e.divideScalar(n)}(s);if(!r)return;const a=r.x*s[0]+r.y*s[1]+r.z*s[2];i.push({points:s,normal:r,d:a})};for(const t of s.values())a(t);for(const t of r.values())a(t)}snap(t,e,i){return 0===i?this.snapToPoint(t,e):1===i?this.snapToLine(t,e):2===i?this.snapToFace(t,e):null}snapToPoint(t,e){const i=e.vertices;if(0===i.length)return null;const n=this.maxDistance*this.maxDistance;let s=-1,r=1/0;for(let e=0;e<i.length;e+=3){const o=i[e]-t.x,a=i[e+1]-t.y,l=i[e+2]-t.z,c=o*o+a*a+l*l;c<=n&&c<r&&(r=c,s=e)}return s<0?null:{result:{point:new u.Vector3(i[s],i[s+1],i[s+2]),snappingClass:0}}}snapToLine(t,e){const i=e.edges;if(0===i.length)return null;const n=this.maxDistance*this.maxDistance,s=new u.Vector3,r=new u.Vector3;let o=1/0,a=-1;for(let e=0;e<i.length;e+=6){const l=fo(t,i[e],i[e+1],i[e+2],i[e+3],i[e+4],i[e+5],r);l<=n&&l<o&&(o=l,a=e,s.copy(r))}return a<0?null:{result:{point:s.clone(),snappingClass:1,snappedEdgeP1:new u.Vector3(i[a],i[a+1],i[a+2]),snappedEdgeP2:new u.Vector3(i[a+3],i[a+4],i[a+5])}}}snapToFace(t,e){const i=e.faces;if(0===i.length)return null;let n=null,s=1/0,r=!1;for(const e of i){const i=this.signedDistance(e,t),o=Math.abs(i);if(o>this.maxDistance)continue;const a=this.containsPoint(e,this.projectOntoPlane(t,e,i));r&&!a||(!a||r?o<s&&(s=o,n=e):(r=!0,s=o,n=e))}if(!n)return null;return{result:{point:this.projectOntoPlane(t,n,this.signedDistance(n,t)),normal:n.normal.clone(),snappingClass:2,facePoints:n.points,faceIndices:ho(n.points.length/3)}}}signedDistance(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z-t.d}projectOntoPlane(t,e,i){return t.clone().sub(e.normal.clone().multiplyScalar(i))}containsPoint(t,e){const{points:i,normal:n}=t,s=i.length/3;if(s<3)return!1;const r=Math.abs(n.x),o=Math.abs(n.y),a=Math.abs(n.z);let l=0,c=1;r>=o&&r>=a?(l=1,c=2):o>=a&&(l=0,c=2);const h=e.getComponent(l),u=e.getComponent(c);let d=!1;for(let t=0,e=s-1;t<s;e=t,t+=1){const n=i[3*t+l],s=i[3*t+c],r=i[3*e+l],o=i[3*e+c];if(!(s>u!=o>u))continue;h<(r-n)*(u-s)/(o-s)+n&&(d=!d)}return d}}const io=new u.Matrix4,no=new u.Vector3,so=new u.Vector3,ro=new u.Vector3;function oo(t,e){if(!t)return e.identity();const i=t.position[0],n=t.position[1],s=t.position[2];return no.set(t.xDirection[0],t.xDirection[1],t.xDirection[2]),so.set(t.yDirection[0],t.yDirection[1],t.yDirection[2]),ro.crossVectors(no,so),e.set(no.x,so.x,ro.x,i,no.y,so.y,ro.y,n,no.z,so.z,ro.z,s,0,0,0,1),e}const ao=new u.Matrix4,lo=new u.Matrix4;function co(t,e,i){return oo(e,ao),oo(i,lo),io.copy(t).multiply(ao).multiply(lo).clone()}function ho(t){if(t<3)return new Uint32Array(0);const e=t-2,i=new Uint32Array(3*e);for(let t=0;t<e;t++)i[3*t]=0,i[3*t+1]=t+1,i[3*t+2]=t+2;return i}function uo(t,e,i){return`${Math.round(t*to)},${Math.round(e*to)},${Math.round(i*to)}`}function po(t,e,i,n,s,r){const o=uo(t,e,i),a=uo(n,s,r);return o<a?`${o}|${a}`:`${a}|${o}`}function fo(t,e,i,n,s,r,o,a){const l=s-e,c=r-i,h=o-n,u=l*l+c*c+h*h;let d=0;u>0&&(d=((t.x-e)*l+(t.y-i)*c+(t.z-n)*h)/u,d<0?d=0:d>1&&(d=1));const p=e+d*l,f=i+d*c,m=n+d*h;a.set(p,f,m);const g=t.x-p,w=t.y-f,y=t.z-m;return g*g+w*w+y*y}const mo=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"_resolver"),i.add(t.uuid,this),this._resolver=new eo(i)}get(){return this._resolver}dispose(){this._resolver.dispose(),this.onDisposed.trigger()}};e(mo,"uuid","be9b8e6c-7f5b-4a36-8e7e-3a1f5e2a6c9d");let go=mo;class wo{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new f),e(this,"mouse"),e(this,"three",new u.Raycaster),e(this,"world");const n=i.renderer;if(!n)throw new Error("A renderer is needed for the raycaster to work!");this.world=i,this.mouse=new _e(n.three.domElement),this.components=t}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRayToObjects(t=Array.from(this.world.meshes),e=this.mouse.position){if(!this.world)throw new Error("A world is needed to cast rays!");const i=this.world.camera.three;return this.three.setFromCamera(e,i),this.intersect(t)}async castRay(t){const e=null==t?void 0:t.snappingClasses,i=(null==t?void 0:t.items)??Array.from(this.world.meshes),n=(null==t?void 0:t.position)??this.mouse.position;if(!this.world)throw new Error("A world is needed to cast rays!");const s=this.world.camera.three,r=this.components.get(bs);let o=null;if(r.initialized){const t=this.components.get(Qr).get(this.world),a=await t.getFullPick(n);if(a){const t=r.list.get(a.modelId);if(o={localId:a.localId,point:a.point,normal:a.normal,distance:a.distance,fragments:t,object:null==t?void 0:t.object,ray:void 0,frustum:void 0},e&&e.length>0){const t=await this.components.get(go).get().resolve(a.point,a.modelId,a.itemId,e);t&&(o.point=t.point,t.normal&&(o.normal=t.normal),o.snappingClass=t.snappingClass,t.facePoints&&(o.facePoints=t.facePoints),t.faceIndices&&(o.faceIndices=t.faceIndices),t.snappedEdgeP1&&(o.snappedEdgeP1=t.snappedEdgeP1),t.snappedEdgeP2&&(o.snappedEdgeP2=t.snappedEdgeP2),o.distance=t.point.distanceTo(s.position))}}if(0===i.length)return o}this.three.setFromCamera(n,s);const a=this.intersect(i);return o?a&&a.distance<o.distance?a:o:a}castRayFromVector(t,e,i=Array.from(this.world.meshes)){return this.three.set(t,e),this.intersect(i)}intersect(t=Array.from(this.world.meshes)){const e=this.three.intersectObjects(t),i=this.filterClippingPlanes(e);return i.length>0?i[0]:null}filterClippingPlanes(t){if(!this.world.renderer)throw new Error("Renderer not found!");const e=this.world.renderer.three;if(!e.clippingPlanes)return t;const i=e.clippingPlanes;return t.length<=0||!i||(null==i?void 0:i.length)<=0?t:t.filter(t=>i.every(e=>e.distanceToPoint(t.point)>0))}}const yo=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new f),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new wo(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(yo,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let _o=yo;class bo extends m{constructor(){super(...arguments),e(this,"onCameraChanged",new f),e(this,"meshes",new Set),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"isDisposing",!1),e(this,"enabled",!0),e(this,"_dynamicAnchor",!1),e(this,"_anchorRequestId",0),e(this,"uuid",A.create()),e(this,"name"),e(this,"_scene"),e(this,"_camera"),e(this,"_renderer",null),e(this,"onPointerDown",t=>{if(!this.camera.hasCameraControls())throw new Error("World: can't set dynamic anchor if the camera doesn't have controls.");if(0!==t.button)return;const e=this.getPointerPosition(t);if(!e)return;const i=this.components.get(_o).get(this),n=this.getPlaneAnchor(i,e);n&&this.camera.controls.setOrbitPoint(n.x,n.y,n.z);const s=++this._anchorRequestId;i.castRay({position:e}).then(t=>{if(s!==this._anchorRequestId||this.isDisposing||!this._dynamicAnchor)return;if(!(null==t?void 0:t.point)||!this.camera.hasCameraControls())return;const{x:e,y:i,z:n}=t.point;this.camera.controls.setOrbitPoint(e,i,n)})}),e(this,"_defaultCamera")}set dynamicAnchor(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(!i)throw new Error("World: the renderer must have a parentElement to set dynamic anchoring.");t?(this.camera.controls&&(this.camera.controls.minDistance=.01),i.addEventListener("pointerdown",this.onPointerDown)):i.removeEventListener("pointerdown",this.onPointerDown),this._dynamicAnchor=t}get dynamicAnchor(){return this._dynamicAnchor}getPointerPosition(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement;if(!i)return null;const n=i.getBoundingClientRect();return new u.Vector2((t.clientX-n.left)/(n.right-n.left)*2-1,-(t.clientY-n.top)/(n.bottom-n.top)*2+1)}getPlaneAnchor(t,e){if(!this.camera.hasCameraControls())return null;const i=this.camera.three;t.three.setFromCamera(e,i);const n=this.camera.controls.getTarget(new u.Vector3),s=i.getWorldDirection(new u.Vector3),r=(new u.Plane).setFromNormalAndCoplanarPoint(s,n);return t.three.ray.intersectPlane(r,new u.Vector3)}get defaultCamera(){if(!this._defaultCamera)throw new Error("World: there is no default camera defined.");return this._defaultCamera}set defaultCamera(t){this._defaultCamera=t}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera||(this.defaultCamera=t),this._camera=t,t.currentWorld=this,this.onCameraChanged.trigger(t)}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}useDefaultCamera(){this.camera=this.defaultCamera}update(t){this.enabled&&this._scene&&this._camera&&(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger())}dispose(t=!0){var e;if(this.isDisposing)return;this.enabled=!1,this.isDisposing=!0;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(i&&i.removeEventListener("pointerdown",this.onPointerDown),this._dynamicAnchor=!1,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const t=this.components.get(v);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const e of this.meshes)t.destroy(e);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(Eo).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class vo{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(t){this._list.directionalLight.color.value=t;for(const[,e]of this._scene.directionalLights)e.color.copy(t)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(t){this._list.directionalLight.intensity.value=t;for(const[,e]of this._scene.directionalLights)e.intensity=t}get position(){return this._list.directionalLight.position.value.clone()}set position(t){this._list.directionalLight.position.value=t;for(const[,e]of this._scene.directionalLights)e.position.copy(t)}}class xo{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(t){this._list.ambientLight.color.value=t;for(const[,e]of this._scene.ambientLights)e.color.copy(t)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(t){this._list.ambientLight.intensity.value=t;for(const[,e]of this._scene.ambientLights)e.intensity=t}}class Co extends ge{constructor(){super(...arguments),e(this,"_config",{backgroundColor:{value:new u.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new u.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new u.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new u.Vector3}}}),e(this,"ambientLight",new xo(this._config,this._component)),e(this,"directionalLight",new vo(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class So extends x{constructor(t){super(t),e(this,"onSetup",new f),e(this,"isSetup",!1),e(this,"three"),e(this,"config",new Co(this,this.components,"Scene")),e(this,"_defaultConfig",{backgroundColor:new u.Color(2107698),directionalLight:{color:new u.Color("white"),intensity:1.5,position:new u.Vector3(5,10,3)},ambientLight:{color:new u.Color("white"),intensity:1}}),this.three=new u.Scene,this.three.background=new u.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const i=e.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const n=e.directionalLight;this.config.directionalLight.color=n.color,this.config.directionalLight.intensity=n.intensity,this.config.directionalLight.position=n.position,this.deleteAllLights();const{color:s,intensity:r}=this.config.directionalLight,o=new u.DirectionalLight(s,r);o.position.copy(n.position);const{color:a,intensity:l}=this.config.directionalLight,c=new u.AmbientLight(a,l);this.three.add(o,c),this.directionalLights.set(o.uuid,o),this.ambientLights.set(c.uuid,c),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get(ye).list.delete(this.config.uuid)}}const Ao='\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 40" fill="none" aria-label="That Open Company">\n<path d="M42.2856 19.6517V8.4048H38.8676V7.14978H46.998V8.40976H43.6131V19.6566L42.2856 19.6517Z" fill="#BCF124"/>\n<path d="M48.459 19.6516V7.14978H49.7032V12.404L49.4204 12.3371C49.6285 11.7727 50.0095 11.2904 50.5078 10.9607C51.0285 10.6201 51.638 10.4449 52.2578 10.4577C52.853 10.4483 53.44 10.5988 53.9589 10.8938C54.456 11.1789 54.8687 11.5934 55.1541 12.0943C55.449 12.6164 55.6 13.2089 55.5913 13.8102V19.6516H54.3495V14.2958C54.3637 13.8139 54.2611 13.3359 54.0507 12.9033C53.8646 12.537 53.5797 12.2315 53.229 12.0224C52.8685 11.8121 52.4584 11.7046 52.0423 11.7115C51.624 11.7054 51.2117 11.8128 50.8483 12.0224C50.4912 12.2324 50.2006 12.541 50.0106 12.912C49.7956 13.3401 49.6899 13.8158 49.7032 14.2958V19.6516H48.459Z" fill="#BCF124"/>\n<path d="M60.5388 19.8524C60.0174 19.8619 59.5007 19.75 59.0289 19.5253C58.6071 19.3259 58.2459 19.0157 57.983 18.6271C57.7263 18.2403 57.593 17.7833 57.6009 17.3175C57.5959 16.8715 57.6984 16.4309 57.8997 16.034C58.1173 15.6285 58.4383 15.2892 58.8292 15.0516C59.3232 14.7561 59.8701 14.5624 60.4384 14.4817L63.9188 13.8932V15.0355L60.7348 15.5744C60.0931 15.6867 59.6314 15.8932 59.3497 16.1938C59.0735 16.4811 58.9212 16.8673 58.926 17.268C58.9244 17.4635 58.9661 17.657 59.0481 17.8341C59.1301 18.0112 59.2503 18.1674 59.3999 18.2913C59.7416 18.5818 60.1787 18.7318 60.6246 18.7113C61.1803 18.7244 61.7296 18.5884 62.2166 18.3173C62.6597 18.066 63.0268 17.6972 63.2784 17.2506C63.535 16.7959 63.6669 16.2801 63.6604 15.7565V13.4744C63.6679 13.2259 63.6196 12.979 63.519 12.7521C63.4185 12.5253 63.2684 12.3245 63.08 12.1649C62.693 11.8287 62.1897 11.6607 61.57 11.6607C61.0801 11.6502 60.5978 11.7845 60.1822 12.047C59.7665 12.3095 59.4355 12.6888 59.2297 13.1387L58.1018 12.5192C58.2839 12.117 58.553 11.7614 58.8892 11.4785C59.2572 11.162 59.6754 10.9107 60.1261 10.7352C60.5858 10.5517 61.0758 10.4579 61.57 10.4589C62.1703 10.4448 62.7654 10.5748 63.3065 10.838C63.7888 11.077 64.1965 11.4462 64.4846 11.9047C64.7683 12.3771 64.912 12.9219 64.8986 13.4744V19.6517H63.658V17.8552L63.8405 18.0398C63.6702 18.3954 63.4238 18.7081 63.1191 18.9554C62.7772 19.238 62.3899 19.4593 61.9741 19.6095C61.5136 19.7756 61.0277 19.8578 60.5388 19.8524Z" fill="#BCF124"/>\n<path d="M70.6935 19.752C69.8975 19.752 69.2852 19.517 68.8566 19.0471C68.428 18.5771 68.2108 17.9056 68.2051 17.0326V11.9122H66.5616V10.6534H66.9804C67.1477 10.662 67.3148 10.6332 67.4697 10.5689C67.6247 10.5047 67.7637 10.4066 67.8769 10.2818C68.1017 10.0195 68.2202 9.68094 68.2088 9.33398V8.57825H69.453V10.6596H71.4124V11.9184H69.453V17.0388C69.4478 17.3107 69.4926 17.5813 69.5853 17.8366C69.6729 18.065 69.8337 18.2569 70.042 18.3818C70.3083 18.5292 70.6096 18.5991 70.9128 18.5837C71.0009 18.5837 71.1063 18.5775 71.2287 18.5664C71.3512 18.5552 71.4553 18.5441 71.5434 18.5329V19.6578C71.396 19.6937 71.2462 19.7189 71.0952 19.7334C70.9262 19.7433 70.7927 19.752 70.6935 19.752Z" fill="#BCF124"/>\n<path d="M82.2003 19.8523C81.3145 19.8603 80.4355 19.6954 79.6114 19.3666C78.4307 18.8928 77.4197 18.068 76.7118 17.001C76.0038 15.9341 75.6323 14.6751 75.646 13.3901C75.6376 12.5147 75.8043 11.6466 76.1359 10.838C76.453 10.0681 76.9213 9.37141 77.5123 8.79004C78.1118 8.20273 78.819 7.73977 79.5942 7.42723C81.2715 6.778 83.1266 6.778 84.8039 7.42723C85.5794 7.73911 86.2867 8.20215 86.8857 8.79004C87.4768 9.3717 87.9454 10.0683 88.2635 10.838C88.5945 11.6468 88.7611 12.5148 88.7533 13.3901C88.7674 14.6752 88.396 15.9343 87.688 17.0013C86.98 18.0683 85.9688 18.8931 84.7879 19.3666C83.9642 19.6952 83.0857 19.8601 82.2003 19.8523ZM82.2003 17.4984C82.7378 17.5032 83.2709 17.4005 83.769 17.1961C84.2425 16.9994 84.6735 16.7111 85.0378 16.3474C85.4069 15.9786 85.6952 15.5354 85.884 15.0465C86.0882 14.5173 86.1896 13.9532 86.1828 13.3852C86.1898 12.8203 86.0883 12.2594 85.884 11.7337C85.6922 11.2464 85.4043 10.8038 85.0378 10.4328C84.6764 10.0659 84.2446 9.77748 83.769 9.58542C82.7594 9.19396 81.6424 9.19396 80.6327 9.58542C80.1568 9.77745 79.7246 10.0658 79.3628 10.4328C78.9967 10.8041 78.7088 11.2467 78.5166 11.7337C78.3119 12.2602 78.2104 12.8219 78.2177 13.3876C78.2109 13.9557 78.3123 14.5198 78.5166 15.049C78.7058 15.5377 78.994 15.9808 79.3628 16.3499C79.7275 16.7136 80.1589 17.0019 80.6327 17.1985C81.1302 17.4038 81.663 17.5074 82.2003 17.5033V17.4984Z" fill="#BCF124"/>\n<path d="M90.398 23.2209V10.4861H92.7248V12.2293L92.5081 11.7251C92.8117 11.2627 93.2354 10.8941 93.7327 10.6596C94.2857 10.3994 94.8901 10.2702 95.4999 10.2817C96.3233 10.271 97.1335 10.4919 97.8401 10.9198C98.5312 11.3384 99.1029 11.9314 99.4995 12.6406C99.9126 13.38 100.124 14.2172 100.112 15.0664C100.122 15.9116 99.913 16.7448 99.5069 17.4835C99.1168 18.1988 98.5469 18.7971 97.8548 19.218C97.1376 19.6483 96.3164 19.8688 95.4827 19.8548C94.894 19.8605 94.3104 19.7437 93.7682 19.5116C93.2614 19.2967 92.8226 18.9454 92.4995 18.4957L92.8975 17.9754V23.2234L90.398 23.2209ZM95.1741 17.5863C95.6033 17.5949 96.0268 17.4848 96.3987 17.268C96.7521 17.0559 97.0394 16.7477 97.2278 16.3784C97.4328 15.9736 97.5355 15.5237 97.5266 15.0689C97.5364 14.6168 97.4337 14.1694 97.2278 13.768C97.0366 13.4007 96.7499 13.0932 96.3987 12.8785C96.0288 12.6556 95.6046 12.5419 95.1741 12.5502C94.7569 12.5434 94.3461 12.6541 93.9874 12.8698C93.6387 13.0826 93.3568 13.391 93.1743 13.7593C92.9832 14.1688 92.8841 14.6161 92.8841 15.0689C92.8841 15.5217 92.9832 15.9689 93.1743 16.3784C93.3571 16.7465 93.639 17.0548 93.9874 17.268C94.3469 17.4837 94.7586 17.594 95.1766 17.5863H95.1741Z" fill="#BCF124"/>\n<path d="M105.924 19.8524C104.961 19.8524 104.126 19.6372 103.418 19.2069C102.724 18.7915 102.156 18.1916 101.776 17.4724C101.384 16.7291 101.184 15.8977 101.194 15.0553C101.179 14.1986 101.388 13.3532 101.801 12.6047C102.189 11.9046 102.753 11.3198 103.434 10.9087C104.139 10.4899 104.944 10.2756 105.761 10.2892C106.414 10.277 107.062 10.394 107.67 10.6336C108.202 10.8483 108.68 11.1777 109.073 11.5987C109.454 12.0141 109.75 12.5023 109.943 13.0346C110.147 13.6019 110.248 14.2016 110.242 14.805C110.242 14.9847 110.234 15.1606 110.218 15.334C110.205 15.4855 110.174 15.6349 110.126 15.7788H103.34V13.9266H108.716L107.538 14.8001C107.65 14.3786 107.645 13.9339 107.522 13.5153C107.411 13.1561 107.186 12.8437 106.883 12.6258C106.553 12.4 106.161 12.2855 105.762 12.2987C105.368 12.2877 104.981 12.3993 104.652 12.6184C104.327 12.8492 104.083 13.1779 103.955 13.5574C103.79 14.0428 103.728 14.5577 103.772 15.0689C103.719 15.5315 103.782 16.0001 103.955 16.4317C104.108 16.81 104.375 17.1302 104.718 17.3473C105.08 17.5514 105.486 17.6634 105.901 17.6736C106.316 17.6837 106.727 17.5917 107.098 17.4055C107.407 17.2317 107.661 16.9743 107.833 16.6622L109.824 17.6186C109.643 18.0737 109.355 18.4776 108.986 18.7956C108.59 19.1398 108.132 19.4046 107.638 19.5761C107.087 19.766 106.507 19.8594 105.924 19.8524Z" fill="#BCF124"/>\n<path d="M111.703 19.6516V10.4837H114.03V12.2962L113.898 11.8935C114.081 11.3764 114.443 10.944 114.918 10.6769C115.425 10.404 115.994 10.2679 116.569 10.2817C117.196 10.2676 117.816 10.4179 118.369 10.7178C118.875 11.0011 119.293 11.4232 119.573 11.9357C119.87 12.4948 120.018 13.1223 120.004 13.7569V19.6491H117.515V14.2958C117.524 13.9753 117.452 13.6579 117.307 13.3728C117.173 13.1206 116.972 12.9112 116.727 12.7682C116.459 12.625 116.162 12.5502 115.859 12.5502C115.557 12.5502 115.26 12.625 114.992 12.7682C114.743 12.9091 114.539 13.1188 114.403 13.3728C114.259 13.658 114.188 13.9754 114.196 14.2958V19.6516H111.703Z" fill="#BCF124"/>\n<path d="M45.7329 35.9372C44.8875 35.9451 44.0493 35.7794 43.269 35.4503C42.525 35.134 41.851 34.6707 41.2863 34.0875C40.7178 33.4992 40.2696 32.8033 39.9673 32.0396C39.6453 31.2229 39.4843 30.3504 39.4934 29.4713C39.4848 28.5902 39.6427 27.7155 39.9588 26.8943C40.2511 26.1324 40.6939 25.4388 41.2601 24.8558C41.8262 24.2727 42.504 23.8126 43.2518 23.5034C44.039 23.178 44.8826 23.015 45.7329 23.024C46.5598 23.0107 47.3809 23.1649 48.1479 23.4774C48.8259 23.756 49.443 24.1669 49.9641 24.6866C50.4412 25.1559 50.8045 25.7304 51.0258 26.3653L48.7529 27.4729C48.5362 26.8433 48.1263 26.3001 47.5831 25.9226C47.0399 25.5451 46.3917 25.3529 45.7329 25.3742C45.0556 25.3604 44.3882 25.5408 43.8078 25.8945C43.2553 26.2426 42.8099 26.74 42.5219 27.3304C42.2056 27.9978 42.0495 28.7313 42.0664 29.4713C42.0503 30.2135 42.2063 30.9493 42.5219 31.6196C42.8077 32.2136 43.2534 32.7139 43.8078 33.0629C44.3879 33.4172 45.0555 33.5976 45.7329 33.5832C46.3917 33.6045 47.0399 33.4124 47.5831 33.0348C48.1263 32.6573 48.5362 32.1142 48.7529 31.4845L51.0258 32.5933C50.8056 33.2316 50.4422 33.8096 49.9641 34.282C49.4426 34.8009 48.8256 35.2113 48.1479 35.4899C47.3805 35.8004 46.5594 35.9524 45.7329 35.9372Z" fill="#BCF124"/>\n<path d="M56.8159 35.9372C55.9603 35.9485 55.1164 35.735 54.3667 35.3177C53.6426 34.9153 53.0357 34.3274 52.6069 33.613C52.1777 32.8648 51.9517 32.0151 51.9517 31.15C51.9517 30.285 52.1777 29.4353 52.6069 28.6871C53.0376 27.9762 53.6442 27.3911 54.3667 26.9898C55.118 26.5823 55.9573 26.3691 56.8098 26.3691C57.6623 26.3691 58.5016 26.5823 59.253 26.9898C59.9716 27.3928 60.5749 27.9771 61.0042 28.6858C61.4334 29.4341 61.6594 30.2837 61.6594 31.1488C61.6594 32.0139 61.4334 32.8635 61.0042 33.6118C60.577 34.3244 59.9733 34.912 59.253 35.3165C58.5078 35.7343 57.6678 35.9482 56.8159 35.9372ZM56.8159 33.6712C57.2335 33.681 57.6451 33.5701 58.0026 33.3516C58.3443 33.1354 58.6199 32.8274 58.7986 32.462C58.9985 32.0556 59.0985 31.6064 59.0901 31.1525C59.099 30.7014 58.9989 30.2548 58.7986 29.8517C58.6161 29.4889 58.3414 29.1818 58.0026 28.9621C57.6468 28.739 57.2345 28.6254 56.8159 28.635C56.3952 28.6261 55.9807 28.7396 55.6219 28.9621C55.2792 29.18 55.0008 29.4873 54.8161 29.8517C54.6162 30.2549 54.5166 30.7015 54.5259 31.1525C54.517 31.6063 54.6166 32.0555 54.8161 32.462C54.997 32.8291 55.2762 33.1373 55.6219 33.3516C55.9824 33.5695 56.3962 33.6803 56.8159 33.6712Z" fill="#BCF124"/>\n<path d="M63.1228 35.7364V26.5685H65.4496V28.7985L65.2047 28.4269C65.337 27.7223 65.6574 27.202 66.1661 26.8658C66.7124 26.5198 67.3477 26.3448 67.992 26.3628C68.6955 26.3487 69.3867 26.5504 69.9747 26.9414C70.2455 27.1163 70.4794 27.3435 70.6631 27.6102C70.8468 27.8768 70.9766 28.1775 71.045 28.495L70.3311 28.5619C70.6299 27.8128 71.056 27.2586 71.6096 26.8993C72.1912 26.5332 72.8658 26.3468 73.5506 26.3628C74.1566 26.3506 74.755 26.5011 75.2847 26.7989C75.7839 27.0856 76.1947 27.5068 76.4714 28.0155C76.7686 28.5772 76.9163 29.2073 76.9 29.8442V35.7364H74.4067V30.3806C74.4151 30.0621 74.3496 29.746 74.2156 29.4576C74.0956 29.2086 73.9084 28.999 73.6756 28.853C73.4175 28.71 73.1279 28.635 72.8336 28.635C72.5393 28.635 72.2498 28.71 71.9917 28.853C71.7556 28.9972 71.5655 29.2071 71.4443 29.4576C71.3103 29.746 71.2448 30.0621 71.2532 30.3806V35.7364H68.7648V30.3806C68.7731 30.0621 68.7077 29.746 68.5737 29.4576C68.4538 29.2089 68.267 28.9994 68.0349 28.853C67.7765 28.71 67.4868 28.635 67.1923 28.635C66.8978 28.635 66.6081 28.71 66.3498 28.853C66.1137 28.9972 65.9236 29.2071 65.8023 29.4576C65.6683 29.746 65.6029 30.0621 65.6113 30.3806V35.7364H63.1228Z" fill="#BCF124"/>\n<path d="M78.5374 39.3107V26.5697H80.8642V28.3166L80.6486 27.8123C80.9522 27.35 81.376 26.9813 81.8733 26.7469C82.4266 26.4883 83.0311 26.3611 83.6404 26.3752C84.464 26.3639 85.2743 26.5848 85.9807 27.0132C86.6715 27.4323 87.2431 28.0251 87.6401 28.7341C88.0532 29.473 88.2645 30.3098 88.2524 31.1586C88.2623 32.0044 88.0533 32.8381 87.6462 33.577C87.2571 34.2926 86.6875 34.8911 85.9954 35.3115C85.2785 35.7427 84.4572 35.9636 83.6233 35.9495C83.0345 35.9548 82.4509 35.8376 81.9088 35.6051C81.4019 35.391 80.963 35.04 80.6401 34.5904L81.0381 34.0701V39.3231L78.5374 39.3107ZM83.3134 33.6712C83.7428 33.6796 84.1663 33.5691 84.5381 33.3515C84.892 33.1399 85.1798 32.8316 85.3684 32.462C85.573 32.057 85.6757 31.6072 85.6672 31.1524C85.6761 30.7004 85.5734 30.2533 85.3684 29.8516C85.176 29.4847 84.8891 29.1774 84.5381 28.962C84.1679 28.7398 83.7438 28.6266 83.3134 28.635C82.8964 28.6281 82.4856 28.7383 82.1268 28.9534C81.778 29.1666 81.496 29.4755 81.3136 29.8442C81.1225 30.2534 81.0233 30.7004 81.0233 31.1531C81.0233 31.6057 81.1225 32.0527 81.3136 32.462C81.4954 32.8308 81.7775 33.1394 82.1268 33.3515C82.4863 33.5682 82.8986 33.679 83.3171 33.6712H83.3134Z" fill="#BCF124"/>\n<path d="M92.5093 35.9371C91.9294 35.9511 91.353 35.8427 90.8168 35.6187C90.3699 35.4306 89.9887 35.1118 89.722 34.7032C89.4607 34.2804 89.3278 33.7893 89.3399 33.2908C89.3319 32.8129 89.4525 32.3418 89.689 31.928C89.9498 31.5033 90.3197 31.1581 90.7593 30.9295C91.3217 30.6339 91.931 30.4406 92.5595 30.3583L95.3296 29.9049V31.7521L93.0028 32.1708C92.7069 32.2127 92.4268 32.3314 92.1897 32.5153C92.0938 32.6024 92.0186 32.7102 91.9696 32.8307C91.9207 32.9513 91.8992 33.0814 91.9068 33.2115C91.9015 33.3387 91.9277 33.4652 91.9828 33.5796C92.038 33.6941 92.1204 33.7928 92.2227 33.8669C92.4503 34.0296 92.7243 34.1123 93.0028 34.1023C93.3792 34.1101 93.7509 34.0174 94.0805 33.8335C94.3832 33.6617 94.6332 33.4087 94.803 33.1025C94.9751 32.7929 95.0638 32.443 95.0602 32.0878V29.698C95.062 29.5308 95.0264 29.3654 94.956 29.2141C94.8855 29.0628 94.7822 28.9296 94.6536 28.8245C94.3818 28.5891 94.0144 28.4714 93.5515 28.4714C93.1318 28.4645 92.7212 28.5949 92.3807 28.8431C92.0467 29.0873 91.7912 29.4256 91.6459 29.8157L89.6547 28.8592C89.826 28.354 90.1169 27.8989 90.5021 27.5336C90.9038 27.1547 91.3782 26.8634 91.8958 26.6775C92.4648 26.471 93.0657 26.3686 93.6702 26.3752C94.3679 26.3612 95.0599 26.5046 95.6958 26.7952C96.2502 27.0473 96.724 27.4511 97.0637 27.961C97.3951 28.4765 97.5658 29.0807 97.5536 29.6955V35.7389H95.2268V34.2584L95.7913 34.1581C95.5497 34.5339 95.2533 34.8706 94.912 35.1566C94.5921 35.4193 94.2261 35.6185 93.8331 35.7439C93.4044 35.877 92.9578 35.9422 92.5093 35.9371Z" fill="#BCF124"/>\n<path d="M99.3795 35.7365V26.5685H101.706V28.3823L101.573 27.9796C101.757 27.4626 102.119 27.0301 102.593 26.7618C103.101 26.4898 103.67 26.3542 104.245 26.3678C104.872 26.3532 105.493 26.5034 106.045 26.8039C106.551 27.0867 106.968 27.5085 107.248 28.0205C107.545 28.5801 107.693 29.208 107.679 29.8429V35.7352H105.189V30.3806C105.197 30.0603 105.126 29.743 104.982 29.4576C104.848 29.2051 104.646 28.9957 104.401 28.8531C104.135 28.7035 103.834 28.6282 103.53 28.635C103.23 28.6314 102.935 28.7065 102.673 28.8531C102.423 28.9936 102.219 29.2034 102.084 29.4576C101.939 29.7428 101.868 30.0603 101.877 30.3806V35.7365H99.3795Z" fill="#BCF124"/>\n<path d="M110.563 39.4631C110.304 39.4633 110.046 39.4405 109.791 39.3949C109.563 39.3571 109.342 39.2835 109.136 39.1769V37.1128C109.316 37.1628 109.499 37.2017 109.684 37.2293C109.875 37.2621 110.07 37.2791 110.264 37.2801C110.754 37.2801 111.099 37.1562 111.31 36.9282C111.522 36.6884 111.696 36.4162 111.824 36.1217L112.437 34.6945L112.404 36.7932L108.421 26.5697H111.093L113.731 33.8384H112.735L115.373 26.5697H118.048L114.165 36.5925C113.955 37.1702 113.652 37.7089 113.269 38.187C112.942 38.5905 112.531 38.9169 112.066 39.1434C111.594 39.3617 111.081 39.4709 110.563 39.4631Z" fill="#BCF124"/>\n<path d="M7.00861 16.1097H0C0.00583172 11.8399 1.68502 7.74676 4.66939 4.7276C7.65377 1.70844 11.6998 0.00968387 15.9203 0.00378418V7.09408C13.558 7.09801 11.2935 8.04913 9.62308 9.73902C7.95266 11.4289 7.0125 13.7198 7.00861 16.1097Z" fill="#BCF124"/>\n<path d="M15.9243 39.3094C11.7037 39.3035 7.65771 37.6047 4.67333 34.5856C1.68896 31.5664 0.00976849 27.4732 0.00393677 23.2035H7.01255C7.01255 24.9874 7.53543 26.7311 8.51506 28.2144C9.4947 29.6976 10.8871 30.8536 12.5162 31.5362C14.1452 32.2189 15.9378 32.3975 17.6672 32.0495C19.3966 31.7015 20.9852 30.8425 22.2321 29.5811C23.4789 28.3197 24.328 26.7127 24.672 24.9631C25.016 23.2135 24.8394 21.4 24.1647 19.752C23.4899 18.1039 22.3472 16.6953 20.881 15.7042C19.4149 14.7132 17.6912 14.1842 15.9279 14.1842V7.09021C20.1512 7.09021 24.2016 8.78747 27.1879 11.8086C30.1742 14.8297 31.8519 18.9273 31.8519 23.1998C31.8519 27.4723 30.1742 31.5699 27.1879 34.591C24.2016 37.6121 20.1512 39.3094 15.9279 39.3094H15.9243Z" fill="#BCF124"/>\n</svg>\n'.trim();var Po=(t=>(t[t.MANUAL=0]="MANUAL",t[t.AUTO=1]="AUTO",t))(Po||{});class To extends y{constructor(t){super(t),e(this,"onBeforeUpdate",new f),e(this,"onAfterUpdate",new f),e(this,"onAspectUpdated",new f),e(this,"onDisposed",new f),e(this,"three"),e(this,"_resizeObserver",null),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof u.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this.setupEvents(!0),this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{var e;const i=this._allControls.get(t.uuid);i&&(i.dispose(),this._allControls.delete(t.uuid)),null==(e=this._resizeObserver)||e.disconnect()})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(bs),i=this.components.get($r);i.list.clear();const n=new u.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(n),i.list.clear(),n}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new u.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new u.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");a.install({THREE:To.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new a(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){if(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),t){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");const{domElement:t}=this.currentWorld.renderer.three;this._resizeObserver=new ResizeObserver(this.updateAspect),this._resizeObserver.observe(t)}}static getSubsetOfThree(){return{MOUSE:u.MOUSE,Vector2:u.Vector2,Vector3:u.Vector3,Vector4:u.Vector4,Quaternion:u.Quaternion,Matrix4:u.Matrix4,Spherical:u.Spherical,Box3:u.Box3,Sphere:u.Sphere,Raycaster:u.Raycaster,MathUtils:u.MathUtils}}}const Mo=class t extends g{constructor(n){super(n),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}create(){const t=new bo(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(Mo,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Eo=Mo;class Io extends ge{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new u.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class Do{constructor(t,i){e(this,"onDisposed",new f),e(this,"onSetup",new f),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new u.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof To&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:n,primarySize:s,secondarySize:r,distance:o}=this._defaultConfig;this.components=t,this.config=new Io(this,this.components,"Grid");const a=new u.PlaneGeometry(2,2,1,1),l=new u.ShaderMaterial({side:u.DoubleSide,uniforms:{uSize1:{value:s},uSize2:{value:r},uColor:{value:n},uDistance:{value:o},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new u.Mesh(a,l),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get(ye).list.delete(this.config.uuid);this.components.get(v).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof To))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const zo=class t extends g{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new f),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new Do(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(zo,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let ko=zo;const Bo=class t{constructor(){e(this,"onDisposed",new f),e(this,"list",new i.DataMap),e(this,"enabled",!1),e(this,"_timer"),e(this,"onInit",new f),e(this,"update",()=>{if(!this.enabled)return;this._timer.update();const t=this._timer.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._timer=new u.Timer,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");A.validate(t),this.list.set(t,e)}get(t){var e;const i=t.uuid;if(!this.list.has(i)){const n=new t(this);return(null==(e=n.isDisposeable)?void 0:e.call(n))&&n.onDisposed.add(()=>this.list.delete(i)),this.list.has(i)||this.add(i,n),n}return this.list.get(i)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._timer.reset(),this.update(),this.onInit.trigger()}dispose(){let t,e;this.enabled=!1;for(const[i,n]of this.list)n.enabled=!1,i!==bs.uuid?i!==Eo.uuid?n.isDisposeable()&&n.dispose():e=n:t=n;(null==e?void 0:e.isDisposeable())&&e.dispose(),null==t||t.dispose(),this._timer.dispose(),this.onDisposed.trigger()}static setupBVH(){u.BufferGeometry.prototype.computeBoundsTree=ws,u.BufferGeometry.prototype.disposeBoundsTree=ys,u.Mesh.prototype.raycast=ms,u.LineSegments.prototype.raycast=ms}};e(Bo,"release","2.4.3");let Oo=Bo;class Vo{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new u.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=a.ACTION.DOLLY,t.touches.two=a.ACTION.TOUCH_ZOOM_TRUCK}}class Lo{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new u.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:n}=this.camera.three,s=new u.Vector3(0,0,-1).applyEuler(n),r=e.addScaledVector(s,i);t.moveTo(r.x,r.y,r.z)}}class No{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=a.ACTION.TRUCK,e.touches.one=a.ACTION.TOUCH_TRUCK,e.touches.two=a.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=a.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class Fo{constructor(t){e(this,"onChanged",new f),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new u.Vector3;this._component.threePersp.getWorldDirection(e);const i=new u.Vector3;this._component.controls.getTarget(i);const n=i.clone().sub(this._component.threePersp.position).dot(e),s=t.renderer.getSize(),r=s.x/s.y,o=this._component.threePersp,a=2*n*Math.atan(o.fov*(Math.PI/180)/2);return{width:a*r,height:a}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=a.ACTION.ZOOM,this._component.controls.mouseButtons.middle=a.ACTION.ZOOM;const i=this._component.threePersp,n=this._component.threeOrtho;n.zoom=1,n.left=e/-2,n.right=e/2,n.top=t/2,n.bottom=t/-2,n.updateProjectionMatrix(),n.position.copy(i.position),n.quaternion.copy(i.quaternion),this._component.controls.camera=n}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=a.ACTION.DOLLY,this._component.controls.mouseButtons.middle=a.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=a.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class Ro extends To{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new Fo(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new Lo(this)),this._navigationModes.set("FirstPerson",new Vo(this)),this._navigationModes.set("Plan",new No(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,n=Number.MIN_VALUE,s=new u.Vector3(i,i,i),r=new u.Vector3(n,n,n);for(const e of t){const t=(new u.Box3).setFromObject(e);t.min.x<s.x&&(s.x=t.min.x),t.min.y<s.y&&(s.y=t.min.y),t.min.z<s.z&&(s.z=t.min.z),t.max.x>r.x&&(r.x=t.max.x),t.max.y>r.y&&(r.y=t.max.y),t.max.z>r.z&&(r.z=t.max.z)}const o=new u.Box3(s,r),a=this.components.get(bs);if(a.initialized)for(const[,t]of a.list){const e=t.box;e.min.x<s.x&&(s.x=e.min.x),e.min.y<s.y&&(s.y=e.min.y),e.min.z<s.z&&(s.z=e.min.z),e.max.x>r.x&&(r.x=e.max.x),e.max.y>r.y&&(r.y=e.max.y),e.max.z>r.z&&(r.z=e.max.z)}const l=new u.Vector3;o.getSize(l);const c=new u.Vector3;o.getCenter(c);const h=Math.max(l.x,l.y,l.z)*e,d=new u.Sphere(c,h);await this.controls.fitToSphere(d,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}addCustomNavigationMode(t){this._navigationModes.set(t.id,t)}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new u.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,n=e*(t.y/this.previousSize.y),s=i*(t.x/this.previousSize.x);this.threeOrtho.left=-s,this.threeOrtho.right=s,this.threeOrtho.top=n,this.threeOrtho.bottom=-n,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}var Uo="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function jo(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function $o(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Wo={exports:{}};
1
+ "use strict";var t=Object.defineProperty,e=(e,i,n)=>(((e,i,n)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n})(e,"symbol"!=typeof i?i+"":i,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@thatopen/fragments"),n=require("three"),s=require("three/webgpu"),r=require("three/tsl"),o=require("web-ifc"),a=require("camera-controls"),l=require("three/examples/jsm/controls/TransformControls.js");function c(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const h=c(i),u=c(n),d=c(s),p=c(o);class f{constructor(){e(this,"enabled",!0),e(this,"trigger",t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class m{constructor(t){e(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),e(this,"isResizeable",()=>"resize"in this&&"getSize"in this),e(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),e(this,"isHideable",()=>"visible"in this),e(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),e(this,"isSerializable",()=>"import"in this&&"export"in this),this.components=t}}class g extends m{}class w extends m{constructor(t){super(t),e(this,"worlds",new i.DataMap),e(this,"onWorldChanged",new f),e(this,"_currentWorld",null),this.onWorldChanged.add(({world:t,action:e})=>{"removed"===e&&this.worlds.delete(t.uuid)})}set currentWorld(t){this._currentWorld=t}get currentWorld(){return this._currentWorld}}class y extends w{constructor(){super(...arguments),e(this,"hasCameraControls",()=>"controls"in this)}}class _ extends w{constructor(){super(...arguments),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"onResize",new f),e(this,"onClippingPlanesUpdated",new f),e(this,"clippingPlanes",[]),e(this,"localClippingPlanes",!1)}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i=this.localClippingPlanes){e.isLocal=i;const n=this.clippingPlanes.indexOf(e);t&&-1===n?this.clippingPlanes.push(e):!t&&n>-1&&this.clippingPlanes.splice(n,1),this.three.clippingPlanes=this.clippingPlanes.filter(t=>!t.isLocal),this.updateClippingPlanes()}}const b=class t extends g{constructor(i){super(i),e(this,"_disposedComponents",new Set),e(this,"enabled",!0),i.add(t.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const n=t;n.dispose&&n.dispose(),this.disposeGeometryAndMaterials(t,e),i&&n.children&&n.children.length&&this.disposeChildren(n),t.children.length=0}disposeGeometry(t){t.boundsTree&&t.disposeBoundsTree&&t.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(e,i){const n=e;n.geometry&&this.disposeGeometry(n.geometry),i&&n.material&&t.disposeMaterial(n),n.material=[],n.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};e(b,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let v=b;class x extends w{constructor(t){super(t),e(this,"onDisposed",new f),e(this,"directionalLights",new Map),e(this,"ambientLights",new Map)}dispose(){const t=this.components.get(v);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,t]of this.directionalLights)t.removeFromParent(),t.target.removeFromParent(),t.dispose();this.directionalLights.clear();for(const[,t]of this.ambientLights)t.removeFromParent(),t.dispose();this.ambientLights.clear()}}class C extends Set{constructor(t){super(t),e(this,"onItemAdded",new f),e(this,"onItemDeleted",new f),e(this,"onCleared",new f),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}add(...t){for(const e of t){if(this.has(e))continue;this.guard(e)&&(super.add(e),this.onItemAdded||(this.onItemAdded=new f),this.onItemAdded.trigger(e))}return this}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(),e}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}const S=class t{static create(){const e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return`${t._lut[255&e]+t._lut[e>>8&255]+t._lut[e>>16&255]+t._lut[e>>24&255]}-${t._lut[255&i]}${t._lut[i>>8&255]}-${t._lut[i>>16&15|64]}${t._lut[i>>24&255]}-${t._lut[63&n|128]}${t._lut[n>>8&255]}-${t._lut[n>>16&255]}${t._lut[n>>24&255]}${t._lut[255&s]}${t._lut[s>>8&255]}${t._lut[s>>16&255]}${t._lut[s>>24&255]}`.toLowerCase()}static validate(e){if(!t._pattern.test(e))throw new Error(`${e} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};e(S,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),e(S,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let A=S;const P=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",T=new RegExp("^"+("["+P+"]["+(P+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function M(t,e){const i=[];let n=e.exec(t);for(;n;){const s=[];s.startIndex=e.lastIndex-n[0].length;const r=n.length;for(let t=0;t<r;t++)s.push(n[t]);i.push(s),n=e.exec(t)}return i}const E=function(t){const e=T.exec(t);return!(null==e)};const I=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],D=["__proto__","constructor","prototype"],z={allowBooleanAttributes:!1,unpairedTags:[]};function k(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function B(t,e){const i=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const n=t.substr(i,e-i);if(e>5&&"xml"===n)return j("InvalidXml","XML declaration allowed only at the start of the document.",G(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function O(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&(i--,0===i))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}const V='"',L="'";function N(t,e){let i="",n="",s=!1;for(;e<t.length;e++){if(t[e]===V||t[e]===L)""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){s=!0;break}i+=t[e]}return""===n&&{value:i,index:e,tagClosed:s}}const F=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function R(t,e){const i=M(t,F),n={};for(let t=0;t<i.length;t++){if(0===i[t][1].length)return j("InvalidAttr","Attribute '"+i[t][2]+"' has no space in starting.",H(i[t]));if(void 0!==i[t][3]&&void 0===i[t][4])return j("InvalidAttr","Attribute '"+i[t][2]+"' is without value.",H(i[t]));if(void 0===i[t][3]&&!e.allowBooleanAttributes)return j("InvalidAttr","boolean attribute '"+i[t][2]+"' is not allowed.",H(i[t]));const s=i[t][2];if(!$(s))return j("InvalidAttr","Attribute '"+s+"' is an invalid name.",H(i[t]));if(Object.prototype.hasOwnProperty.call(n,s))return j("InvalidAttr","Attribute '"+s+"' is repeated.",H(i[t]));n[s]=1}return!0}function U(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);let i=0;for(;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function j(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function $(t){return E(t)}function W(t){return E(t)}function G(t,e){const i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function H(t){return t.startIndex+t[1].length}const q={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",euro:"€",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},Z={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},Y={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},X=new Set("!?\\\\/[]$%{}^&*()<>|+");function K(t){if("#"===t[0])throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${t}"`);for(const e of t)if(X.has(e))throw new Error(`[EntityReplacer] Invalid character '${e}' in entity name: "${t}"`);return t}function Q(...t){const e=Object.create(null);for(const i of t)if(i)for(const t of Object.keys(i)){const n=i[t];if("string"==typeof n)e[t]=n;else if(n&&"object"==typeof n&&void 0!==n.val){const i=n.val;"string"==typeof i&&(e[t]=i)}}return e}const J="external",tt="base",et="all";const it=Object.freeze({allow:0,leave:1,remove:2,throw:3}),nt=new Set([9,10,13]);class st{constructor(t={}){var e;this._limit=t.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck="function"==typeof t.postCheck?t.postCheck:t=>t,this._limitTiers=(e=this._limit.applyLimitsTo??J)&&e!==J?e===et?new Set([et]):e===tt?new Set([tt]):Array.isArray(e)?new Set(e):new Set([J]):new Set([J]),this._numericAllowed=t.numericAllowed??!0,this._baseMap=Q(Z,t.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(t.remove&&Array.isArray(t.remove)?t.remove:[]),this._leaveSet=new Set(t.leave&&Array.isArray(t.leave)?t.leave:[]);const i=function(t){if(!t)return{xmlVersion:1,onLevel:it.allow,nullLevel:it.remove};const e=1.1===t.xmlVersion?1.1:1,i=it[t.onNCR]??it.allow,n=it[t.nullNCR]??it.remove;return{xmlVersion:e,onLevel:i,nullLevel:Math.max(n,it.remove)}}(t.ncr);this._ncrXmlVersion=i.xmlVersion,this._ncrOnLevel=i.onLevel,this._ncrNullLevel=i.nullLevel}setExternalEntities(t){if(t)for(const e of Object.keys(t))K(e);this._externalMap=Q(t)}addExternalEntity(t,e){K(t),"string"==typeof e&&-1===e.indexOf("&")&&(this._externalMap[t]=e)}addInputEntities(t){this._totalExpansions=0,this._expandedLength=0,this._inputMap=Q(t)}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(t){this._ncrXmlVersion=1.1===t?1.1:1}decode(t){if("string"!=typeof t||0===t.length)return t;const e=t,i=[],n=t.length;let s=0,r=0;const o=this._maxTotalExpansions>0,a=this._maxExpandedLength>0,l=o||a;for(;r<n;){if(38!==t.charCodeAt(r)){r++;continue}let e=r+1;for(;e<n&&59!==t.charCodeAt(e)&&e-r<=32;)e++;if(e>=n||59!==t.charCodeAt(e)){r++;continue}const c=t.slice(r+1,e);if(0===c.length){r++;continue}let h,u;if(this._removeSet.has(c))h="",void 0===u&&(u=J);else{if(this._leaveSet.has(c)){r++;continue}if(35===c.charCodeAt(0)){const t=this._resolveNCR(c);if(void 0===t){r++;continue}h=t,u=tt}else{const t=this._resolveName(c);h=null==t?void 0:t.value,u=null==t?void 0:t.tier}}if(void 0!==h){if(r>s&&i.push(t.slice(s,r)),i.push(h),s=e+1,r=s,l&&this._tierCounts(u)){if(o&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(a){const t=h.length-(c.length+2);if(t>0&&(this._expandedLength+=t,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}else r++}s<n&&i.push(t.slice(s));const c=0===i.length?t:i.join("");return this._postCheck(c,e)}_tierCounts(t){return!!this._limitTiers.has(et)||this._limitTiers.has(t)}_resolveName(t){return t in this._inputMap?{value:this._inputMap[t],tier:J}:t in this._externalMap?{value:this._externalMap[t],tier:J}:t in this._baseMap?{value:this._baseMap[t],tier:tt}:void 0}_classifyNCR(t){return 0===t?this._ncrNullLevel:t>=55296&&t<=57343||1===this._ncrXmlVersion&&t>=1&&t<=31&&!nt.has(t)?it.remove:-1}_applyNCRAction(t,e,i){switch(t){case it.allow:return String.fromCodePoint(i);case it.remove:return"";case it.leave:return;case it.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${e}; (U+${i.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(i)}}_resolveNCR(t){const e=t.charCodeAt(1);let i;if(i=120===e||88===e?parseInt(t.slice(2),16):parseInt(t.slice(1),10),Number.isNaN(i)||i<0||i>1114111)return;const n=this._classifyNCR(i);if(!this._numericAllowed&&n<it.remove)return;const s=-1===n?this._ncrOnLevel:Math.max(this._ncrOnLevel,n);return this._applyNCRAction(s,t,i)}}const rt=t=>I.includes(t)?"__"+t:t,ot={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:rt};function at(t,e){if("string"!=typeof t)return;const i=t.toLowerCase();if(I.some(t=>i===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);if(D.some(t=>i===t.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`)}function lt(t,e){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:Math.max(1,t.maxEntitySize??1e4),maxExpansionDepth:Math.max(1,t.maxExpansionDepth??1e4),maxTotalExpansions:Math.max(1,t.maxTotalExpansions??1/0),maxExpandedLength:Math.max(1,t.maxExpandedLength??1e5),maxEntityCount:Math.max(1,t.maxEntityCount??1e3),allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null,appliesTo:t.appliesTo??"all"}:lt(!0)}const ct=function(t){const e=Object.assign({},ot,t),i=[{value:e.attributeNamePrefix,name:"attributeNamePrefix"},{value:e.attributesGroupName,name:"attributesGroupName"},{value:e.textNodeName,name:"textNodeName"},{value:e.cdataPropName,name:"cdataPropName"},{value:e.commentPropName,name:"commentPropName"}];for(const{value:t,name:e}of i)t&&at(t,e);return null===e.onDangerousProperty&&(e.onDangerousProperty=rt),e.processEntities=lt(e.processEntities,e.htmlEntities),e.unpairedTagsSet=new Set(e.unpairedTags),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),e};let ht;ht="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class ut{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][ht]={startIndex:e})}static getMetaDataSymbol(){return ht}}class dt{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const i=Object.create(null);let n=0;if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let s=1,r=!1,o=!1,a="";for(;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,s--):s--,0===s)break}else"["===t[e]?r=!0:a+=t[e];else{if(r&&ft(t,"!ENTITY",e)){let s,r;if(e+=7,[s,r,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===r.indexOf("&")){if(!1!==this.options.enabled&&null!=this.options.maxEntityCount&&n>=this.options.maxEntityCount)throw new Error(`Entity count (${n+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);i[s]=r,n++}}else if(r&&ft(t,"!ELEMENT",e)){e+=8;const{index:i}=this.readElementExp(t,e+1);e=i}else if(r&&ft(t,"!ATTLIST",e))e+=8;else if(r&&ft(t,"!NOTATION",e)){e+=9;const{index:i}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=i}else{if(!ft(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}s++,a=""}if(0!==s)throw new Error("Unclosed DOCTYPE")}return{entities:i,i:e}}readEntityExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)e++;let n=t.substring(i,e);if(mt(n),e=pt(t,e),!this.suppressValidationErr){if("SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported")}let s="";if([e,s]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&null!=this.options.maxEntitySize&&s.length>this.options.maxEntitySize)throw new Error(`Entity "${n}" size (${s.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[n,s,--e]}readNotationExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);!this.suppressValidationErr&&mt(n),e=pt(t,e);const s=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==s&&"PUBLIC"!==s)throw new Error(`Expected SYSTEM or PUBLIC, found "${s}"`);e+=s.length,e=pt(t,e);let r=null,o=null;if("PUBLIC"===s)[e,r]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=pt(t,e)]&&"'"!==t[e]||([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===s&&([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:r,systemIdentifier:o,index:--e}}readIdentifierVal(t,e,i){let n="";const s=t[e];if('"'!==s&&"'"!==s)throw new Error(`Expected quoted string, found "${s}"`);const r=++e;for(;e<t.length&&t[e]!==s;)e++;if(n=t.substring(r,e),t[e]!==s)throw new Error(`Unterminated ${i} value`);return[++e,n]}readElementExp(t,e){const i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);if(!this.suppressValidationErr&&!E(n))throw new Error(`Invalid element name: "${n}"`);let s="";if("E"===t[e=pt(t,e)]&&ft(t,"MPTY",e))e+=4;else if("A"===t[e]&&ft(t,"NY",e))e+=2;else if("("===t[e]){const i=++e;for(;e<t.length&&")"!==t[e];)e++;if(s=t.substring(i,e),")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:n,contentModel:s.trim(),index:e}}readAttlistExp(t,e){let i=e=pt(t,e);for(;e<t.length&&!/\s/.test(t[e]);)e++;let n=t.substring(i,e);for(mt(n),i=e=pt(t,e);e<t.length&&!/\s/.test(t[e]);)e++;let s=t.substring(i,e);if(!mt(s))throw new Error(`Invalid attribute name: "${s}"`);e=pt(t,e);let r="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(r="NOTATION","("!==t[e=pt(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let i=[];for(;e<t.length&&")"!==t[e];){const n=e;for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)e++;let s=t.substring(n,e);if(s=s.trim(),!mt(s))throw new Error(`Invalid notation name: "${s}"`);i.push(s),"|"===t[e]&&(e++,e=pt(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,r+=" ("+i.join("|")+")"}else{const i=e;for(;e<t.length&&!/\s/.test(t[e]);)e++;r+=t.substring(i,e);const n=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!n.includes(r.toUpperCase()))throw new Error(`Invalid attribute type: "${r}"`)}e=pt(t,e);let o="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(o="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(o="#IMPLIED",e+=7):[e,o]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:n,attributeName:s,attributeType:r,defaultValue:o,index:e}}}const pt=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function ft(t,e,i){for(let n=0;n<e.length;n++)if(e[n]!==t[i+n+1])return!1;return!0}function mt(t){if(E(t))return t;throw new Error(`Invalid entity name ${t}`)}const gt=/^[-+]?0x[a-fA-F0-9]+$/,wt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,yt={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original"};function _t(t,e={}){if(e=Object.assign({},yt,e),!t||"string"!=typeof t)return t;let i=t.trim();if(0===i.length)return t;if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===i)return 0;if(e.hex&&gt.test(i))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(i,16);if(isFinite(i)){if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const n=e.match(bt);if(n){let s=n[1]||"";const r=-1===n[3].indexOf("e")?"E":"e",o=n[2],a=s?t[o.length+1]===r:t[o.length]===r;return o.length>1&&a?t:(1!==o.length||!n[3].startsWith(`.${r}`)&&n[3][0]!==r)&&o.length>0?i.leadingZeros&&!a?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,i,e);{const n=wt.exec(i);if(n){const s=n[1]||"",r=n[2];let o=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),t;return t}(n[3]);const a=s?"."===t[r.length+1]:"."===t[r.length];if(!e.leadingZeros&&(r.length>1||1===r.length&&!a))return t;{const n=Number(i),a=String(n);if(0===n)return n;if(-1!==a.search(/[eE]/))return e.eNotation?n:t;if(-1!==i.indexOf("."))return"0"===a||a===o||a===`${s}${o}`?n:t;let l=r?o:i;return r?l===a||s+l===a?n:t:l===a||l===s+a?n:t}}return t}}return function(t,e,i){const n=e===1/0;switch(i.infinity.toLowerCase()){case"null":return null;case"infinity":return e;case"string":return n?"Infinity":"-Infinity";default:return t}}(t,Number(i),e)}const bt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class vt{constructor(t,e={},i){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=i,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,n="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(n.trim()&&(e.push(this._parseSegment(n.trim())),n=""),e.push({type:"deep-wildcard"}),i+=2):(n.trim()&&e.push(this._parseSegment(n.trim())),n="",i++):(n+=t[i],i++);return n.trim()&&e.push(this._parseSegment(n.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,n=t;const s=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(s&&(n=s[1]+s[3],s[2])){const t=s[2].slice(1,-1);t&&(i=t)}let r,o,a=n;if(n.includes("::")){const e=n.indexOf("::");if(r=n.substring(0,e).trim(),a=n.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let l=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,l=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(l){const t=l.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=l}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class xt{constructor(){this._byDepthAndTag=new Map,this._wildcardByDepth=new Map,this._deepWildcards=[],this._patterns=new Set,this._sealed=!1}add(t){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(t.pattern))return this;if(this._patterns.add(t.pattern),t.hasDeepWildcard())return this._deepWildcards.push(t),this;const e=t.length,i=t.segments[t.segments.length-1],n=null==i?void 0:i.tag;if(n&&"*"!==n){const i=`${e}:${n}`;this._byDepthAndTag.has(i)||this._byDepthAndTag.set(i,[]),this._byDepthAndTag.get(i).push(t)}else this._wildcardByDepth.has(e)||this._wildcardByDepth.set(e,[]),this._wildcardByDepth.get(e).push(t);return this}addAll(t){for(const e of t)this.add(e);return this}has(t){return this._patterns.has(t.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(t){return null!==this.findMatch(t)}findMatch(t){const e=t.getDepth(),i=`${e}:${t.getCurrentTag()}`,n=this._byDepthAndTag.get(i);if(n)for(let e=0;e<n.length;e++)if(t.matches(n[e]))return n[e];const s=this._wildcardByDepth.get(e);if(s)for(let e=0;e<s.length;e++)if(t.matches(s[e]))return s[e];for(let e=0;e<this._deepWildcards.length;e++)if(t.matches(this._deepWildcards[e]))return this._deepWildcards[e];return null}}class Ct{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){var e;const i=this._matcher.path;if(0!==i.length)return null==(e=i[i.length-1].values)?void 0:e[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const i=e[e.length-1];return void 0!==i.values&&t in i.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class St{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new Ct(this)}push(t,e=null,i=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const n=this.path.length;this.siblingStacks[n]||(this.siblingStacks[n]=new Map);const s=this.siblingStacks[n],r=i?`${i}:${t}`:t,o=s.get(r)||0;let a=0;for(const t of s.values())a+=t;s.set(r,o+1);const l={tag:t,position:a,counter:o};null!=i&&(l.namespace=i),null!=e&&(l.values=e),this.path.push(l)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){var e;if(0!==this.path.length)return null==(e=this.path[this.path.length-1].values)?void 0:e[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;if(i===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const n=t[i];if("deep-wildcard"===n.type){if(i--,i<0)return!0;const n=t[i];let s=!1;for(let t=e;t>=0;t--)if(this._matchSegment(n,this.path[t],t===this.path.length-1)){e=t-1,i--,s=!0;break}if(!s)return!1}else{if(!this._matchSegment(n,this.path[e],e===this.path.length-1))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!i)return!1;const n=e.counter??0;if("first"===t.position&&0!==n)return!1;if("odd"===t.position&&n%2!=1)return!1;if("even"===t.position&&n%2!=0)return!1;if("nth"===t.position&&n!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function At(t,e){if(!t)return{};const i=e.attributesGroupName?t[e.attributesGroupName]:t;if(!i)return{};const n={};for(const t in i)if(t.startsWith(e.attributeNamePrefix)){n[t.substring(e.attributeNamePrefix.length)]=i[t]}else n[t]=i[t];return n}function Pt(t){if(!t||"string"!=typeof t)return;const e=t.indexOf(":");if(-1!==e&&e>0){const i=t.substring(0,e);if("xmlns"!==i)return i}}class Tt{constructor(t,e){var i;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=zt,this.parseTextData=Mt,this.resolveNameSpace=Et,this.buildAttributesMap=Dt,this.isItStopNode=Vt,this.replaceEntitiesValue=Bt,this.readStopNodeData=Rt,this.saveTextToParentTag=Ot,this.addChild=kt,this.ignoreAttributesFn="function"==typeof(i=this.options.ignoreAttributes)?i:Array.isArray(i)?t=>{for(const e of i){if("string"==typeof e&&t===e)return!0;if(e instanceof RegExp&&e.test(t))return!0}}:()=>!1,this.entityExpansionCount=0,this.currentExpandedLength=0;let n={...Z};this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:("object"==typeof this.options.htmlEntities?n=this.options.htmlEntities:!0===this.options.htmlEntities&&(n={...Y,...q}),this.entityDecoder=new st({namedEntities:{...n,...e},numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo}})),this.matcher=new St,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new xt;const s=this.options.stopNodes;if(s&&s.length>0){for(let t=0;t<s.length;t++){const e=s[t];"string"==typeof e?this.stopNodeExpressionsSet.add(new vt(e)):e instanceof vt&&this.stopNodeExpressionsSet.add(e)}this.stopNodeExpressionsSet.seal()}}}function Mt(t,e,i,n,s,r,o){const a=this.options;if(void 0!==t&&(a.trimValues&&!n&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));const n=a.jPath?i.toString():i,l=a.tagValueProcessor(e,t,n,s,r);if(null==l)return t;if(typeof l!=typeof t||l!==t)return l;if(a.trimValues)return Ut(t,a.parseTagValue,a.numberParseOptions);return t.trim()===t?Ut(t,a.parseTagValue,a.numberParseOptions):t}}function Et(t){if(this.options.removeNSPrefix){const e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}const It=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function Dt(t,e,i,n=!1){const s=this.options;if(!0===n||!0!==s.ignoreAttributes&&"string"==typeof t){const n=M(t,It),r=n.length,o={},a=new Array(r);let l=!1;const c={};for(let t=0;t<r;t++){const e=this.resolveNameSpace(n[t][1]),r=n[t][4];if(e.length&&void 0!==r){let n=r;s.trimValues&&(n=n.trim()),n=this.replaceEntitiesValue(n,i,this.readonlyMatcher),a[t]=n,c[e]=n,l=!0}}l&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(c);const h=s.jPath?e.toString():this.readonlyMatcher;let u=!1;for(let t=0;t<r;t++){const e=this.resolveNameSpace(n[t][1]);if(this.ignoreAttributesFn(e,h))continue;let i=s.attributeNamePrefix+e;if(e.length)if(s.transformAttributeName&&(i=s.transformAttributeName(i)),i=$t(i,s),void 0!==n[t][4]){const n=a[t],r=s.attributeValueProcessor(e,n,h);o[i]=null==r?n:typeof r!=typeof n||r!==n?r:Ut(n,s.parseAttributeValue,s.numberParseOptions),u=!0}else s.allowBooleanAttributes&&(o[i]=!0,u=!0)}if(!u)return;if(s.attributesGroupName&&!s.preserveOrder){const t={};return t[s.attributesGroupName]=o,t}return o}}const zt=function(t){t=t.replace(/\r\n?/g,"\n");const e=new ut("!xml");let i=e,n="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const s=this.options,r=new dt(s.processEntities),o=t.length;for(let a=0;a<o;a++){if("<"===t[a]){const l=t.charCodeAt(a+1);if(47===l){const e=Lt(t,">",a,"Closing Tag is not closed.");let r=t.substring(a+2,e).trim();if(s.removeNSPrefix){const t=r.indexOf(":");-1!==t&&(r=r.substr(t+1))}r=jt(s.transformTagName,r,"",s).tagName,i&&(n=this.saveTextToParentTag(n,i,this.readonlyMatcher));const o=this.matcher.getCurrentTag();if(r&&s.unpairedTagsSet.has(r))throw new Error(`Unpaired tag can not be used as closing tag: </${r}>`);o&&s.unpairedTagsSet.has(o)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,i=this.tagsNodeStack.pop(),n="",a=e}else if(63===l){let e=Ft(t,a,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");n=this.saveTextToParentTag(n,i,this.readonlyMatcher);const r=this.buildAttributesMap(e.tagExp,this.matcher,e.tagName,!0);if(r){const t=r[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(t)||1)}if(s.ignoreDeclaration&&"?xml"===e.tagName||s.ignorePiTags);else{const t=new ut(e.tagName);t.add(s.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&!0!==s.ignoreAttributes&&(t[":@"]=r),this.addChild(i,t,this.readonlyMatcher,a)}a=e.closeIndex+1}else if(33===l&&45===t.charCodeAt(a+2)&&45===t.charCodeAt(a+3)){const e=Lt(t,"--\x3e",a+4,"Comment is not closed.");if(s.commentPropName){const r=t.substring(a+4,e-2);n=this.saveTextToParentTag(n,i,this.readonlyMatcher),i.add(s.commentPropName,[{[s.textNodeName]:r}])}a=e}else if(33===l&&68===t.charCodeAt(a+2)){const e=r.readDocType(t,a);this.entityDecoder.addInputEntities(e.entities),a=e.i}else if(33===l&&91===t.charCodeAt(a+2)){const e=Lt(t,"]]>",a,"CDATA is not closed.")-2,r=t.substring(a+9,e);n=this.saveTextToParentTag(n,i,this.readonlyMatcher);let o=this.parseTextData(r,i.tagname,this.readonlyMatcher,!0,!1,!0,!0);null==o&&(o=""),s.cdataPropName?i.add(s.cdataPropName,[{[s.textNodeName]:r}]):i.add(s.textNodeName,o),a=e+2}else{let r=Ft(t,a,s.removeNSPrefix);if(!r){const e=t.substring(Math.max(0,a-50),Math.min(o,a+50));throw new Error(`readTagExp returned undefined at position ${a}. Context: "${e}"`)}let l=r.tagName;const c=r.rawTagName;let h=r.tagExp,u=r.attrExpPresent,d=r.closeIndex;if(({tagName:l,tagExp:h}=jt(s.transformTagName,l,h,s)),s.strictReservedNames&&(l===s.commentPropName||l===s.cdataPropName||l===s.textNodeName||l===s.attributesGroupName))throw new Error(`Invalid tag name: ${l}`);i&&n&&"!xml"!==i.tagname&&(n=this.saveTextToParentTag(n,i,this.readonlyMatcher,!1));const p=i;p&&s.unpairedTagsSet.has(p.tagname)&&(i=this.tagsNodeStack.pop(),this.matcher.pop());let f=!1;h.length>0&&h.lastIndexOf("/")===h.length-1&&(f=!0,"/"===l[l.length-1]?(l=l.substr(0,l.length-1),h=l):h=h.substr(0,h.length-1),u=l!==h);let m,g=null;m=Pt(c),l!==e.tagname&&this.matcher.push(l,{},m),l!==h&&u&&(g=this.buildAttributesMap(h,this.matcher,l),g&&At(g,s)),l!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());const w=a;if(this.isCurrentNodeStopNode){let e="";if(f)a=r.closeIndex;else if(s.unpairedTagsSet.has(l))a=r.closeIndex;else{const i=this.readStopNodeData(t,c,d+1);if(!i)throw new Error(`Unexpected end of ${c}`);a=i.i,e=i.tagContent}const n=new ut(l);g&&(n[":@"]=g),n.add(s.textNodeName,e),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(i,n,this.readonlyMatcher,w)}else{if(f){({tagName:l,tagExp:h}=jt(s.transformTagName,l,h,s));const t=new ut(l);g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(s.unpairedTagsSet.has(l)){const t=new ut(l);g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),this.matcher.pop(),this.isCurrentNodeStopNode=!1,a=r.closeIndex;continue}{const t=new ut(l);if(this.tagsNodeStack.length>s.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),g&&(t[":@"]=g),this.addChild(i,t,this.readonlyMatcher,w),i=t}}n="",a=d}}}else n+=t[a]}return e.child};function kt(t,e,i,n){this.options.captureMetaData||(n=void 0);const s=this.options.jPath?i.toString():i,r=this.options.updateTag(e.tagname,s,e[":@"]);!1===r||("string"==typeof r?(e.tagname=r,t.addChild(e,n)):t.addChild(e,n))}function Bt(t,e,i){const n=this.options.processEntities;if(!n||!n.enabled)return t;if(n.allowedTags){const s=this.options.jPath?i.toString():i;if(!(Array.isArray(n.allowedTags)?n.allowedTags.includes(e):n.allowedTags(e,s)))return t}if(n.tagFilter){const s=this.options.jPath?i.toString():i;if(!n.tagFilter(e,s))return t}return this.entityDecoder.decode(t)}function Ot(t,e,i,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function Vt(){return 0!==this.stopNodeExpressionsSet.size&&this.matcher.matchesAny(this.stopNodeExpressionsSet)}function Lt(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s+e.length-1}function Nt(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s}function Ft(t,e,i,n=">"){const s=function(t,e,i=">"){let n=0;const s=t.length,r=i.charCodeAt(0),o=i.length>1?i.charCodeAt(1):-1;let a="",l=e;for(let i=e;i<s;i++){const e=t.charCodeAt(i);if(n)e===n&&(n=0);else if(34===e||39===e)n=e;else if(e===r){if(-1===o)return a+=t.substring(l,i),{data:a,index:i};if(t.charCodeAt(i+1)===o)return a+=t.substring(l,i),{data:a,index:i}}else 9!==e||n||(a+=t.substring(l,i)+" ",l=i+1)}}(t,e+1,n);if(!s)return;let r=s.data;const o=s.index,a=r.search(/\s/);let l=r,c=!0;-1!==a&&(l=r.substring(0,a),r=r.substring(a+1).trimStart());const h=l;if(i){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),c=l!==s.data.substr(t+1))}return{tagName:l,tagExp:r,closeIndex:o,attrExpPresent:c,rawTagName:h}}function Rt(t,e,i){const n=i;let s=1;const r=t.length;for(;i<r;i++)if("<"===t[i]){const r=t.charCodeAt(i+1);if(47===r){const r=Nt(t,">",i,`${e} is not closed`);if(t.substring(i+2,r).trim()===e&&(s--,0===s))return{tagContent:t.substring(n,i),i:r};i=r}else if(63===r){i=Lt(t,"?>",i+1,"StopNode is not closed.")}else if(33===r&&45===t.charCodeAt(i+2)&&45===t.charCodeAt(i+3)){i=Lt(t,"--\x3e",i+3,"StopNode is not closed.")}else if(33===r&&91===t.charCodeAt(i+2)){i=Lt(t,"]]>",i,"StopNode is not closed.")-2}else{const n=Ft(t,i,">");if(n){(n&&n.tagName)===e&&"/"!==n.tagExp[n.tagExp.length-1]&&s++,i=n.closeIndex}}}}function Ut(t,e,i){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&_t(t,i)}return void 0!==t?t:""}function jt(t,e,i,n){if(t){const n=t(e);i===e&&(i=n),e=n}return{tagName:e=$t(e,n),tagExp:i}}function $t(t,e){if(D.includes(t))throw new Error(`[SECURITY] Invalid name: "${t}" is a reserved JavaScript keyword that could cause prototype pollution`);return I.includes(t)?e.onDangerousProperty(t):t}const Wt=ut.getMetaDataSymbol();function Gt(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;const i={};for(const n in t)if(n.startsWith(e)){i[n.substring(e.length)]=t[n]}else i[n]=t[n];return i}function Ht(t,e,i,n){return qt(t,e,i,n)}function qt(t,e,i,n){let s;const r={};for(let o=0;o<t.length;o++){const a=t[o],l=Zt(a);if(void 0!==l&&l!==e.textNodeName){const t=Gt(a[":@"]||{},e.attributeNamePrefix);i.push(l,t)}if(l===e.textNodeName)void 0===s?s=a[l]:s+=""+a[l];else{if(void 0===l)continue;if(a[l]){let t=qt(a[l],e,i,n);const s=Xt(t,e);if(a[":@"]?Yt(t,a[":@"],n,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==a[Wt]&&"object"==typeof t&&null!==t&&(t[Wt]=a[Wt]),void 0!==r[l]&&Object.prototype.hasOwnProperty.call(r,l))Array.isArray(r[l])||(r[l]=[r[l]]),r[l].push(t);else{const i=e.jPath?n.toString():n;e.isArray(l,i,s)?r[l]=[t]:r[l]=t}void 0!==l&&l!==e.textNodeName&&i.pop()}}}return"string"==typeof s?s.length>0&&(r[e.textNodeName]=s):void 0!==s&&(r[e.textNodeName]=s),r}function Zt(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const i=e[t];if(":@"!==i)return i}}function Yt(t,e,i,n){if(e){const s=Object.keys(e),r=s.length;for(let o=0;o<r;o++){const r=s[o],a=r.startsWith(n.attributeNamePrefix)?r.substring(n.attributeNamePrefix.length):r,l=n.jPath?i.toString()+"."+a:i;n.isArray(r,l,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function Xt(t,e){const{textNodeName:i}=e,n=Object.keys(t).length;return 0===n||!(1!==n||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}class Kt{constructor(t){this.externalEntities={},this.options=ct(t)}parse(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");if(e){!0===e&&(e={});const i=function(t,e){e=Object.assign({},z,e);const i=[];let n=!1,s=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=B(t,r),r.err)return r}else{if("<"!==t[r]){if(k(t[r]))continue;return j("InvalidChar","char '"+t[r]+"' is not expected.",G(t,r))}{let o=r;if(r++,"!"===t[r]){r=O(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let l="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)l+=t[r];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),r--),!W(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",j("InvalidTag",e,G(t,r))}const c=N(t,r);if(!1===c)return j("InvalidAttr","Attributes for '"+l+"' have open quote.",G(t,r));let h=c.value;if(r=c.index,"/"===h[h.length-1]){const i=r-h.length;h=h.substring(0,h.length-1);const s=R(h,e);if(!0!==s)return j(s.err.code,s.err.msg,G(t,i+s.err.line));n=!0}else if(a){if(!c.tagClosed)return j("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",G(t,r));if(h.trim().length>0)return j("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",G(t,o));if(0===i.length)return j("InvalidTag","Closing tag '"+l+"' has not been opened.",G(t,o));{const e=i.pop();if(l!==e.tagName){let i=G(t,e.tagStartPos);return j("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+i.line+", col "+i.col+") instead of closing tag '"+l+"'.",G(t,o))}0==i.length&&(s=!0)}}else{const a=R(h,e);if(!0!==a)return j(a.err.code,a.err.msg,G(t,r-h.length+a.err.line));if(!0===s)return j("InvalidXml","Multiple possible root nodes found.",G(t,r));-1!==e.unpairedTags.indexOf(l)||i.push({tagName:l,tagStartPos:o}),n=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=O(t,r);continue}if("?"!==t[r+1])break;if(r=B(t,++r),r.err)return r}else if("&"===t[r]){const e=U(t,r);if(-1==e)return j("InvalidChar","char '&' is not expected.",G(t,r));r=e}else if(!0===s&&!k(t[r]))return j("InvalidXml","Extra text at the end",G(t,r));"<"===t[r]&&r--}}}return n?1==i.length?j("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",G(t,i[0].tagStartPos)):!(i.length>0)||j("InvalidXml","Invalid '"+JSON.stringify(i.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):j("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==i)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const i=new Tt(this.options,this.externalEntities),n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:Ht(n,this.options,i.matcher,i.readonlyMatcher)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return ut.getMetaDataSymbol()}}function Qt(t,e){let i="";e.format&&e.indentBy.length>0&&(i="\n");const n=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const i=e.stopNodes[t];"string"==typeof i?n.push(new vt(i)):i instanceof vt&&n.push(i)}return Jt(t,e,i,new St,n)}function Jt(t,e,i,n,s){let r="",o=!1;if(e.maxNestedTags&&n.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=oe(i,e),i}return""}for(let a=0;a<t.length;a++){const l=t[a],c=ne(l);if(void 0===c)continue;const h=te(l[":@"],e);n.push(c,h);const u=re(n,s);if(c===e.textNodeName){let t=l[c];u||(t=e.tagValueProcessor(c,t),t=oe(t,e)),o&&(r+=i),r+=t,o=!1,n.pop();continue}if(c===e.cdataPropName){o&&(r+=i);const t=l[c][0][e.textNodeName];r+=`<![CDATA[${String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}]]>`,o=!1,n.pop();continue}if(c===e.commentPropName){const t=l[c][0][e.textNodeName];r+=i+`\x3c!--${String(t).replace(/--/g,"- -").replace(/-$/,"- ")}--\x3e`,o=!0,n.pop();continue}if("?"===c[0]){const t=se(l[":@"],e,u),s="?xml"===c?"":i;let a=l[c][0][e.textNodeName];a=0!==a.length?" "+a:"",r+=s+`<${c}${a}${t}?>`,o=!0,n.pop();continue}let d=i;""!==d&&(d+=e.indentBy);const p=i+`<${c}${se(l[":@"],e,u)}`;let f;f=u?ee(l[c],e):Jt(l[c],e,d,n,s),-1!==e.unpairedTags.indexOf(c)?e.suppressUnpairedNode?r+=p+">":r+=p+"/>":f&&0!==f.length||!e.suppressEmptyNode?f&&f.endsWith(">")?r+=p+`>${f}${i}</${c}>`:(r+=p+">",f&&""!==i&&(f.includes("/>")||f.includes("</"))?r+=i+e.indentBy+f+i:r+=f,r+=`</${c}>`):r+=p+"/>",o=!0,n.pop()}return r}function te(t,e){if(!t||e.ignoreAttributes)return null;const i={};let n=!1;for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;i[s.startsWith(e.attributeNamePrefix)?s.substr(e.attributeNamePrefix.length):s]=t[s],n=!0}return n?i:null}function ee(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let n=0;n<t.length;n++){const s=t[n],r=ne(s);if(r===e.textNodeName)i+=s[r];else if(r===e.cdataPropName)i+=s[r][0][e.textNodeName];else if(r===e.commentPropName)i+=s[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=ie(s[":@"],e),n=ee(s[r],e);n&&0!==n.length?i+=`<${r}${t}>${n}</${r}>`:i+=`<${r}${t}/>`}}}return i}function ie(t,e){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let s=t[n];!0===s&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return i}function ne(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i];if(Object.prototype.hasOwnProperty.call(t,n)&&":@"!==n)return n}}function se(t,e,i){let n="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let r;i?r=t[s]:(r=e.attributeValueProcessor(s,t[s]),r=oe(r,e)),!0===r&&e.suppressBooleanAttributes?n+=` ${s.substr(e.attributeNamePrefix.length)}`:n+=` ${s.substr(e.attributeNamePrefix.length)}="${r}"`}return n}function re(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function oe(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const n=e.entities[i];t=t.replace(n.regex,n.val)}return t}const ae={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0};function le(t){if(this.options=Object.assign({},ae,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new vt(e)):e instanceof vt&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ue),this.processTextOrObjNode=ce,this.options.format?(this.indentate=he,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function ce(t,e,i,n){const s=this.extractAttributes(t);n.push(e,s);if(this.checkStopNode(n)){const s=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return n.pop(),this.buildObjectNode(s,e,r,i)}const r=this.j2x(t,i+1,n);return n.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i,n):this.buildObjectNode(r.val,e,r.attrStr,i)}function he(t){return this.options.indentBy.repeat(t)}function ue(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}le.prototype.build=function(t){if(this.options.preserveOrder)return Qt(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new St;return this.j2x(t,0,e).val}},le.prototype.j2x=function(t,e,i){let n="",s="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const r=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(s+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?s+="":"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)s+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const l=this.isAttribute(a);if(l&&!this.ignoreAttributesFn(l,r))n+=this.buildAttrPairStr(l,""+t[a],o);else if(!l)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);s+=this.replaceEntitiesValue(e)}else{i.push(a);const n=this.checkStopNode(i);if(i.pop(),n){const i=""+t[a];s+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else s+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const n=t[a].length;let r="",o="";for(let l=0;l<n;l++){const n=t[a][l];if(void 0===n);else if(null===n)"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){i.push(a);const t=this.j2x(n,e+1,i);i.pop(),r+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(n,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,n);t=this.replaceEntitiesValue(t),r+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+n;r+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else r+=this.buildTextValNode(n,a,"",e,i)}}this.options.oneListGroup&&(r=this.buildObjectNode(r,a,o,e)),s+=r}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let s=0;s<i;s++)n+=this.buildAttrPairStr(e[s],""+t[a][e[s]],o)}else s+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:n,val:s}},le.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},le.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const n=t[this.options.attributesGroupName];for(let t in n){if(!Object.prototype.hasOwnProperty.call(n,t))continue;e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=n[t],i=!0}}else for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const s=this.isAttribute(n);s&&(e[s]=t[n],i=!0)}return i?e:null},le.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const n=t[i];if(i===this.options.textNodeName)e+=n;else if(Array.isArray(n)){for(let t of n)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const n=this.buildRawContent(t),s=this.buildAttributesForStopNode(t);e+=""===n?`<${i}${s}/>`:`<${i}${s}>${n}</${i}>`}}else if("object"==typeof n&&null!==n){const t=this.buildRawContent(n),s=this.buildAttributesForStopNode(n);e+=""===t?`<${i}${s}/>`:`<${i}${s}>${t}</${i}>`}else e+=`<${i}>${n}</${i}>`}return e},le.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const n=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,s=i[t];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const n=this.isAttribute(i);if(n){const s=t[i];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}return e},le.prototype.buildObjectNode=function(t,e,i,n){if(""===t)return"?"===e[0]?this.indentate(n)+"<"+e+i+"?"+this.tagEndChar:this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let s="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",s=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(n)+"<"+e+i+r+this.tagEndChar+t+this.indentate(n)+s:this.indentate(n)+"<"+e+i+r+">"+t+s}},le.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},le.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},le.prototype.buildTextValNode=function(t,e,i,n,s){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName){const e=String(t).replace(/\]\]>/g,"]]]]><![CDATA[>");return this.indentate(n)+`<![CDATA[${e}]]>`+this.newLine}if(!1!==this.options.commentPropName&&e===this.options.commentPropName){const e=String(t).replace(/--/g,"- -").replace(/-$/,"- ");return this.indentate(n)+`\x3c!--${e}--\x3e`+this.newLine}if("?"===e[0])return this.indentate(n)+"<"+e+i+"?"+this.tagEndChar;{let s=this.options.tagValueProcessor(e,t);return s=this.replaceEntitiesValue(s),""===s?this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(n)+"<"+e+i+">"+s+"</"+e+this.tagEndChar}},le.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};class de{}e(de,"parser",new Kt({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0})),e(de,"builder",new le({attributeNamePrefix:"$",ignoreAttributes:!1,suppressBooleanAttributes:!1}));class pe{static join(t){const e={};for(const i of t)for(const t in i)if(e[t])for(const n of i[t])e[t].add(n);else e[t]=new Set(i[t]);return e}static intersect(t){if(0===t.length)return{};let e=pe.clone(t[0]);for(let i=1;i<t.length;i++){const n=t[i],s={};for(const t in e)if(n[t]){const i=new Set;for(const s of e[t])n[t].has(s)&&i.add(s);i.size>0&&(s[t]=i)}e=s}return e}static clone(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}static remove(t,e,i=!1){i&&(t=pe.clone(t));for(const i in e)if(t[i]){for(const n of e[i])t[i].delete(n);0===t[i].size&&delete t[i]}}static add(t,e,i=!1){i&&(t=pe.clone(t));for(const i in e)if(t[i])for(const n of e[i])t[i].add(n);else t[i]=new Set(e[i])}static append(t,e,...i){let n=t[e];n||(n=new Set,t[e]=n);for(const t of i)n.add(t)}static isEqual(t,e){const i=Object.keys(t),n=Object.keys(e);if(i.length!==n.length)return!1;for(const n of i){if(!e[n])return!1;if(t[n].size!==e[n].size)return!1;for(const i of t[n])if(!e[n].has(i))return!1}return!0}static isEmpty(t){return 0===Object.values(t).reduce((t,e)=>t+e.size,0)}static toRaw(t){const e={};for(const i in t)e[i]=Array.from(t[i]);return e}static fromRaw(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}}class fe extends Map{constructor(t){super(t),e(this,"onItemSet",new f),e(this,"onItemUpdated",new f),e(this,"onItemDeleted",new f),e(this,"onCleared",new f),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}set(t,e){const i=this.has(t);if(!(this.guard??(()=>!0))(t,e))return this;const n=super.set(t,e);return i?(this.onItemUpdated||(this.onItemUpdated=new f),this.onItemUpdated.trigger({key:t,value:e})):(this.onItemSet||(this.onItemSet=new f),this.onItemSet.trigger({key:t,value:e})),n}add(t){const e=A.create();return this.set(e,t),e}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(t),e}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class me{static isEntry(t){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(t.type)}static copySchema(t,e={}){for(const i in t){const n=t[i];this.isEntry(n)?e[i]=this.copyEntry(n):(e[i]={},this.copySchema(n,e[i]))}return e}static copyEntry(t){if("Boolean"===t.type){const e=t;return{type:e.type,value:e.value}}if("Color"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("Text"===t.type){const e=t;return{type:e.type,value:e.value}}if("Number"===t.type){const e=t;return{type:e.type,value:e.value,min:e.min,max:e.max,interpolable:e.interpolable}}if("Select"===t.type){const e=t;return{type:e.type,value:e.value,multiple:e.multiple,options:new Set(e.options)}}if("Vector3"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("TextSet"===t.type){const e=t;return{type:e.type,value:new Set(e.value)}}if("None"===t.type){const e=t;return{type:e.type,value:e.value}}throw new Error("Invalid entry!")}}class ge{constructor(t,i,n,s){e(this,"_component"),e(this,"name"),e(this,"uuid"),this._component=t,this.name=n,this.uuid=s??A.create();i.get(ye).list.set(this.uuid,this)}get controls(){return me.copySchema(this._config)}set(t){for(const e in t)if(e in this){this[e]=t[e].value}}export(t=this._config,e={}){for(const i in t){const n=t[i];if(me.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:{r:t,g:s,b:r}}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:{x:t,y:s,z:r}}}else if("TextSet"===n.type){const t=Array.from(n.value);e[i]={...n,value:t}}else if("Select"===n.type){const t=Array.from(n.options);e[i]={...n,options:t}}else e[i]={...n};else e[i]={},this.export(n,e[i])}return e}import(t,e={},i=!0){for(const i in t){const n=t[i];if(me.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:new u.Color(t,s,r)}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:new u.Vector3(t,s,r)}}else"TextSet"===n.type?e[i]={...n,value:new Set(n.value)}:"Select"===n.type?e[i]={...n,options:new Set(n.options)}:e[i]={...n};else e[i]={},this.import(n,e[i],!1)}i&&this.set(e)}}const we=class t extends g{constructor(n){super(n),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}};e(we,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let ye=we;class _e{constructor(t){e(this,"_event"),e(this,"_position",new u.Vector2),e(this,"onDisposed",new f),e(this,"updateMouseInfo",t=>{this._event=t}),this.dom=t,this.setupEvents(!0)}get position(){return this.updatePosition(!1),this._position.clone()}get rawPosition(){return this.updatePosition(!0),this._position.clone()}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}updatePosition(t){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event,t),this._position.y=this.getPositionY(e,this._event,t)}}getPositionY(t,e,i){const n=this.getDataObject(e);return i?n.clientY:-(n.clientY-t.top)/(t.bottom-t.top)*2+1}getPositionX(t,e,i){const n=this.getDataObject(e);return i?n.clientX:(n.clientX-t.left)/(t.right-t.left)*2-1}getDataObject(t){return t instanceof MouseEvent?t:t.touches[0]}setupEvents(t){t?(this.dom.addEventListener("pointermove",this.updateMouseInfo),this.dom.addEventListener("touchstart",this.updateMouseInfo)):(this.dom.removeEventListener("pointermove",this.updateMouseInfo),this.dom.removeEventListener("touchstart",this.updateMouseInfo))}}const be=1.25,ve=32,xe=Math.pow(2,-24),Ce=Symbol("SKIP_GENERATION"),Se={strategy:0,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ce]:!1};function Ae(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function Pe(t){let e=-1,i=-1/0;for(let n=0;n<3;n++){const s=t[n+3]-t[n];s>i&&(i=s,e=n)}return e}function Te(t,e){e.set(t)}function Me(t,e,i){let n,s;for(let r=0;r<3;r++){const o=r+3;n=t[r],s=e[r],i[r]=n<s?n:s,n=t[o],s=e[o],i[o]=n>s?n:s}}function Ee(t,e,i){for(let n=0;n<3;n++){const s=e[t+2*n],r=e[t+2*n+1],o=s-r,a=s+r;o<i[n]&&(i[n]=o),a>i[n+3]&&(i[n+3]=a)}}function Ie(t){const e=t[3]-t[0],i=t[4]-t[1],n=t[5]-t[2];return 2*(e*i+i*n+n*e)}function De(t,e){return 65535===e[t+15]}function ze(t,e){return e[t+6]}function ke(t,e){return e[t+14]}function Be(t){return t+8}function Oe(t,e){return t+8*e[t+6]}function Ve(t,e){return e[t+7]}function Le(t){return t}function Ne(t,e,i,n,s){let r=1/0,o=1/0,a=1/0,l=-1/0,c=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const w=t.offset||0;for(let n=6*(e-w),s=6*(e+i-w);n<s;n+=6){const e=t[n+0],i=t[n+1],s=e-i,w=e+i;s<r&&(r=s),w>l&&(l=w),e<u&&(u=e),e>f&&(f=e);const y=t[n+2],_=t[n+3],b=y-_,v=y+_;b<o&&(o=b),v>c&&(c=v),y<d&&(d=y),y>m&&(m=y);const x=t[n+4],C=t[n+5],S=x-C,A=x+C;S<a&&(a=S),A>h&&(h=A),x<p&&(p=x),x>g&&(g=x)}n[0]=r,n[1]=o,n[2]=a,n[3]=l,n[4]=c,n[5]=h,s[0]=u,s[1]=d,s[2]=p,s[3]=f,s[4]=m,s[5]=g}const Fe=32,Re=(t,e)=>t.candidate-e.candidate,Ue=new Array(Fe).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),je=new Float32Array(6);class $e{constructor(){this.boundingData=new Float32Array(6)}}let We,Ge,He,qe;const Ze=Math.pow(2,32);function Ye(t){return"count"in t?1:1+Ye(t.left)+Ye(t.right)}function Xe(t,e,i){return We=new Float32Array(i),Ge=new Uint32Array(i),He=new Uint16Array(i),qe=new Uint8Array(i),Ke(t,e)}function Ke(t,e){const i=t/4,n=t/2,s="count"in e,r=e.boundingData;for(let t=0;t<6;t++)We[i+t]=r[t];if(s)return e.buffer?(qe.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(Ge[i+6]=e.offset,He[n+14]=e.count,He[n+15]=65535,t+ve);{const{left:n,right:s,splitAxis:r}=e;let o=Ke(t+ve,n);const a=o/ve-t/ve;if(a>Ze)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ge[i+6]=a,Ge[i+7]=r,Ke(o,s)}}function Qe(t,e,i,n,s,r){const{maxDepth:o,verbose:a,maxLeafSize:l,strategy:c,onProgress:h}=s,u=t.primitiveBuffer,d=t.primitiveBufferStride,p=new Float32Array(6);let f=!1;const m=new $e;return Ne(e,i,n,m.boundingData,p),function t(i,n,s,r=null,h=0){!f&&h>=o&&(f=!0,a&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));if(s<=l||h>=o)return g(n+s),i.offset=n,i.count=s,i;const m=function(t,e,i,n,s,r){let o=-1,a=0;if(0===r)o=Pe(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=Pe(t),-1!==o&&(a=function(t,e,i,n){let s=0;const r=t.offset;for(let o=e,a=e+i;o<a;o++)s+=t[6*(o-r)+2*n];return s/i}(i,n,s,o));else if(2===r){const r=Ie(t);let l=be*s;const c=i.offset||0,h=6*(n-c),u=6*(n+s-c);for(let t=0;t<3;t++){const n=e[t],c=(e[t+3]-n)/Fe;if(s<8){const e=[...Ue];e.length=s;let n=0;for(let s=h;s<u;s+=6,n++){const r=e[n];r.candidate=i[s+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Ee(s,i,o)}e.sort(Re);let c=s;for(let t=0;t<c;t++){const i=e[t];for(;t+1<c&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),c--}for(let n=h;n<u;n+=6){const s=i[n+2*t];for(let t=0;t<c;t++){const r=e[t];s>=r.candidate?Ee(n,i,r.rightCacheBounds):(Ee(n,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<c;i++){const n=e[i],c=n.count,h=s-n.count,u=n.leftCacheBounds,d=n.rightCacheBounds;let p=0;0!==c&&(p=Ie(u)/r);let f=0;0!==h&&(f=Ie(d)/r);const m=1+be*(p*c+f*h);m<l&&(o=t,l=m,a=n.candidate)}}else{for(let t=0;t<Fe;t++){const e=Ue[t];e.count=0,e.candidate=n+c+t*c;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=h;e<u;e+=6){let s=~~((i[e+2*t]-n)/c);s>=Fe&&(s=31);const r=Ue[s];r.count++,Ee(e,i,r.bounds)}const e=Ue[31];Te(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Ue[t],i=Ue[t+1];Me(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let e=0;e<31;e++){const i=Ue[e],n=i.count,c=i.bounds,h=Ue[e+1].rightCacheBounds;0!==n&&(0===d?Te(c,je):Me(c,je,je)),d+=n;let u=0,p=0;0!==d&&(u=Ie(je)/r);const f=s-d;0!==f&&(p=Ie(h)/r);const m=1+be*(u*d+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(i.boundingData,r,e,n,s,c);if(-1===m.axis)return g(n+s),i.offset=n,i.count=s,i;const w=function(t,e,i,n,s,r){let o=n,a=n+s-1;const l=r.pos,c=2*r.axis,h=i.offset||0;for(;;){for(;o<=a&&i[6*(o-h)+c]<l;)o++;for(;o<=a&&i[6*(a-h)+c]>=l;)a--;if(!(o<a))return o;for(let i=0;i<e;i++){let n=t[o*e+i];t[o*e+i]=t[a*e+i],t[a*e+i]=n}for(let t=0;t<6;t++){const e=o-h,n=a-h,s=i[6*e+t];i[6*e+t]=i[6*n+t],i[6*n+t]=s}o++,a--}}(u,d,e,n,s,m);if(w===n||w===n+s)g(n+s),i.offset=n,i.count=s;else{i.splitAxis=m.axis;const r=new $e,o=n,a=w-n;i.left=r,Ne(e,o,a,r.boundingData,p),t(r,o,a,p,h+1);const l=new $e,c=w,u=s-a;i.right=l,Ne(e,c,u,l.boundingData,p),t(l,c,u,p,h+1)}return i}(m,i,n,p),m;function g(t){h&&h((t-r.offset)/r.count)}}function Je(t,e){const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=t.getRootRanges(e.range),s=n[0],r=n[n.length-1],o={offset:s.offset,count:r.offset+r.count-s.offset},a=new Float32Array(6*o.count);a.offset=o.offset,t.computePrimitiveBounds(o.offset,o.count,a),t._roots=n.map(n=>{const s=Qe(t,a,n.offset,n.count,e,o),r=Ye(s),l=new i(ve*r);return Xe(0,s,l),l})}class ti{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class ei{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}}const ii=new ei;let ni,si;const ri=[],oi=new ti(()=>new n.Box3);function ai(t,e,i,n,s,r){ni=oi.getPrimitive(),si=oi.getPrimitive(),ri.push(ni,si),ii.setBuffer(t._roots[e]);const o=li(0,t.geometry,i,n,s,r);ii.clearBuffer(),oi.releasePrimitive(ni),oi.releasePrimitive(si),ri.pop(),ri.pop();const a=ri.length;return a>0&&(si=ri[a-1],ni=ri[a-2]),o}function li(t,e,i,n,s=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:c}=ii;let h=2*t;if(De(h,l)){const e=ze(t,c),i=ke(h,l);return Ae(t,a,ni),n(e,i,!1,o,r+t/8,ni)}{let h=function(t){const{uint16Array:e,uint32Array:i}=ii;let n=2*t;for(;!De(n,e);)n=2*(t=Be(t));return ze(t,i)},u=function(t){const{uint16Array:e,uint32Array:i}=ii;let n=2*t;for(;!De(n,e);)n=2*(t=Oe(t,i));return ze(t,i)+ke(n,e)};const d=Be(t),p=Oe(t,c);let f,m,g,w,y=d,_=p;if(s&&(g=ni,w=si,Ae(y,a,g),Ae(_,a,w),f=s(g),m=s(w),m<f)){y=p,_=d;const t=f;f=m,m=t,g=w}g||(g=ni,Ae(y,a,g));const b=i(g,De(2*y,l),f,o+1,r+y/8);let v;if(2===b){const t=h(y);v=n(t,u(y)-t,!0,o+1,r+y/8,g)}else v=b&&li(y,e,i,n,s,r,o+1);if(v)return!0;w=si,Ae(_,a,w);const x=i(w,De(2*_,l),m,o+1,r+_/8);let C;if(2===x){const t=h(_);C=n(t,u(_)-t,!0,o+1,r+_/8,w)}else C=x&&li(_,e,i,n,s,r,o+1);return!!C}}const ci=new ii.constructor,hi=new ii.constructor,ui=new ti(()=>new n.Box3),di=new n.Box3,pi=new n.Box3,fi=new n.Box3,mi=new n.Box3;let gi=!1;function wi(t,e,i,n,s,r=0,o=0,a=0,l=0,c=null,h=!1){let u,d;h?(u=hi,d=ci):(u=ci,d=hi);const p=u.float32Array,f=u.uint32Array,m=u.uint16Array,g=d.float32Array,w=d.uint32Array,y=d.uint16Array,_=2*e,b=De(2*t,m),v=De(_,y);let x=!1;if(v&&b)x=h?s(ze(e,w),ke(2*e,y),ze(t,f),ke(2*t,m),l,o+e/8,a,r+t/8):s(ze(t,f),ke(2*t,m),ze(e,w),ke(2*e,y),a,r+t/8,l,o+e/8);else if(v){const c=ui.getPrimitive();Ae(e,g,c),c.applyMatrix4(i);const u=Be(t),d=Oe(t,f);Ae(u,p,di),Ae(d,p,pi);const m=c.intersectsBox(di),w=c.intersectsBox(pi);x=m&&wi(e,u,n,i,s,o,r,l,a+1,c,!h)||w&&wi(e,d,n,i,s,o,r,l,a+1,c,!h),ui.releasePrimitive(c)}else{const u=Be(e),d=Oe(e,w);Ae(u,g,fi),Ae(d,g,mi);const m=c.intersectsBox(fi),y=c.intersectsBox(mi);if(m&&y)x=wi(t,u,i,n,s,r,o,a,l+1,c,h)||wi(t,d,i,n,s,r,o,a,l+1,c,h);else if(m)if(b)x=wi(t,u,i,n,s,r,o,a,l+1,c,h);else{const e=ui.getPrimitive();e.copy(fi).applyMatrix4(i);const c=Be(t),d=Oe(t,f);Ae(c,p,di),Ae(d,p,pi);const m=e.intersectsBox(di),g=e.intersectsBox(pi);x=m&&wi(u,c,n,i,s,o,r,l,a+1,e,!h)||g&&wi(u,d,n,i,s,o,r,l,a+1,e,!h),ui.releasePrimitive(e)}else if(y)if(b)x=wi(t,d,i,n,s,r,o,a,l+1,c,h);else{const e=ui.getPrimitive();e.copy(mi).applyMatrix4(i);const c=Be(t),u=Oe(t,f);Ae(c,p,di),Ae(u,p,pi);const m=e.intersectsBox(di),g=e.intersectsBox(pi);x=m&&wi(d,c,n,i,s,o,r,l,a+1,e,!h)||g&&wi(d,u,n,i,s,o,r,l,a+1,e,!h),ui.releasePrimitive(e)}}return x}const yi=new n.Box3,_i=new Float32Array(6);class bi{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){Je(this,t={...Se,...t})}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,n){let s=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,c=-1/0;for(let i=t,n=t+e;i<n;i++){this.writePrimitiveBounds(i,_i,0);const[t,e,n,h,u,d]=_i;t<s&&(s=t),h>a&&(a=h),e<r&&(r=e),u>l&&(l=u),n<o&&(o=n),d>c&&(c=d)}return i[n+0]=s,i[n+1]=r,i[n+2]=o,i[n+3]=a,i[n+4]=l,i[n+5]=c,i}computePrimitiveBounds(t,e,i){const n=i.offset||0;for(let s=t,r=t+e;s<r;s++){this.writePrimitiveBounds(s,_i,0);const[t,e,r,o,a,l]=_i,c=(t+o)/2,h=(e+a)/2,u=(r+l)/2,d=(o-t)/2,p=(a-e)/2,f=(l-r)/2,m=6*(s-n);i[m+0]=c,i[m+1]=d+(Math.abs(c)+d)*xe,i[m+2]=h,i[m+3]=p+(Math.abs(h)+p)*xe,i[m+4]=u,i[m+5]=f+(Math.abs(u)+f)*xe}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,n=e.length;i<n;i++)e[i]+=t;else{const e=this._roots;for(let i=0;i<e.length;i++){const n=e[i],s=new Uint32Array(n),r=new Uint16Array(n),o=n.byteLength/ve;for(let e=0;e<o;e++){const i=8*e;De(2*i,r)&&(s[i+6]+=t)}}}}traverse(t,e=0){const i=this._roots[e],n=new Uint32Array(i),s=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=De(a,s);if(l){const e=n[r+6],c=s[a+14];t(o,l,new Float32Array(i,4*r,6),e,c)}else{const s=Be(r),a=Oe(r,n),c=Ve(r,n);t(o,l,new Float32Array(i,4*r,6),c)||(e(s,o+1),e(a,o+1))}}(0)}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const i=t[e],n=new Uint32Array(i),s=new Uint16Array(i),r=new Float32Array(i);for(let t=i.byteLength/ve-1;t>=0;t--){const e=8*t,i=2*e;if(De(i,s)){const t=ze(e,n),o=ke(i,s);this.writePrimitiveRangeBounds(t,o,_i,0),r.set(_i,e)}else{const t=Be(e),i=Oe(e,n);for(let n=0;n<3;n++){const s=r[t+n],o=r[t+n+3],a=r[i+n],l=r[i+n+3];r[e+n]=s<a?s:a,r[e+n+3]=o>l?o:l}}}}}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{Ae(0,new Float32Array(e),yi),t.union(yi)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:n,intersectsPrimitive:s,scratchPrimitive:r,iterate:o}=t;if(n&&s){const t=n;n=(e,i,n,a,l)=>!!t(e,i,n,a,l)||o(e,i,this,s,n,a,r)}else n||(n=s?(t,e,i,n)=>o(t,e,this,s,i,n,r):(t,e,i)=>i);let a=!1,l=0;const c=this._roots;for(let t=0,s=c.length;t<s;t++){const s=c[t];if(a=ai(this,t,i,n,e,l),a)break;l+=s.byteLength/ve}return a}bvhcast(t,e,i){let{intersectsRanges:s}=i;return function(t,e,i,s){if(gi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");gi=!0;const r=t._roots,o=e._roots;let a,l=0,c=0;const h=(new n.Matrix4).copy(i).invert();for(let t=0,e=r.length;t<e;t++){ci.setBuffer(r[t]),c=0;const e=ui.getPrimitive();Ae(Le(0),ci.float32Array,e),e.applyMatrix4(h);for(let t=0,n=o.length;t<n&&(hi.setBuffer(o[t]),a=wi(0,0,i,h,s,l,c,0,0,e),hi.clearBuffer(),c+=o[t].byteLength/ve,!a);t++);if(ui.releasePrimitive(e),ci.clearBuffer(),l+=r[t].byteLength/ve,a)break}return gi=!1,a}(this,t,e,s)}}function vi(t){return t.index?t.index.count:t.attributes.position.count}function xi(t){return vi(t)/3}function Ci(t,e){if(!t.index){const i=t.attributes.position.count,s=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new n.BufferAttribute(s,1));for(let t=0;t<i;t++)s[t]=t}}function Si(t,e,i){const n=function(t,e,i){const n=vi(t)/i,s=e||t.drawRange,r=s.start/i,o=(s.start+s.count)/i,a=Math.max(0,r),l=Math.min(n,o)-a;return{offset:Math.floor(a),count:Math.floor(l)}}(t,e,i),s=function(t,e){return t.groups.map(t=>({offset:t.start/e,count:t.count/e}))}(t,i);if(!s.length)return[n];const r=[],o=n.offset,a=n.offset+n.count,l=vi(t)/i,c=[];for(const t of s){const{offset:e,count:i}=t,n=e,s=e+(isFinite(i)?i:l-e);n<a&&s>o&&(c.push({pos:Math.max(o,n),isStart:!0}),c.push({pos:Math.min(a,s),isStart:!1}))}c.sort((t,e)=>t.pos!==e.pos?t.pos-e.pos:"end"===t.type?-1:1);let h=0,u=null;for(const t of c){const e=t.pos;0!==h&&e!==u&&r.push({offset:u,count:e-u}),h+=t.isStart?1:-1,u=e}return r}class Ai extends bi{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("BVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");if(e.useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?t=>this._indirectBuffer[t]:t=>t,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,(e={...Se,...e})[Ce]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const n=function(t,e){const i=t[t.length-1],n=i.offset+i.count>65536,s=t.reduce((t,e)=>t+e.count,0),r=n?4:2,o=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),a=n?new Uint32Array(o):new Uint16Array(o);let l=0;for(let e=0;e<t.length;e++){const{offset:i,count:n}=t[e];for(let t=0;t<n;t++)a[l+t]=i+t;l+=n}return a}(Si(e,t.range,i),t.useSharedArrayBuffer);this._indirectBuffer=n}else Ci(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new n.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Si(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class Pi{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,n=-1/0;for(let s=0,r=t.length;s<r;s++){const r=t[s][e];i=r<i?r:i,n=r>n?r:n}this.min=i,this.max=n}setFromPoints(t,e){let i=1/0,n=-1/0;for(let s=0,r=e.length;s<r;s++){const r=e[s],o=t.dot(r);i=o<i?o:i,n=o>n?o:n}this.min=i,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Pi.prototype.setFromBox=function(){const t=new n.Vector3;return function(e,i){const n=i.min,s=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=n.x*i+s.x*(1-i),t.y=n.y*a+s.y*(1-a),t.z=n.z*l+s.z*(1-l);const c=e.dot(t);r=Math.min(c,r),o=Math.max(c,o)}this.min=r,this.max=o}}();const Ti=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Vector3;return function(n,s,r){const o=n.start,a=t,l=s.start,c=e;i.subVectors(o,l),t.subVectors(n.end,n.start),e.subVectors(s.end,s.start);const h=i.dot(c),u=c.dot(a),d=c.dot(c),p=i.dot(a),f=a.dot(a)*d-u*u;let m,g;m=0!==f?(h*u-p*d)/f:0,g=(h+m*u)/d,r.x=m,r.y=g}}(),Mi=function(){const t=new n.Vector2,e=new n.Vector3,i=new n.Vector3;return function(n,s,r,o){Ti(n,s,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return n.at(a,r),void s.at(l,o);if(a>=0&&a<=1)return l<0?s.at(0,o):s.at(1,o),void n.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?n.at(0,r):n.at(1,r),void s.closestPointToPoint(r,!0,o);{let t,c;t=a<0?n.start:n.end,c=l<0?s.start:s.end;const h=e,u=i;return n.closestPointToPoint(c,!0,e),s.closestPointToPoint(t,!0,i),h.distanceToSquared(c)<=u.distanceToSquared(t)?(r.copy(h),void o.copy(c)):(r.copy(t),void o.copy(u))}}}(),Ei=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Plane,s=new n.Line3;return function(n,r){const{radius:o,center:a}=n,{a:l,b:c,c:h}=r;s.start=l,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=l,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=c,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const u=r.getPlane(i);if(Math.abs(u.distanceToPoint(a))<=o){const t=u.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}(),Ii=["x","y","z"],Di=1e-15;function zi(t){return Math.abs(t)<Di}class ki extends n.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new n.Vector3),this.satBounds=new Array(4).fill().map(()=>new Pi),this.points=[this.a,this.b,this.c],this.plane=new n.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new n.Line3,this.needsUpdate=!0}intersectsSphere(t){return Ei(t,this)}update(){const t=this.a,e=this.b,i=this.c,n=this.points,s=this.satAxes,r=this.satBounds,o=s[0],a=r[0];this.getNormal(o),a.setFromPoints(o,n);const l=s[1],c=r[1];l.subVectors(t,e),c.setFromPoints(l,n);const h=s[2],u=r[2];h.subVectors(e,i),u.setFromPoints(h,n);const d=s[3],p=r[3];d.subVectors(i,t),p.setFromPoints(d,n);const f=l.length(),m=h.length(),g=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,f<Di?m<Di||g<Di?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):m<Di?g<Di?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):g<Di&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}ki.prototype.closestPointToSegment=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Line3;return function(n,s=null,r=null){const{start:o,end:a}=n,l=this.points;let c,h=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),Mi(i,n,t,e),c=t.distanceToSquared(e),c<h&&(h=c,s&&s.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),c=o.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),c=a.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(a)),Math.sqrt(h)}}(),ki.prototype.intersectsTriangle=function(){const t=new ki,e=new Pi,i=new Pi,s=new n.Vector3,r=new n.Vector3,o=new n.Vector3,a=new n.Vector3,l=new n.Line3,c=new n.Line3,h=new n.Vector3,u=new n.Vector2,d=new n.Vector2;function p(t,n,r,o){const l=s;t.isDegenerateIntoPoint||t.isDegenerateIntoSegment?l.copy(n.plane.normal):l.copy(t.plane.normal);const c=t.satBounds,h=t.satAxes;for(let s=1;s<4;s++){const r=c[s],o=h[s];if(e.setFromPoints(o,n.points),r.isSeparated(e))return!1;if(a.copy(l).cross(o),e.setFromPoints(a,t.points),i.setFromPoints(a,n.points),e.isSeparated(i))return!1}const u=n.satBounds,d=n.satAxes;for(let s=1;s<4;s++){const r=u[s],o=d[s];if(e.setFromPoints(o,t.points),r.isSeparated(e))return!1;if(a.crossVectors(l,o),e.setFromPoints(a,t.points),i.setFromPoints(a,n.points),e.isSeparated(i))return!1}return r&&(o||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),r.start.set(0,0,0),r.end.set(0,0,0)),!0}function f(t,e,i,n,s,r,o,a,l,c,h){let u=o/(o-a);c.x=n+(s-n)*u,h.start.subVectors(e,t).multiplyScalar(u).add(t),u=o/(o-l),c.y=n+(r-n)*u,h.end.subVectors(i,t).multiplyScalar(u).add(t)}function m(t,e,i,n,s,r,o,a,l,c,h){if(s>0)f(t.c,t.a,t.b,n,e,i,l,o,a,c,h);else if(r>0)f(t.b,t.a,t.c,i,e,n,a,o,l,c,h);else if(a*l>0||0!=o)f(t.a,t.b,t.c,e,i,n,o,a,l,c,h);else if(0!=a)f(t.b,t.a,t.c,i,e,n,a,o,l,c,h);else{if(0==l)return!0;f(t.c,t.a,t.b,n,e,i,l,o,a,c,h)}return!1}function g(t,e,i,n){const r=e.degenerateSegment,o=t.plane.distanceToPoint(r.start),a=t.plane.distanceToPoint(r.end);return zi(o)?zi(a)?p(t,e,i,n):(i&&(i.start.copy(r.start),i.end.copy(r.start)),t.containsPoint(r.start)):zi(a)?(i&&(i.start.copy(r.end),i.end.copy(r.end)),t.containsPoint(r.end)):null!=t.plane.intersectLine(r,s)&&(i&&(i.start.copy(s),i.end.copy(s)),t.containsPoint(s))}function w(t,e,i){const n=e.a;return!(!zi(t.plane.distanceToPoint(n))||!t.containsPoint(n))&&(i&&(i.start.copy(n),i.end.copy(n)),!0)}function y(t,e,i){const n=t.degenerateSegment,r=e.a;return n.closestPointToPoint(r,!0,s),r.distanceToSquared(s)<1e-30&&(i&&(i.start.copy(r),i.end.copy(r)),!0)}return function(e,i=null,n=!1){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);const a=function(t,e,i,n){if(t.isDegenerateIntoSegment){if(e.isDegenerateIntoSegment){const n=t.degenerateSegment,a=e.degenerateSegment,l=r,c=o;n.delta(l),a.delta(c);const h=s.subVectors(a.start,n.start),u=l.x*c.y-l.y*c.x;if(zi(u))return!1;const d=(h.x*c.y-h.y*c.x)/u,p=-(l.x*h.y-l.y*h.x)/u;return!(d<0||d>1||p<0||p>1)&&(!!zi(n.start.z+l.z*d-(a.start.z+c.z*p))&&(i&&(i.start.copy(n.start).addScaledVector(l,d),i.end.copy(n.start).addScaledVector(l,d)),!0))}return e.isDegenerateIntoPoint?y(t,e,i):g(e,t,i,n)}return t.isDegenerateIntoPoint?e.isDegenerateIntoPoint?e.a.distanceToSquared(t.a)<1e-30&&(i&&(i.start.copy(t.a),i.end.copy(t.a)),!0):e.isDegenerateIntoSegment?y(e,t,i):w(e,t,i):e.isDegenerateIntoPoint?w(t,e,i):e.isDegenerateIntoSegment?g(t,e,i,n):void 0}(this,e,i,n);if(void 0!==a)return a;const f=this.plane,_=e.plane;let b=_.distanceToPoint(this.a),v=_.distanceToPoint(this.b),x=_.distanceToPoint(this.c);zi(b)&&(b=0),zi(v)&&(v=0),zi(x)&&(x=0);const C=b*v,S=b*x;if(C>0&&S>0)return!1;let A=f.distanceToPoint(e.a),P=f.distanceToPoint(e.b),T=f.distanceToPoint(e.c);zi(A)&&(A=0),zi(P)&&(P=0),zi(T)&&(T=0);const M=A*P,E=A*T;if(M>0&&E>0)return!1;r.copy(f.normal),o.copy(_.normal);const I=r.cross(o);let D=0,z=Math.abs(I.x);const k=Math.abs(I.y);k>z&&(z=k,D=1);Math.abs(I.z)>z&&(D=2);const B=Ii[D],O=this.a[B],V=this.b[B],L=this.c[B],N=e.a[B],F=e.b[B],R=e.c[B];if(m(this,O,V,L,C,S,b,v,x,u,l))return p(this,e,i,n);if(m(e,N,F,R,M,E,A,P,T,d,c))return p(this,e,i,n);if(u.y<u.x){const t=u.y;u.y=u.x,u.x=t,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}if(d.y<d.x){const t=d.y;d.y=d.x,d.x=t,h.copy(c.start),c.start.copy(c.end),c.end.copy(h)}return!(u.y<d.x||d.y<u.x)&&(i&&(d.x>u.x?i.start.copy(c.start):i.start.copy(l.start),d.y<u.y?i.end.copy(c.end):i.end.copy(l.end)),!0)}}(),ki.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),ki.prototype.distanceToTriangle=function(){const t=new n.Vector3,e=new n.Vector3,i=["a","b","c"],s=new n.Line3,r=new n.Line3;return function(n,o=null,a=null){const l=o||a?s:null;if(this.intersectsTriangle(n,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let c=1/0;for(let e=0;e<3;e++){let s;const r=i[e],l=n[r];this.closestPointToPoint(l,t),s=l.distanceToSquared(t),s<c&&(c=s,o&&o.copy(t),a&&a.copy(l));const h=this[r];n.closestPointToPoint(h,t),s=h.distanceToSquared(t),s<c&&(c=s,o&&o.copy(h),a&&a.copy(t))}for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];s.set(this[h],this[u]);for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];r.set(n[h],n[u]),Mi(s,r,t,e);const d=t.distanceToSquared(e);d<c&&(c=d,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(c)}}();class Bi{constructor(t,e,i){this.isOrientedBox=!0,this.min=new n.Vector3,this.max=new n.Vector3,this.matrix=new n.Matrix4,this.invMatrix=new n.Matrix4,this.points=new Array(8).fill().map(()=>new n.Vector3),this.satAxes=new Array(3).fill().map(()=>new n.Vector3),this.satBounds=new Array(3).fill().map(()=>new Pi),this.alignedSatBounds=new Array(3).fill().map(()=>new Pi),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Bi.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,n=this.points;for(let s=0;s<=1;s++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=n[1*s|2*r|4*o];a.x=s?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const s=this.satBounds,r=this.satAxes,o=n[0];for(let t=0;t<3;t++){const e=r[t],i=s[t],a=n[1<<t];e.subVectors(o,a),i.setFromPoints(e,n)}const a=this.alignedSatBounds;a[0].setFromPointsField(n,"x"),a[1].setFromPointsField(n,"y"),a[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Bi.prototype.intersectsBox=function(){const t=new Pi;return function(e){this.needsUpdate&&this.update();const i=e.min,n=e.max,s=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=n.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=n.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=n.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const n=r[i],o=s[i];if(t.setFromBox(n,e),o.isSeparated(t))return!1}return!0}}(),Bi.prototype.intersectsTriangle=function(){const t=new ki,e=new Array(3),i=new Pi,s=new Pi,r=new n.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(t.copy(n),t.update(),n=t);const o=this.satBounds,a=this.satAxes;e[0]=n.a,e[1]=n.b,e[2]=n.c;for(let t=0;t<3;t++){const n=o[t],s=a[t];if(i.setFromPoints(s,e),n.isSeparated(i))return!1}const l=n.satBounds,c=n.satAxes,h=this.points;for(let t=0;t<3;t++){const e=l[t],n=c[t];if(i.setFromPoints(n,h),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const n=a[t];for(let t=0;t<4;t++){const o=c[t];if(r.crossVectors(n,o),i.setFromPoints(r,e),s.setFromPoints(r,h),i.isSeparated(s))return!1}}return!0}}(),Bi.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Bi.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Bi.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new n.Line3),i=new Array(12).fill().map(()=>new n.Line3),s=new n.Vector3,r=new n.Vector3;return function(n,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||l)&&(n.getCenter(r),this.closestPointToPoint(r,s),n.closestPointToPoint(s,r),a&&a.copy(s),l&&l.copy(r)),0;const c=o*o,h=n.min,u=n.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(h,u);const i=e.distanceToSquared(r);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(r),i<c))return Math.sqrt(i)}let f=0;for(let n=0;n<3;n++)for(let s=0;s<=1;s++)for(let r=0;r<=1;r++){const o=(n+1)%3,a=(n+2)%3,l=1<<n|s<<o|r<<a,c=d[s<<o|r<<a],p=d[l];e[f].set(c,p);const m=t[n],g=t[o],w=t[a],y=i[f],_=y.start,b=y.end;_[m]=h[m],_[g]=s?h[g]:u[g],_[w]=r?h[w]:u[g],b[m]=u[m],b[g]=s?h[g]:u[g],b[w]=r?h[w]:u[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){r.x=t?u.x:h.x,r.y=e?u.y:h.y,r.z=i?u.z:h.z,this.closestPointToPoint(r,s);const n=r.distanceToSquared(s);if(n<p&&(p=n,a&&a.copy(s),l&&l.copy(r),n<c))return Math.sqrt(n)}for(let t=0;t<12;t++){const n=e[t];for(let t=0;t<12;t++){const e=i[t];Mi(n,e,s,r);const o=s.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(s),l&&l.copy(r),o<c))return Math.sqrt(o)}}return Math.sqrt(p)}}();class Oi extends ti{constructor(){super(()=>new ki)}}const Vi=new Oi,Li=new n.Vector3,Ni=new n.Vector3;const Fi=parseInt(n.REVISION)>=169,Ri=parseInt(n.REVISION)<=161,Ui=new n.Vector3,ji=new n.Vector3,$i=new n.Vector3,Wi=new n.Vector2,Gi=new n.Vector2,Hi=new n.Vector2,qi=new n.Vector3,Zi=new n.Vector3,Yi=new n.Vector3,Xi=new n.Vector3;function Ki(t,e,i,s,r,o,a,l,c,h,u){Ui.fromBufferAttribute(e,o),ji.fromBufferAttribute(e,a),$i.fromBufferAttribute(e,l);const d=function(t,e,i,s,r,o,a,l){let c;if(c=o===n.BackSide?t.intersectTriangle(s,i,e,!0,r):t.intersectTriangle(e,i,s,o!==n.DoubleSide,r),null===c)return null;const h=t.origin.distanceTo(r);return h<a||h>l?null:{distance:h,point:r.clone()}}(t,Ui,ji,$i,Xi,c,h,u);if(d){if(s){Wi.fromBufferAttribute(s,o),Gi.fromBufferAttribute(s,a),Hi.fromBufferAttribute(s,l),d.uv=new n.Vector2;const t=n.Triangle.getInterpolation(Xi,Ui,ji,$i,Wi,Gi,Hi,d.uv);Fi||(d.uv=t)}if(r){Wi.fromBufferAttribute(r,o),Gi.fromBufferAttribute(r,a),Hi.fromBufferAttribute(r,l),d.uv1=new n.Vector2;const t=n.Triangle.getInterpolation(Xi,Ui,ji,$i,Wi,Gi,Hi,d.uv1);Fi||(d.uv1=t),Ri&&(d.uv2=d.uv1)}if(i){qi.fromBufferAttribute(i,o),Zi.fromBufferAttribute(i,a),Yi.fromBufferAttribute(i,l),d.normal=new n.Vector3;const e=n.Triangle.getInterpolation(Xi,Ui,ji,$i,qi,Zi,Yi,d.normal);d.normal.dot(t.direction)>0&&d.normal.multiplyScalar(-1),Fi||(d.normal=e)}const e={a:o,b:a,c:l,normal:new n.Vector3,materialIndex:0};if(n.Triangle.getNormal(Ui,ji,$i,e.normal),d.face=e,d.faceIndex=o,Fi){const t=new n.Vector3;n.Triangle.getBarycoord(Xi,Ui,ji,$i,t),d.barycoord=t}}return d}function Qi(t){return t&&t.isMaterial?t.side:t}function Ji(t,e,i,n,s,r,o){const a=3*n;let l=a+0,c=a+1,h=a+2;const{index:u,groups:d}=t;t.index&&(l=u.getX(l),c=u.getX(c),h=u.getX(h));const{position:p,normal:f,uv:m,uv1:g}=t.attributes;if(Array.isArray(e)){const t=3*n;for(let a=0,u=d.length;a<u;a++){const{start:u,count:w,materialIndex:y}=d[a];if(t>=u&&t<u+w){const t=Ki(i,p,f,m,g,l,c,h,Qi(e[y]),r,o);if(t){if(t.faceIndex=n,t.face.materialIndex=y,!s)return t;s.push(t)}}}}else{const t=Ki(i,p,f,m,g,l,c,h,Qi(e),r,o);if(t){if(t.faceIndex=n,t.face.materialIndex=0,!s)return t;s.push(t)}}return null}function tn(t,e,i,n){const s=t.a,r=t.b,o=t.c;let a=e,l=e+1,c=e+2;i&&(a=i.getX(a),l=i.getX(l),c=i.getX(c)),s.x=n.getX(a),s.y=n.getY(a),s.z=n.getZ(a),r.x=n.getX(l),r.y=n.getY(l),r.z=n.getZ(l),o.x=n.getX(c),o.y=n.getY(c),o.z=n.getZ(c)}function en(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,tn(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}function nn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(t,i,r=!1){const c=2*t;if(De(c,a)){const e=ze(t,o);let i=1/0,r=1/0,h=1/0,u=-1/0,d=-1/0,p=-1/0;for(let t=3*e,o=3*(e+ke(c,a));t<o;t++){let e=n[t];const o=s.getX(e),a=s.getY(e),l=s.getZ(e);o<i&&(i=o),o>u&&(u=o),a<r&&(r=a),a>d&&(d=a),l<h&&(h=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==h||l[t+3]!==u||l[t+4]!==d||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=h,l[t+3]=u,l[t+4]=d,l[t+5]=p,!0)}{const n=Be(t),s=Oe(t,o);let a=r,c=!1,h=!1;if(e){if(!a){const t=n/8+i/ve,r=s/8+i/ve;c=e.has(t),h=e.has(r),a=!c&&!h}}else c=!0,h=!0;const d=a||h;let p=!1;(a||c)&&(p=u(n,i,a));let f=!1;d&&(f=u(s,i,a));const m=p||f;if(m)for(let e=0;e<3;e++){const i=n+e,r=s+e,o=l[i],a=l[i+3],c=l[r],h=l[r+3];l[t+e]=o<c?o:c,l[t+e+3]=a>h?a:h}return m}}}function sn(t,e,i,n,s){let r,o,a,l,c,h;const u=1/i.direction.x,d=1/i.direction.y,p=1/i.direction.z,f=i.origin.x,m=i.origin.y,g=i.origin.z;let w=e[t],y=e[t+3],_=e[t+1],b=e[t+3+1],v=e[t+2],x=e[t+3+2];return u>=0?(r=(w-f)*u,o=(y-f)*u):(r=(y-f)*u,o=(w-f)*u),d>=0?(a=(_-m)*d,l=(b-m)*d):(a=(b-m)*d,l=(_-m)*d),!(r>l||a>o)&&((a>r||isNaN(r))&&(r=a),(l<o||isNaN(o))&&(o=l),p>=0?(c=(v-g)*p,h=(x-g)*p):(c=(x-g)*p,h=(v-g)*p),!(r>h||c>o)&&((c>r||r!=r)&&(r=c),(h<o||o!=o)&&(o=h),r<=s&&o>=n))}function rn(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let a=t,h=e+t;a<h;a++){let t;if(t=i.resolveTriangleIndex(a),tn(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}function on(t,e,i,n,s,r,o){ii.setBuffer(t._roots[e]),an(0,t,i,n,s,r,o),ii.clearBuffer()}function an(t,e,i,n,s,r,o){const{float32Array:a,uint16Array:l,uint32Array:c}=ii,h=2*t;if(De(h,l)){!function(t,e,i,n,s,r,o,a){const{geometry:l,_indirectBuffer:c}=t;for(let t=n,c=n+s;t<c;t++)Ji(l,e,i,t,r,o,a)}(e,i,n,ze(t,c),ke(h,l),s,r,o)}else{const l=Be(t);sn(l,a,n,r,o)&&an(l,e,i,n,s,r,o);const h=Oe(t,c);sn(h,a,n,r,o)&&an(h,e,i,n,s,r,o)}}const ln=["x","y","z"];function cn(t,e,i,n,s,r){ii.setBuffer(t._roots[e]);const o=hn(0,t,i,n,s,r);return ii.clearBuffer(),o}function hn(t,e,i,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:l}=ii;let c=2*t;if(De(c,a)){return function(t,e,i,n,s,r,o){const{geometry:a,_indirectBuffer:l}=t;let c=1/0,h=null;for(let t=n,l=n+s;t<l;t++){let n;n=Ji(a,e,i,t,null,r,o),n&&n.distance<c&&(h=n,c=n.distance)}return h}(e,i,n,ze(t,l),ke(c,a),s,r)}{const a=Ve(t,l),c=ln[a],h=n.direction[c]>=0;let u,d;h?(u=Be(t),d=Oe(t,l)):(u=Oe(t,l),d=Be(t));const p=sn(u,o,n,s,r)?hn(u,e,i,n,s,r):null;if(p){const t=p.point[c];if(h?t<=o[d+a]:t>=o[d+a+3])return p}const f=sn(d,o,n,s,r)?hn(d,e,i,n,s,r):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const un=new n.Box3,dn=new ki,pn=new ki,fn=new n.Matrix4,mn=new Bi,gn=new Bi;function wn(t,e,i,n){ii.setBuffer(t._roots[e]);const s=yn(0,t,i,n);return ii.clearBuffer(),s}function yn(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ii;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),mn.set(i.boundingBox.min,i.boundingBox.max,n),s=mn);if(!De(l,o)){const o=Be(t),l=Oe(t,a);Ae(o,r,un);if(s.intersectsBox(un)&&yn(o,e,i,n,s))return!0;Ae(l,r,un);return!!(s.intersectsBox(un)&&yn(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=ze(t,a),f=ke(l,o);if(fn.copy(n).invert(),i.boundsTree){Ae(t,r,gn),gn.matrix.copy(fn),gn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>gn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(tn(pn,e,c,h),pn.needsUpdate=!0,t.intersectsTriangle(pn))return!0;return!1}})}{const t=xi(i);for(let e=3*p,i=3*(f+p);e<i;e+=3){tn(dn,e,c,h),dn.a.applyMatrix4(fn),dn.b.applyMatrix4(fn),dn.c.applyMatrix4(fn),dn.needsUpdate=!0;for(let e=0,i=3*t;e<i;e+=3)if(tn(pn,e,u,d),pn.needsUpdate=!0,dn.intersectsTriangle(pn))return!0}}}}const _n=new n.Matrix4,bn=new Bi,vn=new Bi,xn=new n.Vector3,Cn=new n.Vector3,Sn=new n.Vector3,An=new n.Vector3;function Pn(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),bn.set(e.boundingBox.min,e.boundingBox.max,i),bn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=Vi.getPrimitive(),p=Vi.getPrimitive();let f=xn,m=Cn,g=null,w=null;s&&(g=Sn,w=An);let y=1/0,_=null,b=null;return _n.copy(i).invert(),vn.matrix.copy(_n),t.shapecast({boundsTraverseOrder:t=>bn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(vn.min.copy(t.min),vn.max.copy(t.max),vn.needsUpdate=!0),!0),intersectsRange:(t,n)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>vn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,s)=>{for(let o=e,a=e+s;o<a;o++){tn(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){tn(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),w&&w.copy(g),y=t,_=e,b=o),t<r)return!0}}}})}for(let s=0,o=xi(e);s<o;s++){tn(p,3*s,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){tn(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),w&&w.copy(g),y=t,_=e,b=s),t<r)return!0}}}}),Vi.releasePrimitive(d),Vi.releasePrimitive(p),y===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=y,n.faceIndex=_,s&&(s.point?s.point.copy(w):s.point=w.clone(),s.point.applyMatrix4(_n),m.applyMatrix4(_n),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}function Tn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(i,r,c=!1){const h=2*i;if(De(h,a)){const e=ze(i,o);let r=1/0,c=1/0,u=1/0,d=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+ke(h,a);i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=n?n[i]:i;const o=s.getX(i),a=s.getY(i),l=s.getZ(i);o<r&&(r=o),o>d&&(d=o),a<c&&(c=a),a>p&&(p=a),l<u&&(u=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==c||l[i+2]!==u||l[i+3]!==d||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=c,l[i+2]=u,l[i+3]=d,l[i+4]=p,l[i+5]=f,!0)}{const t=Be(i),n=Oe(i,o);let s=c,a=!1,h=!1;if(e){if(!s){const i=t/8+r/ve,o=n/8+r/ve;a=e.has(i),h=e.has(o),s=!a&&!h}}else a=!0,h=!0;const d=s||h;let p=!1;(s||a)&&(p=u(t,r,s));let f=!1;d&&(f=u(n,r,s));const m=p||f;if(m)for(let e=0;e<3;e++){const s=t+e,r=n+e,o=l[s],a=l[s+3],c=l[r],h=l[r+3];l[i+e]=o<c?o:c,l[i+e+3]=a>h?a:h}return m}}}function Mn(t,e,i,n,s,r,o){ii.setBuffer(t._roots[e]),En(0,t,i,n,s,r,o),ii.clearBuffer()}function En(t,e,i,n,s,r,o){const{float32Array:a,uint16Array:l,uint32Array:c}=ii,h=2*t;if(De(h,l)){!function(t,e,i,n,s,r,o,a){const{geometry:l,_indirectBuffer:c}=t;for(let t=n,h=n+s;t<h;t++)Ji(l,e,i,c?c[t]:t,r,o,a)}(e,i,n,ze(t,c),ke(h,l),s,r,o)}else{const l=Be(t);sn(l,a,n,r,o)&&En(l,e,i,n,s,r,o);const h=Oe(t,c);sn(h,a,n,r,o)&&En(h,e,i,n,s,r,o)}}const In=["x","y","z"];function Dn(t,e,i,n,s,r){ii.setBuffer(t._roots[e]);const o=zn(0,t,i,n,s,r);return ii.clearBuffer(),o}function zn(t,e,i,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:l}=ii;let c=2*t;if(De(c,a)){return function(t,e,i,n,s,r,o){const{geometry:a,_indirectBuffer:l}=t;let c=1/0,h=null;for(let t=n,u=n+s;t<u;t++){let n;n=Ji(a,e,i,l?l[t]:t,null,r,o),n&&n.distance<c&&(h=n,c=n.distance)}return h}(e,i,n,ze(t,l),ke(c,a),s,r)}{const a=Ve(t,l),c=In[a],h=n.direction[c]>=0;let u,d;h?(u=Be(t),d=Oe(t,l)):(u=Oe(t,l),d=Be(t));const p=sn(u,o,n,s,r)?zn(u,e,i,n,s,r):null;if(p){const t=p.point[c];if(h?t<=o[d+a]:t>=o[d+a+3])return p}const f=sn(d,o,n,s,r)?zn(d,e,i,n,s,r):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const kn=new n.Box3,Bn=new ki,On=new ki,Vn=new n.Matrix4,Ln=new Bi,Nn=new Bi;function Fn(t,e,i,n){ii.setBuffer(t._roots[e]);const s=Rn(0,t,i,n);return ii.clearBuffer(),s}function Rn(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ii;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),Ln.set(i.boundingBox.min,i.boundingBox.max,n),s=Ln);if(!De(l,o)){const o=Be(t),l=Oe(t,a);Ae(o,r,kn);if(s.intersectsBox(kn)&&Rn(o,e,i,n,s))return!0;Ae(l,r,kn);return!!(s.intersectsBox(kn)&&Rn(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=ze(t,a),f=ke(l,o);if(Vn.copy(n).invert(),i.boundsTree){Ae(t,r,Nn),Nn.matrix.copy(Vn),Nn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>Nn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let i=p,n=f+p;i<n;i++)if(tn(On,3*e.resolveTriangleIndex(i),c,h),On.needsUpdate=!0,t.intersectsTriangle(On))return!0;return!1}})}{const t=xi(i);for(let i=p,n=f+p;i<n;i++){const n=e.resolveTriangleIndex(i);tn(Bn,3*n,c,h),Bn.a.applyMatrix4(Vn),Bn.b.applyMatrix4(Vn),Bn.c.applyMatrix4(Vn),Bn.needsUpdate=!0;for(let e=0,i=3*t;e<i;e+=3)if(tn(On,e,u,d),On.needsUpdate=!0,Bn.intersectsTriangle(On))return!0}}}}const Un=new n.Matrix4,jn=new Bi,$n=new Bi,Wn=new n.Vector3,Gn=new n.Vector3,Hn=new n.Vector3,qn=new n.Vector3;function Zn(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),jn.set(e.boundingBox.min,e.boundingBox.max,i),jn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=Vi.getPrimitive(),p=Vi.getPrimitive();let f=Wn,m=Gn,g=null,w=null;s&&(g=Hn,w=qn);let y=1/0,_=null,b=null;return Un.copy(i).invert(),$n.matrix.copy(Un),t.shapecast({boundsTraverseOrder:t=>jn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&($n.min.copy(t.min),$n.max.copy(t.max),$n.needsUpdate=!0),!0),intersectsRange:(n,s)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>$n.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,o)=>{for(let v=e,x=e+o;v<x;v++){const e=a.resolveTriangleIndex(v);tn(p,3*e,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);tn(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<y&&(m.copy(f),w&&w.copy(g),y=n,_=e,b=v),n<r)return!0}}}})}for(let o=0,a=xi(e);o<a;o++){tn(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);tn(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<y&&(m.copy(f),w&&w.copy(g),y=n,_=e,b=o),n<r)return!0}}}}),Vi.releasePrimitive(d),Vi.releasePrimitive(p),y===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=y,n.faceIndex=_,s&&(s.point?s.point.copy(w):s.point=w.clone(),s.point.applyMatrix4(Un),m.applyMatrix4(Un),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}function Yn(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t)}const Xn=new Bi,Kn=new n.Ray,Qn=new n.Vector3,Jn=new n.Matrix4,ts=new n.Vector3,es=["getX","getY","getZ"];class is extends Ai{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,n=t._roots,s=t._indirectBuffer,r=i.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(o.roots=n.map(t=>t.slice()),o.index=r?r.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=n,o.index=r?r.array:null,o.indirectBuffer=s),o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:s,roots:r,indirectBuffer:o}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),function(t){for(let e=0;e<t.length;e++){const i=t[e],n=new Uint32Array(i),s=new Uint16Array(i);for(let t=0,e=i.byteLength/ve;t<e;t++){const e=8*t;De(2*e,s)||(n[e+6]=n[e+6]/8-t)}}}(r));const a=new is(e,{...i,[Ce]:!0});if(a._roots=r,a._indirectBuffer=o||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new n.BufferAttribute(t.index,1,!1);e.setIndex(i)}else i.array!==s&&(i.array.set(s),i.needsUpdate=!0)}return a}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),e={...e,maxLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const n=this.geometry,s=this._indirectBuffer,r=n.attributes.position,o=n.index?n.index.array:null,a=3*(s?s[t]:t);let l=a+0,c=a+1,h=a+2;o&&(l=o[l],c=o[c],h=o[h]);for(let t=0;t<3;t++){const n=r[es[t]](l),s=r[es[t]](c),o=r[es[t]](h);let a=n;s<a&&(a=s),o<a&&(a=o);let u=n;s>u&&(u=s),o>u&&(u=o),e[i+t]=a,e[i+t+3]=u}return e}computePrimitiveBounds(t,e,i){const n=this.geometry,s=this._indirectBuffer,r=n.attributes.position,o=n.index?n.index.array:null,a=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=r.array,c=r.offset||0;let h=3;r.isInterleavedBufferAttribute&&(h=r.data.stride);const u=["getX","getY","getZ"],d=i.offset;for(let n=t,p=t+e;n<p;n++){const t=3*(s?s[n]:n),e=6*(n-d);let p=t+0,f=t+1,m=t+2;o&&(p=o[p],f=o[f],m=o[m]),a||(p=p*h+c,f=f*h+c,m=m*h+c);for(let t=0;t<3;t++){let n,s,o;a?(n=r[u[t]](p),s=r[u[t]](f),o=r[u[t]](m)):(n=l[p+t],s=l[f+t],o=l[m+t]);let c=n;s<c&&(c=s),o<c&&(c=o);let h=n;s>h&&(h=s),o>h&&(h=o);const d=(h-c)/2,g=2*t;i[e+g+0]=c+d,i[e+g+1]=d+(Math.abs(c)+d)*xe}}return i}raycastObject3D(t,e,i=[]){const{material:n}=t;if(void 0===n)return;Jn.copy(t.matrixWorld).invert(),Kn.copy(e.ray).applyMatrix4(Jn),ts.setFromMatrixScale(t.matrixWorld),Qn.copy(Kn.direction).multiply(ts);const s=Qn.length(),r=e.near/s,o=e.far/s;if(!0===e.firstHitOnly){let s=this.raycastFirst(Kn,n,r,o);s=Yn(s,t,e),s&&i.push(s)}else{const s=this.raycast(Kn,n,r,o);for(let n=0,r=s.length;n<r;n++){const r=Yn(s[n],t,e);r&&i.push(r)}}return i}refit(t=null){return(this.indirect?Tn:nn)(this,t)}raycast(t,e=n.FrontSide,i=0,s=1/0){const r=this._roots,o=[],a=this.indirect?Mn:on;for(let n=0,l=r.length;n<l;n++)a(this,n,e,t,o,i,s);return o}raycastFirst(t,e=n.FrontSide,i=0,s=1/0){const r=this._roots;let o=null;const a=this.indirect?Dn:cn;for(let n=0,l=r.length;n<l;n++){const r=a(this,n,e,t,i,s);null!=r&&(null==o||r.distance<o.distance)&&(o=r)}return o}intersectsGeometry(t,e){let i=!1;const n=this._roots,s=this.indirect?Fn:wn;for(let r=0,o=n.length;r<o&&(i=s(this,r,t,e),!i);r++);return i}shapecast(t){const e=Vi.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?rn:en});return Vi.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:n,intersectsTriangles:s}=i;const r=Vi.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?t=>{const e=this.resolveTriangleIndex(t);tn(r,3*e,o,a)}:t=>{tn(r,3*t,o,a)},c=Vi.getPrimitive(),h=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?e=>{const i=t.resolveTriangleIndex(e);tn(c,3*i,h,u)}:t=>{tn(c,3*t,h,u)};if(s){if(!(t instanceof is))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const i=(t,i,n,o,a,h,u,p)=>{for(let f=n,m=n+o;f<m;f++){d(f),c.a.applyMatrix4(e),c.b.applyMatrix4(e),c.c.applyMatrix4(e),c.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++)if(l(e),r.needsUpdate=!0,s(r,c,e,f,a,h,u,p))return!0}return!1};if(n){const t=n;n=function(e,n,s,r,o,a,l,c){return!!t(e,n,s,r,o,a,l,c)||i(e,n,s,r,o,a,l,c)}}else n=i}return super.bvhcast(t,e,{intersectsRanges:n})}intersectsBox(t,e){return Xn.set(t.min,t.max,e),Xn.needsUpdate=!0,this.shapecast({intersectsBounds:t=>Xn.intersectsBox(t),intersectsTriangle:t=>Xn.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},n={},s=0,r=1/0){return(this.indirect?Zn:Pn)(this,t,e,i,n,s,r)}closestPointToPoint(t,e={},i=0,n=1/0){return function(t,e,i={},n=0,s=1/0){const r=n*n,o=s*s;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(Li.copy(e).clamp(t.min,t.max),Li.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,Li);const n=e.distanceToSquared(Li);return n<a&&(Ni.copy(Li),a=n,l=i),n<r}}),a===1/0)return null;const c=Math.sqrt(a);return i.point?i.point.copy(Ni):i.point=Ni.clone(),i.distance=c,i.faceIndex=l,i}(this,t,e,i,n)}}const ns=new n.Matrix4,ss=new n.Ray,rs=new ti(()=>new n.Line3),os=new n.Vector3,as=new n.Vector3,ls=new n.Box3,cs=["getX","getY","getZ"];class hs extends Ai{get primitiveStride(){return 2}writePrimitiveBounds(t,e,i){const n=this._indirectBuffer,{geometry:s,primitiveStride:r}=this,o=s.attributes.position,a=s.index,l=a?a.count:o.count;let c=(n?n[t]:t)*r,h=(c+1)%l;a&&(c=a.getX(c),h=a.getX(h));for(let t=0;t<3;t++){const n=o[cs[t]](c),s=o[cs[t]](h),r=n<s?n:s,a=n>s?n:s;e[i+t]=r,e[i+t+3]=a}return e}shapecast(t){const e=rs.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsLine,scratchPrimitive:e,iterate:us});return rs.releasePrimitive(e),i}raycastObject3D(t,e,i=[]){const{matrixWorld:n}=t,{firstHitOnly:s}=e;ns.copy(n).invert(),ss.copy(e.ray).applyMatrix4(ns);const r=e.params.Line.threshold/((t.scale.x+t.scale.y+t.scale.z)/3),o=r*r;let a=null,l=1/0;return this.shapecast({boundsTraverseOrder:t=>t.distanceToPoint(ss.origin),intersectsBounds:t=>(ls.copy(t).expandByScalar(Math.abs(r)),ss.intersectsBox(ls)?1:0),intersectsLine:(r,c)=>{if(ss.distanceSqToSegment(r.start,r.end,os,as)>o)return;os.applyMatrix4(t.matrixWorld);const h=e.ray.origin.distanceTo(os);h<e.near||h>e.far||s&&h>=l||(l=h,c=this.resolvePrimitiveIndex(c),a={distance:h,point:as.clone().applyMatrix4(n),index:c*this.primitiveStride,face:null,faceIndex:null,barycoord:null,object:t},s||i.push(a))}}),s&&a&&i.push(a),i}}function us(t,e,i,n,s,r,o){const{geometry:a,primitiveStride:l}=i,{index:c}=a,h=a.attributes.position,u=c?c.count:h.count;for(let a=t,d=e+t;a<d;a++){let t=i.resolvePrimitiveIndex(a)*l,e=(t+1)%u;if(c&&(t=c.getX(t),e=c.getX(e)),o.start.fromBufferAttribute(h,t),o.end.fromBufferAttribute(h,e),n(o,a,s,r))return!0}return!1}const ds={Mesh:n.Mesh.prototype.raycast,Line:n.Line.prototype.raycast,LineSegments:n.LineSegments.prototype.raycast,LineLoop:n.LineLoop.prototype.raycast,Points:n.Points.prototype.raycast,BatchedMesh:n.BatchedMesh.prototype.raycast},ps=new n.Mesh,fs=[];function ms(t,e){if(this.isBatchedMesh)gs.call(this,t,e);else{const{geometry:i}=this;if(i.boundsTree)i.boundsTree.raycastObject3D(this,t,e);else{let i;if(this instanceof n.Mesh)i=ds.Mesh;else if(this instanceof n.LineSegments)i=ds.LineSegments;else if(this instanceof n.LineLoop)i=ds.LineLoop;else if(this instanceof n.Line)i=ds.Line;else{if(!(this instanceof n.Points))throw new Error("BVH: Fallback raycast function not found.");i=ds.Points}i.call(this,t,e)}}}function gs(t,e){if(this.boundsTrees){const i=this.boundsTrees,s=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,o=this.matrixWorld;ps.material=this.material,ps.geometry=this.geometry;const a=ps.geometry.boundsTree,l=ps.geometry.drawRange;null===ps.geometry.boundingSphere&&(ps.geometry.boundingSphere=new n.Sphere);for(let n=0,a=s.length;n<a;n++){if(!this.getVisibleAt(n))continue;const a=s[n].geometryIndex;if(ps.geometry.boundsTree=i[a],this.getMatrixAt(n,ps.matrixWorld).premultiply(o),!ps.geometry.boundsTree){this.getBoundingBoxAt(a,ps.geometry.boundingBox),this.getBoundingSphereAt(a,ps.geometry.boundingSphere);const t=r[a];ps.geometry.setDrawRange(t.start,t.count)}ps.raycast(t,fs);for(let t=0,i=fs.length;t<i;t++){const i=fs[t];i.object=this,i.batchId=n,e.push(i)}fs.length=0}ps.geometry.boundsTree=a,ps.geometry.drawRange=l,ps.material=null,ps.geometry=null}else ds.BatchedMesh.call(this,t,e)}function ws(t={}){const{type:e=is}=t;return this.boundsTree=new e(this,t),this.boundsTree}function ys(){this.boundsTree=null}const _s=class t extends g{constructor(i){super(i),e(this,"onDisposed",new f),e(this,"onBeforeDispose",new f),e(this,"onFragmentsLoaded",new f),e(this,"baseCoordinationModel",""),e(this,"baseCoordinationMatrix",new u.Matrix4),e(this,"enabled",!0),e(this,"_core"),this.components.add(t.uuid,this)}static getWorker(){return i.FragmentsModels.getWorker()}get initialized(){return!!this._core}get list(){return this.core.models.list}get core(){if(!this._core)throw new Error("FragmentsManager not initialized. Call init() first.");return this._core}get _hasCoordinationModel(){return""!==this.baseCoordinationModel}dispose(){this.onBeforeDispose.trigger(),this._core&&(this.core.dispose(),this._core=void 0),this.baseCoordinationModel="",this.onFragmentsLoaded.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}init(t,e){this._core=new i.FragmentsModels(t,e),this.core.onModelLoaded.add(async()=>{if(this._hasCoordinationModel)return;const t=[...this.list.values()][0];t&&(this.baseCoordinationModel=t.modelId,this.baseCoordinationMatrix=await t.getCoordinationMatrix())}),this.list.onItemDeleted.add(()=>{this.list.size>0||(this.baseCoordinationModel="",this.baseCoordinationMatrix=new u.Matrix4)})}async raycast(t){const e=[];for(const i of this.core.models.list.values())if(t.snappingClasses&&t.snappingClasses.length>0){const n=await i.raycastWithSnapping(t);if(n&&n.length>0)e.push(n[0]);else{const n=await i.raycast(t);n&&e.push(n)}}else{const n=await i.raycast(t);n&&e.push(n)}if(await Promise.all(e),0===e.length)return;let i=e[0],n=i.distance;for(let t=1;t<e.length;t++)e[t].distance<n&&(n=e[t].distance,i=e[t]);return i}async getPositions(t){const e=[],i=async(t,i)=>{const n=await t.getPositions(i);for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async getBBoxes(t){const e=[],i=async(t,i)=>{const n=await t.getBoxes(i);if(n)for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async highlight(t,e){await this.forEachModel(e,"highlight",t)}async getData(t,e){const i={};for(const[n,s]of Object.entries(t)){const t=this.list.get(n);if(!t)continue;if(0===s.size){i[n]=[];continue}const r=await t.getItemsData([...s],e);i[n]=r}return i}async resetHighlight(t){await this.forEachModel(t,"resetHighlight")}async forEachModel(t,e,...i){const n={};if(t)for(const e in t){const i=t[e];n[e]=Array.from(i)}else for(const t of this.core.models.list.keys())n[t]=void 0;const s=[];for(const t in n){const r=this.core.models.list.get(t);if(r){const o=n[t],a=r[e](o,...i);s.push(a)}}await Promise.all(s)}async guidsToModelIdMap(t){const e={};for(const[i,n]of this.list){const s=(await n.getLocalIdsByGuids([...t])).filter(t=>null!==t);e[i]=new Set(s)}return e}async modelIdMapToGuids(t){const e=[];for(const[i,n]of Object.entries(t)){const t=this.list.get(i);if(!t)continue;const s=(await t.getGuidsByLocalIds([...n])).filter(t=>null!==t);e.push(...s)}return e}applyBaseCoordinateSystem(t,e){const i=new u.Matrix4;return e&&i.copy(e.clone()).invert(),i.multiply(this.baseCoordinationMatrix),t.applyMatrix4(i),i}};e(_s,"uuid","fef46874-46a3-461b-8c44-2922ab77c806");let bs=_s;function vs(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16}class xs{constructor(t,e={}){const{pixelsPerMeter:i=.1}=e;this.pixelsPerMeter=i,this.renderer=t}async cull(t){t=function(t){const e=new Set;return t.traverse(t=>{t.isMesh&&e.add(t)}),Array.from(e)}(t);const{renderer:e,pixelsPerMeter:i}=this,s=new n.Vector3,r=new n.OrthographicCamera,o=new n.Box3,a=new n.WebGLRenderTarget(1,1);o.makeEmpty(),t.forEach(t=>{o.expandByObject(t)}),o.getSize(s);const l=Math.min(e.capabilities.maxTextureSize,8192),c=Math.ceil(s.x/i),h=Math.ceil(s.z/i),u=Math.ceil(c/l),d=Math.ceil(h/l);a.setSize(Math.ceil(c/u),Math.ceil(h/d));const p=.01*Math.max(s.y,1);r.rotation.x=-Math.PI/2,r.near=0,r.far=s.y+2*p,r.position.y=o.max.y+p;const f=new n.Scene,m=new Map,g=new Map,w=[];for(let e=0;e<t.length;e++){const i=t[e];m.set(i,i.material),g.set(i,i.parent);const n=new Cs;n.objectId=e,w.push(n),i.material=n,f.add(i)}const y=e.getClearColor(new n.Color),_=e.getClearAlpha(),b=e.getRenderTarget(),v=e.autoClear;e.autoClear=!0,e.setClearColor(0,0),e.setRenderTarget(a);const x=new Uint8Array(a.width*a.height*4),C=new Set,S=s.x/u,A=s.z/d;for(let i=0;i<u;i++)for(let n=0;n<d;n++){const s=o.min.x+S*i,l=s+S,c=o.min.z+A*n,h=(s+l)/2,u=(c+(c+A))/2;r.position.set(h,o.max.y+p,u);const d=S/2,m=A/2;r.left=-d,r.right=d,r.top=m,r.bottom=-m,r.updateProjectionMatrix(),e.render(f,r);const g=await e.readRenderTargetPixelsAsync(a,0,0,a.width,a.height,x);for(let e=0,i=g.length;e<i;e+=4){if(0===g[e+3])continue;const i=vs(g,e);C.add(t[i])}}for(const e of t){e.material=m.get(e);const t=g.get(e);t?t.add(e):f.remove(e)}e.setClearColor(y,_),e.setRenderTarget(b),e.autoClear=v;for(const t of w)t.dispose();return a.dispose(),Array.from(C)}}class Cs extends n.ShaderMaterial{get objectId(){return this._objectId}set objectId(t){var e,i;this._objectId=t,e=t,(i=this.uniforms.objectId.value).x=(255&e)/255,i.y=(e>>8&255)/255,i.z=(e>>16&255)/255,i.w=1}constructor(t){super({glslVersion:n.GLSL3,blending:n.NoBlending,side:n.DoubleSide,uniforms:{objectId:{value:new n.Vector4}},vertexShader:"\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\t\t\t\tlayout(location = 0) out vec4 out_id;\n\t\t\t\tuniform vec4 objectId;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tout_id = objectId;\n\n\t\t\t\t}\n\t\t\t"}),this._objectId=0,this.setValues(t)}}const Ss=1e-16,As=new n.Vector3(0,1,0),Ps=new n.Vector3;function Ts(t){return t.delta(Ps).normalize(),Math.abs(Ps.dot(As))>=1-Ss}function Ms(t,e){const{start:i,end:n}=e,s=t.points;let r=!1,o=!1;for(let t=0;t<3;t++){const e=s[t];if(!r&&i.distanceToSquared(e)<=Ss&&(r=!0),!o&&n.distanceToSquared(e)<=Ss&&(o=!0),r&&o)return!0}return r&&o}const Es=new n.Line3;function Is(t,e,i=!1,n=[]){let s=[[0,1]];for(let t=0,i=e.length;t<i;t++){const i=s[t],n=e[t];i[1]=n[0],s.push([n[1],1])}i&&([e,s]=[s,e]);for(let e=0,i=s.length;e<i;e++){const{start:i,end:r}=t;Es.start.lerpVectors(i,r,s[e][0]),Es.end.lerpVectors(i,r,s[e][1]),n.push(new Float32Array([Es.start.x,Es.start.y,Es.start.z,Es.end.x,Es.end.y,Es.end.z]))}return n}const Ds=new n.Vector3(0,1,0),zs=new n.Vector3,ks=new n.Vector3,Bs=new n.Vector3,Os=new n.Triangle;function*Vs(t,e=[],i={}){const{projectionDirection:s=Ds,thresholdAngle:r=1,iterationTime:o=30}=i,a=Math.pow(10,4),l=Math.cos(n.MathUtils.DEG2RAD*r),c=t.getIndex(),h=t.getAttribute("position"),u=c?c.count:h.count,d=[0,0,0],p=["a","b","c"],f=new Array(3),m={};let g=performance.now();for(let t=0;t<u;t+=3){performance.now()-g>o&&(yield,g=performance.now()),c?(d[0]=c.getX(t),d[1]=c.getX(t+1),d[2]=c.getX(t+2)):(d[0]=t,d[1]=t+1,d[2]=t+2);const{a:i,b:r,c:u}=Os;if(i.fromBufferAttribute(h,d[0]),r.fromBufferAttribute(h,d[1]),u.fromBufferAttribute(h,d[2]),Os.getNormal(Bs),f[0]=`${Math.round(i.x*a)},${Math.round(i.y*a)},${Math.round(i.z*a)}`,f[1]=`${Math.round(r.x*a)},${Math.round(r.y*a)},${Math.round(r.z*a)}`,f[2]=`${Math.round(u.x*a)},${Math.round(u.y*a)},${Math.round(u.z*a)}`,f[0]!==f[1]&&f[1]!==f[2]&&f[2]!==f[0])for(let t=0;t<3;t++){const i=(t+1)%3,r=f[t],o=f[i],a=Os[p[t]],c=Os[p[i]],h=`${r}_${o}`,u=`${o}_${r}`;if(u in m&&m[u]){const t=m[u].normal,i=Bs.dot(t)<=l;let r=!1;if(null!==s){let e=s.dot(Bs);e=Math.abs(e)<1e-10?0:e;let i=s.dot(t);i=Math.abs(i)<1e-10?0:i,r=Math.sign(e)!==Math.sign(i)}if(i||r){const t=new n.Line3;t.start.copy(a),t.end.copy(c),e.push(t)}m[u]=null}else h in m||(m[h]={index0:d[t],index1:d[i],normal:Bs.clone()})}}for(const t in m)if(m[t]){const{index0:i,index1:s}=m[t];zs.fromBufferAttribute(h,i),ks.fromBufferAttribute(h,s);const r=new n.Line3;r.start.copy(zs),r.end.copy(ks),e.push(r)}return e}const Ls=new n.Line3;function Ns(t,e,i,n=[]){return t.bvhcast(e,i,{intersectsTriangles:(t,e)=>!function(t,e){const i=["a","b","c"];let n=0;for(let s=0;s<3;s++)for(let r=0;r<3;r++){Fs(t[i[s]],e[i[r]])&&n++}return n>=2}(t,e)&&(t.needsUpdate&&t.update(),e.needsUpdate&&e.update(),!(Math.abs(t.plane.normal.dot(e.plane.normal))>.999999)&&void(!t.intersectsTriangle(e,Ls,!0)||Ms(t,Ls)||Ms(e,Ls)||n.push(Ls.clone())))}),n}function Fs(t,e){return t.distanceTo(e)<1e-10}function Rs(t){Us(t);let e=[];return t.traverse(t=>{t.geometry&&t.visible&&e.push(t)}),e}const Us=t=>{if(void 0===t)return;const e=[...t.children];for(const i of e)void 0===i?t.children.splice(t.children.indexOf(i),1):Us(i)},js=new n.Matrix4,$s=new n.Matrix4;class Ws{constructor(){this.projectionDirection=new n.Vector3(0,1,0),this.thresholdAngle=50,this.iterationTime=30}getEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.getEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*getEdgesGenerator(t,e=[],i=null){const{projectionDirection:s,thresholdAngle:r,iterationTime:o}=this;if(t.isObject3D){const a=Rs(t);let l=null;s&&(l=new n.Vector3);let c=performance.now();for(let t=0;t<a.length;t++){c-performance.now()>o&&(yield);const n=a[t];l&&($s.copy(n.matrixWorld).invert(),l.copy(s).transformDirection($s).normalize());const h=yield*Vs(n.geometry,[],{projectionDirection:l,thresholdAngle:r,iterationTime:o});Gs(h,n.matrixWorld);for(let t=0;t<h.length;t++)e.push(h[t]);if(null!==i)for(let t=0;t<h.length;t++)i.push(n)}return e}return yield*Vs(t,e,{projectionDirection:s,thresholdAngle:r,iterationTime:o})}getIntersectionEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.getIntersectionEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*getIntersectionEdgesGenerator(t,e=[],i=null){const{iterationTime:n}=this;if(t.isObject3D){const s=Rs(t),r=new Map;let o=performance.now();for(let t=0;t<s.length;t++){performance.now()-o>n&&(yield,o=performance.now());const e=s[t].geometry;if(!r.has(e)){const t=e.boundsTree||new is(e,{maxLeafSize:1});r.set(e,t)}}o=performance.now();for(let t=0;t<s.length;t++)for(let a=t;a<s.length;a++){performance.now()-o>n&&(yield,o=performance.now());const l=s[t],c=s[a],h=r.get(l.geometry),u=r.get(c.geometry);js.copy(l.matrixWorld).invert().multiply(c.matrixWorld);const d=Ns(h,u,js,[]);Gs(d,l.matrixWorld);for(let t=0;t<d.length;t++)e.push(d[t]);if(null!==i)for(let t=0;t<d.length;t++)i.push(l)}return e}{let i;return t.isBufferGeometry?i=t.boundsTree||new is(t,{maxLeafSize:1}):(i=t,t=i.geometry),js.identity(),Ns(i,i,js,e)}}}function Gs(t,e,i=1e-6){for(let n=0;n<t.length;n++){const s=t[n];s.applyMatrix4(e),s.start.y+=i,s.end.y+=i}}class Hs extends bi{get lines(){return this.primitiveBuffer}constructor(t,e){super(e),this.primitiveBuffer=t,this.primitiveBufferStride=1,this.heightOffset=e.heightOffset??1e3,this.init(e)}writePrimitiveBounds(t,e,i){const{primitiveBuffer:n,heightOffset:s}=this,{start:r,end:o}=n[t];e[i+0]=Math.min(r.x,o.x),e[i+1]=Math.min(r.y,o.y),e[i+2]=Math.min(r.z,o.z),e[i+3]=Math.max(r.x,o.x),e[i+4]=Math.max(r.y,o.y)+s,e[i+5]=Math.max(r.z,o.z)}getRootRanges(){return[{offset:0,count:this.primitiveBuffer.length}]}}const qs=new n.Vector3(0,1,0),Zs=new n.Plane,Ys=new n.Vector3,Xs=new n.Vector3;function Ks(t,e,i){t.needsUpdate&&t.update(),Zs.copy(t.plane),Zs.normal.dot(qs)<0&&(Zs.normal.multiplyScalar(-1),Zs.constant*=-1);const s=Zs.distanceToPoint(e.start),r=Zs.distanceToPoint(e.end),o=Math.abs(s)<1e-16,a=s<0,l=r<0;if(e.delta(Xs).normalize(),Math.abs(Zs.normal.dot(Xs))<1e-16)return!(o||!a)&&(i.copy(e),!0);if(a&&l)return i.copy(e),!0;if(!a&&!l)return!1;{const t=n.MathUtils.mapLinear(0,s,r,0,1);if(e.at(t,Ys),a)return i.start.copy(e.start),i.end.copy(Ys),!0;if(l)return i.end.copy(e.end),i.start.copy(Ys),!0}return!1}const Qs=new n.Plane,Js=new n.Vector3,tr=new n.Vector3,er=new ki,ir=new n.Line3,nr=new n.Line3,sr=new n.Vector3,rr=new n.Vector3,or=new n.Vector3;function ar(t,e,i=new n.Line3){if(er.copy(e),er.a.y=0,er.b.y=0,er.c.y=0,er.update(),ir.copy(t),ir.start.y=0,ir.end.y=0,er.getArea()<=1e-16)return null;const s=ir.distance();ir.delta(sr).divideScalar(s),rr.copy(sr).cross(er.plane.normal).normalize(),Qs.setFromNormalAndCoplanarPoint(rr,ir.start);let r=0;const{points:o}=er;for(let t=0;t<3;t++){const e=o[t],i=o[(t+1)%3],n=Qs.distanceToPoint(e),s=Qs.distanceToPoint(i),a=Math.abs(n)<1e-16,l=Math.abs(s)<1e-16;let c=!1;if(!a&&!l&&n*s<0){const t=n/(n-s);Js.lerpVectors(e,i,t),c=!0}if((c&&!l||a)&&(a&&!c&&Js.copy(e),0===r?nr.start.copy(Js):nr.end.copy(Js),r++,2===r))break}if(2===r){if(nr.delta(or).normalize(),sr.dot(or)<0){const t=nr.start;nr.start=nr.end,nr.end=t}const e=0,n=tr.subVectors(ir.end,ir.start).dot(sr),r=tr.subVectors(nr.start,ir.start).dot(sr),o=tr.subVectors(nr.end,ir.start).dot(sr);return n<=r||o<=e?null:(t.at(Math.max(e,r)/s,i.start),t.at(Math.min(n,o)/s,i.end),i)}return null}const lr=new n.Vector3,cr=new n.Vector3,hr=new n.Vector3;function ur(t,e,i){const n=function(t,e){t.delta(lr),cr.subVectors(e.start,t.start),hr.subVectors(e.end,t.start);const i=lr.length();let n=cr.length()/i,s=hr.length()/i;if(n=Math.min(Math.max(n,0),1),s=Math.min(Math.max(s,0),1),Math.abs(n-s)<=1e-16)return null;return[n,s]}(t,e);return!!n&&(dr(n,i),!0)}function dr(t,e){let[i,n]=t,s=0,r=e.length;for(;s<r;){const t=s+r>>>1;e[t][0]<=i?s=t+1:r=t}let o=Math.max(0,s-1),a=0;for(let t=o,s=e.length;t<s;t++){const[s,r]=e[t];if(i<=r&&n>=s)i=Math.min(s,i),n=Math.max(r,n),a++;else{if(!(i>=s))break;o=t+1}}e.splice(o,a,[i,n])}const pr=new n.Vector3(0,1,0),fr=new n.Line3,mr=new n.Line3,gr=new ki;function wr(t,e,i,s,r=null){const{geometry:o,matrixWorld:a,material:l}=i,c=l.side,h=a.determinant()<0,u=t.lines;t.bvhcast(e,a,{intersectsRanges:(t,e,i,l)=>{r&&(r.candidates+=e*l);for(let d=i,p=l+i;d<p;d++){let i=3*d+0,l=3*d+1,p=3*d+2;o.index&&(i=o.index.getX(i),l=o.index.getX(l),p=o.index.getX(p));const{a:f,b:m,c:g}=gr;if(f.fromBufferAttribute(o.attributes.position,i).applyMatrix4(a),m.fromBufferAttribute(o.attributes.position,l).applyMatrix4(a),g.fromBufferAttribute(o.attributes.position,p).applyMatrix4(a),gr.needsUpdate=!0,gr.update(),c!==n.DoubleSide){if(gr.plane.normal.dot(pr)!==h===(c===n.BackSide)){r&&(r.backFaceCulled+=e);continue}}const w=Math.max(f.y,m.y,g.y),y=Math.min(f.y,m.y,g.y),_=gr.plane.normal;let b=_.x,v=_.y,x=_.z,C=gr.plane.constant;v<0&&(b=-b,v=-v,x=-x,C=-C);for(let i=t,n=e+t;i<n;i++){const t=u[i],e=Math.min(t.start.y,t.end.y),n=Math.max(t.start.y,t.end.y);if(w<=e){r&&r.yBoundsCulled++;continue}const o=t.end.x-t.start.x,a=t.end.z-t.start.z,l=o*o+a*a;if(l>1e-20){const e=1/Math.sqrt(l),i=o*e,n=a*e,s=-n,c=i,h=f.x-t.start.x,u=f.z-t.start.z,d=m.x-t.start.x,p=m.z-t.start.z,w=g.x-t.start.x,y=g.z-t.start.z,_=h*i+u*n,b=d*i+p*n,v=w*i+y*n,x=1/e,C=Math.min(_,b,v);if(Math.max(_,b,v)<0||C>x){r&&r.xzBoundsCulled++;continue}const S=h*s+u*c,A=d*s+p*c,P=w*s+y*c,T=Math.min(S,A,P),M=Math.max(S,A,P);if(T>0||M<0){r&&r.xzBoundsCulled++;continue}}const c=b*t.start.x+v*t.start.y+x*t.start.z+C,h=b*t.end.x+v*t.end.y+x*t.end.z+C;if(c>=0&&h>=0)r&&r.planeTrimCulled++;else if(Ms(gr,t))r&&r.triangleEdgeCulled++;else{if(n<y)fr.copy(t);else if(!Ks(gr,t,fr)){r&&r.planeTrimCulled++;continue}fr.distance()<1e-10?r&&r.distThresholdCulled++:ar(fr,gr,mr)?(r&&r.used++,ur(t,mr,s[i])):r&&r.noOverlapCulled++}}}}})}gr.update=()=>{gr.plane.setFromCoplanarPoints(...gr.points)};let yr=!1;const _r={},br={};let vr=null,xr=0,Cr=0;const Sr={get enabled(){return yr},set enabled(t){yr=t},reset(){for(const t in _r)delete _r[t];for(const t in br)delete br[t];vr=null,xr=0,Cr=0},setStat(t,e){br[t]=e},startTotal(){yr&&(Cr=performance.now())},startStep(t){yr&&(null!==vr&&this.endStep(),vr=t,xr=performance.now())},endStep(){if(!yr||null===vr)return;const t=performance.now()-xr;_r[vr]=t,vr=null},printSummary(){if(!yr)return;null!==vr&&this.endStep();const t=performance.now()-Cr;console.log("\n=== Projection Summary ==="),console.log(`Total time: ${t.toFixed(1)}ms\n`);for(const[e,i]of Object.entries(_r)){const n=(i/t*100).toFixed(1);console.log(` ${e}: ${i.toFixed(1)}ms (${n}%)`)}if(Object.keys(br).length>0){console.log("\n--- Stats ---");for(const[t,e]of Object.entries(br))console.log(` ${t}: ${e}`)}console.log("")}},Ar=1e-5,Pr=1e-16,Tr=1e-16;function Mr(t,e,i,n,s){t.bvhcast(e,i.matrixWorld,{intersectsRanges:(t,e,i,r)=>{n._edgeOffsets.push(t),n._edgeCounts.push(e),n._meshOffsets.push(i),n._meshCounts.push(r),n._meshIndex.push(s),n.groupCount++}})}let Er=null;async function Ir(t,e,i,n,s=null){const o=await async function(){return null===Er&&(Er=new d.WebGPURenderer,await Er.init()),Er}();t._edgeOffsets&&(t.edgeOffsets=new Uint32Array(t._edgeOffsets),t.edgeCounts=new Uint32Array(t._edgeCounts),t.meshOffsets=new Uint32Array(t._meshOffsets),t.meshCounts=new Uint32Array(t._meshCounts),t.meshIndex=new Uint32Array(t._meshIndex),t._edgeOffsets=null,t._edgeCounts=null,t._meshOffsets=null,t._meshCounts=null,t._meshIndex=null);const a=r.instancedArray(function(t){const e=new Float32Array(6*t.length);for(let i=0;i<t.length;i++){const n=t[i];e[6*i+0]=n.start.x,e[6*i+1]=n.start.y,e[6*i+2]=n.start.z,e[6*i+3]=n.end.x,e[6*i+4]=n.end.y,e[6*i+5]=n.end.z}return e}(i.lines),"float");Sr.enabled&&console.log("Number of meshes:",e.length),Sr.enabled&&console.log("Group count:",t.groupCount);const l=[];{let t=0;for(;t<e.length;){let i=t,n=0;for(;i<e.length;){const s=e[i].geometry,r=s.index?s.index.count/3:s.attributes.position.count/3;if(i>t&&(i-t>=1e3||n+r>1e5))break;n+=r,i++}l.push({start:t,end:i}),t=i}}Sr.enabled&&console.log(`Split ${e.length} meshes into ${l.length} batches`);let c=0,h=0,u=0,p=0,f=0;for(let i=0;i<l.length;i++){const{start:d,end:m}=l[i],g=m-d;Sr.enabled&&console.log(`Processing batch ${i+1}/${l.length} (meshes ${d}-${m-1})`);let w=0,y=0;const _=[];for(let t=d;t<m;t++){const i=e[t].geometry;_.push(y/3),w+=i.attributes.position.array.length,y+=i.index.array.length}const b=new Float32Array(w),v=new Uint32Array(y);let x=0,C=0,S=0;for(let t=d;t<m;t++){const i=e[t].geometry,n=i.attributes.position.array,s=i.index.array;b.set(n,x),x+=n.length;for(let t=0;t<s.length;t++)v[C+t]=s[t]+S;C+=s.length,S+=i.attributes.position.count}const A=new Float32Array(16*g);for(let t=d;t<m;t++){const i=t-d;A.set(e[t].matrixWorld.elements,16*i)}const P=[];for(let e=0;e<t.groupCount;e++){const i=t.meshIndex[e];if(i>=d&&i<m){const n=i-d,s=_[n]+t.meshOffsets[e];P.push({edgeOffset:t.edgeOffsets[e],edgeCount:t.edgeCounts[e],triOffset:s,triCount:t.meshCounts[e],meshIdx:n})}}if(0===P.length){Sr.enabled&&console.log(` Batch ${i+1}: no groups, skipping`);continue}const T=new Uint32Array(5*P.length);for(let t=0;t<P.length;t++){const e=P[t],i=5*t;T[i+0]=e.edgeOffset,T[i+1]=e.edgeCount,T[i+2]=e.triOffset,T[i+3]=e.triCount,T[i+4]=e.meshIdx}let M=0;for(let t=0;t<P.length;t++)M+=P[t].edgeCount*P[t].triCount;s&&(s.candidates+=M);let E=Math.min(Math.ceil(.1*M),2e6),I=Math.max(E,1e4);Sr.enabled&&console.log(` Batch ${i+1}: ${P.length} groups, ${w/3} vertices, ${y/3} triangles, ${M} pairs, buffer for ${I} overlaps`);const D=performance.now(),z=r.instancedArray(b,"float"),k=r.instancedArray(v,"uint"),B=r.instancedArray(A,"float"),O=r.instancedArray(T,"uint");let V=r.instancedArray(new Uint32Array([0]),"uint").toAtomic(),L=r.instancedArray(new Float32Array(3*I),"float");p+=performance.now()-D;const N=performance.now(),F=r.Fn(()=>{const t=r.instanceIndex.mul(5),e=O.element(t),i=O.element(t.add(1)),n=O.element(t.add(2)),s=O.element(t.add(3)),o=O.element(t.add(4)).mul(16),l=r.mat4(B.element(o),B.element(o.add(1)),B.element(o.add(2)),B.element(o.add(3)),B.element(o.add(4)),B.element(o.add(5)),B.element(o.add(6)),B.element(o.add(7)),B.element(o.add(8)),B.element(o.add(9)),B.element(o.add(10)),B.element(o.add(11)),B.element(o.add(12)),B.element(o.add(13)),B.element(o.add(14)),B.element(o.add(15)));r.Loop({start:r.int(0),end:s.toInt(),type:"int",condition:"<",name:"triIdx"},({triIdx:t})=>{const s=n.add(t.toUint()).mul(3),o=k.element(s),c=k.element(s.add(1)),h=k.element(s.add(2)),u=r.vec3(z.element(o.mul(3)),z.element(o.mul(3).add(1)),z.element(o.mul(3).add(2))),d=r.vec3(z.element(c.mul(3)),z.element(c.mul(3).add(1)),z.element(c.mul(3).add(2))),p=r.vec3(z.element(h.mul(3)),z.element(h.mul(3).add(1)),z.element(h.mul(3).add(2))),f=l.mul(r.vec4(u,r.float(1))).xyz,m=l.mul(r.vec4(d,r.float(1))).xyz,g=l.mul(r.vec4(p,r.float(1))).xyz,w=m.sub(f),y=g.sub(f),_=r.cross(w,y),b=_.dot(_);r.If(b.lessThan(r.float(4e-16*Pr)),()=>{r.Continue()}),r.If(_.y.lessThan(0),()=>{r.Continue()});const v=r.max(f.y,r.max(m.y,g.y));r.Loop({start:r.int(0),end:i.toInt(),type:"int",condition:"<",name:"edgeIdx"},({edgeIdx:t})=>{const i=e.add(t.toUint()),n=i.mul(6),s=r.vec3(a.element(n),a.element(n.add(1)),a.element(n.add(2))),o=r.vec3(a.element(n.add(3)),a.element(n.add(4)),a.element(n.add(5))),l=r.min(s.y,o.y);r.If(v.lessThanEqual(l),()=>{r.Continue()});const c=r.normalize(_),h=c.dot(f).negate(),u=c.y.lessThan(0),d=r.select(u,c.negate(),c),p=r.select(u,h.negate(),h),w=d.dot(s).add(p),y=d.dot(o).add(p),b=w.lessThan(0),x=y.lessThan(0),C=r.abs(w).lessThan(r.float(Ar)),S=b.not().and(x.not()),A=y.sub(w),P=r.abs(A).lessThan(r.float(Ar)),T=P.and(C.or(b.not()));r.If(T,()=>{r.Continue()}),r.If(S.and(P.not()),()=>{r.Continue()});const M=w.negate().div(A),E=r.mix(s,o,M),D=r.vec3(r.select(P.or(b),s.x,E.x),r.select(P.or(b),s.y,E.y),r.select(P.or(b),s.z,E.z)),z=r.vec3(r.select(P.or(x),o.x,E.x),r.select(P.or(x),o.y,E.y),r.select(P.or(x),o.z,E.z)),k=z.sub(D),B=k.dot(k);r.If(B.lessThan(r.float(Ar)),()=>{r.Continue()});const O=s.sub(f),N=s.sub(m),F=s.sub(g),R=o.sub(f),U=o.sub(m),j=o.sub(g),$=O.dot(O).lessThanEqual(r.float(Ar)),W=N.dot(N).lessThanEqual(r.float(Ar)),G=F.dot(F).lessThanEqual(r.float(Ar)),H=R.dot(R).lessThanEqual(r.float(Ar)),q=U.dot(U).lessThanEqual(r.float(Ar)),Z=j.dot(j).lessThanEqual(r.float(Ar)),Y=$.or(W).or(G),X=H.or(q).or(Z),K=Y.and(X);r.If(K,()=>{r.Continue()});const Q=r.vec3(f.x,r.float(0),f.z),J=r.vec3(m.x,r.float(0),m.z),tt=r.vec3(g.x,r.float(0),g.z),et=r.vec3(D.x,r.float(0),D.z),it=r.vec3(z.x,r.float(0),z.z),nt=r.vec3(s.x,r.float(0),s.z),st=r.vec3(o.x,r.float(0),o.z).sub(nt),rt=st.dot(st);r.If(rt.lessThan(r.float(Ar)),()=>{r.Continue()});const ot=rt.sqrt(),at=J.sub(Q),lt=tt.sub(Q),ct=r.cross(at,lt),ht=ct.dot(ct);r.If(ht.lessThanEqual(r.float(4e-16*Pr)),()=>{r.Continue()});const ut=it.sub(et),dt=ut.dot(ut);r.If(dt.lessThan(r.float(Ar)),()=>{r.Continue()});const pt=dt.sqrt(),ft=ut.div(pt),mt=st.div(ot),gt=r.normalize(ct),wt=r.cross(ft,gt),yt=r.float(0).toVar(),_t=r.float(0).toVar(),bt=r.float(0).toVar(),vt=r.float(0).toVar(),xt=r.uint(0).toVar(),Ct=wt.dot(Q.sub(et)),St=wt.dot(J.sub(et)),At=r.abs(Ct).lessThan(r.float(Tr)),Pt=r.abs(St).lessThan(r.float(Tr)),Tt=At.not().and(Pt.not()).and(Ct.mul(St).lessThan(0));r.If(Tt,()=>{const t=Ct.div(Ct.sub(St)),e=r.mix(Q.x,J.x,t),i=r.mix(Q.z,J.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(At,()=>{r.If(xt.equal(0),()=>{yt.assign(Q.x),_t.assign(Q.z)}).Else(()=>{bt.assign(Q.x),vt.assign(Q.z)}),xt.addAssign(1)});const Mt=St,Et=wt.dot(tt.sub(et)),It=Pt,Dt=r.abs(Et).lessThan(r.float(Tr)),zt=It.not().and(Dt.not()).and(Mt.mul(Et).lessThan(0));r.If(xt.lessThan(2),()=>{r.If(zt,()=>{const t=Mt.div(Mt.sub(Et)),e=r.mix(J.x,tt.x,t),i=r.mix(J.z,tt.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(It.and(Tt.not()).and(At.not()),()=>{r.If(xt.equal(0),()=>{yt.assign(J.x),_t.assign(J.z)}).Else(()=>{bt.assign(J.x),vt.assign(J.z)}),xt.addAssign(1)})});const kt=Et,Bt=Ct,Ot=Dt,Vt=At,Lt=Ot.not().and(Vt.not()).and(kt.mul(Bt).lessThan(0));r.If(xt.lessThan(2),()=>{r.If(Lt,()=>{const t=kt.div(kt.sub(Bt)),e=r.mix(tt.x,Q.x,t),i=r.mix(tt.z,Q.z,t);r.If(xt.equal(0),()=>{yt.assign(e),_t.assign(i)}).Else(()=>{bt.assign(e),vt.assign(i)}),xt.addAssign(1)}).ElseIf(Ot.and(zt.not()).and(It.not()),()=>{r.If(xt.equal(0),()=>{yt.assign(tt.x),_t.assign(tt.z)}).Else(()=>{bt.assign(tt.x),vt.assign(tt.z)}),xt.addAssign(1)})}),r.If(xt.notEqual(2),()=>{r.Continue()});const Nt=r.vec3(yt,r.float(0),_t),Ft=r.vec3(bt,r.float(0),vt).sub(Nt).dot(ft),Rt=r.vec3(yt,r.float(0),_t).toVar(),Ut=r.vec3(bt,r.float(0),vt).toVar();r.If(Ft.lessThan(0),()=>{const t=yt,e=_t;Rt.x.assign(bt),Rt.z.assign(vt),Ut.x.assign(t),Ut.z.assign(e)});const jt=r.float(0),$t=pt,Wt=Rt.sub(et).dot(ft),Gt=Ut.sub(et).dot(ft),Ht=$t.lessThanEqual(Wt).or(Gt.lessThanEqual(jt));r.If(Ht,()=>{r.Continue()});const qt=r.max(jt,Wt),Zt=r.min($t,Gt),Yt=et.add(ft.mul(qt)),Xt=et.add(ft.mul(Zt)),Kt=Yt.sub(nt).dot(mt).div(ot),Qt=Xt.sub(nt).dot(mt).div(ot),Jt=r.max(r.float(0),r.min(r.float(1),Kt)),te=r.max(r.float(0),r.min(r.float(1),Qt)),ee=r.abs(te.sub(Jt));r.If(ee.lessThanEqual(r.float(Tr)),()=>{r.Continue()});const ie=r.atomicAdd(V.element(0),1);r.If(ie.lessThan(r.uint(I)),()=>{const t=ie.mul(3);L.element(t).assign(i.toFloat()),L.element(t.add(1)).assign(Jt),L.element(t.add(2)).assign(te)})})})})().compute(P.length);f+=performance.now()-N;const R=performance.now();await o.computeAsync(F),c+=performance.now()-R;const U=performance.now(),j=await o.getArrayBufferAsync(V.value),$=new Uint32Array(j)[0];if(s&&(s.used+=Math.min($,I)),Sr.enabled&&console.log(` Batch ${i+1}: ${$} overlaps found (capacity: ${I})`),$>I&&Sr.enabled&&console.warn(` WARNING: Overlap buffer overflow! ${$} > ${I}. Some occlusion data lost.`),$>0){const t=await o.getArrayBufferAsync(L.value),e=new Float32Array(t);h+=performance.now()-U;const i=performance.now(),s=Math.min($,I);for(let t=0;t<s;t++){const i=3*t,s=Math.round(e[i]);dr([e[i+1],e[i+2]],n[s])}u+=performance.now()-i,Sr.enabled&&console.log(` Processed ${s} overlaps into hiddenOverlapMap`)}else h+=performance.now()-U}o.dispose(),Er=null;const m=p+f+c+h+u;Sr.enabled&&(console.log(`WebGPU timing breakdown (total: ${m.toFixed(1)}ms):`),console.log(` Buffer creation: ${p.toFixed(1)}ms`),console.log(` Shader build: ${f.toFixed(1)}ms`),console.log(` GPU compute: ${c.toFixed(1)}ms`),console.log(` Readback: ${h.toFixed(1)}ms`),console.log(` CPU merge: ${u.toFixed(1)}ms`))}const Dr=new n.Vector3(0,1,0);function zr(t,e=null){const i=new Float32Array(6*t.length);let s=0;for(let e=0,n=t.length;e<n;e++){const n=t[e];i[s++]=n[0],i[s++]=0,i[s++]=n[2],i[s++]=n[3],i[s++]=0,i[s++]=n[5]}const r=new n.BufferGeometry,o=new n.BufferAttribute(i,3,!0);if(r.setAttribute("position",o),e){const i=new Float32Array(2*t.length);for(let t=0,n=e.length;t<n;t++)i[2*t]=e[t],i[2*t+1]=e[t];r.setAttribute("group",new n.BufferAttribute(i,1))}return r}class kr{constructor(t,e=!0){this.meshes=Rs(t),this.bvhs=new Map,this.visibleEdges=[],this.hiddenEdges=[],this.visibleGroupIndices=[],this.hiddenGroupIndices=[],this.groupKeyToIndex=null,this.hasGroups=!1,this.iterationTime=30,this.useWebGPU=e}reset(){this.visibleEdges.length=0,this.hiddenEdges.length=0,this.visibleGroupIndices.length=0,this.hiddenGroupIndices.length=0,this.groupKeyToIndex=null,this.hasGroups=!1}getVisibleLineGeometry(){return zr(this.visibleEdges,this.groupKeyToIndex?this.visibleGroupIndices:null)}getHiddenLineGeometry(){return zr(this.hiddenEdges,this.groupKeyToIndex?this.hiddenGroupIndices:null)}getGroupKeys(){return this.groupKeyToIndex?Object.fromEntries(this.groupKeyToIndex):{}}addEdges(...t){const e=this.iterationTime;this.iterationTime=1/0;const i=this.addEdgesGenerator(...t).next().value;return this.iterationTime=e,i}*addEdgesGenerator(t,e={}){const{meshes:i,bvhs:n,visibleEdges:s,hiddenEdges:r,iterationTime:o}=this;let a=performance.now();Sr.startStep("Building mesh BVH");for(let t=0;t<i.length;t++){performance.now()-a>o&&(yield,a=performance.now());const e=i[t].geometry;if(!n.has(e)){const t=e.boundsTree||new is(e);n.set(e,t)}}let l=0;for(let t=0;t<i.length;t++){const e=i[t].geometry;l+=e.index?e.index.count/3:e.attributes.position.count/3}const c={};for(let e=0;e<t.length;e++)c[e]=[];Sr.startStep("Building line BVH");const h=new Hs(t,{maxLeafSize:2,strategy:2});Sr.startStep("BVHcast overlaps"),a=performance.now();const u={candidates:0,backFaceCulled:0,yBoundsCulled:0,xzBoundsCulled:0,triangleEdgeCulled:0,planeTrimCulled:0,distThresholdCulled:0,noOverlapCulled:0,used:0,totalEdges:t.length,totalTriangles:l},d=this.useWebGPU,p={};d&&(p._edgeOffsets=[],p._edgeCounts=[],p._meshOffsets=[],p._meshCounts=[],p._meshIndex=[],p.groupCount=0);for(let t=0;t<i.length;t++){performance.now()-a>o&&(e.onProgress&&e.onProgress(t,i.length),yield,a=performance.now());const s=i[t];d?Mr(h,n.get(s.geometry),s,p,t):wr(h,n.get(s.geometry),s,c,u)}if(d){let t=!1;for(Ir(p,i,h,c,u).then(()=>{t=!0});!t;)yield}const f=u.totalEdges*u.totalTriangles;if(Sr.setStat("Total edges",u.totalEdges.toLocaleString()),Sr.setStat("Total triangles",u.totalTriangles.toLocaleString()),Sr.setStat("Brute-force pairs (edges × triangles)",f.toLocaleString()),Sr.setStat("BVH candidate pairs",u.candidates.toLocaleString()),f>0&&Sr.setStat("BVH reduction",(u.candidates/f*100).toFixed(3)+"% of brute-force"),u.candidates>0){const t=u.candidates,e=e=>(e/t*100).toFixed(2)+"%";d||(Sr.setStat("Rejected: back-face culling",u.backFaceCulled.toLocaleString()+" ("+e(u.backFaceCulled)+")"),Sr.setStat("Rejected: Y-bounds (tri below edge)",u.yBoundsCulled.toLocaleString()+" ("+e(u.yBoundsCulled)+")"),Sr.setStat("Rejected: XZ-bounds (no 2D overlap)",u.xzBoundsCulled.toLocaleString()+" ("+e(u.xzBoundsCulled)+")"),Sr.setStat("Rejected: edge lies on triangle",u.triangleEdgeCulled.toLocaleString()+" ("+e(u.triangleEdgeCulled)+")"),Sr.setStat("Rejected: line above tri plane",u.planeTrimCulled.toLocaleString()+" ("+e(u.planeTrimCulled)+")"),Sr.setStat("Rejected: trimmed edge too small",u.distThresholdCulled.toLocaleString()+" ("+e(u.distThresholdCulled)+")"),Sr.setStat("Rejected: no projected overlap",u.noOverlapCulled.toLocaleString()+" ("+e(u.noOverlapCulled)+")")),Sr.setStat("Producing overlaps",u.used.toLocaleString()+" ("+e(u.used)+")")}Sr.startStep("Converting overlaps to lines");const m=this.hasGroups;for(let e=0;e<t.length;e++){performance.now()-a>o&&(yield,a=performance.now());const i=t[e],n=c[e],l=s.length,h=r.length;if(Is(i,n,!1,s),Is(i,n,!0,r),m){const t=i.groupIndex;for(let e=l;e<s.length;e++)this.visibleGroupIndices.push(t);for(let e=h;e<r.length;e++)this.hiddenGroupIndices.push(t)}}}}class Br{constructor(){this.iterationTime=30,this.angleThreshold=50,this.includeIntersectionEdges=!0,this.useWebGPU=!0}generateAsync(t,e={}){return new Promise((i,n)=>{const{signal:s}=e,r=this.generate(t,e);!function t(){if(s&&s.aborted)return void n(new Error("ProjectionGenerator: Process aborted via AbortSignal."));const e=r.next();e.done?i(e.value):requestAnimationFrame(t)}()})}*generate(t,e){const{iterationTime:i,angleThreshold:s,includeIntersectionEdges:r}=this,{onProgress:o=()=>{},visibilityCuller:a=null,groupFn:l=null}=e;if(Sr.reset(),Sr.startTotal(),t.isBufferGeometry&&(t=new n.Mesh(t)),a){Sr.startStep("Visibility culling");let e=!1;for(a.cull(t).then(i=>{(t=new n.Scene).children=i,e=!0});!e;)yield}const c=new Ws;c.iterationTime=i,c.thresholdAngle=s,c.projectionDirection.copy(Dr),Sr.startStep("Generating candidate edges"),o("Generating candidate edges");let h=[],u=l?[]:null;if(yield*c.getEdgesGenerator(t,h,u),r&&(Sr.startStep("Generating intersection edges"),o("Generating intersection edges"),yield*c.getIntersectionEdgesGenerator(t,h,u)),Sr.startStep("Pre-filtering edges"),o("Pre-filtering edges"),u){const t=[],e=[];for(let i=0;i<h.length;i++)Ts(h[i])||(t.push(h[i]),e.push(u[i]));h=t,u=e}else h=h.filter(t=>!Ts(t));yield;const d=new kr(t,this.useWebGPU);if(d.iterationTime=i,l&&u){const t=new Map;for(let e=0;e<h.length;e++){const i=l(u[e]);t.has(i)||t.set(i,t.size),h[e].groupIndex=t.get(i)}d.groupKeyToIndex=t,d.hasGroups=!0}return o("Building BVH & computing overlaps"),yield*d.addEdgesGenerator(h,{onProgress:o?(t,e)=>{o("Building BVH & computing overlaps",t/e,d)}:null}),Sr.printSummary(),d}}new n.Line3,new n.Line3,new n.Vector3;const Or=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"generator",new Br),e(this,"cullerPixelsPerMeter",.05),e(this,"projectionDirection",new u.Vector3(0,-1,0)),e(this,"nearPlane",-1/0),e(this,"farPlane",1/0),this.components.add(t.uuid,this),this.generator.includeIntersectionEdges=!1}async get(t,e,i){const n=this.components.get(bs),s=new u.Group,r=new Map;for(const[e,i]of Object.entries(t)){const t=n.list.get(e);if(!t)continue;const o=(await t.getItemsIdsWithGeometry()).filter(t=>i.has(t));if(0===o.length)continue;const a=await t.getItemsGeometry(o);for(const i in a){const n=a[i];for(const i of n){if(!(i.positions&&i.indices&&i.transform&&i.representationId))continue;const n=i.representationId;if(!r.has(n)){const t=new u.BufferGeometry;t.setAttribute("position",new u.Float32BufferAttribute(i.positions,3)),i.normals&&t.setAttribute("normal",new u.Float32BufferAttribute(i.normals,3)),t.setIndex(Array.from(i.indices)),r.set(n,t)}const o=r.get(n),a=new u.Mesh(o);a.applyMatrix4(i.transform),a.applyMatrix4(t.object.matrixWorld),a.updateWorldMatrix(!0,!0),a.userData._edgeProjectorModelId=e,a.userData._edgeProjectorLocalId=i.localId,s.add(a)}}}const o=this.projectionDirection.clone().normalize(),a=new u.Vector3(0,-1,0),l=(new u.Quaternion).setFromUnitVectors(o,a),c=(new u.Matrix4).makeRotationFromQuaternion(l),h=c.clone().invert();for(const t of s.children)t.applyMatrix4(c),t.updateWorldMatrix(!1,!1);if(s.traverse(t=>{const e=t;if(e.geometry&&!e.geometry.boundsTree){const t=e.geometry.index?e.geometry.index.count:e.geometry.attributes.position.count;e.geometry.groups.forEach(e=>{e.count===1/0&&(e.count=t-e.start)}),e.geometry.boundsTree=new is(e.geometry,{maxLeafSize:1,strategy:2})}}),this.nearPlane!==-1/0||this.farPlane!==1/0){const t=new u.Box3,e=[];for(const i of s.children){const n=i;n.geometry&&(t.setFromObject(n),(t.max.y<this.nearPlane||t.min.y>this.farPlane)&&e.push(n))}for(const t of e)s.remove(t)}const d=e.renderer.three,p=new xs(d,{pixelsPerMeter:this.cullerPixelsPerMeter}),f=await this.generator.generateAsync(s,{visibilityCuller:p,groupFn:t=>`${t.userData._edgeProjectorModelId??"unknown"}:${t.userData._edgeProjectorLocalId??0}`,onProgress:null==i?void 0:i.onProgress}),m=f.getVisibleLineGeometry(),g=f.getHiddenLineGeometry();m.applyMatrix4(h),g.applyMatrix4(h);const w=f.getGroupKeys(),y={};for(const[t,e]of Object.entries(w)){const i=t.lastIndexOf(":"),n=t.substring(0,i),s=Number(t.substring(i+1));y[e]={modelId:n,localId:s}}for(const t of r.values())t.dispose();return{visible:m,hidden:g,groups:y}}dispose(){this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}};e(Or,"uuid","f2e76c3a-8b1d-4d5e-9a3f-7c6b2d4e8f1a");let Vr=Or;class Lr{constructor(){e(this,"wasm",{path:"",absolute:!1,logLevel:p.LogLevel.LOG_LEVEL_OFF}),e(this,"webIfc",{COORDINATE_TO_ORIGIN:!0}),e(this,"autoSetWasm",!0),e(this,"customLocateFileHandler",null)}}const Nr=class t extends g{constructor(i){super(i),e(this,"onDisposed",new f),e(this,"onIfcStartedLoading",new f),e(this,"onIfcImporterInitialized",new f),e(this,"onSetup",new f),e(this,"settings",new Lr),e(this,"webIfc",new p.IfcAPI),e(this,"enabled",!0),this.components.add(t.uuid,this)}dispose(){this.webIfc=null,this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async setup(t){this.settings={...this.settings,...t},this.settings.autoSetWasm&&await this.autoSetWasm(),this.onSetup.trigger()}async load(t,e,i,n){const s=this.components.get(bs);if(!s.initialized)throw new Error("You need to initialize fragments first.");this.settings.autoSetWasm&&await this.autoSetWasm(),s.core.settings.autoCoordinate=e;const r=new h.IfcImporter;r.wasm.path=this.settings.wasm.path,r.wasm.absolute=this.settings.wasm.absolute,r.webIfcSettings=this.settings.webIfc,this.onIfcImporterInitialized.trigger(r),(null==n?void 0:n.instanceCallback)&&n.instanceCallback(r);const o=await r.process({...null==n?void 0:n.processData,bytes:t});return await s.core.load(o,{modelId:i,userData:null==n?void 0:n.userData})}async readIfcFile(t){const{path:e,absolute:i,logLevel:n}=this.settings.wasm;return this.webIfc.SetWasmPath(e,i),await this.webIfc.Init(this.settings.customLocateFileHandler||void 0),n&&this.webIfc.SetLogLevel(n),this.webIfc.OpenModel(t,this.settings.webIfc)}cleanUp(){try{this.webIfc.Dispose()}catch(t){console.log("Web-ifc wasn't disposed.")}this.webIfc=null,this.webIfc=new p.IfcAPI}async autoSetWasm(){const t=await fetch(`https://unpkg.com/@thatopen/components@${Oo.release}/package.json`);if(!t.ok)return void console.warn("Couldn't get openbim-components package.json. Set wasm settings manually.");const e=await t.json();if("web-ifc"in e.peerDependencies){const t=e.peerDependencies["web-ifc"];this.settings.wasm.path=`https://unpkg.com/web-ifc@${t}/`,this.settings.wasm.absolute=!0}else console.warn("Couldn't get web-ifc from peer dependencies in openbim-components. Set wasm settings manually.")}};e(Nr,"uuid","a659add7-1418-4771-a0d6-7d4d438e4624");let Fr=Nr;const Rr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),this.components.add(t.uuid,this)}async set(t,e){const i=this.components.get(bs),n=[];if(e)for(const[s,r]of Object.entries(e)){const e=i.list.get(s);e&&n.push(e.setVisible([...r],t))}else for(const e of i.list.values())n.push(e.setVisible(void 0,t));await Promise.all(n),await i.core.update(!0)}async isolate(t){await Promise.all([this.set(!1),this.set(!0,t)])}async toggle(t){const e=[],i=this.components.get(bs);for(const[n,s]of Object.entries(t)){const t=i.list.get(n);t&&e.push(t.toggleVisible([...s]))}await Promise.all(e),await i.core.update(!0)}async getVisibilityMap(t,e){const i=[],n=[],s=this.components.get(bs);if(e)for(const r of e){const e=s.list.get(r);e&&(i.push(e.modelId),n.push(e.getItemsByVisibility(t)))}else for(const e of s.list.values())i.push(e.modelId),n.push(e.getItemsByVisibility(t));const r=await Promise.all(n),o={};for(const[t,e]of i.entries())o[e]=r[t];return o}};e(Rr,"uuid","dd9ccf2d-8a21-4821-b7f6-2949add16a29");let Ur=Rr;const jr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"list",new h.DataSet),this.components.add(t.uuid,this)}dispose(e=!0){this.list.clear(),this.onDisposed.trigger(t.uuid),e&&(this.onDisposed.reset(),this.list.eventsEnabled=!1,this.list.dispose())}get(){const t=new u.Box3;for(const e of this.list)t.union(e);return t}async addFromModelIdMap(t){const e=this.components.get(bs),i=new u.Box3;for(const[n,s]of Object.entries(t)){const t=e.list.get(n);if(!t)continue;const r=await t.getMergedBox([...s]);i.union(r)}this.list.add(i)}addFromModels(t){const e=this.components.get(bs);for(const[i,n]of e.list)t&&!t.some(t=>t.test(i))||this.list.add(n.box)}async getCenter(t){this.list.clear(),await this.addFromModelIdMap(t);const e=this.get();this.list.clear();const i=new u.Vector3;return e.getCenter(i),i}async getCameraOrientation(t,e=1){const i=this.components.get(bs);this.list.clear();for(const[t,e]of i.list)this.list.add(e.box);const n=this.get();this.list.clear();const s=new u.Vector3;n.getCenter(s);const r=new u.Vector3;n.getSize(r);const o=Math.max(r.x,r.y,r.z)*e,a=new u.Vector3;switch(t){case"front":default:a.set(s.x,s.y,s.z+o);break;case"back":a.set(s.x,s.y,s.z-o);break;case"left":a.set(s.x-o,s.y,s.z);break;case"right":a.set(s.x+o,s.y,s.z);break;case"top":a.set(s.x,s.y+o,s.z);break;case"bottom":a.set(s.x,s.y-o,s.z)}return{position:a,target:s}}};e(jr,"uuid","d1444724-dba6-4cdd-a0c7-68ee1450d166");let $r=jr;class Wr{constructor(t,i){e(this,"name","Query"),e(this,"customData",{}),e(this,"_components"),e(this,"_queries",[]),e(this,"_aggregation","exclusive"),e(this,"result",null),e(this,"cache",!0),e(this,"serializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>t.source),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.serializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.serializeQueryParameters(t.relation.query):void 0}:void 0}}),e(this,"deserializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>new RegExp(t)),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.deserializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.deserializeQueryParameters(t.relation.query):void 0}:void 0}}),this._components=t,this.queries=i}set queries(t){this._queries=t,this.clearCache()}get queries(){return this._queries}set aggregation(t){t!==this._aggregation&&this.clearCache(),this._aggregation=t}get aggregation(){return this._aggregation}async test(t){const{modelIds:e,force:i}={force:!1,...t};if(this.result&&!i)return this.result;const n=this._components.get(Hr),s=await n.getItems(this.queries,{modelIds:e,aggregation:this.aggregation});return this.cache&&(this.result=s),s}clearCache(){this.result=null}serializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>t.source):t.value instanceof RegExp?t.value.source:t.value;return{name:t.name.source,value:e,type:t.type instanceof RegExp?t.type.source:t.type,negate:t.negate,itemIds:t.itemIds}}toJSON(){return{guid:this._components.get(Hr).list.getKey(this)??A.create(),name:this.name,customData:this.customData,queries:this.queries.map(this.serializeQueryParameters),aggregation:this.aggregation,cache:this.cache}}deserializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>new RegExp(t)):"string"==typeof t.value?new RegExp(t.value):t.value;return{name:new RegExp(t.name),value:e,type:t.type?new RegExp(t.type):void 0,negate:t.negate,itemIds:t.itemIds}}fromJSON(t){return this.name=t.name,this.customData=t.customData,this.aggregation=t.aggregation,this.cache=t.cache,this.queries=t.queries.map(this.deserializeQueryParameters),this}}const Gr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new h.DataMap),i.add(t.uuid,this)}async getItems(t,e){let i;if(e){const{modelIds:t,items:n}=e;if(n){const t=Object.keys(n);t.length>0&&(i=t.map(t=>new RegExp(`^${t}$`)))}else t&&(i=t)}const n=(null==e?void 0:e.aggregation)??"exclusive",s=this.components.get(bs),r=await Promise.all(t.map(async t=>{const n={};return await Promise.all(Array.from(s.list).map(async([s,r])=>{var o;if(i&&!i.some(t=>t.test(s)))return;const a=null==(o=null==e?void 0:e.items)?void 0:o[s],l=await r.getItemsByQuery(t,{localIds:a?[...a]:void 0});n[s]=new Set(l)})),n}));return"inclusive"===n?pe.join(r):pe.intersect(r)}create(t,e){const i=new Wr(this.components,e);return this.list.set(t,i),i}async addFromCategories(t){const e=new Set,i=this.components.get(bs);for(const[n,s]of i.list){if(t&&!t.some(t=>t.test(n)))continue;const i=(await s.getItemsWithGeometryCategories()).filter(t=>null!==t),r=new Set(i);for(const t of r)this.list.has(t)||(this.create(t,[{categories:[new RegExp(`^${t}$`)]}]),e.add(t))}return[...e]}import(t){const{data:e}=t,i=[];if(!e)return i;for(const t of e){const e=this.create(t.guid,[]);e.fromJSON(t),i.push(e)}return i}export(){const t=[];for(const[e,i]of this.list.entries()){const n={...i.toJSON(),name:e};t.push(n)}return{data:t}}};e(Gr,"uuid","0da7ad77-f734-42ca-942f-a074adfd1e3a");let Hr=Gr;const qr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"list",new h.DataMap),e(this,"defaultSaveFunction",t=>"value"in t.Name?t.Name.value:null),e(this,"onBeforeFragmentsDispose",async t=>{const{key:e,value:i}=t,n=await i.getLocalIds(),s={[e]:new Set(n)};this.removeItems(s)}),i.add(t.uuid,this),this.setupEvents();i.get(bs).list.onBeforeDelete.add(this.onBeforeFragmentsDispose)}setupEvents(){this.list.onBeforeDelete.add(({value:t})=>t.dispose())}getClassificationGroups(t){let e=this.list.get(t);return e||(e=new h.DataMap,this.list.set(t,e)),e}getModelItems(t,e,i){const{map:n}=this.getGroupData(t,e);let s=n[i];return s||(s=new Set,n[i]=s),s}getGroupData(t,e){const i=this.components.get(Hr),n=this.getClassificationGroups(t);let s=n.get(e);return s||(s={map:{},get:()=>new Promise(t=>{if(s)if(s.query){const{name:e,config:n}=s.query,r=i.list.get(e);if(!r)throw new Error("Classifier: the query name associated with the group doesn't exist in the ItemsFinder component");r.test(n).then(e=>{if(!s)return void t({});const i=pe.join([e,s.map]);t(i)})}else t(s.map);else t({})})},n.set(e,s)),s}async aggregateItems(t,e,i){const n=(null==i?void 0:i.data)??void 0,s=(null==i?void 0:i.aggregationCallback)??this.defaultSaveFunction,r=this.components.get(bs),o=this.components.get(Hr),a=await o.getItems([e],{modelIds:null==i?void 0:i.modelIds});for(const[e,i]of Object.entries(a)){const o=r.list.get(e);if(!o)continue;const a=(i,...n)=>{const s=this.getModelItems(t,i,e);for(const t of n)s.add(t)},l=await o.getItemsData([...i],n);for(const t of l)s(t,a)}}addGroupItems(t,e,i){const{map:n}=this.getGroupData(t,e);pe.add(n,i)}setGroupQuery(t,e,i){this.getGroupData(t,e).query=i}async find(t){const e=[];for(const[i,n]of Object.entries(t)){const t=[],s=this.list.get(i);if(!s)continue;for(const e of n){const i=s.get(e);if(!i)continue;const n=await i.get();t.push(n)}const r=pe.join(t);e.push(r)}return pe.intersect(e)}async aggregateItemRelations(t,e,i,n){const s=(null==n?void 0:n.attribute)??"Name",r={relations:{[i]:{attributes:!0,relations:!1}}};await this.aggregateItems(t,e,{modelIds:null==n?void 0:n.modelIds,data:r,aggregationCallback:(t,e)=>{if(!(null==t?void 0:t[s]))return;const n=t[s];if(!("value"in n))return;const r=t[i];if(Array.isArray(r))for(const t of r)"value"in t._localId&&e(n.value,t._localId.value)}})}async byIfcBuildingStorey(t){await this.aggregateItemRelations((null==t?void 0:t.classificationName)??"Storeys",{categories:[/BUILDINGSTOREY/]},"ContainsElements",{modelIds:null==t?void 0:t.modelIds})}async byCategory(t){const e=this.components.get(Hr),i=await e.addFromCategories(null==t?void 0:t.modelIds);for(const e of i)this.setGroupQuery((null==t?void 0:t.classificationName)??"Categories",e,{name:e})}dispose(){this.list.clear();this.components.get(bs).list.onBeforeDelete.remove(this.onBeforeFragmentsDispose),this.onDisposed.trigger()}removeItems(t,e){if(e&&e.classificationName){const i=this.list.get(e.classificationName);if(!i)return;if(e.groupName){if(!i.get(e.groupName))return}for(const[,e]of i)pe.remove(e.map,t);return}for(const[,e]of this.list.entries())for(const[,i]of e)pe.remove(i.map,t)}async byModel(t){const e=this.components.get(bs),i=(null==t?void 0:t.classificationName)??"Models";for(const[n,s]of e.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(n)))continue;const e=await s.getItemsIdsWithGeometry(),r={[n]:new Set(e)};this.getGroupData(i,n),this.addGroupItems(i,n,r)}}};e(qr,"uuid","e25a7f3c-46c4-4a14-9d3d-5115f24ebeb7");let Zr=qr;const Yr=class t{constructor(t,i){if(e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new f),e(this,"mouse"),e(this,"world"),e(this,"debugMode",!1),e(this,"_renderTarget"),e(this,"_renderTargetSize",new u.Vector2),e(this,"_debugCanvas"),e(this,"_debugContainer"),e(this,"_idMaterial"),e(this,"_depthMaterial"),e(this,"_normalMaterial"),e(this,"_originalMaterials",new Map),e(this,"_hiddenLods",[]),e(this,"_ownMeshes",new Map),!i.renderer)throw new Error("A renderer is needed for the FastModelPicker to work!");this.world=i,this.mouse=new _e(i.renderer.three.domElement),this.components=t,this._idMaterial=this.buildIdMaterial(),this._depthMaterial=this.buildDepthMaterial(),this._normalMaterial=this.buildNormalMaterial(),this.setupRenderTarget()}async getModelAt(t){const e=await this.runIdPass(t);return e?e.modelId:null}async getItemAt(t){const e=await this.runIdPass(t);if(!e)return null;const i=this.components.get(bs).list.get(e.modelId);if(!i)return null;const n=await i.getLocalIdsFromItemIds([e.itemId]),s=null==n?void 0:n[0];return null==s?null:{modelId:e.modelId,localId:s,itemId:e.itemId}}async getPointAt(t){if(!this.enabled)return null;if(!this._renderTarget||!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;this.renderDepthPass();const i=t??this.mouse.position,n=this.readPixelAt(i);if(!n)return null;if(0===n[0]&&0===n[1]&&0===n[2]&&0===n[3])return null;const s=function(t){const e=t[0]/255,i=t[1]/255,n=t[2]/255,s=t[3]/255;return 255/256*(e/16777216+i/65536+n/256+s)}(n);return s>=.999999?null:function(t,e,i){const n=new u.Vector3(t.x,t.y,2*e-1);return n.unproject(i),n}(i,s,this.world.camera.three)}async getNormalAt(t){if(!this.enabled)return null;if(!this._renderTarget||!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;this.renderNormalPass();const i=t??this.mouse.position,n=this.readPixelAt(i);if(!n)return null;if(0===n[3])return null;const s=n[0]/255*2-1,r=n[1]/255*2-1,o=n[2]/255*2-1,a=new u.Vector3(s,r,o);return a.lengthSq()<1e-8?null:a.normalize()}async getFullPick(t){const e=await this.getItemAt(t);if(!e)return null;const i=await this.getPointAt(t);if(!i)return null;const n=await this.getNormalAt(t),s=i.distanceTo(this.world.camera.three.position);return{...e,point:i,normal:n,distance:s}}setDebugMode(t){this.debugMode=t,t?this.setupDebugCanvas():this.removeDebugCanvas()}dispose(){this.mouse.dispose(),this.removeDebugCanvas(),this._idMaterial.dispose(),this._depthMaterial.dispose(),this._normalMaterial.dispose(),this._renderTarget&&this._renderTarget.dispose(),this._renderTarget=void 0,this._originalMaterials.clear(),this._hiddenLods.length=0,this.onDisposed.trigger(),this.onDisposed.reset()}async runIdPass(t){if(!this.enabled)return null;if(!this._renderTarget)return null;if(!this.world.renderer)return null;const e=this.components.get(bs);if(!e.initialized||0===e.list.size)return null;const i=this.applyIdMaterial();if(0===i.size)return this.restoreOriginalMaterials(),null;const n=t??this.mouse.position;this.renderIdPass(i,n),this.restoreOriginalMaterials(),this.debugMode&&this._debugCanvas&&this.updateDebugCanvas();const s=this.readPixelAt(this._renderTarget,n);if(!s)return null;const r=s[0];if(0===r)return null;const o=i.get(r);if(!o)return null;const a=s[1]<<16|s[2]<<8|s[3];if(0===a)return null;return{modelId:o,itemId:a-1}}applyIdMaterial(){const e=this.components.get(bs),i=new Map,n=this.getModelRoots();this._ownMeshes.clear();let s=1;for(const[r,o]of e.list){if(s>t.MAX_MODELS)break;const e=[];this.traverseOwn(o.object,n,t=>{if(!(t instanceof u.Mesh))return;const i=t.geometry;if(!i)return;if(!i.attributes||!i.attributes.id)return void(t.visible&&(this._hiddenLods.push(t),t.visible=!1));this._originalMaterials.set(t,t.material);const n=t.material,s=Array.isArray(n)?n.length:1;t.material=new Array(s).fill(this._idMaterial),e.push(t)}),e.length&&(this._ownMeshes.set(r,e),i.set(s,r),s+=1)}return i}getModelRoots(){const t=this.components.get(bs),e=new Set;for(const[,i]of t.list)e.add(i.object);return e}traverseOwn(t,e,i){const n=[t];for(;n.length;){const s=n.pop();if(s===t||!e.has(s)){i(s);for(const t of s.children)n.push(t)}}}renderIdPass(t,e){this.renderPickPass(t,this._renderTarget,this._idMaterial,e)}renderPickPass(t,e,i,n){const s=this.world.renderer.three,r=this.world.scene.three,o=this.world.camera.three,a=this.components.get(bs),l=s.clippingPlanes??[];i.clippingPlanes=l,i.clipping=l.length>0;const c=s.getRenderTarget(),h=s.autoClear,d=s.getClearColor(new u.Color),p=s.getClearAlpha(),f=s.getScissorTest(),m=s.getScissor(new u.Vector4),g=r.background;r.background=null,s.setRenderTarget(e),s.setClearColor(0,0),s.autoClear=!1,s.setScissorTest(!1),s.clear(!0,!0,!1);const w=e.width,y=e.height,_=Math.floor(.5*(n.x+1)*w),b=Math.floor(.5*(n.y+1)*(y-1)),v=Math.max(0,Math.min(w-4,_-2)),x=Math.max(0,Math.min(y-4,b-2)),C=s.getPixelRatio();s.setScissor(v/C,x/C,4/C,4/C),s.setScissorTest(!0);const S=new Map;for(const[t,e]of a.list)S.set(t,e.object);const A=new Set(S.values()),P=new Map;r.traverse(t=>{t!==r&&t.isMesh&&((t=>{let e=t;for(;e;){if(A.has(e))return!0;e=e.parent}return!1})(t)||(P.set(t,t.visible),t.visible=!1))});const T=new Map;for(const[t,e]of S){let i=!0,n=e;for(;n;){if(!n.visible){i=!1;break}n=n.parent}T.set(t,i)}const M=new Map;for(const t of S.values())M.set(t,t.visible),t.visible=!0;const E=new Map;for(const t of this._ownMeshes.values())for(const e of t)E.set(e,e.visible),e.visible=!1;for(const[e,n]of t){if(!T.get(n))continue;const t=this._ownMeshes.get(n);if(t){for(const e of t)e.visible=E.get(e);i.uniforms.modelByte.value=e,s.render(r,o);for(const e of t)e.visible=!1}}for(const[t,e]of E)t.visible=e;for(const[t,e]of M)t.visible=e;for(const[t,e]of P)t.visible=e;s.setScissorTest(f),s.setScissor(m),s.setRenderTarget(c),s.autoClear=h,s.setClearColor(d,p),r.background=g}renderWithTileMaterial(t){const e=this.world.renderer.three,i=this.world.scene.three,n=this.world.camera.three,s=this.components.get(bs),r=e.clippingPlanes??[];t.clippingPlanes=r,t.clipping=r.length>0;const o=e.getRenderTarget(),a=e.autoClear,l=e.getClearColor(new u.Color),c=e.getClearAlpha(),h=i.background;i.background=null;const d=new Map,p=[],f=this.getModelRoots();for(const[,e]of s.list)this.traverseOwn(e.object,f,e=>{if(!(e instanceof u.Mesh))return;const i=e.geometry;if(!i)return;if(!i.attributes||!i.attributes.id)return void(e.visible&&(p.push(e),e.visible=!1));if(!e.visible)return;d.set(e,e.material);const n=e.material,s=Array.isArray(n)?n.length:1;e.material=new Array(s).fill(t)});const m=new Set;for(const[,t]of s.list)m.add(t.object);const g=new Map;i.traverse(t=>{t!==i&&t.isMesh&&((t=>{let e=t;for(;e;){if(m.has(e))return!0;e=e.parent}return!1})(t)||(g.set(t,t.visible),t.visible=!1))}),e.setRenderTarget(this._renderTarget),e.setClearColor(0,0),e.autoClear=!1,e.clear(!0,!0,!1),e.render(i,n);for(const[t,e]of d)t.material=e;for(const t of p)t.visible=!0;for(const[t,e]of g)t.visible=e;e.setRenderTarget(o),e.autoClear=a,e.setClearColor(l,c),i.background=h}renderDepthPass(){this.renderWithTileMaterial(this._depthMaterial)}renderNormalPass(){this.renderWithTileMaterial(this._normalMaterial)}restoreOriginalMaterials(){for(const[t,e]of this._originalMaterials)t.material=e;this._originalMaterials.clear(),this._ownMeshes.clear();for(const t of this._hiddenLods)t.visible=!0;this._hiddenLods.length=0}readPixelAt(t,e){let i,n;t instanceof u.WebGLRenderTarget?(i=t,n=e):(i=this._renderTarget,n=t);const s=this.world.renderer.three,r=this._renderTargetSize,o=Math.floor(.5*(n.x+1)*r.x),a=Math.floor(.5*(n.y+1)*(r.y-1)),l=Math.max(0,Math.min(r.x-1,o)),c=Math.max(0,Math.min(r.y-1,a)),h=new Uint8Array(4);return s.readRenderTargetPixels(i,l,c,1,1,h),h}buildIdMaterial(){return new u.ShaderMaterial({uniforms:{modelByte:{value:1}},vertexShader:"\n attribute vec4 id;\n varying vec4 vId;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vId = id;\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n precision highp float;\n uniform float modelByte;\n varying vec4 vId;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n gl_FragColor = vec4(modelByte / 255.0, vId.y / 255.0, vId.z / 255.0, vId.w / 255.0);\n }\n ",side:u.DoubleSide})}buildDepthMaterial(){return new u.ShaderMaterial({uniforms:{},vertexShader:"\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n float v = gl_FragCoord.z;\n vec4 r = vec4(\n fract(v * 16777216.0),\n fract(v * 65536.0),\n fract(v * 256.0),\n v\n );\n r.yzw -= r.xyz * (1.0 / 256.0);\n gl_FragColor = r * (256.0 / 255.0);\n }\n ",side:u.DoubleSide})}buildNormalMaterial(){return new u.ShaderMaterial({uniforms:{},vertexShader:"\n varying vec3 vWorldNormal;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n #endif\n void main() {\n vWorldNormal = normalize(\n (modelMatrix * vec4(normal, 0.0)).xyz\n );\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n #if NUM_CLIPPING_PLANES > 0\n vClipPosition = -mvPosition.xyz;\n #endif\n gl_Position = projectionMatrix * mvPosition;\n }\n ",fragmentShader:"\n varying vec3 vWorldNormal;\n #if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n #endif\n void main() {\n #if NUM_CLIPPING_PLANES > 0\n for (int i = 0; i < NUM_CLIPPING_PLANES; i++) {\n vec4 plane = clippingPlanes[i];\n if (dot(vClipPosition, plane.xyz) > plane.w) discard;\n }\n #endif\n vec3 n = normalize(vWorldNormal);\n if (!gl_FrontFacing) n = -n;\n gl_FragColor = vec4(n * 0.5 + 0.5, 1.0);\n }\n ",side:u.DoubleSide})}setupRenderTarget(){const t=this.world.renderer.three.getSize(new u.Vector2);this._renderTargetSize.copy(t);const e={format:u.RGBAFormat,type:u.UnsignedByteType,minFilter:u.NearestFilter,magFilter:u.NearestFilter,depthBuffer:!0};this._renderTarget=new u.WebGLRenderTarget(t.x,t.y,e),this.debugMode&&this.setupDebugCanvas(),this.world.renderer.onResize.add(t=>{this._renderTargetSize.copy(t),this._renderTarget.setSize(t.x,t.y),this._debugCanvas&&(this._debugCanvas.width=t.x,this._debugCanvas.height=t.y)})}setupDebugCanvas(){if(this._debugCanvas)return;const t=this.world.renderer.three.getSize(new u.Vector2);this._debugContainer=document.createElement("div"),this._debugContainer.style.position="fixed",this._debugContainer.style.top="10px",this._debugContainer.style.right="10px",this._debugContainer.style.width="300px",this._debugContainer.style.height="300px",this._debugContainer.style.border="2px solid #fff",this._debugContainer.style.backgroundColor="#000",this._debugContainer.style.zIndex="10000",this._debugContainer.style.pointerEvents="none",this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=t.x,this._debugCanvas.height=t.y,this._debugCanvas.style.width="100%",this._debugCanvas.style.height="100%",this._debugCanvas.style.imageRendering="pixelated",this._debugContainer.appendChild(this._debugCanvas),document.body.appendChild(this._debugContainer)}removeDebugCanvas(){this._debugContainer&&(this._debugContainer.remove(),this._debugContainer=void 0,this._debugCanvas=void 0)}updateDebugCanvas(){if(!this._debugCanvas||!this._renderTarget||!this.world.renderer)return;const t=this.world.renderer.three,e=this._renderTargetSize,i=new Uint8Array(e.x*e.y*4);t.readRenderTargetPixels(this._renderTarget,0,0,e.x,e.y,i);const n=this._debugCanvas.getContext("2d");if(!n)return;const s=n.createImageData(e.x,e.y),r=4*e.x;for(let t=0;t<e.y;t++){const n=t*r,o=(e.y-1-t)*r;s.data.set(i.subarray(n,n+r),o)}n.putImageData(s,0,0)}};e(Yr,"MAX_MODELS",254);let Xr=Yr;const Kr=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new f),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new Xr(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(Kr,"uuid","4a82430c-7ff2-49ea-9401-60807502dad6");let Qr=Kr;var Jr=(t=>(t[t.POINT=0]="POINT",t[t.LINE=1]="LINE",t[t.FACE=2]="FACE",t))(Jr||{});const to=1e3;class eo{constructor(t){e(this,"onDisposed",new f),e(this,"maxDistance",1),e(this,"maxCacheSize",1e3),e(this,"components"),e(this,"_precision","half"),e(this,"cache",new Map),this.components=t}get precision(){return this._precision}set precision(t){t!==this._precision&&(this._precision=t,this.clear())}dispose(){this.cache.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}async resolve(t,e,i,n){const s=eo.keyOf(e,i);let r=this.cache.get(s);if(r)this.cache.delete(s),this.cache.set(s,r);else{if(r=await this.fetchItemSnapData(e,i),!r)return null;this.storeWithLRU(s,r)}const o=this.snap(t,r,2),a=new Set(n),l=[0,1,2];let c=null;for(const e of l){if(!a.has(e))continue;const i=this.snap(t,r,e);if(i){c=i.result;break}}if(!c)return o?o.result:null;if(o&&2!==c.snappingClass){const t=o.result;!c.normal&&t.normal&&(c.normal=t.normal),!c.facePoints&&t.facePoints&&(c.facePoints=t.facePoints),!c.faceIndices&&t.faceIndices&&(c.faceIndices=t.faceIndices)}return c}async prefetch(t,e){const i=eo.keyOf(t,e);if(this.cache.has(i))return;const n=await this.fetchItemSnapData(t,e);n&&this.storeWithLRU(i,n)}invalidate(t,e){const i=eo.keyOf(t,e);this.cache.delete(i)}clear(){this.cache.clear()}static keyOf(t,e){return`${t}:${e}`}storeWithLRU(t,e){for(this.cache.set(t,e);this.cache.size>this.maxCacheSize;){const t=this.cache.keys().next().value;if(void 0===t)break;this.cache.delete(t)}}async fetchItemSnapData(t,e){const i=this.components.get(bs).list.get(t);if(!i)return null;const n=await i._getItemSnapData(e);if(!n)return null;const s=i.object.matrixWorld,r=[];for(const t of Object.keys(n.samples??{})){const e=n.samples[Number(t)],i=n.representations[e.representation];if(!i||1!==i.representationClass)continue;const o=i.geometry;if(!o)continue;const a=n.localTransforms[e.localTransform],l=co(s,n.globalTransforms[e.item],a);this.collectPolygonsFromShell(o,l,r)}if(0===r.length)return null;return{faces:r,edges:function(t,e){const i=new Set,n=[];for(const e of t){const t=e.points,s=t.length/3;for(let e=0;e<s;e++){const r=(e+1)%s,o=t[3*e],a=t[3*e+1],l=t[3*e+2],c=t[3*r],h=t[3*r+1],u=t[3*r+2],d=po(o,a,l,c,h,u);i.has(d)||(i.add(d),n.push(o,a,l,c,h,u))}}return new("full"===e?Float64Array:Float32Array)(n)}(r,this._precision),vertices:function(t,e){const i=new Set,n=[];for(const e of t){const t=e.points,s=t.length/3;for(let e=0;e<s;e++){const s=t[3*e],r=t[3*e+1],o=t[3*e+2],a=uo(s,r,o);i.has(a)||(i.add(a),n.push(s,r,o))}}return new("full"===e?Float64Array:Float32Array)(n)}(r,this._precision)}}collectPolygonsFromShell(t,e,i){const n=t.points,s=t.profiles??new Map,r=t.bigProfiles??new Map,o=new u.Vector3,a=t=>{if(t.length<3)return;const s=new("full"===this._precision?Float64Array:Float32Array)(3*t.length);for(let i=0;i<t.length;i++){const r=n[t[i]];o.set(r[0],r[1],r[2]).applyMatrix4(e),s[3*i]=o.x,s[3*i+1]=o.y,s[3*i+2]=o.z}const r=function(t){const e=new u.Vector3,i=t.length/3;for(let n=0;n<i;n++){const s=(n+1)%i,r=t[3*n],o=t[3*n+1],a=t[3*n+2],l=t[3*s],c=t[3*s+1],h=t[3*s+2];e.x+=(o-c)*(a+h),e.y+=(a-h)*(r+l),e.z+=(r-l)*(o+c)}const n=e.length();return n<1e-10?null:e.divideScalar(n)}(s);if(!r)return;const a=r.x*s[0]+r.y*s[1]+r.z*s[2];i.push({points:s,normal:r,d:a})};for(const t of s.values())a(t);for(const t of r.values())a(t)}snap(t,e,i){return 0===i?this.snapToPoint(t,e):1===i?this.snapToLine(t,e):2===i?this.snapToFace(t,e):null}snapToPoint(t,e){const i=e.vertices;if(0===i.length)return null;const n=this.maxDistance*this.maxDistance;let s=-1,r=1/0;for(let e=0;e<i.length;e+=3){const o=i[e]-t.x,a=i[e+1]-t.y,l=i[e+2]-t.z,c=o*o+a*a+l*l;c<=n&&c<r&&(r=c,s=e)}return s<0?null:{result:{point:new u.Vector3(i[s],i[s+1],i[s+2]),snappingClass:0}}}snapToLine(t,e){const i=e.edges;if(0===i.length)return null;const n=this.maxDistance*this.maxDistance,s=new u.Vector3,r=new u.Vector3;let o=1/0,a=-1;for(let e=0;e<i.length;e+=6){const l=fo(t,i[e],i[e+1],i[e+2],i[e+3],i[e+4],i[e+5],r);l<=n&&l<o&&(o=l,a=e,s.copy(r))}return a<0?null:{result:{point:s.clone(),snappingClass:1,snappedEdgeP1:new u.Vector3(i[a],i[a+1],i[a+2]),snappedEdgeP2:new u.Vector3(i[a+3],i[a+4],i[a+5])}}}snapToFace(t,e){const i=e.faces;if(0===i.length)return null;let n=null,s=1/0,r=!1;for(const e of i){const i=this.signedDistance(e,t),o=Math.abs(i);if(o>this.maxDistance)continue;const a=this.containsPoint(e,this.projectOntoPlane(t,e,i));r&&!a||(!a||r?o<s&&(s=o,n=e):(r=!0,s=o,n=e))}if(!n)return null;return{result:{point:this.projectOntoPlane(t,n,this.signedDistance(n,t)),normal:n.normal.clone(),snappingClass:2,facePoints:n.points,faceIndices:ho(n.points.length/3)}}}signedDistance(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z-t.d}projectOntoPlane(t,e,i){return t.clone().sub(e.normal.clone().multiplyScalar(i))}containsPoint(t,e){const{points:i,normal:n}=t,s=i.length/3;if(s<3)return!1;const r=Math.abs(n.x),o=Math.abs(n.y),a=Math.abs(n.z);let l=0,c=1;r>=o&&r>=a?(l=1,c=2):o>=a&&(l=0,c=2);const h=e.getComponent(l),u=e.getComponent(c);let d=!1;for(let t=0,e=s-1;t<s;e=t,t+=1){const n=i[3*t+l],s=i[3*t+c],r=i[3*e+l],o=i[3*e+c];if(!(s>u!=o>u))continue;h<(r-n)*(u-s)/(o-s)+n&&(d=!d)}return d}}const io=new u.Matrix4,no=new u.Vector3,so=new u.Vector3,ro=new u.Vector3;function oo(t,e){if(!t)return e.identity();const i=t.position[0],n=t.position[1],s=t.position[2];return no.set(t.xDirection[0],t.xDirection[1],t.xDirection[2]),so.set(t.yDirection[0],t.yDirection[1],t.yDirection[2]),ro.crossVectors(no,so),e.set(no.x,so.x,ro.x,i,no.y,so.y,ro.y,n,no.z,so.z,ro.z,s,0,0,0,1),e}const ao=new u.Matrix4,lo=new u.Matrix4;function co(t,e,i){return oo(e,ao),oo(i,lo),io.copy(t).multiply(ao).multiply(lo).clone()}function ho(t){if(t<3)return new Uint32Array(0);const e=t-2,i=new Uint32Array(3*e);for(let t=0;t<e;t++)i[3*t]=0,i[3*t+1]=t+1,i[3*t+2]=t+2;return i}function uo(t,e,i){return`${Math.round(t*to)},${Math.round(e*to)},${Math.round(i*to)}`}function po(t,e,i,n,s,r){const o=uo(t,e,i),a=uo(n,s,r);return o<a?`${o}|${a}`:`${a}|${o}`}function fo(t,e,i,n,s,r,o,a){const l=s-e,c=r-i,h=o-n,u=l*l+c*c+h*h;let d=0;u>0&&(d=((t.x-e)*l+(t.y-i)*c+(t.z-n)*h)/u,d<0?d=0:d>1&&(d=1));const p=e+d*l,f=i+d*c,m=n+d*h;a.set(p,f,m);const g=t.x-p,w=t.y-f,y=t.z-m;return g*g+w*w+y*y}const mo=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new f),e(this,"_resolver"),i.add(t.uuid,this),this._resolver=new eo(i)}get(){return this._resolver}dispose(){this._resolver.dispose(),this.onDisposed.trigger()}};e(mo,"uuid","be9b8e6c-7f5b-4a36-8e7e-3a1f5e2a6c9d");let go=mo;class wo{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new f),e(this,"mouse"),e(this,"three",new u.Raycaster),e(this,"world");const n=i.renderer;if(!n)throw new Error("A renderer is needed for the raycaster to work!");this.world=i,this.mouse=new _e(n.three.domElement),this.components=t}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRayToObjects(t=Array.from(this.world.meshes),e=this.mouse.position){if(!this.world)throw new Error("A world is needed to cast rays!");const i=this.world.camera.three;return this.three.setFromCamera(e,i),this.intersect(t)}async castRay(t){const e=null==t?void 0:t.snappingClasses,i=(null==t?void 0:t.items)??Array.from(this.world.meshes),n=(null==t?void 0:t.position)??this.mouse.position;if(!this.world)throw new Error("A world is needed to cast rays!");const s=this.world.camera.three,r=this.components.get(bs);let o=null;if(r.initialized){const t=this.components.get(Qr).get(this.world),a=await t.getFullPick(n);if(a){const t=r.list.get(a.modelId);if(o={localId:a.localId,point:a.point,normal:a.normal,distance:a.distance,fragments:t,object:null==t?void 0:t.object,ray:void 0,frustum:void 0},e&&e.length>0){const t=await this.components.get(go).get().resolve(a.point,a.modelId,a.itemId,e);t&&(o.point=t.point,t.normal&&(o.normal=t.normal),o.snappingClass=t.snappingClass,t.facePoints&&(o.facePoints=t.facePoints),t.faceIndices&&(o.faceIndices=t.faceIndices),t.snappedEdgeP1&&(o.snappedEdgeP1=t.snappedEdgeP1),t.snappedEdgeP2&&(o.snappedEdgeP2=t.snappedEdgeP2),o.distance=t.point.distanceTo(s.position))}}if(0===i.length)return o}this.three.setFromCamera(n,s);const a=this.intersect(i);return o?a&&a.distance<o.distance?a:o:a}castRayFromVector(t,e,i=Array.from(this.world.meshes)){return this.three.set(t,e),this.intersect(i)}intersect(t=Array.from(this.world.meshes)){const e=this.three.intersectObjects(t),i=this.filterClippingPlanes(e);return i.length>0?i[0]:null}filterClippingPlanes(t){if(!this.world.renderer)throw new Error("Renderer not found!");const e=this.world.renderer.three;if(!e.clippingPlanes)return t;const i=e.clippingPlanes;return t.length<=0||!i||(null==i?void 0:i.length)<=0?t:t.filter(t=>i.every(e=>e.distanceToPoint(t.point)>0))}}const yo=class t extends g{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new f),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new wo(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(yo,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let _o=yo;class bo extends m{constructor(){super(...arguments),e(this,"onCameraChanged",new f),e(this,"meshes",new Set),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"isDisposing",!1),e(this,"enabled",!0),e(this,"_dynamicAnchor",!1),e(this,"_anchorRequestId",0),e(this,"uuid",A.create()),e(this,"name"),e(this,"_scene"),e(this,"_camera"),e(this,"_renderer",null),e(this,"onPointerDown",t=>{if(!this.camera.hasCameraControls())throw new Error("World: can't set dynamic anchor if the camera doesn't have controls.");if(0!==t.button)return;const e=this.getPointerPosition(t);if(!e)return;const i=this.components.get(_o).get(this),n=this.getPlaneAnchor(i,e);n&&this.camera.controls.setOrbitPoint(n.x,n.y,n.z);const s=++this._anchorRequestId;i.castRay({position:e}).then(t=>{if(s!==this._anchorRequestId||this.isDisposing||!this._dynamicAnchor)return;if(!(null==t?void 0:t.point)||!this.camera.hasCameraControls())return;const{x:e,y:i,z:n}=t.point;this.camera.controls.setOrbitPoint(e,i,n)})}),e(this,"_defaultCamera")}set dynamicAnchor(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(!i)throw new Error("World: the renderer must have a parentElement to set dynamic anchoring.");t?(this.camera.controls&&(this.camera.controls.minDistance=.01),i.addEventListener("pointerdown",this.onPointerDown)):i.removeEventListener("pointerdown",this.onPointerDown),this._dynamicAnchor=t}get dynamicAnchor(){return this._dynamicAnchor}getPointerPosition(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement;if(!i)return null;const n=i.getBoundingClientRect();return new u.Vector2((t.clientX-n.left)/(n.right-n.left)*2-1,-(t.clientY-n.top)/(n.bottom-n.top)*2+1)}getPlaneAnchor(t,e){if(!this.camera.hasCameraControls())return null;const i=this.camera.three;t.three.setFromCamera(e,i);const n=this.camera.controls.getTarget(new u.Vector3),s=i.getWorldDirection(new u.Vector3),r=(new u.Plane).setFromNormalAndCoplanarPoint(s,n);return t.three.ray.intersectPlane(r,new u.Vector3)}get defaultCamera(){if(!this._defaultCamera)throw new Error("World: there is no default camera defined.");return this._defaultCamera}set defaultCamera(t){this._defaultCamera=t}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera||(this.defaultCamera=t),this._camera=t,t.currentWorld=this,this.onCameraChanged.trigger(t)}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}useDefaultCamera(){this.camera=this.defaultCamera}update(t){this.enabled&&this._scene&&this._camera&&(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger())}dispose(t=!0){var e;if(this.isDisposing)return;this.enabled=!1,this.isDisposing=!0;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(i&&i.removeEventListener("pointerdown",this.onPointerDown),this._dynamicAnchor=!1,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const t=this.components.get(v);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const e of this.meshes)t.destroy(e);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(Eo).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class vo{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(t){this._list.directionalLight.color.value=t;for(const[,e]of this._scene.directionalLights)e.color.copy(t)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(t){this._list.directionalLight.intensity.value=t;for(const[,e]of this._scene.directionalLights)e.intensity=t}get position(){return this._list.directionalLight.position.value.clone()}set position(t){this._list.directionalLight.position.value=t;for(const[,e]of this._scene.directionalLights)e.position.copy(t)}}class xo{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(t){this._list.ambientLight.color.value=t;for(const[,e]of this._scene.ambientLights)e.color.copy(t)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(t){this._list.ambientLight.intensity.value=t;for(const[,e]of this._scene.ambientLights)e.intensity=t}}class Co extends ge{constructor(){super(...arguments),e(this,"_config",{backgroundColor:{value:new u.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new u.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new u.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new u.Vector3}}}),e(this,"ambientLight",new xo(this._config,this._component)),e(this,"directionalLight",new vo(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class So extends x{constructor(t){super(t),e(this,"onSetup",new f),e(this,"isSetup",!1),e(this,"three"),e(this,"config",new Co(this,this.components,"Scene")),e(this,"_defaultConfig",{backgroundColor:new u.Color(2107698),directionalLight:{color:new u.Color("white"),intensity:1.5,position:new u.Vector3(5,10,3)},ambientLight:{color:new u.Color("white"),intensity:1}}),this.three=new u.Scene,this.three.background=new u.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const i=e.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const n=e.directionalLight;this.config.directionalLight.color=n.color,this.config.directionalLight.intensity=n.intensity,this.config.directionalLight.position=n.position,this.deleteAllLights();const{color:s,intensity:r}=this.config.directionalLight,o=new u.DirectionalLight(s,r);o.position.copy(n.position);const{color:a,intensity:l}=this.config.directionalLight,c=new u.AmbientLight(a,l);this.three.add(o,c),this.directionalLights.set(o.uuid,o),this.ambientLights.set(c.uuid,c),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get(ye).list.delete(this.config.uuid)}}const Ao='\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 40" fill="none" aria-label="That Open Company">\n<path d="M42.2856 19.6517V8.4048H38.8676V7.14978H46.998V8.40976H43.6131V19.6566L42.2856 19.6517Z" fill="#BCF124"/>\n<path d="M48.459 19.6516V7.14978H49.7032V12.404L49.4204 12.3371C49.6285 11.7727 50.0095 11.2904 50.5078 10.9607C51.0285 10.6201 51.638 10.4449 52.2578 10.4577C52.853 10.4483 53.44 10.5988 53.9589 10.8938C54.456 11.1789 54.8687 11.5934 55.1541 12.0943C55.449 12.6164 55.6 13.2089 55.5913 13.8102V19.6516H54.3495V14.2958C54.3637 13.8139 54.2611 13.3359 54.0507 12.9033C53.8646 12.537 53.5797 12.2315 53.229 12.0224C52.8685 11.8121 52.4584 11.7046 52.0423 11.7115C51.624 11.7054 51.2117 11.8128 50.8483 12.0224C50.4912 12.2324 50.2006 12.541 50.0106 12.912C49.7956 13.3401 49.6899 13.8158 49.7032 14.2958V19.6516H48.459Z" fill="#BCF124"/>\n<path d="M60.5388 19.8524C60.0174 19.8619 59.5007 19.75 59.0289 19.5253C58.6071 19.3259 58.2459 19.0157 57.983 18.6271C57.7263 18.2403 57.593 17.7833 57.6009 17.3175C57.5959 16.8715 57.6984 16.4309 57.8997 16.034C58.1173 15.6285 58.4383 15.2892 58.8292 15.0516C59.3232 14.7561 59.8701 14.5624 60.4384 14.4817L63.9188 13.8932V15.0355L60.7348 15.5744C60.0931 15.6867 59.6314 15.8932 59.3497 16.1938C59.0735 16.4811 58.9212 16.8673 58.926 17.268C58.9244 17.4635 58.9661 17.657 59.0481 17.8341C59.1301 18.0112 59.2503 18.1674 59.3999 18.2913C59.7416 18.5818 60.1787 18.7318 60.6246 18.7113C61.1803 18.7244 61.7296 18.5884 62.2166 18.3173C62.6597 18.066 63.0268 17.6972 63.2784 17.2506C63.535 16.7959 63.6669 16.2801 63.6604 15.7565V13.4744C63.6679 13.2259 63.6196 12.979 63.519 12.7521C63.4185 12.5253 63.2684 12.3245 63.08 12.1649C62.693 11.8287 62.1897 11.6607 61.57 11.6607C61.0801 11.6502 60.5978 11.7845 60.1822 12.047C59.7665 12.3095 59.4355 12.6888 59.2297 13.1387L58.1018 12.5192C58.2839 12.117 58.553 11.7614 58.8892 11.4785C59.2572 11.162 59.6754 10.9107 60.1261 10.7352C60.5858 10.5517 61.0758 10.4579 61.57 10.4589C62.1703 10.4448 62.7654 10.5748 63.3065 10.838C63.7888 11.077 64.1965 11.4462 64.4846 11.9047C64.7683 12.3771 64.912 12.9219 64.8986 13.4744V19.6517H63.658V17.8552L63.8405 18.0398C63.6702 18.3954 63.4238 18.7081 63.1191 18.9554C62.7772 19.238 62.3899 19.4593 61.9741 19.6095C61.5136 19.7756 61.0277 19.8578 60.5388 19.8524Z" fill="#BCF124"/>\n<path d="M70.6935 19.752C69.8975 19.752 69.2852 19.517 68.8566 19.0471C68.428 18.5771 68.2108 17.9056 68.2051 17.0326V11.9122H66.5616V10.6534H66.9804C67.1477 10.662 67.3148 10.6332 67.4697 10.5689C67.6247 10.5047 67.7637 10.4066 67.8769 10.2818C68.1017 10.0195 68.2202 9.68094 68.2088 9.33398V8.57825H69.453V10.6596H71.4124V11.9184H69.453V17.0388C69.4478 17.3107 69.4926 17.5813 69.5853 17.8366C69.6729 18.065 69.8337 18.2569 70.042 18.3818C70.3083 18.5292 70.6096 18.5991 70.9128 18.5837C71.0009 18.5837 71.1063 18.5775 71.2287 18.5664C71.3512 18.5552 71.4553 18.5441 71.5434 18.5329V19.6578C71.396 19.6937 71.2462 19.7189 71.0952 19.7334C70.9262 19.7433 70.7927 19.752 70.6935 19.752Z" fill="#BCF124"/>\n<path d="M82.2003 19.8523C81.3145 19.8603 80.4355 19.6954 79.6114 19.3666C78.4307 18.8928 77.4197 18.068 76.7118 17.001C76.0038 15.9341 75.6323 14.6751 75.646 13.3901C75.6376 12.5147 75.8043 11.6466 76.1359 10.838C76.453 10.0681 76.9213 9.37141 77.5123 8.79004C78.1118 8.20273 78.819 7.73977 79.5942 7.42723C81.2715 6.778 83.1266 6.778 84.8039 7.42723C85.5794 7.73911 86.2867 8.20215 86.8857 8.79004C87.4768 9.3717 87.9454 10.0683 88.2635 10.838C88.5945 11.6468 88.7611 12.5148 88.7533 13.3901C88.7674 14.6752 88.396 15.9343 87.688 17.0013C86.98 18.0683 85.9688 18.8931 84.7879 19.3666C83.9642 19.6952 83.0857 19.8601 82.2003 19.8523ZM82.2003 17.4984C82.7378 17.5032 83.2709 17.4005 83.769 17.1961C84.2425 16.9994 84.6735 16.7111 85.0378 16.3474C85.4069 15.9786 85.6952 15.5354 85.884 15.0465C86.0882 14.5173 86.1896 13.9532 86.1828 13.3852C86.1898 12.8203 86.0883 12.2594 85.884 11.7337C85.6922 11.2464 85.4043 10.8038 85.0378 10.4328C84.6764 10.0659 84.2446 9.77748 83.769 9.58542C82.7594 9.19396 81.6424 9.19396 80.6327 9.58542C80.1568 9.77745 79.7246 10.0658 79.3628 10.4328C78.9967 10.8041 78.7088 11.2467 78.5166 11.7337C78.3119 12.2602 78.2104 12.8219 78.2177 13.3876C78.2109 13.9557 78.3123 14.5198 78.5166 15.049C78.7058 15.5377 78.994 15.9808 79.3628 16.3499C79.7275 16.7136 80.1589 17.0019 80.6327 17.1985C81.1302 17.4038 81.663 17.5074 82.2003 17.5033V17.4984Z" fill="#BCF124"/>\n<path d="M90.398 23.2209V10.4861H92.7248V12.2293L92.5081 11.7251C92.8117 11.2627 93.2354 10.8941 93.7327 10.6596C94.2857 10.3994 94.8901 10.2702 95.4999 10.2817C96.3233 10.271 97.1335 10.4919 97.8401 10.9198C98.5312 11.3384 99.1029 11.9314 99.4995 12.6406C99.9126 13.38 100.124 14.2172 100.112 15.0664C100.122 15.9116 99.913 16.7448 99.5069 17.4835C99.1168 18.1988 98.5469 18.7971 97.8548 19.218C97.1376 19.6483 96.3164 19.8688 95.4827 19.8548C94.894 19.8605 94.3104 19.7437 93.7682 19.5116C93.2614 19.2967 92.8226 18.9454 92.4995 18.4957L92.8975 17.9754V23.2234L90.398 23.2209ZM95.1741 17.5863C95.6033 17.5949 96.0268 17.4848 96.3987 17.268C96.7521 17.0559 97.0394 16.7477 97.2278 16.3784C97.4328 15.9736 97.5355 15.5237 97.5266 15.0689C97.5364 14.6168 97.4337 14.1694 97.2278 13.768C97.0366 13.4007 96.7499 13.0932 96.3987 12.8785C96.0288 12.6556 95.6046 12.5419 95.1741 12.5502C94.7569 12.5434 94.3461 12.6541 93.9874 12.8698C93.6387 13.0826 93.3568 13.391 93.1743 13.7593C92.9832 14.1688 92.8841 14.6161 92.8841 15.0689C92.8841 15.5217 92.9832 15.9689 93.1743 16.3784C93.3571 16.7465 93.639 17.0548 93.9874 17.268C94.3469 17.4837 94.7586 17.594 95.1766 17.5863H95.1741Z" fill="#BCF124"/>\n<path d="M105.924 19.8524C104.961 19.8524 104.126 19.6372 103.418 19.2069C102.724 18.7915 102.156 18.1916 101.776 17.4724C101.384 16.7291 101.184 15.8977 101.194 15.0553C101.179 14.1986 101.388 13.3532 101.801 12.6047C102.189 11.9046 102.753 11.3198 103.434 10.9087C104.139 10.4899 104.944 10.2756 105.761 10.2892C106.414 10.277 107.062 10.394 107.67 10.6336C108.202 10.8483 108.68 11.1777 109.073 11.5987C109.454 12.0141 109.75 12.5023 109.943 13.0346C110.147 13.6019 110.248 14.2016 110.242 14.805C110.242 14.9847 110.234 15.1606 110.218 15.334C110.205 15.4855 110.174 15.6349 110.126 15.7788H103.34V13.9266H108.716L107.538 14.8001C107.65 14.3786 107.645 13.9339 107.522 13.5153C107.411 13.1561 107.186 12.8437 106.883 12.6258C106.553 12.4 106.161 12.2855 105.762 12.2987C105.368 12.2877 104.981 12.3993 104.652 12.6184C104.327 12.8492 104.083 13.1779 103.955 13.5574C103.79 14.0428 103.728 14.5577 103.772 15.0689C103.719 15.5315 103.782 16.0001 103.955 16.4317C104.108 16.81 104.375 17.1302 104.718 17.3473C105.08 17.5514 105.486 17.6634 105.901 17.6736C106.316 17.6837 106.727 17.5917 107.098 17.4055C107.407 17.2317 107.661 16.9743 107.833 16.6622L109.824 17.6186C109.643 18.0737 109.355 18.4776 108.986 18.7956C108.59 19.1398 108.132 19.4046 107.638 19.5761C107.087 19.766 106.507 19.8594 105.924 19.8524Z" fill="#BCF124"/>\n<path d="M111.703 19.6516V10.4837H114.03V12.2962L113.898 11.8935C114.081 11.3764 114.443 10.944 114.918 10.6769C115.425 10.404 115.994 10.2679 116.569 10.2817C117.196 10.2676 117.816 10.4179 118.369 10.7178C118.875 11.0011 119.293 11.4232 119.573 11.9357C119.87 12.4948 120.018 13.1223 120.004 13.7569V19.6491H117.515V14.2958C117.524 13.9753 117.452 13.6579 117.307 13.3728C117.173 13.1206 116.972 12.9112 116.727 12.7682C116.459 12.625 116.162 12.5502 115.859 12.5502C115.557 12.5502 115.26 12.625 114.992 12.7682C114.743 12.9091 114.539 13.1188 114.403 13.3728C114.259 13.658 114.188 13.9754 114.196 14.2958V19.6516H111.703Z" fill="#BCF124"/>\n<path d="M45.7329 35.9372C44.8875 35.9451 44.0493 35.7794 43.269 35.4503C42.525 35.134 41.851 34.6707 41.2863 34.0875C40.7178 33.4992 40.2696 32.8033 39.9673 32.0396C39.6453 31.2229 39.4843 30.3504 39.4934 29.4713C39.4848 28.5902 39.6427 27.7155 39.9588 26.8943C40.2511 26.1324 40.6939 25.4388 41.2601 24.8558C41.8262 24.2727 42.504 23.8126 43.2518 23.5034C44.039 23.178 44.8826 23.015 45.7329 23.024C46.5598 23.0107 47.3809 23.1649 48.1479 23.4774C48.8259 23.756 49.443 24.1669 49.9641 24.6866C50.4412 25.1559 50.8045 25.7304 51.0258 26.3653L48.7529 27.4729C48.5362 26.8433 48.1263 26.3001 47.5831 25.9226C47.0399 25.5451 46.3917 25.3529 45.7329 25.3742C45.0556 25.3604 44.3882 25.5408 43.8078 25.8945C43.2553 26.2426 42.8099 26.74 42.5219 27.3304C42.2056 27.9978 42.0495 28.7313 42.0664 29.4713C42.0503 30.2135 42.2063 30.9493 42.5219 31.6196C42.8077 32.2136 43.2534 32.7139 43.8078 33.0629C44.3879 33.4172 45.0555 33.5976 45.7329 33.5832C46.3917 33.6045 47.0399 33.4124 47.5831 33.0348C48.1263 32.6573 48.5362 32.1142 48.7529 31.4845L51.0258 32.5933C50.8056 33.2316 50.4422 33.8096 49.9641 34.282C49.4426 34.8009 48.8256 35.2113 48.1479 35.4899C47.3805 35.8004 46.5594 35.9524 45.7329 35.9372Z" fill="#BCF124"/>\n<path d="M56.8159 35.9372C55.9603 35.9485 55.1164 35.735 54.3667 35.3177C53.6426 34.9153 53.0357 34.3274 52.6069 33.613C52.1777 32.8648 51.9517 32.0151 51.9517 31.15C51.9517 30.285 52.1777 29.4353 52.6069 28.6871C53.0376 27.9762 53.6442 27.3911 54.3667 26.9898C55.118 26.5823 55.9573 26.3691 56.8098 26.3691C57.6623 26.3691 58.5016 26.5823 59.253 26.9898C59.9716 27.3928 60.5749 27.9771 61.0042 28.6858C61.4334 29.4341 61.6594 30.2837 61.6594 31.1488C61.6594 32.0139 61.4334 32.8635 61.0042 33.6118C60.577 34.3244 59.9733 34.912 59.253 35.3165C58.5078 35.7343 57.6678 35.9482 56.8159 35.9372ZM56.8159 33.6712C57.2335 33.681 57.6451 33.5701 58.0026 33.3516C58.3443 33.1354 58.6199 32.8274 58.7986 32.462C58.9985 32.0556 59.0985 31.6064 59.0901 31.1525C59.099 30.7014 58.9989 30.2548 58.7986 29.8517C58.6161 29.4889 58.3414 29.1818 58.0026 28.9621C57.6468 28.739 57.2345 28.6254 56.8159 28.635C56.3952 28.6261 55.9807 28.7396 55.6219 28.9621C55.2792 29.18 55.0008 29.4873 54.8161 29.8517C54.6162 30.2549 54.5166 30.7015 54.5259 31.1525C54.517 31.6063 54.6166 32.0555 54.8161 32.462C54.997 32.8291 55.2762 33.1373 55.6219 33.3516C55.9824 33.5695 56.3962 33.6803 56.8159 33.6712Z" fill="#BCF124"/>\n<path d="M63.1228 35.7364V26.5685H65.4496V28.7985L65.2047 28.4269C65.337 27.7223 65.6574 27.202 66.1661 26.8658C66.7124 26.5198 67.3477 26.3448 67.992 26.3628C68.6955 26.3487 69.3867 26.5504 69.9747 26.9414C70.2455 27.1163 70.4794 27.3435 70.6631 27.6102C70.8468 27.8768 70.9766 28.1775 71.045 28.495L70.3311 28.5619C70.6299 27.8128 71.056 27.2586 71.6096 26.8993C72.1912 26.5332 72.8658 26.3468 73.5506 26.3628C74.1566 26.3506 74.755 26.5011 75.2847 26.7989C75.7839 27.0856 76.1947 27.5068 76.4714 28.0155C76.7686 28.5772 76.9163 29.2073 76.9 29.8442V35.7364H74.4067V30.3806C74.4151 30.0621 74.3496 29.746 74.2156 29.4576C74.0956 29.2086 73.9084 28.999 73.6756 28.853C73.4175 28.71 73.1279 28.635 72.8336 28.635C72.5393 28.635 72.2498 28.71 71.9917 28.853C71.7556 28.9972 71.5655 29.2071 71.4443 29.4576C71.3103 29.746 71.2448 30.0621 71.2532 30.3806V35.7364H68.7648V30.3806C68.7731 30.0621 68.7077 29.746 68.5737 29.4576C68.4538 29.2089 68.267 28.9994 68.0349 28.853C67.7765 28.71 67.4868 28.635 67.1923 28.635C66.8978 28.635 66.6081 28.71 66.3498 28.853C66.1137 28.9972 65.9236 29.2071 65.8023 29.4576C65.6683 29.746 65.6029 30.0621 65.6113 30.3806V35.7364H63.1228Z" fill="#BCF124"/>\n<path d="M78.5374 39.3107V26.5697H80.8642V28.3166L80.6486 27.8123C80.9522 27.35 81.376 26.9813 81.8733 26.7469C82.4266 26.4883 83.0311 26.3611 83.6404 26.3752C84.464 26.3639 85.2743 26.5848 85.9807 27.0132C86.6715 27.4323 87.2431 28.0251 87.6401 28.7341C88.0532 29.473 88.2645 30.3098 88.2524 31.1586C88.2623 32.0044 88.0533 32.8381 87.6462 33.577C87.2571 34.2926 86.6875 34.8911 85.9954 35.3115C85.2785 35.7427 84.4572 35.9636 83.6233 35.9495C83.0345 35.9548 82.4509 35.8376 81.9088 35.6051C81.4019 35.391 80.963 35.04 80.6401 34.5904L81.0381 34.0701V39.3231L78.5374 39.3107ZM83.3134 33.6712C83.7428 33.6796 84.1663 33.5691 84.5381 33.3515C84.892 33.1399 85.1798 32.8316 85.3684 32.462C85.573 32.057 85.6757 31.6072 85.6672 31.1524C85.6761 30.7004 85.5734 30.2533 85.3684 29.8516C85.176 29.4847 84.8891 29.1774 84.5381 28.962C84.1679 28.7398 83.7438 28.6266 83.3134 28.635C82.8964 28.6281 82.4856 28.7383 82.1268 28.9534C81.778 29.1666 81.496 29.4755 81.3136 29.8442C81.1225 30.2534 81.0233 30.7004 81.0233 31.1531C81.0233 31.6057 81.1225 32.0527 81.3136 32.462C81.4954 32.8308 81.7775 33.1394 82.1268 33.3515C82.4863 33.5682 82.8986 33.679 83.3171 33.6712H83.3134Z" fill="#BCF124"/>\n<path d="M92.5093 35.9371C91.9294 35.9511 91.353 35.8427 90.8168 35.6187C90.3699 35.4306 89.9887 35.1118 89.722 34.7032C89.4607 34.2804 89.3278 33.7893 89.3399 33.2908C89.3319 32.8129 89.4525 32.3418 89.689 31.928C89.9498 31.5033 90.3197 31.1581 90.7593 30.9295C91.3217 30.6339 91.931 30.4406 92.5595 30.3583L95.3296 29.9049V31.7521L93.0028 32.1708C92.7069 32.2127 92.4268 32.3314 92.1897 32.5153C92.0938 32.6024 92.0186 32.7102 91.9696 32.8307C91.9207 32.9513 91.8992 33.0814 91.9068 33.2115C91.9015 33.3387 91.9277 33.4652 91.9828 33.5796C92.038 33.6941 92.1204 33.7928 92.2227 33.8669C92.4503 34.0296 92.7243 34.1123 93.0028 34.1023C93.3792 34.1101 93.7509 34.0174 94.0805 33.8335C94.3832 33.6617 94.6332 33.4087 94.803 33.1025C94.9751 32.7929 95.0638 32.443 95.0602 32.0878V29.698C95.062 29.5308 95.0264 29.3654 94.956 29.2141C94.8855 29.0628 94.7822 28.9296 94.6536 28.8245C94.3818 28.5891 94.0144 28.4714 93.5515 28.4714C93.1318 28.4645 92.7212 28.5949 92.3807 28.8431C92.0467 29.0873 91.7912 29.4256 91.6459 29.8157L89.6547 28.8592C89.826 28.354 90.1169 27.8989 90.5021 27.5336C90.9038 27.1547 91.3782 26.8634 91.8958 26.6775C92.4648 26.471 93.0657 26.3686 93.6702 26.3752C94.3679 26.3612 95.0599 26.5046 95.6958 26.7952C96.2502 27.0473 96.724 27.4511 97.0637 27.961C97.3951 28.4765 97.5658 29.0807 97.5536 29.6955V35.7389H95.2268V34.2584L95.7913 34.1581C95.5497 34.5339 95.2533 34.8706 94.912 35.1566C94.5921 35.4193 94.2261 35.6185 93.8331 35.7439C93.4044 35.877 92.9578 35.9422 92.5093 35.9371Z" fill="#BCF124"/>\n<path d="M99.3795 35.7365V26.5685H101.706V28.3823L101.573 27.9796C101.757 27.4626 102.119 27.0301 102.593 26.7618C103.101 26.4898 103.67 26.3542 104.245 26.3678C104.872 26.3532 105.493 26.5034 106.045 26.8039C106.551 27.0867 106.968 27.5085 107.248 28.0205C107.545 28.5801 107.693 29.208 107.679 29.8429V35.7352H105.189V30.3806C105.197 30.0603 105.126 29.743 104.982 29.4576C104.848 29.2051 104.646 28.9957 104.401 28.8531C104.135 28.7035 103.834 28.6282 103.53 28.635C103.23 28.6314 102.935 28.7065 102.673 28.8531C102.423 28.9936 102.219 29.2034 102.084 29.4576C101.939 29.7428 101.868 30.0603 101.877 30.3806V35.7365H99.3795Z" fill="#BCF124"/>\n<path d="M110.563 39.4631C110.304 39.4633 110.046 39.4405 109.791 39.3949C109.563 39.3571 109.342 39.2835 109.136 39.1769V37.1128C109.316 37.1628 109.499 37.2017 109.684 37.2293C109.875 37.2621 110.07 37.2791 110.264 37.2801C110.754 37.2801 111.099 37.1562 111.31 36.9282C111.522 36.6884 111.696 36.4162 111.824 36.1217L112.437 34.6945L112.404 36.7932L108.421 26.5697H111.093L113.731 33.8384H112.735L115.373 26.5697H118.048L114.165 36.5925C113.955 37.1702 113.652 37.7089 113.269 38.187C112.942 38.5905 112.531 38.9169 112.066 39.1434C111.594 39.3617 111.081 39.4709 110.563 39.4631Z" fill="#BCF124"/>\n<path d="M7.00861 16.1097H0C0.00583172 11.8399 1.68502 7.74676 4.66939 4.7276C7.65377 1.70844 11.6998 0.00968387 15.9203 0.00378418V7.09408C13.558 7.09801 11.2935 8.04913 9.62308 9.73902C7.95266 11.4289 7.0125 13.7198 7.00861 16.1097Z" fill="#BCF124"/>\n<path d="M15.9243 39.3094C11.7037 39.3035 7.65771 37.6047 4.67333 34.5856C1.68896 31.5664 0.00976849 27.4732 0.00393677 23.2035H7.01255C7.01255 24.9874 7.53543 26.7311 8.51506 28.2144C9.4947 29.6976 10.8871 30.8536 12.5162 31.5362C14.1452 32.2189 15.9378 32.3975 17.6672 32.0495C19.3966 31.7015 20.9852 30.8425 22.2321 29.5811C23.4789 28.3197 24.328 26.7127 24.672 24.9631C25.016 23.2135 24.8394 21.4 24.1647 19.752C23.4899 18.1039 22.3472 16.6953 20.881 15.7042C19.4149 14.7132 17.6912 14.1842 15.9279 14.1842V7.09021C20.1512 7.09021 24.2016 8.78747 27.1879 11.8086C30.1742 14.8297 31.8519 18.9273 31.8519 23.1998C31.8519 27.4723 30.1742 31.5699 27.1879 34.591C24.2016 37.6121 20.1512 39.3094 15.9279 39.3094H15.9243Z" fill="#BCF124"/>\n</svg>\n'.trim();var Po=(t=>(t[t.MANUAL=0]="MANUAL",t[t.AUTO=1]="AUTO",t))(Po||{});class To extends y{constructor(t){super(t),e(this,"onBeforeUpdate",new f),e(this,"onAfterUpdate",new f),e(this,"onAspectUpdated",new f),e(this,"onDisposed",new f),e(this,"three"),e(this,"_resizeObserver",null),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof u.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this.setupEvents(!0),this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{var e;const i=this._allControls.get(t.uuid);i&&(i.dispose(),this._allControls.delete(t.uuid)),null==(e=this._resizeObserver)||e.disconnect()})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(bs),i=this.components.get($r);i.list.clear();const n=new u.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(n),i.list.clear(),n}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new u.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new u.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");a.install({THREE:To.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new a(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){if(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),t){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");const{domElement:t}=this.currentWorld.renderer.three;this._resizeObserver=new ResizeObserver(this.updateAspect),this._resizeObserver.observe(t)}}static getSubsetOfThree(){return{MOUSE:u.MOUSE,Vector2:u.Vector2,Vector3:u.Vector3,Vector4:u.Vector4,Quaternion:u.Quaternion,Matrix4:u.Matrix4,Spherical:u.Spherical,Box3:u.Box3,Sphere:u.Sphere,Raycaster:u.Raycaster,MathUtils:u.MathUtils}}}const Mo=class t extends g{constructor(n){super(n),e(this,"onAfterUpdate",new f),e(this,"onBeforeUpdate",new f),e(this,"onDisposed",new f),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}create(){const t=new bo(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(Mo,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Eo=Mo;class Io extends ge{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new u.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class Do{constructor(t,i){e(this,"onDisposed",new f),e(this,"onSetup",new f),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new u.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof To&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:n,primarySize:s,secondarySize:r,distance:o}=this._defaultConfig;this.components=t,this.config=new Io(this,this.components,"Grid");const a=new u.PlaneGeometry(2,2,1,1),l=new u.ShaderMaterial({side:u.DoubleSide,uniforms:{uSize1:{value:s},uSize2:{value:r},uColor:{value:n},uDistance:{value:o},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new u.Mesh(a,l),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get(ye).list.delete(this.config.uuid);this.components.get(v).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof To))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const zo=class t extends g{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new f),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new Do(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(zo,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let ko=zo;const Bo=class t{constructor(){e(this,"onDisposed",new f),e(this,"list",new i.DataMap),e(this,"enabled",!1),e(this,"_timer"),e(this,"onInit",new f),e(this,"update",()=>{if(!this.enabled)return;this._timer.update();const t=this._timer.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._timer=new u.Timer,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");A.validate(t),this.list.set(t,e)}get(t){var e;const i=t.uuid;if(!this.list.has(i)){const n=new t(this);return(null==(e=n.isDisposeable)?void 0:e.call(n))&&n.onDisposed.add(()=>this.list.delete(i)),this.list.has(i)||this.add(i,n),n}return this.list.get(i)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._timer.reset(),this.update(),this.onInit.trigger()}dispose(){let t,e;this.enabled=!1;for(const[i,n]of this.list)n.enabled=!1,i!==bs.uuid?i!==Eo.uuid?n.isDisposeable()&&n.dispose():e=n:t=n;(null==e?void 0:e.isDisposeable())&&e.dispose(),null==t||t.dispose(),this._timer.dispose(),this.onDisposed.trigger()}static setupBVH(){u.BufferGeometry.prototype.computeBoundsTree=ws,u.BufferGeometry.prototype.disposeBoundsTree=ys,u.Mesh.prototype.raycast=ms,u.LineSegments.prototype.raycast=ms}};e(Bo,"release","2.4.3");let Oo=Bo;class Vo{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new u.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=a.ACTION.DOLLY,t.touches.two=a.ACTION.TOUCH_ZOOM_TRUCK}}class Lo{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new u.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:n}=this.camera.three,s=new u.Vector3(0,0,-1).applyEuler(n),r=e.addScaledVector(s,i);t.moveTo(r.x,r.y,r.z)}}class No{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=a.ACTION.TRUCK,e.touches.one=a.ACTION.TOUCH_TRUCK,e.touches.two=a.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=a.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class Fo{constructor(t){e(this,"onChanged",new f),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new u.Vector3;this._component.threePersp.getWorldDirection(e);const i=new u.Vector3;this._component.controls.getTarget(i);const n=i.clone().sub(this._component.threePersp.position).dot(e),s=t.renderer.getSize(),r=s.x/s.y,o=this._component.threePersp,a=2*n*Math.atan(o.fov*(Math.PI/180)/2);return{width:a*r,height:a}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=a.ACTION.ZOOM,this._component.controls.mouseButtons.middle=a.ACTION.ZOOM;const i=this._component.threePersp,n=this._component.threeOrtho;n.zoom=1,n.left=e/-2,n.right=e/2,n.top=t/2,n.bottom=t/-2,n.updateProjectionMatrix(),n.position.copy(i.position),n.quaternion.copy(i.quaternion),this._component.controls.camera=n}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=a.ACTION.DOLLY,this._component.controls.mouseButtons.middle=a.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=a.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class Ro extends To{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new Fo(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new Lo(this)),this._navigationModes.set("FirstPerson",new Vo(this)),this._navigationModes.set("Plan",new No(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,n=Number.MIN_VALUE,s=new u.Vector3(i,i,i),r=new u.Vector3(n,n,n);for(const e of t){const t=(new u.Box3).setFromObject(e);t.min.x<s.x&&(s.x=t.min.x),t.min.y<s.y&&(s.y=t.min.y),t.min.z<s.z&&(s.z=t.min.z),t.max.x>r.x&&(r.x=t.max.x),t.max.y>r.y&&(r.y=t.max.y),t.max.z>r.z&&(r.z=t.max.z)}const o=new u.Box3(s,r),a=this.components.get(bs);if(a.initialized)for(const[,t]of a.list){const e=t.box;e.min.x<s.x&&(s.x=e.min.x),e.min.y<s.y&&(s.y=e.min.y),e.min.z<s.z&&(s.z=e.min.z),e.max.x>r.x&&(r.x=e.max.x),e.max.y>r.y&&(r.y=e.max.y),e.max.z>r.z&&(r.z=e.max.z)}const l=new u.Vector3;o.getSize(l);const c=new u.Vector3;o.getCenter(c);const h=Math.max(l.x,l.y,l.z)*e,d=new u.Sphere(c,h);await this.controls.fitToSphere(d,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}addCustomNavigationMode(t){this._navigationModes.set(t.id,t)}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new u.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,n=e*(t.y/this.previousSize.y),s=i*(t.x/this.previousSize.x);this.threeOrtho.left=-s,this.threeOrtho.right=s,this.threeOrtho.top=n,this.threeOrtho.bottom=-n,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}var Uo="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function jo(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function $o(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Wo={exports:{}};
2
2
  /*!
3
3
 
4
4
  JSZip v3.10.1 - A JavaScript class for generating and reading zip files